Xen Security Modules: Tools.

Signed-off-by: George Coker <gscoker@alpha.ncsc.mil>
This commit is contained in:
kfraser@localhost.localdomain committed 2007-08-31 11:37:20 +01:00
1 parent b1ed041464
commit d89af62954
40 files changed
+2053 -61

No files matched your search

+3
View File
@@ -3,6 +3,9 @@ include $(XEN_ROOT)/tools/Rules.mk
SUBDIRS-y :=
SUBDIRS-y += libxc
ifeq ($(FLASK_ENABLE),y)
SUBDIRS-y += flask
endif
SUBDIRS-y += xenstore
SUBDIRS-y += misc
SUBDIRS-y += examples
+26
View File
@@ -0,0 +1,26 @@
XEN_ROOT = ../..
include $(XEN_ROOT)/tools/Rules.mk
SUBDIRS :=
SUBDIRS += libflask
SUBDIRS += loadpolicy
.PHONY: all
all:
@set -e; for subdir in $(SUBDIRS); do \
$(MAKE) -C $$subdir $@; \
done
.PHONY: install
install:
@set -e; for subdir in $(SUBDIRS); do \
$(MAKE) -C $$subdir $@; \
done
.PHONY: clean
clean:
@set -e; for subdir in $(SUBDIRS); do \
$(MAKE) -C $$subdir $@; \
done
+65
View File
@@ -0,0 +1,65 @@
MAJOR = 1.0
MINOR = 0
XEN_ROOT = ../../..
include $(XEN_ROOT)/tools/Rules.mk
XEN_LIBXC = $(XEN_ROOT)/tools/libxc
SRCS :=
SRCS += flask_op.c
CFLAGS += -Werror
CFLAGS += -fno-strict-aliasing
CFLAGS += $(INCLUDES) -I./include -I$(XEN_LIBXC)
# Get gcc to generate the dependencies for us.
CFLAGS += -Wp,-MD,.$(@F).d
LDFLAGS += -L.
DEPS = .*.d
LIB_OBJS := $(patsubst %.c,%.o,$(SRCS))
PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS))
LIB := libflask.a
LIB += libflask.so libflask.so.$(MAJOR) libflask.so.$(MAJOR).$(MINOR)
.PHONY: all
all: build
.PHONY: build
build:
$(MAKE) $(LIB)
.PHONY: install
install: build
[ -d $(DESTDIR)/usr/$(LIBDIR) ] || $(INSTALL_DIR) $(DESTDIR)/usr/$(LIBDIR)
[ -d $(DESTDIR)/usr/include ] || $(INSTALL_DIR) $(DESTDIR)/usr/include
$(INSTALL_PROG) libflask.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)
$(INSTALL_DATA) libflask.a $(DESTDIR)/usr/$(LIBDIR)
ln -sf libflask.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)/libflask.so.$(MAJOR)
ln -sf libflask.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libflask.so
$(INSTALL_DATA) include/flask_op.h $(DESTDIR)/usr/include
.PHONY: TAGS
TAGS:
etags -t *.c *.h
.PHONY: clean
clean:
rm -rf *.a *.so* *.o *.opic *.rpm $(LIB) *~ $(DEPS) xen
# libflask
libflask.a: $(LIB_OBJS)
$(AR) rc $@ $^
libflask.so: libflask.so.$(MAJOR)
ln -sf $< $@
libflask.so.$(MAJOR): libflask.so.$(MAJOR).$(MINOR)
ln -sf $< $@
libflask.so.$(MAJOR).$(MINOR): $(PIC_OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libflask.so.$(MAJOR) -shared -o $@ $^
-include $(DEPS)
+100
View File
@@ -0,0 +1,100 @@
/*
*
* Authors: Michael LeMay, <mdlemay@epoch.ncsc.mil>
* George Coker, <gscoker@alpha.ncsc.mil>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*/
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <xc_private.h>
#include <flask_op.h>
int flask_load(int xc_handle, char *buf, int size)
{
int err;
flask_op_t op;
op.cmd = FLASK_LOAD;
op.buf = buf;
op.size = size;
if ( (err = do_flask_op(xc_handle, &op)) != 0 )
return err;
return 0;
}
int flask_context_to_sid(int xc_handle, char *buf, int size, uint32_t *sid)
{
int err;
flask_op_t op;
op.cmd = FLASK_CONTEXT_TO_SID;
op.buf = buf;
op.size = size;
if ( (err = do_flask_op(xc_handle, &op)) != 0 )
return err;
sscanf(buf, "%u", sid);
return 0;
}
int flask_sid_to_context(int xc_handle, int sid, char *buf, int size)
{
int err;
flask_op_t op;
op.cmd = FLASK_SID_TO_CONTEXT;
op.buf = buf;
op.size = size;
snprintf(buf, size, "%u", sid);
if ( (err = do_flask_op(xc_handle, &op)) != 0 )
return err;
return 0;
}
int do_flask_op(int xc_handle, flask_op_t *op)
{
int ret = -1;
DECLARE_HYPERCALL;
hypercall.op = __HYPERVISOR_xsm_op;
hypercall.arg[0] = (unsigned long)op;
if ( mlock(op, sizeof(*op)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out;
}
if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
{
if ( errno == EACCES )
fprintf(stderr, "XSM operation failed!\n");
}
safe_munlock(op, sizeof(*op));
out:
return ret;
}
+46
View File
@@ -0,0 +1,46 @@
/*
*
* Authors: Michael LeMay, <mdlemay@epoch.ncsc.mil>
* George Coker, <gscoker@alpha.ncsc.mil>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*/
#ifndef __FLASK_OP_H
#define __FLASK_OP_H
#define FLASK_LOAD 1
#define FLASK_GETENFORCE 2
#define FLASK_SETENFORCE 3
#define FLASK_CONTEXT_TO_SID 4
#define FLASK_SID_TO_CONTEXT 5
#define FLASK_ACCESS 6
#define FLASK_CREATE 7
#define FLASK_RELABEL 8
#define FLASK_USER 9
#define FLASK_POLICYVERS 10
#define FLASK_GETBOOL 11
#define FLASK_SETBOOL 12
#define FLASK_COMMITBOOLS 13
#define FLASK_MLS 14
#define FLASK_DISABLE 15
#define FLASK_GETAVC_THRESHOLD 16
#define FLASK_SETAVC_THRESHOLD 17
#define FLASK_AVC_HASHSTATS 18
#define FLASK_AVC_CACHESTATS 19
#define FLASK_MEMBER 20
typedef struct flask_op {
int cmd;
int size;
char *buf;
} flask_op_t;
int flask_load(int xc_handle, char *buf, int size);
int flask_context_to_sid(int xc_handle, char *buf, int size, u_int32_t *sid);
int flask_sid_to_context(int xc_handle, int sid, char *buf, int size);
int do_flask_op(int xc_handle, flask_op_t *op);
#endif
+61
View File
@@ -0,0 +1,61 @@
XEN_ROOT=../../..
include $(XEN_ROOT)/tools/Rules.mk
XEN_LIBXC = $(XEN_ROOT)/tools/libxc
INSTALL = install
INSTALL_DATA = $(INSTALL) -m0644
INSTALL_PROG = $(INSTALL) -m0755
INSTALL_DIR = $(INSTALL) -d -m0755
LIBXC_ROOT = $(XEN_ROOT)/tools/libxc
LIBFLASK_ROOT = $(XEN_ROOT)/tools/flask/libflask
PROFILE=#-pg
BASECFLAGS=-Wall -g -Werror
# Make gcc generate dependencies.
BASECFLAGS += -Wp,-MD,.$(@F).d
PROG_DEP = .*.d
BASECFLAGS+= $(PROFILE)
#BASECFLAGS+= -I$(XEN_ROOT)/tools
BASECFLAGS+= -I$(LIBXC_ROOT)
BASECFLAGS+= -I$(LIBFLASK_ROOT)/include
BASECFLAGS+= -I.
CFLAGS += $(BASECFLAGS)
LDFLAGS += $(PROFILE) -L$(XEN_LIBXC) -L$(LIBFLASK_ROOT)
TESTDIR = testsuite/tmp
TESTFLAGS= -DTESTING
TESTENV = XENSTORED_ROOTDIR=$(TESTDIR) XENSTORED_RUNDIR=$(TESTDIR)
CLIENTS := flask-loadpolicy
CLIENTS_OBJS := $(patsubst flask-%,%.o,$(CLIENTS))
.PHONY: all
all: $(CLIENTS)
$(CLIENTS): flask-%: %.o
$(LINK.o) $< $(LOADLIBES) $(LDLIBS) -L. -lflask -lxenctrl -o $@
.PHONY: clean
clean:
rm -f *.o *.opic *.so
rm -f $(CLIENTS)
$(RM) $(PROG_DEP)
.PHONY: print-dir
print-dir:
@echo -n tools/flask/loadpolicy:
.PHONY: print-end
print-end:
@echo
.PHONY: install
install: all
$(INSTALL_DIR) -p $(DESTDIR)/usr/sbin
$(INSTALL_PROG) $(CLIENTS) $(DESTDIR)/usr/sbin
-include $(PROG_DEP)
# never delete any intermediate files.
.SECONDARY:
+130
View File
@@ -0,0 +1,130 @@
/*
*
* Authors: Michael LeMay, <mdlemay@epoch.ncsc.mil>
* George Coker, <gscoker@alpha.ncsc.mil>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*/
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <xenctrl.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <flask_op.h>
#define USE_MMAP
static void usage (int argCnt, const char *args[])
{
fprintf(stderr, "Usage: %s <policy.file>\n", args[0]);
exit(1);
}
int main (int argCnt, const char *args[])
{
const char *polFName;
int polFd = 0;
void *polMem = NULL;
void *polMemCp = NULL;
struct stat info;
int ret;
int xch = 0;
if (argCnt != 2)
usage(argCnt, args);
polFName = args[1];
polFd = open(polFName, O_RDONLY);
if ( polFd < 0 )
{
fprintf(stderr, "Error occurred opening policy file '%s': %s\n",
polFName, strerror(errno));
ret = -1;
goto cleanup;
}
ret = stat(polFName, &info);
if ( ret < 0 )
{
fprintf(stderr, "Error occurred retrieving information about"
"policy file '%s': %s\n", polFName, strerror(errno));
goto cleanup;
}
polMemCp = malloc(info.st_size);
#ifdef USE_MMAP
polMem = mmap(NULL, info.st_size, PROT_READ, MAP_SHARED, polFd, 0);
if ( !polMem )
{
fprintf(stderr, "Error occurred mapping policy file in memory: %s\n",
strerror(errno));
ret = -1;
goto cleanup;
}
xch = xc_interface_open();
if ( xch < 0 )
{
fprintf(stderr, "Unable to create interface to xenctrl: %s\n",
strerror(errno));
ret = -1;
goto cleanup;
}
memcpy(polMemCp, polMem, info.st_size);
#else
ret = read(polFd, polMemCp, info.st_size);
if ( ret < 0 )
{
fprintf(stderr, "Unable to read new Flask policy file: %s\n",
strerror(errno));
goto cleanup;
}
else
{
printf("Read %d bytes from policy file '%s'.\n", ret, polFName);
}
#endif
ret = flask_load(xch, polMemCp, info.st_size);
if ( ret < 0 )
{
errno = -ret;
fprintf(stderr, "Unable to load new Flask policy: %s\n",
strerror(errno));
ret = -1;
goto cleanup;
}
else
{
printf("Successfully loaded policy.\n");
}
done:
if ( polMemCp )
free(polMemCp);
if ( polMem )
{
ret = munmap(polMem, info.st_size);
if ( ret < 0 )
fprintf(stderr, "Unable to unmap policy memory: %s\n", strerror(errno));
}
if ( polFd )
close(polFd);
if ( xch )
xc_interface_close(xch);
return ret;
cleanup:
goto done;
}
+1 -1
View File
@@ -46,7 +46,7 @@ const char *hypercall_name_table[64] =
X(vcpu_op),
X(set_segment_base),
X(mmuext_op),
X(acm_op),
X(xsm_op),
X(nmi_op),
X(sched_op),
X(callback_op),
+23 -3
View File
@@ -1,6 +1,14 @@
XEN_ROOT = ../..
include $(XEN_ROOT)/tools/Rules.mk
XEN_SECURITY_MODULE = dummy
ifeq ($(FLASK_ENABLE),y)
XEN_SECURITY_MODULE = flask
endif
ifeq ($(ACM_SECURITY),y)
XEN_SECURITY_MODULE = acm
endif
.PHONY: all
all: build
@@ -16,9 +24,9 @@ NLSDIR = /usr/share/locale
.PHONY: build buildpy
buildpy:
CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py build
CC="$(CC)" CFLAGS="$(CFLAGS)" XEN_SECURITY_MODULE="$(XEN_SECURITY_MODULE)" python setup.py build
build: buildpy refresh-pot refresh-po $(CATALOGS)
build: xsm.py buildpy refresh-pot refresh-po $(CATALOGS)
# NB we take care to only update the .pot file it strings have
# actually changed. This is complicated by the embedded date
@@ -53,6 +61,18 @@ refresh-po: $(POTFILE)
%.mo: %.po
$(MSGFMT) -c -o $@ $<
xsm.py:
@(set -e; \
echo "XEN_SECURITY_MODULE = \""$(XEN_SECURITY_MODULE)"\""; \
echo "from xsm_core import *"; \
echo ""; \
echo "import xen.util.xsm."$(XEN_SECURITY_MODULE)"."$(XEN_SECURITY_MODULE)" as xsm_module"; \
echo ""; \
echo "xsm_init(xsm_module)"; \
echo "from xen.util.xsm."$(XEN_SECURITY_MODULE)"."$(XEN_SECURITY_MODULE)" import *"; \
echo "del xsm_module"; \
echo "") >xen/util/xsm/$@
.PHONY: install
ifndef XEN_PYTHON_NATIVE_INSTALL
install: LIBPATH=$(shell PYTHONPATH=xen/util python -c "import auxbin; print auxbin.libpath()")
@@ -84,4 +104,4 @@ test:
.PHONY: clean
clean:
rm -rf build *.pyc *.pyo *.o *.a *~ $(CATALOGS)
rm -rf build *.pyc *.pyo *.o *.a *~ $(CATALOGS) xen/util/xsm/xsm.py
+18 -1
View File
@@ -44,6 +44,14 @@ acm = Extension("acm",
libraries = libraries,
sources = [ "xen/lowlevel/acm/acm.c" ])
flask = Extension("flask",
extra_compile_args = extra_compile_args,
include_dirs = include_dirs + [ "xen/lowlevel/flask" ] +
[ "../flask/libflask/include" ],
library_dirs = library_dirs + [ "../flask/libflask" ],
libraries = libraries + [ "flask" ],
sources = [ "xen/lowlevel/flask/flask.c" ])
ptsname = Extension("ptsname",
extra_compile_args = extra_compile_args,
include_dirs = include_dirs + [ "ptsname" ],
@@ -51,16 +59,25 @@ ptsname = Extension("ptsname",
libraries = libraries,
sources = [ "ptsname/ptsname.c" ])
modules = [ xc, xs, acm, ptsname ]
modules = [ xc, xs, ptsname ]
if os.uname()[0] == 'SunOS':
modules.append(scf)
if os.environ.get('XEN_SECURITY_MODULE') == 'acm':
modules.append(acm)
if os.environ.get('XEN_SECURITY_MODULE') == 'flask':
modules.append(flask)
setup(name = 'xen',
version = '3.0',
description = 'Xen',
packages = ['xen',
'xen.lowlevel',
'xen.util',
'xen.util.xsm',
'xen.util.xsm.dummy',
'xen.util.xsm.flask',
'xen.util.xsm.acm',
'xen.xend',
'xen.xend.server',
'xen.xend.xenstore',
+139
View File
@@ -0,0 +1,139 @@
/******************************************************************************
* flask.c
*
* Authors: George Coker, <gscoker@alpha.ncsc.mil>
* Michael LeMay, <mdlemay@epoch.ncsc.mil>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*/
#include <Python.h>
#include <xenctrl.h>
#include <flask_op.h>
#define PKG "xen.lowlevel.flask"
#define CLS "flask"
#define CTX_LEN 1024
static PyObject *xc_error_obj;
typedef struct {
PyObject_HEAD;
int xc_handle;
} XcObject;
static PyObject *pyflask_context_to_sid(PyObject *self, PyObject *args,
PyObject *kwds)
{
int xc_handle;
char *ctx;
char *buf;
uint32_t len;
uint32_t sid;
int ret;
static char *kwd_list[] = { "context", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "s", kwd_list,
&ctx) )
return NULL;
len = strlen(ctx);
buf = malloc(len);
if (!buf) {
errno = -ENOMEM;
PyErr_SetFromErrno(xc_error_obj);
}
memcpy(buf, ctx, len);
xc_handle = xc_interface_open();
if (xc_handle < 0) {
errno = xc_handle;
return PyErr_SetFromErrno(xc_error_obj);
}
ret = flask_context_to_sid(xc_handle, buf, len, &sid);
xc_interface_close(xc_handle);
free(buf);
if ( ret != 0 ) {
errno = -ret;
return PyErr_SetFromErrno(xc_error_obj);
}
return PyInt_FromLong(sid);
}
static PyObject *pyflask_sid_to_context(PyObject *self, PyObject *args,
PyObject *kwds)
{
int xc_handle;
uint32_t sid;
char ctx[CTX_LEN];
uint32_t ctx_len = CTX_LEN;
int ret;
static char *kwd_list[] = { "sid", NULL };
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list,
&sid) )
return NULL;
xc_handle = xc_interface_open();
if (xc_handle < 0) {
errno = xc_handle;
return PyErr_SetFromErrno(xc_error_obj);
}
ret = flask_sid_to_context(xc_handle, sid, ctx, ctx_len);
xc_interface_close(xc_handle);
if ( ret != 0 ) {
errno = -ret;
return PyErr_SetFromErrno(xc_error_obj);
}
return Py_BuildValue("s", ctx, ctx_len);
}
static PyMethodDef pyflask_methods[] = {
{ "flask_context_to_sid",
(PyCFunction)pyflask_context_to_sid,
METH_KEYWORDS, "\n"
"Convert a context string to a dynamic SID.\n"
" context [str]: String specifying context to be converted\n"
"Returns: [int]: Numeric SID on success; -1 on error.\n" },
{ "flask_sid_to_context",
(PyCFunction)pyflask_sid_to_context,
METH_KEYWORDS, "\n"
"Convert a dynamic SID to context string.\n"
" context [int]: SID to be converted\n"
"Returns: [str]: Numeric SID on success; -1 on error.\n" },
{ NULL, NULL, 0, NULL }
};
PyMODINIT_FUNC initflask(void)
{
Py_InitModule("flask", pyflask_methods);
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* End:
*/
+5 -4
View File
@@ -1,4 +1,4 @@
#============================================================================
#============================================================================
# This library is free software; you can redistribute it and/or
# modify it under the terms of version 2.1 of the GNU Lesser General Public
# License as published by the Free Software Foundation.
@@ -23,10 +23,11 @@ import stat
import array
from xml.dom import minidom, Node
from xen.xend.XendLogging import log
from xen.util import security, xsconstants, bootloader, mkdir
from xen.util import xsconstants, bootloader, mkdir
from xen.util.xspolicy import XSPolicy
from xen.util.security import ACMError
from xen.xend.XendError import SecurityError
import xen.util.xsm.acm.acm as security
from xen.util.xsm.xsm import XSMError
ACM_POLICIES_DIR = security.policy_dir_prefix + "/"
@@ -1240,8 +1241,8 @@ class ACMPolicy(XSPolicy):
(major, minor) = self.getVersionTuple()
hdr_bin = struct.pack(headerformat,
ACM_POLICY_VERSION,
ACM_MAGIC,
ACM_POLICY_VERSION,
totallen_bin,
polref_offset,
primpolcode,
+2
View File
@@ -0,0 +1,2 @@
@@ -0,0 +1 @@
File diff suppressed because it is too large. Load diff
@@ -0,0 +1 @@
+53
View File
@@ -0,0 +1,53 @@
import sys
class XSMError(Exception):
def __init__(self,value):
self.value = value
def __str__(self):
return repr(self.value)
policy_dir_prefix = "";
active_policy = "";
NULL_SSIDREF = 0;
def err(msg):
"""Raise XSM-dummy exception.
"""
sys.stderr.write("XSM-dummyError: " + msg + "\n")
raise XSMError(msg)
def on():
return 0
def ssidref2label(ssidref):
return 0
def label2ssidref(label, policy, type):
return 0
def res_security_check(resource, domain_label):
return 1
def get_res_security_details(resource):
return ("","","")
def get_res_label(resource):
return ("","")
def res_security_check_xapi(rlabel, rssidref, rpolicy, xapi_dom_label):
return 1
def parse_security_label(security_label):
return ""
def calc_dom_ssidref_from_info(info):
return ""
def set_security_label(policy, label):
return ""
def ssidref2security_label(ssidref):
return ""
def has_authorization(ssidref):
return True
@@ -0,0 +1 @@
+37
View File
@@ -0,0 +1,37 @@
import sys
from xen.lowlevel import flask
from xen.xend import sxp
def err(msg):
"""Raise XSM-Flask exception.
"""
sys.stderr.write("XSM-FlaskError: " + msg + "\n")
raise XSMError(msg)
def on():
return 1
def ssidref2label(ssidref):
try:
return flask.flask_sid_to_context(ssidref)
except:
return ""
def label2ssidref(label, policy, type):
try:
return flask.flask_context_to_sid(label)
except:
return ""
def parse_security_label(security_label):
return security_label
def calc_dom_ssidref_from_info(info):
ssidref = label2ssidref(info['security_label'], "", "")
return ssidref
def set_security_label(policy, label):
return label
def ssidref2security_label(ssidref):
return ssidref2label(ssidref)
+7
View File
@@ -0,0 +1,7 @@
import sys
import xen.util.xsm.dummy.dummy as dummy
def xsm_init(self):
for op in dir(dummy):
if not hasattr(self, op):
setattr(self, op, getattr(dummy, op, None))
+6 -6
View File
@@ -30,7 +30,6 @@ from xen.xend.PrettyPrint import prettyprintstring
from xen.xend.XendConstants import DOM_STATE_HALTED
from xen.xend.server.netif import randomMAC
from xen.util.blkif import blkdev_name_to_number
from xen.xend.XendXSPolicyAdmin import XSPolicyAdminInstance
from xen.util import xsconstants
log = logging.getLogger("xend.XendConfig")
@@ -433,7 +432,8 @@ class XendConfig(dict):
self['cpu_time'] = dominfo['cpu_time']/1e9
if dominfo.get('ssidref'):
ssidref = int(dominfo.get('ssidref'))
self['security_label'] = XSPolicyAdminInstance().ssidref_to_vmlabel(ssidref)
import xen.util.xsm.xsm as security
self['security_label'] = security.ssidref2security_label(ssidref)
self['shutdown_reason'] = dominfo['shutdown_reason']
@@ -651,7 +651,6 @@ class XendConfig(dict):
# ['ssidref', 196611]]
policy = ""
label = ""
policytype = xsconstants.ACM_POLICY_ID
for idx in range(0, len(secinfo)):
if secinfo[idx][0] == "access_control":
for aidx in range(1, len(secinfo[idx])):
@@ -659,9 +658,10 @@ class XendConfig(dict):
policy = secinfo[idx][aidx][1]
if secinfo[idx][aidx][0] == "label":
label = secinfo[idx][aidx][1]
if label != "" and policy != "":
cfg['security_label'] = "%s:%s:%s" % \
(policytype, policy, label)
import xen.util.xsm.xsm as security
cfg['security_label'] = \
security.set_security_label(policy, label)
if not sxp.child_value(sxp_cfg, 'security_label'):
del cfg['security']
old_state = sxp.child_value(sxp_cfg, 'state')
+1 -1
View File
@@ -36,7 +36,7 @@ from types import StringTypes
import xen.lowlevel.xc
from xen.util import asserts
from xen.util.blkif import blkdev_uname_to_file, blkdev_uname_to_taptype
from xen.util import security
import xen.util.xsm.xsm as security
from xen.xend import balloon, sxp, uuid, image, arch, osdep
from xen.xend import XendOptions, XendNode, XendConfig
+2 -1
View File
@@ -23,7 +23,8 @@ import os
from xen.util.xmlrpclib2 import stringify
from xmlrpclib import dumps, loads
from xen.util import security, xsconstants
from xen.util import xsconstants
import xen.util.xsm.xsm as security
from xen.xend.XendError import SecurityError
KB = 1024
+2 -1
View File
@@ -20,7 +20,8 @@ import logging
from xen.xend.XendBase import XendBase
from xen.xend.XendError import *
from xen.xend.XendXSPolicyAdmin import XSPolicyAdminInstance
from xen.util import xsconstants, security
from xen.util import xsconstants
import xen.util.xsm.xsm as security
import base64
log = logging.getLogger("xend.XendXSPolicy")
+2 -1
View File
@@ -22,7 +22,8 @@ from xml.dom import minidom, Node
from xen.xend.XendLogging import log
from xen.xend import uuid
from xen.util import security, xsconstants, dictio, bootloader
from xen.util import xsconstants, dictio, bootloader
import xen.util.xsm.acm.acm as security
from xen.util.xspolicy import XSPolicy
from xen.util.acmpolicy import ACMPolicy
from xen.xend.XendError import SecurityError
+1 -1
View File
@@ -20,7 +20,7 @@ import re
import string
from xen.util import blkif
from xen.util import security
import xen.util.xsm.xsm as security
from xen.xend.XendError import VmError
from xen.xend.server.DevController import DevController
+1 -1
View File
@@ -27,8 +27,8 @@ import re
from xen.xend import XendOptions
from xen.xend.server.DevController import DevController
from xen.xend.XendError import VmError
from xen.util import security
from xen.xend.XendXSPolicyAdmin import XSPolicyAdminInstance
import xen.util.xsm.xsm as security
from xen.xend.XendLogging import log
+1 -1
View File
@@ -23,7 +23,7 @@ import os
import sys
from xen.util import dictio
from xen.util import security
import xen.util.xsm.xsm as security
from xen.xm.opts import OptionError
from xen.util import xsconstants
from xen.xm import main as xm_main
+5 -5
View File
@@ -26,11 +26,11 @@ import os, stat
import shutil
import string
import re
from xen.util.security import err
from xen.util.security import policy_dir_prefix, xen_title_re
from xen.util.security import boot_filename, altboot_filename
from xen.util.security import any_title_re, xen_kernel_re, any_module_re
from xen.util.security import empty_line_re, binary_name_re, policy_name_re
from xen.util.xsm.xsm import err
from xen.util.xsm.xsm import policy_dir_prefix, xen_title_re
from xen.util.xsm.xsm import boot_filename, altboot_filename
from xen.util.xsm.xsm import any_title_re, xen_kernel_re, any_module_re
from xen.util.xsm.xsm import empty_line_re, binary_name_re, policy_name_re
from xen.util import xsconstants
from xen.xm.opts import OptionError
from xen.xm import main as xm_main
+4 -4
View File
@@ -33,7 +33,7 @@ from xen.xend import osdep
import xen.xend.XendClient
from xen.xend.XendBootloader import bootloader
from xen.util import blkif
from xen.util import security
import xen.util.xsm.xsm as security
from xen.xm.main import serverType, SERVER_XEN_API, get_single_vm
from xen.xm.opts import *
@@ -1221,7 +1221,7 @@ def config_security_check(config, verbose):
if verbose:
print " %s: PERMITTED" % (resource)
except security.ACMError:
except security.XSMError:
print " %s: DENIED" % (resource)
(poltype, res_label, res_policy) = security.get_res_label(resource)
if not res_label:
@@ -1243,7 +1243,7 @@ def create_security_check(config):
passed = 1
else:
print "Checking resources: (skipped)"
except security.ACMError:
except security.XSMError:
sys.exit(-1)
return passed
@@ -1300,7 +1300,7 @@ def main(argv):
map(lambda vm_ref: server.xenapi.VM.start(vm_ref, 0), vm_refs)
elif not opts.is_xml:
if not create_security_check(config):
raise security.ACMError(
raise security.XSMError(
'Security Configuration prevents domain from starting')
dom = make_domain(opts, config)
+1 -1
View File
@@ -19,7 +19,7 @@
"""Tests the security settings for a domain and its resources.
"""
import sys
from xen.util import security
import xen.util.xsm.xsm as security
from xen.xm import create
from xen.xend import sxp
from xen.xm.opts import OptionError
+1 -1
View File
@@ -18,7 +18,7 @@
"""Display currently enforced policy (low-level hypervisor representation).
"""
import sys
from xen.util.security import ACMError, err, dump_policy
from xen.util.xsm.xsm import XSMError, err, dump_policy
from xen.xm.opts import OptionError
def help():
+3 -3
View File
@@ -20,7 +20,7 @@
"""
import sys, os, re
from xen.util import dictio
from xen.util import security
import xen.util.xsm.xsm as security
from xen.util import xsconstants
from xen.xm.opts import OptionError
from xen.xm import main as xm_main
@@ -62,7 +62,7 @@ def get_resource_label(resource):
"Please relabel the resource.")
print policytype+":"+policy+":"+label
else:
raise security.ACMError("Resource not labeled")
raise security.XSMError("Resource not labeled")
def get_domain_label(configfile):
@@ -95,7 +95,7 @@ def get_domain_label(configfile):
# send error message if we didn't find anything
if acline == "":
raise security.ACMError("Domain not labeled")
raise security.XSMError("Domain not labeled")
# print out the label
(title, data) = acline.split("=", 1)
+3 -3
View File
@@ -21,8 +21,8 @@
import sys
import traceback
import string
from xen.util.security import ACMError, err, list_labels, active_policy
from xen.util.security import vm_label_re, res_label_re, all_label_re
from xen.util.xsm.xsm import XSMError, err, list_labels, active_policy
from xen.util.xsm.xsm import vm_label_re, res_label_re, all_label_re
from xen.xm.opts import OptionError
from xen.util.acmpolicy import ACMPolicy
from xen.util import xsconstants
@@ -78,7 +78,7 @@ def labels(policy, ptype):
for label in labels:
print label
except ACMError:
except XSMError:
sys.exit(-1)
except:
traceback.print_exc(limit = 1)
+1 -1
View File
@@ -20,7 +20,7 @@
"""
import sys
import traceback
from xen.util.security import ACMError, err, load_policy
from xen.util.xsm.xsm import XSMError, err, load_policy
from xen.xm.opts import OptionError
from xen.xm import main as xm_main
from xen.util import xsconstants
+12 -16
View File
@@ -49,7 +49,8 @@ from xen.xend.XendConstants import *
from xen.xm.opts import OptionError, Opts, wrap, set_true
from xen.xm import console
from xen.util.xmlrpcclient import ServerProxy
from xen.util.security import ACMError
import xen.util.xsm.xsm as security
from xen.util.xsm.xsm import XSMError
from xen.util.acmpolicy import ACM_LABEL_UNLABELED_DISPLAY
import XenAPI
@@ -872,12 +873,7 @@ def parse_doms_info(info):
}
security_label = get_info('security_label', str, '')
tmp = security_label.split(":")
if len(tmp) != 3:
seclabel = ""
else:
seclabel = security_label
parsed_info['seclabel'] = seclabel
parsed_info['seclabel'] = security.parse_security_label(security_label)
if serverType == SERVER_XEN_API:
parsed_info['mem'] = get_info('memory_actual', int, 0) / 1024
@@ -935,14 +931,14 @@ def xm_brief_list(doms):
print format % d
def xm_label_list(doms):
print '%-32s %5s %5s %5s %10s %9s %-8s' % \
print '%-40s %3s %5s %5s %10s %9s %-10s' % \
('Name', 'ID', 'Mem', 'VCPUs', 'State', 'Time(s)', 'Label')
output = []
format = '%(name)-32s %(domid)5s %(mem)5d %(vcpus)5d %(state)10s ' \
'%(cpu_time)8.1f %(seclabel)9s'
from xen.util import security
output = []
format = '%(name)-40s %(domid)3s %(mem)5d %(vcpus)5d %(state)10s ' \
'%(cpu_time)8.1f %(seclabel)10s'
import xen.util.xsm.xsm as security
for dom in doms:
d = parse_doms_info(dom)
@@ -2580,12 +2576,12 @@ def _run_cmd(cmd, cmd_name, args):
print e.usage
except XenAPIUnsupportedException, e:
err(str(e))
except ACMError, e:
except XSMError, e:
err(str(e))
except Exception, e:
if serverType != SERVER_XEN_API:
from xen.util import security
if isinstance(e, security.ACMError):
import xen.util.xsm.xsm as security
if isinstance(e, security.XSMError):
err(str(e))
return False, 1
print "Unexpected error:", sys.exc_info()[0]
+1 -1
View File
@@ -19,7 +19,7 @@
"""
import sys
import traceback
from xen.util.security import ACMError, err, make_policy
from xen.util.xsm.xsm import ACMError, err, make_policy
from xen.util import xsconstants
from xen.xm.opts import OptionError
from xen.xm import main as xm_main
+1 -1
View File
@@ -20,7 +20,7 @@
"""
import sys
from xen.util import dictio
from xen.util import security
import xen.util.xsm.xsm as security
from xen.util import xsconstants
from xen.xm.opts import OptionError
from xen.xm import main as xm_main
+2 -2
View File
@@ -20,7 +20,7 @@
"""
import sys, os, re
from xen.util import dictio
from xen.util import security
import xen.util.xsm.xsm as security
from xen.xm.opts import OptionError
from xen.xm import main as xm_main
from xen.xm.main import server
@@ -108,7 +108,7 @@ def rm_domain_label(configfile):
# send error message if we didn't find anything to remove
if not removed:
raise security.ACMError('Domain not labeled')
raise security.XSMError('Domain not labeled')
# write the data back out to the file
fd = open(fil, "wb")
+1 -1
View File
@@ -26,7 +26,7 @@ import string
from xen.util import xsconstants
from xen.util.acmpolicy import ACMPolicy
from xen.xm.opts import OptionError
from xen.util.security import policy_dir_prefix
from xen.util.xsm.acm.acm import policy_dir_prefix
from xen.xm import main as xm_main
from xen.xm.main import server
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.