Add a standard authorization framework
Subsystems (2)
v2 cover Add a standard authorization framework
The current network services now support encryption via TLS and in some cases support authentication via SASL. In cases where SASL is not available, x509 client certificates can be used as a crude authorization scheme, but using a sub-CA and controlling who you give certs to. In general this is not very flexible though, so this series introduces a new standard authorization framework.
It comes with four initial authorization mechanisms
- Simple - an exact username match. This is useful when there is exactly one user that is known to connect. For example when live migrating from one QEMU to another with TLS, libvirt would use the simple scheme to whitelist the TLS cert of the source QEMU.
- List - an full access control list, with optional regex matching. This is more flexible and is used to provide 100% backcompat with the existing HMP ACL commands. The caveat is that we can't create these via the CLI -object arg yet.
- ListFile - the same as List, but with the rules stored in JSON format in an external file. This avoids the -object limitation while also allowing the admin to change list entries on the file. QEMU uses inotify to notice these changes and auto-reload the file contents. This is likely a good default choice for most network services, if the "simple" mechanism isn't sufficient.
- PAM - delegate the username lookup to a PAM module, which opens the door to many options including things like SQL/LDAP lookups.
A later series that follows will integrate this framework into the VNC, NBD, migration, and character device servers.
Changed in v2:
- Switch to a global shared instance of the file monitor so only a single inotify file descriptor is required
- Require all watches to be registered against directories. File watches are useless in Linux, since they are tied to inodes, and so stop working when editors save by doing a tmpfile + rename dance.
- Change auth list impl to use a directory based watch instead of filename
- Put MTP const-ness fixes in separate patch
- Split QOM change off into separate patch
- Fix conditionals on Win32 build
Daniel P. Berrangé (11):
util: add helper APIs for dealing with inotify in portable manner
qom: don't require user creatable objects to be registered hw/usb: don't set IN_ISDIR for inotify watch in MTP driver hw/usb: fix const-ness for string params in MTP driver hw/usb: switch MTP to use new inotify APIs
authz: add QAuthZ object as an authorization base class
authz: add QAuthZSimple object type for easy whitelist auth checks
authz: add QAuthZList object type for an access control list
authz: add QAuthZListFile object type for a file access control list
authz: add QAuthZPAM object type for authorizing using PAM
authz: delete existing ACL implementation
.gitignore | 4 + MAINTAINERS | 14 ++ Makefile | 17 +- Makefile.objs | 10 ++ Makefile.target | 2 + authz/Makefile.objs | 7 + authz/base.c | 82 +++++++++ authz/list.c | 315 +++++++++++++++++++++++++++++++++ authz/listfile.c | 284 +++++++++++++++++++++++++++++ authz/pamacct.c | 149 ++++++++++++++++ authz/simple.c | 122 +++++++++++++ authz/trace-events | 18 ++ configure | 37 ++++ crypto/tlssession.c | 35 ++-- crypto/trace-events | 2 +- hw/usb/dev-mtp.c | 257 ++++++++++----------------- hw/usb/trace-events | 2 +- include/authz/base.h | 112 ++++++++++++ include/authz/list.h | 106 +++++++++++ include/authz/listfile.h | 105 +++++++++++ include/authz/pamacct.h | 97 ++++++++++ include/authz/simple.h | 80 +++++++++ include/qemu/acl.h | 66 ------- include/qemu/filemonitor.h | 117 ++++++++++++ monitor.c | 180 ++++++++++++------- qapi/authz.json | 58 ++++++ qapi/qapi-schema.json | 1 + qom/object.c | 12 +- qom/object_interfaces.c | 16 +- tests/.gitignore | 1 + tests/Makefile.include | 8 +- tests/test-authz-list.c | 171 ++++++++++++++++++ tests/test-crypto-tlssession.c | 15 +- tests/test-io-channel-tls.c | 16 +- ui/vnc-auth-sasl.c | 23 ++- ui/vnc-auth-sasl.h | 5 +- ui/vnc-auth-vencrypt.c | 2 +- ui/vnc-ws.c | 2 +- ui/vnc.c | 37 ++-- ui/vnc.h | 4 +- util/Makefile.objs | 2 +- util/acl.c | 179 ------------------- util/filemonitor.c | 315 +++++++++++++++++++++++++++++++++ util/trace-events | 9 + 44 files changed, 2557 insertions(+), 539 deletions(-) create mode 100644 authz/Makefile.objs create mode 100644 authz/base.c create mode 100644 authz/list.c create mode 100644 authz/listfile.c create mode 100644 authz/pamacct.c create mode 100644 authz/simple.c create mode 100644 authz/trace-events create mode 100644 include/authz/base.h create mode 100644 include/authz/list.h create mode 100644 include/authz/listfile.h create mode 100644 include/authz/pamacct.h create mode 100644 include/authz/simple.h delete mode 100644 include/qemu/acl.h create mode 100644 include/qemu/filemonitor.h create mode 100644 qapi/authz.json create mode 100644 tests/test-authz-list.c delete mode 100644 util/acl.c create mode 100644 util/filemonitor.c
Signature · 1 line
2.17.0
PATCH v2 2/11 qom: don't require user creatable objects to be registered
When an object is in turn owned by another user object, it is not desirable to expose this in the QOM object hierarchy, as it is just an internal implementation detail, we should be free to change without exposure.
--- qom/object.c | 12 ++++++++---- qom/object_interfaces.c | 16 ++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-)
qom/object.c +8 -4
@@ -546,15 +546,19 @@ Object *object_new_with_propv(const char *typename, goto error; } -object_property_add_child (parent, id, obj, &local_err); -if (local_err) { - goto error; +if (id !=NULL ) { +object_property_add_child (parent, id, obj, &local_err); +if (local_err) { + goto error; + } }if (object_dynamic_cast (obj,TYPE_USER_CREATABLE )) {user_creatable_complete (obj, &local_err);if (local_err) { -object_unparent (obj); +if (id !=NULL ) { +object_unparent (obj); + } goto error; } }
qom/object_interfaces.c +10 -6
@@ -83,16 +83,20 @@ Object *user_creatable_add_type(const char *type, const char *id, goto out; } -object_property_add_child (object_get_objects_root (), - id, obj, &local_err); -if (local_err) { - goto out; +if (id !=NULL ) { +object_property_add_child (object_get_objects_root (), + id, obj, &local_err); +if (local_err) { + goto out; + } }user_creatable_complete (obj, &local_err);if (local_err) { -object_property_del (object_get_objects_root (), - id, &error_abort); +if (id !=NULL ) { +object_property_del (object_get_objects_root (), + id, &error_abort); + } goto out; } out:
Signature · 1 line
2.17.0
PATCH v2 3/11 hw/usb: don't set IN_ISDIR for inotify watch in MTP driver
In reply to Daniel P. BerrangéIN_ISDIR is not a bit that one can request when registering a watch with inotify_add_watch. Rather it is a bit that is set automatically when reading events from the kernel.
--- hw/usb/dev-mtp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/usb/dev-mtp.c +1 -2
@@ -638,8 +638,7 @@ static void usb_mtp_inotify_cleanup(MTPState *s)static int usb_mtp_add_watch (int inotifyfd,char *path) { -uint32_t mask =IN_CREATE |IN_DELETE |IN_MODIFY | -IN_ISDIR ; +uint32_t mask =IN_CREATE |IN_DELETE |IN_MODIFY ;return inotify_add_watch (inotifyfd, path, mask); }
Signature · 1 line
2.17.0
PATCH v2 4/11 hw/usb: fix const-ness for string params in MTP driver
In reply to Daniel P. BerrangéVarious functions accepting 'char *' string parameters were missing 'const' qualifiers.
--- hw/usb/dev-mtp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/usb/dev-mtp.c +4 -4
@@ -368,7 +368,7 @@ static const USBDesc desc = {/* ----------------------------------------------------------------------- */ static MTPObject *usb_mtp_object_alloc (MTPState *s,uint32_t handle, -MTPObject *parent,char *name) +MTPObject *parent,const char *name) {MTPObject *o =g_new0 (MTPObject,1 );
@@ -450,7 +450,7 @@ static MTPObject *usb_mtp_object_lookup(MTPState *s, uint32_t handle) }static MTPObject *usb_mtp_add_child (MTPState *s,MTPObject *o, -char *name) +const char *name) {MTPObject *child =usb_mtp_object_alloc (s, s->next_handle++, o, name);
@@ -469,7 +469,7 @@ static MTPObject *usb_mtp_add_child(MTPState *s, MTPObject *o, }static MTPObject *usb_mtp_object_lookup_name (MTPObject *parent, -char *name,int len) +const char *name,int len) {MTPObject *iter;
@@ -636,7 +636,7 @@ static void usb_mtp_inotify_cleanup(MTPState *s) } } -static int usb_mtp_add_watch (int inotifyfd,char *path) +static int usb_mtp_add_watch (int inotifyfd,const char *path) {uint32_t mask =IN_CREATE |IN_DELETE |IN_MODIFY ;
Signature · 1 line
2.17.0
PATCH v2 1/11 util: add helper APIs for dealing with inotify in portable manner
In reply to Daniel P. BerrangéThe inotify userspace API for reading events is quite horrible, so it is useful to wrap it in a more friendly API to avoid duplicating code across many users in QEMU. Wrapping it also allows introduction of a platform portability layer, so that we can add impls for non-Linux based equivalents in future.
--- MAINTAINERS | 6 + include/qemu/filemonitor.h | 117 ++++++++++++++ util/Makefile.objs | 1 + util/filemonitor.c | 315 +++++++++++++++++++++++++++++++++++++ util/trace-events | 9 ++ 5 files changed, 448 insertions(+) create mode 100644 include/qemu/filemonitor.h create mode 100644 util/filemonitor.c
MAINTAINERS +6 -0
@@ -1771,6 +1771,12 @@ F: include/qemu/sockets.h F: util/qemu-sockets.c F: qapi/sockets.json +File monitor +M: Daniel P. Berrange <[email protected]> +S: Odd fixes +F: util/filemonitor.c +F: include/qemu/filemonitor.h + Throttling infrastructure M: Alberto Garcia <[email protected]> S: Supported
include/qemu/filemonitor.h new file +117 -0
117 lines not on this page · raw message
util/Makefile.objs +1 -0
@@ -48,4 +48,5 @@ util-obj-y += range.o util-obj-y += stats64.o util-obj-y += systemd.o util-obj-y += iova-tree.o +util-obj-y += filemonitor.o util-obj-$(CONFIG_LINUX) += vfio-helpers.o
util/filemonitor.c new file +315 -0
315 lines not on this page · raw message
util/trace-events +9 -0
@@ -21,6 +21,15 @@ buffer_move_empty(const char *buf, size_t len, const char *from) "%s: %zd bytes buffer_move(const char *buf, size_t len, const char *from) "%s: %zd bytes from %s" buffer_free(const char *buf, size_t len) "%s: capacity %zd" +# util/filemonitor.c +qemu_file_monitor_add_watch(void *mon, const char *dirpath, const char *filename, void *cb, void *opaque, int id) "File monitor %p add watch dir='%s' file='%s' cb=%p opaque=%p id=%u" +qemu_file_monitor_remove_watch(void *mon, const char *dirpath, int id) "File monitor %p remove watch dir='%s' id=%u" +qemu_file_monitor_new(void *mon, int fd) "File monitor %p created fd=%d" +qemu_file_monitor_enable_watch(void *mon, const char *dirpath, int id) "File monitor %p enable watch dir='%s' id=%u" +qemu_file_monitor_disable_watch(void *mon, const char *dirpath, int id) "Fle monitor %p disable watch dir='%s' id=%u" +qemu_file_monitor_event(void *mon, const char *dirpath, const char *filename, int mask, unsigned int id) "File monitor %p event dir='%s' file='%s' mask=0x%x id=%u" +qemu_file_monitor_dispatch(void *mon, const char *dirpath, const char *filename, int ev, void *cb, void *opaque, unsigned int id) "File monitor %p dispatch dir='%s' file='%s' ev=%d cb=%p opaque=%p id=%u" + # util/qemu-coroutine.c qemu_aio_coroutine_enter(void *ctx, void *from, void *to, void *opaque) "ctx %p from %p to %p opaque %p" qemu_coroutine_yield(void *from, void *to) "from %p to %p"
Signature · 1 line
2.17.0
PATCH v2 5/11 hw/usb: switch MTP to use new inotify APIs
In reply to Daniel P. BerrangéThe internal inotify APIs allow alot of conditional statements to be cleared out, and provide a simpler callback for handling events.
--- hw/usb/dev-mtp.c | 250 ++++++++++++++++---------------------------- hw/usb/trace-events | 2 +- 2 files changed, 93 insertions(+), 159 deletions(-)
hw/usb/dev-mtp.c +92 -158
@@ -15,13 +15,11 @@#include <dirent.h> #include <sys/statvfs.h> -#ifdef CONFIG_INOTIFY1 -#include <sys/inotify.h> -#include "qemu/main-loop.h" -#endif +#include "qemu-common.h" #include "qemu/iov.h" +#include "qemu/filemonitor.h" #include "trace.h" #include "hw/usb.h" #include "desc.h"
@@ -123,7 +121,6 @@ enum { EP_EVENT, }; -#ifdef CONFIG_INOTIFY1 typedef struct MTPMonEntry MTPMonEntry ;struct MTPMonEntry {
@@ -132,7 +129,6 @@ struct MTPMonEntry {QTAILQ_ENTRY (MTPMonEntry) next; }; -#endif struct MTPControl {uint16_t code;
@@ -158,10 +154,8 @@ struct MTPObject {char *name;char *path;struct stat stat; -#ifdef CONFIG_INOTIFY1 -/* inotify watch cookie */ +/* file monitor watch cookie */ int watchfd; -#endif MTPObject *parent;uint32_t nchildren; QLIST_HEAD(, MTPObject) children;
@@ -184,11 +178,8 @@ struct MTPState {bool readonly; QTAILQ_HEAD(, MTPObject) objects; -#ifdef CONFIG_INOTIFY1 -/* inotify descriptor */ -int inotifyfd; +QFileMonitor *file_monitor; QTAILQ_HEAD(events, MTPMonEntry) events; -#endif /* Responder is expecting a write operation */ bool write_pending;struct {
@@ -473,6 +464,10 @@ static MTPObject *usb_mtp_object_lookup_name(MTPObject *parent, {MTPObject *iter; +if (len ==-1 ) { + len =strlen (name); + } + QLIST_FOREACH(iter, &parent->children, list) {if (strncmp (iter->name, name, len) ==0 ) {return iter;
@@ -482,7 +477,6 @@ static MTPObject *usb_mtp_object_lookup_name(MTPObject *parent,return NULL ; } -#ifdef CONFIG_INOTIFY1 static MTPObject *usb_mtp_object_lookup_wd (MTPState *s,int wd) {MTPObject *iter;
@@ -496,158 +490,98 @@ static MTPObject *usb_mtp_object_lookup_wd(MTPState *s, int wd)return NULL ; } -static void inotify_watchfn (void *arg) +static void file_monitor_event (int wd, +QFileMonitorEvent ev, +const char *name, +void *opaque) { -MTPState *s = arg; -ssize_t bytes; -/* From the man page: atleast one event can be read */ -int pos; -char buf[sizeof (struct inotify_event ) +NAME_MAX +1 ]; - -for (;;) { - bytes =read (s->inotifyfd, buf,sizeof (buf)); - pos =0 ; - -if (bytes <=0 ) { -/* Better luck next time */ +MTPState *s = opaque; +int watchfd =0 ; +MTPObject *parent =usb_mtp_object_lookup_wd (s, wd); +MTPMonEntry *entry =NULL ; +MTPObject *o; + +if (!parent) { +return ; + } + +switch (ev) { +case QFILE_MONITOR_EVENT_CREATED : +if (usb_mtp_object_lookup_name (parent, name,-1 )) { +/* Duplicate create event */ return ; } + entry =g_new0 (MTPMonEntry,1 ); + entry->handle = s->next_handle; + entry->event =EVT_OBJ_ADDED ; + o =usb_mtp_add_child (s, parent, name); +if (!o) { +g_free (entry); +return ; + } + o->watchfd = watchfd; +trace_usb_mtp_file_monitor_event (s->dev.addr, name,"Obj Added" ); +break ; +case QFILE_MONITOR_EVENT_DELETED :/* -* TODO: Ignore initiator initiated events. -* For now we are good because the store is RO +* The kernel issues a IN_IGNORED event +* when a dir containing a watchpoint is +* deleted, so we don't have to delete the +* watchpoint */ -while (bytes >0 ) { -char *p = buf + pos; -struct inotify_event *event = (struct inotify_event *)p; -int watchfd =0 ; -uint32_t mask = event->mask & (IN_CREATE |IN_DELETE | -IN_MODIFY |IN_IGNORED ); -MTPObject *parent =usb_mtp_object_lookup_wd (s, event->wd); -MTPMonEntry *entry =NULL ; -MTPObject *o; - - pos = pos +sizeof (struct inotify_event ) + event->len; - bytes = bytes - pos; - -if (!parent) { -continue ; - } - -switch (mask) { -case IN_CREATE : -if (usb_mtp_object_lookup_name - (parent, event->name, event->len)) { -/* Duplicate create event */ -continue ; - } - entry =g_new0 (MTPMonEntry,1 ); - entry->handle = s->next_handle; - entry->event =EVT_OBJ_ADDED ; - o =usb_mtp_add_child (s, parent, event->name); -if (!o) { -g_free (entry); -continue ; - } - o->watchfd = watchfd; -trace_usb_mtp_inotify_event (s->dev.addr, event->name, - event->mask,"Obj Added" ); -break ; - -case IN_DELETE : -/* -* The kernel issues a IN_IGNORED event -* when a dir containing a watchpoint is -* deleted, so we don't have to delete the -* watchpoint -*/ - o =usb_mtp_object_lookup_name (parent, event->name, event->len); -if (!o) { -continue ; - } - entry =g_new0 (MTPMonEntry,1 ); - entry->handle = o->handle; - entry->event =EVT_OBJ_REMOVED ; -trace_usb_mtp_inotify_event (s->dev.addr, o->path, - event->mask,"Obj Deleted" ); -usb_mtp_object_free (s, o); -break ; - -case IN_MODIFY : - o =usb_mtp_object_lookup_name (parent, event->name, event->len); -if (!o) { -continue ; - } - entry =g_new0 (MTPMonEntry,1 ); - entry->handle = o->handle; - entry->event =EVT_OBJ_INFO_CHANGED ; -trace_usb_mtp_inotify_event (s->dev.addr, o->path, - event->mask,"Obj Modified" ); -break ; - -case IN_IGNORED : -trace_usb_mtp_inotify_event (s->dev.addr, parent->path, - event->mask,"Obj parent dir ignored" ); -break ; - -default : -fprintf (stderr,"usb-mtp: failed to parse inotify event\n" ); -continue ; - } + o =usb_mtp_object_lookup_name (parent, name,-1 ); +if (!o) { +return ; + } + entry =g_new0 (MTPMonEntry,1 ); + entry->handle = o->handle; + entry->event =EVT_OBJ_REMOVED ; +trace_usb_mtp_file_monitor_event (s->dev.addr, o->path,"Obj Deleted" ); +usb_mtp_object_free (s, o); +break ; -if (entry) { -QTAILQ_INSERT_HEAD (&s->events, entry, next); - } +case QFILE_MONITOR_EVENT_MODIFIED : + o =usb_mtp_object_lookup_name (parent, name,-1 ); +if (!o) { +return ; } - } -} + entry =g_new0 (MTPMonEntry,1 ); + entry->handle = o->handle; + entry->event =EVT_OBJ_INFO_CHANGED ; +trace_usb_mtp_file_monitor_event (s->dev.addr, o->path,"Obj Modified" ); +break ; -static int usb_mtp_inotify_init (MTPState *s) -{ -int fd; +case QFILE_MONITOR_EVENT_IGNORED : +trace_usb_mtp_file_monitor_event (s->dev.addr, parent->path, +"Obj parent dir ignored" ); +break ; - fd =inotify_init1 (IN_NONBLOCK ); -if (fd ==-1 ) { -return 1 ; +default : +g_assert_not_reached (); } -QTAILQ_INIT (&s->events); - s->inotifyfd = fd; - -qemu_set_fd_handler (fd, inotify_watchfn,NULL , s); - -return 0 ; +if (entry) { +QTAILQ_INSERT_HEAD (&s->events, entry, next); + } } -static void usb_mtp_inotify_cleanup (MTPState *s) +static void usb_mtp_file_monitor_cleanup (MTPState *s) {MTPMonEntry *e, *p; -if (!s->inotifyfd) { -return ; - } - -qemu_set_fd_handler (s->inotifyfd,NULL ,NULL , s); -close (s->inotifyfd); - QTAILQ_FOREACH_SAFE(e, &s->events, next, p) {QTAILQ_REMOVE (&s->events, e, next);g_free (e); } } -static int usb_mtp_add_watch (int inotifyfd,const char *path) -{ -uint32_t mask =IN_CREATE |IN_DELETE |IN_MODIFY ; - -return inotify_add_watch (inotifyfd, path, mask); -} -#endif static void usb_mtp_object_readdir (MTPState *s,MTPObject *o) {struct dirent *entry;DIR *dir; +Error *err =NULL ;if (o->have_children) {return ;
@@ -658,16 +592,19 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObject *o)if (!dir) {return ; } -#ifdef CONFIG_INOTIFY1 -int watchfd =usb_mtp_add_watch (s->inotifyfd, o->path); + +int watchfd =qemu_file_monitor_add_watch (s->file_monitor, o->path,NULL , + file_monitor_event, s, &err);if (watchfd ==-1 ) { -fprintf (stderr,"usb-mtp: failed to add watch for %s\n" , o->path); +fprintf (stderr,"usb-mtp: failed to add watch for %s: %s\n" , o->path, +error_get_pretty (err)); +error_free (err); }else { -trace_usb_mtp_inotify_event (s->dev.addr, o->path, -0 ,"Watch Added" ); +trace_usb_mtp_file_monitor_event (s->dev.addr, o->path, +"Watch Added" ); o->watchfd = watchfd; } -#endif +while ((entry =readdir (dir)) !=NULL ) {usb_mtp_add_child (s, o, entry->d_name); }
@@ -1175,13 +1112,11 @@ enum {/* Assumes that children, if any, have been already freed */ static void usb_mtp_object_free_one (MTPState *s,MTPObject *o) { -#ifndef CONFIG_INOTIFY1 assert (o->nchildren ==0 );QTAILQ_REMOVE (&s->objects, o, next);g_free (o->name);g_free (o->path);g_free (o); -#endif }static int usb_mtp_deletefn (MTPState *s,MTPObject *o,uint32_t trans)
@@ -1280,6 +1215,7 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)MTPData *data_in =NULL ;MTPObject *o =NULL ;uint32_t nres =0 , res0 =0 ; +Error *err =NULL ;/* sanity checks */ if (c->code >=CMD_CLOSE_SESSION && s->session ==0 ) {
@@ -1307,19 +1243,21 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)trace_usb_mtp_op_open_session (s->dev.addr); s->session = c->argv[0 ];usb_mtp_object_alloc (s, s->next_handle++,NULL , s->root); -#ifdef CONFIG_INOTIFY1 -if (usb_mtp_inotify_init (s)) { -fprintf (stderr,"usb-mtp: file monitoring init failed\n" ); + + s->file_monitor =qemu_file_monitor_get_instance (&err); +if (err) { +fprintf (stderr,"usb-mtp: file monitoring init failed: %s\n" , +error_get_pretty (err)); +error_free (err); + }else { +QTAILQ_INIT (&s->events); } -#endif break ;case CMD_CLOSE_SESSION :trace_usb_mtp_op_close_session (s->dev.addr); s->session =0 ; s->next_handle =0 ; -#ifdef CONFIG_INOTIFY1 -usb_mtp_inotify_cleanup (s); -#endif +usb_mtp_file_monitor_cleanup (s);usb_mtp_object_free (s,QTAILQ_FIRST (&s->objects));assert (QTAILQ_EMPTY (&s->objects));break ;
@@ -1532,9 +1470,7 @@ static void usb_mtp_handle_reset(USBDevice *dev)trace_usb_mtp_reset (s->dev.addr); -#ifdef CONFIG_INOTIFY1 -usb_mtp_inotify_cleanup (s); -#endif +usb_mtp_file_monitor_cleanup (s);usb_mtp_object_free (s,QTAILQ_FIRST (&s->objects)); s->session =0 ;usb_mtp_data_free (s->data_in);
@@ -1899,7 +1835,6 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p) }break ;case EP_EVENT : -#ifdef CONFIG_INOTIFY1 if (!QTAILQ_EMPTY (&s->events)) {struct MTPMonEntry *e =QTAILQ_LAST (&s->events, events);uint32_t handle;
@@ -1923,7 +1858,6 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p)g_free (e);return ; } -#endif p->status =USB_RET_NAK ;return ;default :
hw/usb/trace-events +1 -1
@@ -237,7 +237,7 @@ usb_mtp_op_unknown(int dev, uint32_t code) "dev %d, command code 0x%x" usb_mtp_object_alloc(int dev, uint32_t handle, const char *path) "dev %d, handle 0x%x, path %s" usb_mtp_object_free(int dev, uint32_t handle, const char *path) "dev %d, handle 0x%x, path %s" usb_mtp_add_child(int dev, uint32_t handle, const char *path) "dev %d, handle 0x%x, path %s" -usb_mtp_inotify_event(int dev, const char *path, uint32_t mask, const char *s) "dev %d, path %s mask 0x%x event %s" +usb_mtp_file_monitor_event(int dev, const char *path, const char *s) "dev %d, path %s event %s" # hw/usb/host-libusb.c usb_host_open_started(int bus, int addr) "dev %d:%d"
Signature · 1 line
2.17.0
PATCH v2 6/11 authz: add QAuthZ object as an authorization base class
In reply to Daniel P. BerrangéFrom: "Daniel P. Berrange" <[email protected]>
The current qemu_acl module provides a simple access control list facility inside QEMU, which is used via a set of monitor commands acl_show, acl_policy, acl_add, acl_remove & acl_reset.
Note there is no ability to create ACLs - the network services (eg VNC server) were expected to create ACLs that they want to check.
There is also no way to define ACLs on the command line, nor potentially integrate with external authorization systems like polkit, pam, ldap lookup, etc.
The QAuthZ object defines a minimal abstract QOM class that can be subclassed for creating different authorization providers.
--- MAINTAINERS | 7 +++ Makefile | 10 ++-- Makefile.objs | 6 +++ Makefile.target | 2 + authz/Makefile.objs | 1 + authz/base.c | 82 +++++++++++++++++++++++++++++++ authz/trace-events | 4 ++ include/authz/base.h | 112 +++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 authz/Makefile.objs create mode 100644 authz/base.c create mode 100644 authz/trace-events create mode 100644 include/authz/base.h
MAINTAINERS +7 -0
@@ -1762,6 +1762,13 @@ F: io/ F: include/io/ F: tests/test-io-* +User authorization +M: Daniel P. Berrange <[email protected]> +S: Maintained +F: authz/ +F: include/authz/ +F: tests/test-authz-* + Sockets M: Daniel P. Berrange <[email protected]> M: Gerd Hoffmann <[email protected]>
Makefile +6 -4
@@ -413,6 +413,7 @@ endif dummy := $(call unnest-vars,, \ stub-obj-y \ + authz-obj-y \ chardev-obj-y \ util-obj-y \ qga-obj-y \
@@ -474,6 +475,7 @@ qemu-options.def: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool SUBDIR_RULES=$(patsubst %,subdir-%, $(TARGET_LIST)) SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES)) +$(SOFTMMU_SUBDIR_RULES): $(authz-obj-y) $(SOFTMMU_SUBDIR_RULES): $(block-obj-y) $(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y) $(SOFTMMU_SUBDIR_RULES): $(io-obj-y)
@@ -536,9 +538,9 @@ COMMON_LDADDS = libqemuutil.a qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) -qemu-io$(EXESUF): qemu-io.o $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-img$(EXESUF): qemu-img.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-nbd$(EXESUF): qemu-nbd.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +qemu-io$(EXESUF): qemu-io.o $(authz-obj-y) $(block-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COMMON_LDADDS)
@@ -547,7 +549,7 @@ qemu-keymap$(EXESUF): qemu-keymap.o ui/input-keymap.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap -scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) +scsi/qemu-pr-helper$(EXESUF): scsi/qemu-pr-helper.o scsi/utils.o $(authz-obj-y) $(crypto-obj-y) $(io-obj-y) $(qom-obj-y) $(COMMON_LDADDS) ifdef CONFIG_MPATH scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist endif
Makefile.objs +6 -0
@@ -62,6 +62,11 @@ util-obj-y += qapi/qapi-introspect.o chardev-obj-y = chardev/ +####################################################################### +# authz-obj-y is code used by both qemu system emulation and qemu-img + +authz-obj-y = authz/ + ####################################################################### # block-obj-y is code used by both qemu system emulation and qemu-img
@@ -199,6 +204,7 @@ trace-events-subdirs = trace-events-subdirs += accel/kvm trace-events-subdirs += accel/tcg trace-events-subdirs += audio +trace-events-subdirs += authz trace-events-subdirs += block trace-events-subdirs += chardev trace-events-subdirs += crypto
Makefile.target +2 -0
@@ -166,6 +166,7 @@ include $(SRC_PATH)/Makefile.objs dummy := $(call unnest-vars,,target-obj-y) target-obj-y-save := $(target-obj-y) dummy := $(call unnest-vars,.., \ + authz-obj-y \ block-obj-y \ block-obj-m \ chardev-obj-y \
@@ -179,6 +180,7 @@ target-obj-y := $(target-obj-y-save) all-obj-y += $(common-obj-y) all-obj-y += $(target-obj-y) all-obj-y += $(qom-obj-y) +all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y) all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y) all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
authz/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +authz-obj-y += base.o
authz/base.c new file +82 -0
82 lines not on this page · raw message
authz/trace-events new file +4 -0
@@ -0,0 +1,4 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# authz/base.c +qauthz_is_allowed(void *authz, const char *identity, bool allowed) "AuthZ %p check identity=%s allowed=%d"
include/authz/base.h new file +112 -0
112 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH v2 7/11 authz: add QAuthZSimple object type for easy whitelist auth checks
In reply to Daniel P. BerrangéIn many cases a single VM will just need to whilelist a single identity as the allowed user of network services. This is especially the case for TLS live migration (optionally with NBD storage) where we just need to whitelist the x509 certificate distinguished name of the source QEMU host.
--- authz/Makefile.objs | 1 + authz/simple.c | 122 +++++++++++++++++++++++++++++++++++++++++ authz/trace-events | 3 + include/authz/simple.h | 80 +++++++++++++++++++++++++++ 4 files changed, 206 insertions(+) create mode 100644 authz/simple.c create mode 100644 include/authz/simple.h
authz/Makefile.objs +1 -0
@@ -1 +1,2 @@ authz-obj-y += base.o +authz-obj-y += simple.o
authz/simple.c new file +122 -0
122 lines not on this page · raw message
authz/trace-events +3 -0
@@ -2,3 +2,6 @@ # authz/base.c qauthz_is_allowed(void *authz, const char *identity, bool allowed) "AuthZ %p check identity=%s allowed=%d" + +# auth/simple.c +qauthz_simple_is_allowed(void *authz, const char *wantidentity, const char *gotidentity) "AuthZ simple %p check want identity=%s got identity=%s"
include/authz/simple.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH v2 9/11 authz: add QAuthZListFile object type for a file access control list
In reply to Daniel P. BerrangéAdd a QAuthZListFile object type that implements the QAuthZ interface. This built-in implementation is a proxy around the QAtuhZList object type, initializing it from an external file, and optionally, automatically reloading it whenever it changes.
To create an instance of this object via the QMP monitor, the syntax used would be:
{
"execute": "object-add",
"arguments": {
"qom-type": "authz-list",
"id": "auth0",
"parameters": {
"filename": "/etc/qemu/vnc.acl",
"refresh": "yes"
}
}
}If "refresh" is "yes", inotify is used to monitor the file, automatically reloading changes. If an error occurs during reloading, all authorizations will fail until the file is next successfully loaded.
The /etc/qemu/vnc.acl file would contain a JSON representation of a QAuthZList object
{
"rules": [
{ "match": "fred", "policy": "allow", "format": "exact" },
{ "match": "bob", "policy": "allow", "format": "exact" },
{ "match": "danb", "policy": "deny", "format": "glob" },
{ "match": "dan*", "policy": "allow", "format": "exact" },
],
"policy": "deny"
}This sets up an authorization rule that allows 'fred', 'bob' and anyone whose name starts with 'dan', except for 'danb'. Everyone unmatched is denied.
The object can be loaded on the comand line using
-object authz-list-file,id=authz0,filename=/etc/qemu/vnc.acl,refresh=yes
--- authz/Makefile.objs | 1 + authz/listfile.c | 284 +++++++++++++++++++++++++++++++++++++++ authz/trace-events | 4 + include/authz/listfile.h | 105 +++++++++++++++ 4 files changed, 394 insertions(+) create mode 100644 authz/listfile.c create mode 100644 include/authz/listfile.h
authz/Makefile.objs +1 -0
@@ -1,3 +1,4 @@ authz-obj-y += base.o authz-obj-y += simple.o authz-obj-y += list.o +authz-obj-y += listfile.o
authz/listfile.c new file +284 -0
284 lines not on this page · raw message
authz/trace-events +4 -0
@@ -9,3 +9,7 @@ qauthz_simple_is_allowed(void *authz, const char *wantidentity, const char *goti # auth/list.c qauthz_list_check_rule(void *authz, const char *identity, const char *rule, int format, int policy) "AuthZ list %p check rule=%s identity=%s format=%d policy=%d" qauthz_list_default_policy(void *authz, const char *identity, int policy) "AuthZ list %p default identity=%s policy=%d" + +# auth/listfile.c +qauthz_list_file_load(void *authz, const char *filename) "AuthZ file %p load filename=%s" +qauthz_list_file_refresh(void *authz, const char *filename, int success) "AuthZ file %p load filename=%s success=%d"
include/authz/listfile.h new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH v2 8/11 authz: add QAuthZList object type for an access control list
In reply to Daniel P. BerrangéFrom: "Daniel P. Berrange" <[email protected]>
Add a QAuthZList object type that implements the QAuthZ interface. This built-in implementation maintains a trivial access control list with a sequence of match rules and a final default policy. This replicates the functionality currently provided by the qemu_acl module.
To create an instance of this object via the QMP monitor, the syntax used would be:
{
"execute": "object-add",
"arguments": {
"qom-type": "authz-list",
"id": "auth0",
"parameters": {
"rules": [
{ "match": "fred", "policy": "allow", "format": "exact" },
{ "match": "bob", "policy": "allow", "format": "exact" },
{ "match": "danb", "policy": "deny", "format": "glob" },
{ "match": "dan*", "policy": "allow", "format": "exact" },
],
"policy": "deny"
}
}
}This sets up an authorization rule that allows 'fred', 'bob' and anyone whose name starts with 'dan', except for 'danb'. Everyone unmatched is denied.
It is not currently possible to create this via -object, since there is no syntax supported to specify non-scalar properties for objects. This is likely to be addressed by later support for using JSON with -object, or an equivalent approach.
In any case the future "authz-listfile" object can be used from the CLI and is likely a better choice, as it allows the ACL to be refreshed automatically on change.
--- .gitignore | 4 + MAINTAINERS | 1 + Makefile | 7 +- Makefile.objs | 4 + authz/Makefile.objs | 1 + authz/list.c | 315 ++++++++++++++++++++++++++++++++++++++++ authz/trace-events | 4 + include/authz/list.h | 106 ++++++++++++++ qapi/authz.json | 58 ++++++++ qapi/qapi-schema.json | 1 + tests/.gitignore | 1 + tests/Makefile.include | 4 + tests/test-authz-list.c | 171 ++++++++++++++++++++++ 13 files changed, 676 insertions(+), 1 deletion(-) create mode 100644 authz/list.c create mode 100644 include/authz/list.h create mode 100644 qapi/authz.json create mode 100644 tests/test-authz-list.c
.gitignore +4 -0
@@ -47,6 +47,7 @@ /qapi/qapi-commands-trace.[ch] /qapi/qapi-commands-transaction.[ch] /qapi/qapi-commands-ui.[ch] +/qapi/qapi-commands-authz.[ch] /qapi/qapi-commands.[ch] /qapi/qapi-events-block-core.[ch] /qapi/qapi-events-block.[ch]
@@ -65,6 +66,7 @@ /qapi/qapi-events-trace.[ch] /qapi/qapi-events-transaction.[ch] /qapi/qapi-events-ui.[ch] +/qapi/qapi-events-authz.[ch] /qapi/qapi-events.[ch] /qapi/qapi-introspect.[ch] /qapi/qapi-types-block-core.[ch]
@@ -84,6 +86,7 @@ /qapi/qapi-types-trace.[ch] /qapi/qapi-types-transaction.[ch] /qapi/qapi-types-ui.[ch] +/qapi/qapi-types-authz.[ch] /qapi/qapi-types.[ch] /qapi/qapi-visit-block-core.[ch] /qapi/qapi-visit-block.[ch]
@@ -102,6 +105,7 @@ /qapi/qapi-visit-trace.[ch] /qapi/qapi-visit-transaction.[ch] /qapi/qapi-visit-ui.[ch] +/qapi/qapi-visit-authz.[ch] /qapi/qapi-visit.[ch] /qapi/qapi-doc.texi /qemu-doc.html
MAINTAINERS +1 -0
@@ -1766,6 +1766,7 @@ User authorization M: Daniel P. Berrange <[email protected]> S: Maintained F: authz/ +F: qapi/authz.json F: include/authz/ F: tests/test-authz-*
Makefile +6 -1
@@ -598,7 +598,8 @@ qapi-modules = $(SRC_PATH)/qapi/qapi-schema.json $(SRC_PATH)/qapi/common.json \ $(SRC_PATH)/qapi/tpm.json \ $(SRC_PATH)/qapi/trace.json \ $(SRC_PATH)/qapi/transaction.json \ - $(SRC_PATH)/qapi/ui.json + $(SRC_PATH)/qapi/ui.json \ + $(SRC_PATH)/qapi/authz.json qapi/qapi-builtin-types.c qapi/qapi-builtin-types.h \ qapi/qapi-types.c qapi/qapi-types.h \
@@ -619,6 +620,7 @@ qapi/qapi-types-tpm.c qapi/qapi-types-tpm.h \ qapi/qapi-types-trace.c qapi/qapi-types-trace.h \ qapi/qapi-types-transaction.c qapi/qapi-types-transaction.h \ qapi/qapi-types-ui.c qapi/qapi-types-ui.h \ +qapi/qapi-types-authz.c qapi/qapi-types-authz.h \ qapi/qapi-builtin-visit.c qapi/qapi-builtin-visit.h \ qapi/qapi-visit.c qapi/qapi-visit.h \ qapi/qapi-visit-block-core.c qapi/qapi-visit-block-core.h \
@@ -638,6 +640,7 @@ qapi/qapi-visit-tpm.c qapi/qapi-visit-tpm.h \ qapi/qapi-visit-trace.c qapi/qapi-visit-trace.h \ qapi/qapi-visit-transaction.c qapi/qapi-visit-transaction.h \ qapi/qapi-visit-ui.c qapi/qapi-visit-ui.h \ +qapi/qapi-visit-authz.c qapi/qapi-visit-authz.h \ qapi/qapi-commands.h qapi/qapi-commands.c \ qapi/qapi-commands-block-core.c qapi/qapi-commands-block-core.h \ qapi/qapi-commands-block.c qapi/qapi-commands-block.h \
@@ -656,6 +659,7 @@ qapi/qapi-commands-tpm.c qapi/qapi-commands-tpm.h \ qapi/qapi-commands-trace.c qapi/qapi-commands-trace.h \ qapi/qapi-commands-transaction.c qapi/qapi-commands-transaction.h \ qapi/qapi-commands-ui.c qapi/qapi-commands-ui.h \ +qapi/qapi-commands-authz.c qapi/qapi-commands-authz.h \ qapi/qapi-events.c qapi/qapi-events.h \ qapi/qapi-events-block-core.c qapi/qapi-events-block-core.h \ qapi/qapi-events-block.c qapi/qapi-events-block.h \
@@ -674,6 +678,7 @@ qapi/qapi-events-tpm.c qapi/qapi-events-tpm.h \ qapi/qapi-events-trace.c qapi/qapi-events-trace.h \ qapi/qapi-events-transaction.c qapi/qapi-events-transaction.h \ qapi/qapi-events-ui.c qapi/qapi-events-ui.h \ +qapi/qapi-events-authz.c qapi/qapi-events-authz.h \ qapi/qapi-introspect.h qapi/qapi-introspect.c \ qapi/qapi-doc.texi: \ qapi-gen-timestamp ;
Makefile.objs +4 -0
@@ -21,6 +21,7 @@ util-obj-y += qapi/qapi-types-tpm.o util-obj-y += qapi/qapi-types-trace.o util-obj-y += qapi/qapi-types-transaction.o util-obj-y += qapi/qapi-types-ui.o +util-obj-y += qapi/qapi-types-authz.o util-obj-y += qapi/qapi-builtin-visit.o util-obj-y += qapi/qapi-visit.o util-obj-y += qapi/qapi-visit-block-core.o
@@ -40,6 +41,7 @@ util-obj-y += qapi/qapi-visit-tpm.o util-obj-y += qapi/qapi-visit-trace.o util-obj-y += qapi/qapi-visit-transaction.o util-obj-y += qapi/qapi-visit-ui.o +util-obj-y += qapi/qapi-visit-authz.o util-obj-y += qapi/qapi-events.o util-obj-y += qapi/qapi-events-block-core.o util-obj-y += qapi/qapi-events-block.o
@@ -58,6 +60,7 @@ util-obj-y += qapi/qapi-events-tpm.o util-obj-y += qapi/qapi-events-trace.o util-obj-y += qapi/qapi-events-transaction.o util-obj-y += qapi/qapi-events-ui.o +util-obj-y += qapi/qapi-events-authz.o util-obj-y += qapi/qapi-introspect.o chardev-obj-y = chardev/
@@ -160,6 +163,7 @@ common-obj-y += qapi/qapi-commands-tpm.o common-obj-y += qapi/qapi-commands-trace.o common-obj-y += qapi/qapi-commands-transaction.o common-obj-y += qapi/qapi-commands-ui.o +common-obj-y += qapi/qapi-commands-authz.o common-obj-y += qapi/qapi-introspect.o common-obj-y += qmp.o hmp.o endif
authz/Makefile.objs +1 -0
@@ -1,2 +1,3 @@ authz-obj-y += base.o authz-obj-y += simple.o +authz-obj-y += list.o
authz/list.c new file +315 -0
315 lines not on this page · raw message
authz/trace-events +4 -0
@@ -5,3 +5,7 @@ qauthz_is_allowed(void *authz, const char *identity, bool allowed) "AuthZ %p che # auth/simple.c qauthz_simple_is_allowed(void *authz, const char *wantidentity, const char *gotidentity) "AuthZ simple %p check want identity=%s got identity=%s" + +# auth/list.c +qauthz_list_check_rule(void *authz, const char *identity, const char *rule, int format, int policy) "AuthZ list %p check rule=%s identity=%s format=%d policy=%d" +qauthz_list_default_policy(void *authz, const char *identity, int policy) "AuthZ list %p default identity=%s policy=%d"
include/authz/list.h new file +106 -0
106 lines not on this page · raw message
qapi/authz.json new file +58 -0
58 lines not on this page · raw message
qapi/qapi-schema.json +1 -0
@@ -89,6 +89,7 @@ { 'include': 'rocker.json' } { 'include': 'tpm.json' } { 'include': 'ui.json' } +{ 'include': 'authz.json' } { 'include': 'migration.json' } { 'include': 'transaction.json' } { 'include': 'trace.json' }
tests/.gitignore +1 -0
@@ -17,6 +17,7 @@ rcutorture test-aio test-aio-multithread test-arm-mptimer +test-authz-simple test-base64 test-bdrv-drain test-bitops
tests/Makefile.include +4 -0
@@ -168,6 +168,7 @@ check-unit-y += tests/ptimer-test$(EXESUF) gcov-files-ptimer-test-y = hw/core/ptimer.c check-unit-y += tests/test-qapi-util$(EXESUF) gcov-files-test-qapi-util-y = qapi/qapi-util.c +check-unit-y += tests/test-authz-list$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -662,6 +663,9 @@ tests/test-timed-average$(EXESUF): tests/test-timed-average.o $(test-util-obj-y) tests/test-base64$(EXESUF): tests/test-base64.o $(test-util-obj-y) tests/ptimer-test$(EXESUF): tests/ptimer-test.o tests/ptimer-test-stubs.o hw/core/ptimer.o +tests/test-authz-list$(EXESUF): tests/test-authz-list.o \ + $(test-util-obj-y) $(authz-obj-y) $(qom-obj-y) + tests/test-logging$(EXESUF): tests/test-logging.o $(test-util-obj-y) tests/test-replication$(EXESUF): tests/test-replication.o $(test-util-obj-y) \
tests/test-authz-list.c new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH v2 10/11 authz: add QAuthZPAM object type for authorizing using PAM
In reply to Daniel P. BerrangéFrom: "Daniel P. Berrange" <[email protected]>
Add an authorization backend that talks to PAM to check whether the user identity is allowed. This only uses the PAM account validation facility, which is essentially just a check to see if the provided username is permitted access. It doesn't use the authentication or session parts of PAM, since that's dealt with by the relevant part of QEMU (eg VNC server).
Consider starting QEMU with a VNC server and telling it to use TLS with x509 client certificates and configuring it to use an PAM to validate the x509 distinguished name. In this example we're telling it to use PAM for the QAuthZ impl with a service name of "qemu-vnc"
$ qemu-system-x86_64 \
-object tls-creds-x509,id=tls0,dir=/home/berrange/security/qemutls,\
endpoint=server,verify-peer=yes \
-object authz-pam,id=authz0,service=qemu-vnc \
-vnc :1,tls-creds=tls0,tls-authz=authz0This requires an /etc/pam/qemu-vnc file to be created with the auth rules. A very simple file based whitelist can be setup using
$ cat > /etc/pam/qemu-vnc <<EOF account requisite pam_listfile.so item=user sense=allow file=/etc/qemu/vnc.allow EOF
The /etc/qemu/vnc.allow file simply contains one username per line. Any username not in the file is denied. The usernames in this example are the x509 distinguished name from the client's x509 cert.
$ cat > /etc/qemu/vnc.allow <<EOF CN=laptop.berrange.com,O=Berrange Home,L=London,ST=London,C=GB EOF
More interesting would be to configure PAM to use an LDAP backend, so that the QEMU authorization check data can be centralized instead of requiring each compute host to have file maintained.
The main limitation with this PAM module is that the rules apply to all QEMU instances on the host. Setting up different rules per VM, would require creating a separate PAM service name & config file for every guest. An alternative approach for the future might be to not pass in the plain username to PAM, but instead combine the VM name or UUID with the username. This requires further consideration though.
--- authz/Makefile.objs | 3 + authz/pamacct.c | 149 ++++++++++++++++++++++++++++++++++++++++ authz/trace-events | 3 + configure | 37 ++++++++++ include/authz/pamacct.h | 97 ++++++++++++++++++++++++++ 5 files changed, 289 insertions(+) create mode 100644 authz/pamacct.c create mode 100644 include/authz/pamacct.h
authz/Makefile.objs +3 -0
@@ -2,3 +2,6 @@ authz-obj-y += base.o authz-obj-y += simple.o authz-obj-y += list.o authz-obj-y += listfile.o +authz-obj-$(CONFIG_AUTH_PAM) += pamacct.o + +pamacct.o-libs = -lpam
authz/pamacct.c new file +149 -0
149 lines not on this page · raw message
authz/trace-events +3 -0
@@ -13,3 +13,6 @@ qauthz_list_default_policy(void *authz, const char *identity, int policy) "AuthZ # auth/listfile.c qauthz_list_file_load(void *authz, const char *filename) "AuthZ file %p load filename=%s" qauthz_list_file_refresh(void *authz, const char *filename, int success) "AuthZ file %p load filename=%s success=%d" + +# auth/pam.c +qauthz_pam_check(void *authz, const char *identity, const char *service) "AuthZ PAM %p identity=%s service=%s"
configure +37 -0
@@ -445,6 +445,7 @@ nettle_kdf="no" gcrypt="" gcrypt_hmac="no" gcrypt_kdf="no" +auth_pam="" vte="" virglrenderer="" tpm="yes"
@@ -1310,6 +1311,10 @@ for opt do ;; --enable-gcrypt) gcrypt="yes" ;; + --disable-auth-pam) auth_pam="no" + ;; + --enable-auth-pam) auth_pam="yes" + ;; --enable-rdma) rdma="yes" ;; --disable-rdma) rdma="no"
@@ -1575,6 +1580,7 @@ disabled with --disable-FEATURE, default is enabled if available: gnutls GNUTLS cryptography support nettle nettle cryptography support gcrypt libgcrypt cryptography support + auth-pam PAM access control sdl SDL UI --with-sdlabi select preferred SDL ABI 1.2 or 2.0 gtk gtk UI
@@ -2814,6 +2820,33 @@ else fi +########################################## +# PAM probe + +if test "x$auth_pam" != "no"; then + cat > $TMPC <<EOF +#include <security/pam_appl.h> +#include <stdio.h> +int main(void) { + const char *service_name = "qemu"; + const char *user = "frank"; + const struct pam_conv *pam_conv = NULL; + pam_handle_t *pamh = NULL; + pam_start(service_name, user, pam_conv, &pamh); + return 0; +} +EOF + if compile_prog "" "-lpam" ; then + auth_pam=yes + else + if test "$auth_pam" = "yes"; then + feature_not_found "PAM" "Install pam-devel" + else + auth_pam=no + fi + fi +fi + ########################################## # getifaddrs (for tests/test-io-channel-socket )
@@ -5826,6 +5859,7 @@ echo "libgcrypt kdf $gcrypt_kdf" echo "nettle $nettle $(echo_version $nettle $nettle_version)" echo "nettle kdf $nettle_kdf" echo "libtasn1 $tasn1" +echo "PAM $auth_pam" echo "curses support $curses" echo "virgl support $virglrenderer" echo "curl support $curl"
@@ -6286,6 +6320,9 @@ fi if test "$tasn1" = "yes" ; then echo "CONFIG_TASN1=y" >> $config_host_mak fi +if test "$auth_pam" = "yes" ; then + echo "CONFIG_AUTH_PAM=y" >> $config_host_mak +fi if test "$have_ifaddrs_h" = "yes" ; then echo "HAVE_IFADDRS_H=y" >> $config_host_mak fi
include/authz/pamacct.h new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH v2 11/11 authz: delete existing ACL implementation
In reply to Daniel P. BerrangéFrom: "Daniel P. Berrange" <[email protected]>
The 'qemu_acl' type was a previous non-QOM based attempt to provide an authorization facility in QEMU. Because it is non-QOM based it cannot be created via the command line and requires special monitor commands to manipulate it.
The new QAuthZ subclasses provide a superset of the functionality in qemu_acl, so the latter can now be deleted. The HMP 'acl_*' monitor commands are converted to use the new QAuthZSimple data type instead in order to provide temporary backwards compatibility.
--- crypto/tlssession.c | 35 ++++--- crypto/trace-events | 2 +- include/qemu/acl.h | 66 ------------ monitor.c | 180 ++++++++++++++++++++++----------- tests/Makefile.include | 4 +- tests/test-crypto-tlssession.c | 15 ++- tests/test-io-channel-tls.c | 16 ++- ui/vnc-auth-sasl.c | 23 +++-- ui/vnc-auth-sasl.h | 5 +- ui/vnc-auth-vencrypt.c | 2 +- ui/vnc-ws.c | 2 +- ui/vnc.c | 37 ++++--- ui/vnc.h | 4 +- util/Makefile.objs | 1 - util/acl.c | 179 -------------------------------- 15 files changed, 210 insertions(+), 361 deletions(-) delete mode 100644 include/qemu/acl.h delete mode 100644 util/acl.c
crypto/tlssession.c +17 -18
@@ -23,7 +23,7 @@#include "crypto/tlscredsanon.h" #include "crypto/tlscredsx509.h" #include "qapi/error.h" -#include "qemu/acl.h" +#include "authz/base.h" #include "trace.h" #ifdef CONFIG_GNUTLS
@@ -36,7 +36,7 @@ struct QCryptoTLSSession {QCryptoTLSCreds *creds;gnutls_session_t handle;char *hostname; -char *aclname; +char *authzid;bool handshakeComplete;QCryptoTLSSessionWriteFunc writeFunc;QCryptoTLSSessionReadFunc readFunc;
@@ -55,7 +55,7 @@ qcrypto_tls_session_free(QCryptoTLSSession *session)gnutls_deinit (session->handle);g_free (session->hostname);g_free (session->peername); -g_free (session->aclname); +g_free (session->authzid);object_unref (OBJECT (session->creds));g_free (session); }
@@ -92,7 +92,7 @@ qcrypto_tls_session_pull(void *opaque, void *buf, size_t len)QCryptoTLSSession *qcrypto_tls_session_new (QCryptoTLSCreds *creds,const char *hostname, -const char *aclname, +const char *authzid,QCryptoTLSCredsEndpoint endpoint,Error **errp) {
@@ -102,13 +102,13 @@ qcrypto_tls_session_new(QCryptoTLSCreds *creds, session =g_new0 (QCryptoTLSSession,1 );trace_qcrypto_tls_session_new ( session, creds, hostname ? hostname :"<none>" , - aclname ? aclname :"<none>" , endpoint); + authzid ? authzid :"<none>" , endpoint);if (hostname) { session->hostname =g_strdup (hostname); } -if (aclname) { - session->aclname =g_strdup (aclname); +if (authzid) { + session->authzid =g_strdup (authzid); } session->creds = creds;object_ref (OBJECT (creds));
@@ -220,6 +220,7 @@ qcrypto_tls_session_check_certificate(QCryptoTLSSession *session,unsigned int nCerts, i;time_t now;gnutls_x509_crt_t cert =NULL ; +Error *err =NULL ; now =time (NULL );if (now == ((time_t)-1 )) {
@@ -307,19 +308,17 @@ qcrypto_tls_session_check_certificate(QCryptoTLSSession *session, gnutls_strerror(ret)); goto error; } -if (session->aclname) { -qemu_acl *acl =qemu_acl_find (session->aclname); -int allow; -if (!acl) { -error_setg (errp,"Cannot find ACL %s" , - session->aclname); +if (session->authzid) { +bool allow; + + allow =qauthz_is_allowed_by_id (session->authzid, + session->peername, &err); +if (err) { +error_propagate (errp, err); goto error; } - - allow =qemu_acl_party_is_allowed (acl, session->peername); -if (!allow) { -error_setg (errp,"TLS x509 ACL check for %s is denied" , +error_setg (errp,"TLS x509 authz check for %s is denied" , session->peername); goto error; }
@@ -506,7 +505,7 @@ qcrypto_tls_session_get_peer_name(QCryptoTLSSession *session) QCryptoTLSSession * qcrypto_tls_session_new(QCryptoTLSCreds *creds G_GNUC_UNUSED, const char *hostname G_GNUC_UNUSED, - const char *aclname G_GNUC_UNUSED, + const char *authzid G_GNUC_UNUSED, QCryptoTLSCredsEndpoint endpoint G_GNUC_UNUSED, Error **errp) {
crypto/trace-events +1 -1
@@ -16,5 +16,5 @@ qcrypto_tls_creds_x509_load_cert(void *creds, int isServer, const char *file) "T qcrypto_tls_creds_x509_load_cert_list(void *creds, const char *file) "TLS creds x509 load cert list creds=%p file=%s" # crypto/tlssession.c -qcrypto_tls_session_new(void *session, void *creds, const char *hostname, const char *aclname, int endpoint) "TLS session new session=%p creds=%p hostname=%s aclname=%s endpoint=%d" +qcrypto_tls_session_new(void *session, void *creds, const char *hostname, const char *authzid, int endpoint) "TLS session new session=%p creds=%p hostname=%s authzid=%s endpoint=%d" qcrypto_tls_session_check_creds(void *session, const char *status) "TLS session check creds session=%p status=%s"
include/qemu/acl.h deleted +0 -66
66 lines not on this page · raw message
monitor.c +120 -60
233 lines not on this page · raw message
tests/Makefile.include +2 -2
@@ -607,8 +607,8 @@ test-qom-obj-y = $(qom-obj-y) $(test-util-obj-y) test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \ tests/test-qapi-events.o tests/test-qapi-introspect.o \ $(test-qom-obj-y) -benchmark-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y) -test-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y) +benchmark-crypto-obj-y = $(authz-obj-y) $(crypto-obj-y) $(test-qom-obj-y) +test-crypto-obj-y = $(authz-obj-y) $(crypto-obj-y) $(test-qom-obj-y) test-io-obj-y = $(io-obj-y) $(test-crypto-obj-y) test-block-obj-y = $(block-obj-y) $(test-io-obj-y) tests/iothread.o
tests/test-crypto-tlssession.c +10 -5
@@ -26,7 +26,7 @@#include "qom/object_interfaces.h" #include "qapi/error.h" #include "qemu/sockets.h" -#include "qemu/acl.h" +#include "authz/list.h" #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
@@ -112,7 +112,7 @@ static void test_crypto_tls_session(const void *opaque)QCryptoTLSCreds *serverCreds;QCryptoTLSSession *clientSess =NULL ;QCryptoTLSSession *serverSess =NULL ; -qemu_acl *acl; +QAuthZList *auth;const char *const *wildcards;int channel[2 ];bool clientShake = false;
@@ -171,11 +171,15 @@ static void test_crypto_tls_session(const void *opaque) &err);g_assert (serverCreds !=NULL ); - acl =qemu_acl_init ("tlssessionacl" ); -qemu_acl_reset (acl); + auth =qauthz_list_new ("tlssessionacl" , +QAUTHZ_LIST_POLICY_DENY , + &error_abort); wildcards = data->wildcards;while (wildcards && *wildcards) { -qemu_acl_append (acl,0 , *wildcards); +qauthz_list_append_rule (auth, *wildcards, +QAUTHZ_LIST_POLICY_ALLOW , +QAUTHZ_LIST_FORMAT_GLOB , + &error_abort); wildcards++; }
@@ -265,6 +269,7 @@ static void test_crypto_tls_session(const void *opaque)object_unparent (OBJECT (serverCreds));object_unparent (OBJECT (clientCreds)); +object_unparent (OBJECT (auth));qcrypto_tls_session_free (serverSess);qcrypto_tls_session_free (clientSess);
tests/test-io-channel-tls.c +11 -5
@@ -29,7 +29,7 @@#include "io-channel-helpers.h" #include "crypto/init.h" #include "crypto/tlscredsx509.h" -#include "qemu/acl.h" +#include "authz/list.h" #include "qom/object_interfaces.h" #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
@@ -116,7 +116,7 @@ static void test_io_channel_tls(const void *opaque)QIOChannelTLS *serverChanTLS;QIOChannelSocket *clientChanSock;QIOChannelSocket *serverChanSock; -qemu_acl *acl; +QAuthZList *auth;const char *const *wildcards;int channel[2 ];struct QIOChannelTLSHandshakeData clientHandshake = { false, false };
@@ -167,11 +167,15 @@ static void test_io_channel_tls(const void *opaque) &err);g_assert (serverCreds !=NULL ); - acl =qemu_acl_init ("channeltlsacl" ); -qemu_acl_reset (acl); + auth =qauthz_list_new ("channeltlsacl" , +QAUTHZ_LIST_POLICY_DENY , + &error_abort); wildcards = data->wildcards;while (wildcards && *wildcards) { -qemu_acl_append (acl,0 , *wildcards); +qauthz_list_append_rule (auth, *wildcards, +QAUTHZ_LIST_POLICY_ALLOW , +QAUTHZ_LIST_FORMAT_GLOB , + &error_abort); wildcards++; }
@@ -259,6 +263,8 @@ static void test_io_channel_tls(const void *opaque)object_unref (OBJECT (serverChanSock));object_unref (OBJECT (clientChanSock)); +object_unparent (OBJECT (auth)); +close (channel[0 ]);close (channel[1 ]); }
ui/vnc-auth-sasl.c +16 -7
@@ -24,6 +24,7 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "authz/base.h" #include "vnc.h" #include "trace.h"
@@ -146,13 +147,14 @@ size_t vnc_client_read_sasl(VncState *vs)static int vnc_auth_sasl_check_access (VncState *vs) {const void *val; -int err; -int allow; +int rv; +Error *err =NULL ; +bool allow; - err =sasl_getprop (vs->sasl.conn,SASL_USERNAME , &val); -if (err !=SASL_OK ) { + rv =sasl_getprop (vs->sasl.conn,SASL_USERNAME , &val); +if (rv !=SASL_OK ) {trace_vnc_auth_fail (vs, vs->auth,"Cannot fetch SASL username" , -sasl_errstring (err,NULL ,NULL )); +sasl_errstring (rv,NULL ,NULL ));return -1 ; }if (val ==NULL ) {
@@ -163,12 +165,19 @@ static int vnc_auth_sasl_check_access(VncState *vs) vs->sasl.username =g_strdup ((const char *)val);trace_vnc_auth_sasl_username (vs, vs->sasl.username); -if (vs->vd->sasl.acl ==NULL ) { +if (vs->vd->sasl.authzid ==NULL ) {trace_vnc_auth_sasl_acl (vs,1 );return 0 ; } - allow =qemu_acl_party_is_allowed (vs->vd->sasl.acl, vs->sasl.username); + allow =qauthz_is_allowed_by_id (vs->vd->sasl.authzid, + vs->sasl.username, &err); +if (err) { +trace_vnc_auth_fail (vs, vs->auth,"Error from authz" , +error_get_pretty (err)); +error_free (err); +return -1 ; + }trace_vnc_auth_sasl_acl (vs, allow);return allow ?0 :-1 ;
ui/vnc-auth-sasl.h +3 -2
@@ -30,8 +30,8 @@typedef struct VncStateSASL VncStateSASL ;typedef struct VncDisplaySASL VncDisplaySASL ; -#include "qemu/acl.h" #include "qemu/main-loop.h" +#include "authz/base.h" struct VncStateSASL {sasl_conn_t *conn;
@@ -60,7 +60,8 @@ struct VncStateSASL { };struct VncDisplaySASL { -qemu_acl *acl; +QAuthZ *authz; +char *authzid; };void vnc_sasl_client_cleanup (VncState *vs);
ui/vnc-auth-vencrypt.c +1 -1
@@ -109,7 +109,7 @@ static int protocol_client_vencrypt_auth(VncState *vs, uint8_t *data, size_t len tls =qio_channel_tls_new_server ( vs->ioc, vs->vd->tlscreds, - vs->vd->tlsaclname, + vs->vd->tlsauthzid, &err);if (!tls) { trace_vnc_auth_fail(vs, vs->auth, "TLS setup failed",
ui/vnc-ws.c +1 -1
@@ -62,7 +62,7 @@ gboolean vncws_tls_handshake_io(QIOChannel *ioc G_GNUC_UNUSED, tls =qio_channel_tls_new_server ( vs->ioc, vs->vd->tlscreds, - vs->vd->tlsaclname, + vs->vd->tlsauthzid, &err);if (!tls) {VNC_DEBUG ("Failed to setup TLS %s\n" ,error_get_pretty (err));
ui/vnc.c +25 -12
@@ -33,7 +33,7 @@#include "qemu/option.h" #include "qemu/sockets.h" #include "qemu/timer.h" -#include "qemu/acl.h" +#include "authz/list.h" #include "qemu/config-file.h" #include "qapi/qapi-events.h" #include "qapi/error.h"
@@ -3267,12 +3267,24 @@ static void vnc_display_close(VncDisplay *vd)object_unparent (OBJECT (vd->tlscreds)); vd->tlscreds =NULL ; } -g_free (vd->tlsaclname); - vd->tlsaclname =NULL ; +if (vd->tlsauthz) { +object_unparent (OBJECT (vd->tlsauthz)); + vd->tlsauthz =NULL ; + } +g_free (vd->tlsauthzid); + vd->tlsauthzid =NULL ;if (vd->lock_key_sync) {qemu_remove_led_event_handler (vd->led); vd->led =NULL ; } +#ifdef CONFIG_VNC_SASL +if (vd->sasl.authz) { +object_unparent (OBJECT (vd->sasl.authz)); + vd->sasl.authz =NULL ; + } +g_free (vd->sasl.authzid); + vd->sasl.authzid =NULL ; +#endif }int vnc_display_password (const char *id,const char *password)
@@ -4019,23 +4031,24 @@ void vnc_display_open(const char *id, Error **errp)if (acl) {if (strcmp (vd->id,"default" ) ==0 ) { - vd->tlsaclname =g_strdup ("vnc.x509dname" ); + vd->tlsauthzid =g_strdup ("vnc.x509dname" ); }else { - vd->tlsaclname =g_strdup_printf ("vnc.%s.x509dname" , vd->id); + vd->tlsauthzid =g_strdup_printf ("vnc.%s.x509dname" , vd->id); } -qemu_acl_init (vd->tlsaclname); + vd->tlsauthz =QAUTHZ (qauthz_list_new (vd->tlsauthzid, +QAUTHZ_LIST_POLICY_DENY , + &error_abort)); }#ifdef CONFIG_VNC_SASL if (acl && sasl) { -char *aclname; -if (strcmp (vd->id,"default" ) ==0 ) { - aclname =g_strdup ("vnc.username" ); + vd->sasl.authzid =g_strdup ("vnc.username" ); }else { - aclname =g_strdup_printf ("vnc.%s.username" , vd->id); + vd->sasl.authzid =g_strdup_printf ("vnc.%s.username" , vd->id); } - vd->sasl.acl =qemu_acl_init (aclname); -g_free (aclname); + vd->sasl.authz =QAUTHZ (qauthz_list_new (vd->sasl.authzid, +QAUTHZ_LIST_POLICY_DENY , + &error_abort)); }#endif
ui/vnc.h +3 -1
@@ -39,6 +39,7 @@#include "io/channel-socket.h" #include "io/channel-tls.h" #include "io/net-listener.h" +#include "authz/base.h" #include <zlib.h> #include "keymaps.h"
@@ -177,7 +178,8 @@ struct VncDisplaybool lossy;bool non_adaptive;QCryptoTLSCreds *tlscreds; -char *tlsaclname; +QAuthZ *tlsauthz; +char *tlsauthzid;#ifdef CONFIG_VNC_SASL VncDisplaySASL sasl;#endif
util/Makefile.objs +0 -1
@@ -19,7 +19,6 @@ util-obj-y += envlist.o path.o module.o util-obj-y += host-utils.o util-obj-y += bitmap.o bitops.o hbitmap.o util-obj-y += fifo8.o -util-obj-y += acl.o util-obj-y += cacheinfo.o util-obj-y += error.o qemu-error.o util-obj-y += id.o
util/acl.c deleted +0 -179
179 lines not on this page · raw message
Signature · 1 line
2.17.0
Re: [Qemu-devel] [PATCH v2 08/11] authz: add QAuthZList object type for an access control list
In reply to Daniel P. BerrangéQuoted 9 lines · Daniel P. Berrangé
From: "Daniel P. Berrange" <[email protected]>
Add a QAuthZList object type that implements the QAuthZ interface. This built-in implementation maintains a trivial access control list with a sequence of match rules and a final default policy. This replicates the functionality currently provided by the
qemu_aclmodule.
Quoted 4 lines
It is not currently possible to create this via -object, since there is no syntax supported to specify non-scalar properties for objects. This is likely to be addressed by later support for using JSON with -object, or an equivalent approach.
Is this statement slightly stale, since we have JSON support with --object already?
Quoted 25 lines
In any case the future "authz-listfile" object can be used from the CLI and is likely a better choice, as it allows the ACL to be refreshed automatically on change.
Signed-off-by Daniel P. Berrange <[email protected]>---
+++
b/qapi/authz.jsonqapi/authz.json new file +15
-0@@ -0,0 +1,58 @@ +# -*- Mode: Python -*- +# +# QAPI authz definitions + +## +# @QAuthZListPolicy: +# +# The authorization policy result +# +# @deny: deny access +# @allow: allow access +# +# Since: 3.0 +## +{ 'enum': 'QAuthZListPolicy',
qapi/authz.json line 25
Quoted 10 lines
qapi/authz.json new file +10
-0+ 'prefix': 'QAUTHZ_LIST_POLICY', + 'data': ['deny', 'allow']} + +## +# @QAuthZListFormat: +# +# The authorization policy result +# +# @exact: an exact string match +# @glob: string with ? and * shell wildcard support
The shell also has [] globbing: a[bc]d matches 'abd' and 'acd'. Worth mentioning?
Quoted 18 lines
qapi/authz.json new file +18
-0+# +# Since: 3.0 +## +{ 'enum': 'QAuthZListFormat', + 'prefix': 'QAUTHZ_LIST_FORMAT', + 'data': ['exact', 'glob']} + +## +# @QAuthZListRule: +# +# A single authorization rule. +# +# @match: a glob to match against a user identity +# @policy: the result to return if @match evaluates to true +# @format: (optional) the format of the @match rule (default 'exact') +# +# Since: 3.0 +##
qapi/authz.json line 53
Quoted 10 lines
qapi/authz.json new file +10
-0+{ 'struct': 'QAuthZListRule', + 'data': {'match': 'str', + 'policy': 'QAuthZListPolicy', + '*format': 'QAuthZListFormat'}} + +## +# @QAuthZListRuleListHack: +# +# Not exposed via QMP; hack to generate QAuthZListRuleList +# for use internally by the code.
Someday, it would be nice if qom-set were fully specified rather than requiring hacks like this. Oh well, not new to your patches. I take it this is one case where order matters: the first rule that matches is applied (with no further rules tested), even if later rules in the list would also match.
Quoted 5 lines
qapi/authz.json new file +5
-0+# +# Since: 3.0 +## +{ 'struct': 'QAuthZListRuleListHack', + 'data': { 'unused': ['QAuthZListRule'] } }
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 09/11] authz: add QAuthZListFile object type for a file access control list
In reply to Daniel P. BerrangéQuoted 8 lines · Daniel P. Berrangé
Add a QAuthZListFile object type that implements the QAuthZ interface. This built-in implementation is a proxy around the QAtuhZList object type, initializing it from an external file, and optionally, automatically reloading it whenever it changes.
To create an instance of this object via the QMP monitor, the syntax used would be:
Quoted 8 lines
{
"execute": "object-add",
"arguments": {
"qom-type": "authz-list",
"id": "auth0",
"parameters": {
"filename": "/etc/qemu/vnc.acl",
"refresh": "yes"Would this be better as a JSON bool instead of a "yes"/"no" string?
TAB damage.
Quoted 22 lines
} } }If "refresh" is "yes", inotify is used to monitor the file, automatically reloading changes. If an error occurs during reloading, all authorizations will fail until the file is next successfully loaded.
The
/etc/qemu/vnc.aclfile would contain a JSON representation of a QAuthZList object{ "rules": [ { "match": "fred", "policy": "allow", "format": "exact" }, { "match": "bob", "policy": "allow", "format": "exact" }, { "match": "danb", "policy": "deny", "format": "glob" }, { "match": "dan*", "policy": "allow", "format": "exact" }, ], "policy": "deny" }
Quoted 5 lines
This sets up an authorization rule that allows 'fred', 'bob' and anyone whose name starts with 'dan', except for 'danb'. Everyone unmatched is denied.
The object can be loaded on the comand line using
s/comand/command/
Quoted 2 lines
-object authz-list-file,id=authz0,filename=/etc/qemu/vnc.acl,refresh=yes
Double dash, for the sake of qemu-img
Quoted 17 lines
Signed-off-by Daniel P. Berrangé <[email protected]>---
+/**
+ * QAuthZListFile:
+ *
+ * This authorization driver provides a file mechanism
+ * for granting access by matching user names against a
+ * file of globs. Each match rule has an associated policy
+ * and a catch all policy applies if no rule matches
+ *
+ * To create an instance of this class via QMP:
+ *
+ * {
+ * "execute": "object-add",
+ * "arguments": {
Quoted 6 lines
+ * "qom-type": "authz-list-file", + * "id": "authz0", + * "parameters": {+ * "filename": "
/etc/qemu/myvm-vnc.acl",
+ * "refresh": "yes"
+ * }
If you change the commit message to use bool, also change this comment to match.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 08/11] authz: add QAuthZList object type for an access control list
In reply to Eric BlakeQuoted 10 lines · Eric Blake
Quoted 9 lines · Daniel P. Berrangé
From: "Daniel P. Berrange" <[email protected]>
Add a QAuthZList object type that implements the QAuthZ interface. This built-in implementation maintains a trivial access control list with a sequence of match rules and a final default policy. This replicates the functionality currently provided by the
qemu_aclmodule.
Quoted 7 lines
Quoted 4 lines
It is not currently possible to create this via -object, since there is no syntax supported to specify non-scalar properties for objects. This is likely to be addressed by later support for using JSON with -object, or an equivalent approach.
Is this statement slightly stale, since we have JSON support with --object already?
That's news to me if we do. Markus did a PoC but AFAIK it was never proposed for merge so far.
Quoted 10 lines
qapi/authz.json line 25
Quoted 7 lines
qapi/authz.json new file +7
-0+## +# @QAuthZListFormat: +# +# The authorization policy result +# +# @exact: an exact string match +# @glob: string with ? and * shell wildcard supportThe shell also has [] globbing: a[bc]d matches 'abd' and 'acd'. Worth mentioning?
Sure,
Quoted 27 lines
Quoted 27 lines
qapi/authz.json new file +26
-0+# +# Since: 3.0 +## +{ 'enum': 'QAuthZListFormat', + 'prefix': 'QAUTHZ_LIST_FORMAT', + 'data': ['exact', 'glob']} + +## +# @QAuthZListRule: +# +# A single authorization rule. +# +# @match: a glob to match against a user identity +# @policy: the result to return if @match evaluates to true +# @format: (optional) the format of the @match rule (default 'exact') +# +# Since: 3.0 +## +{ 'struct': 'QAuthZListRule', + 'data': {'match': 'str', + 'policy': 'QAuthZListPolicy', + '*format': 'QAuthZListFormat'}} + +## +# @QAuthZListRuleListHack: +#
Quoted 8 lines
qapi/authz.json line 53
Quoted 2 lines
qapi/authz.json new file +2
-0+# Not exposed via QMP; hack to generate QAuthZListRuleList +# for use internally by the code.Someday, it would be nice if qom-set were fully specified rather than requiring hacks like this. Oh well, not new to your patches. I take it this is one case where order matters: the first rule that matches is applied (with no further rules tested), even if later rules in the list would also match.
NB this isn't needed for qom-set - its so that the include/authz/list.h header file can reference this data type in the struct it defines.
Yes, ordering is important - first matching rule wins.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v2 09/11] authz: add QAuthZListFile object type for a file access control list
In reply to Eric BlakeQuoted 18 lines · Eric Blake
Quoted 8 lines · Daniel P. Berrangé
Add a QAuthZListFile object type that implements the QAuthZ interface. This built-in implementation is a proxy around the QAtuhZList object type, initializing it from an external file, and optionally, automatically reloading it whenever it changes.
To create an instance of this object via the QMP monitor, the syntax used would be:
Quoted 8 lines
{ "execute": "object-add", "arguments": { "qom-type": "authz-list", "id": "auth0", "parameters": { "filename": "/etc/qemu/vnc.acl", "refresh": "yes"
Quoted 1 line
Would this be better as a JSON bool instead of a "yes"/"no" string?
Quiet probably - I'll have to double check it does work
Quoted 62 lines
TAB damage.
Quoted 22 lines
} } }If "refresh" is "yes", inotify is used to monitor the file, automatically reloading changes. If an error occurs during reloading, all authorizations will fail until the file is next successfully loaded.
The
/etc/qemu/vnc.aclfile would contain a JSON representation of a QAuthZList object{ "rules": [ { "match": "fred", "policy": "allow", "format": "exact" }, { "match": "bob", "policy": "allow", "format": "exact" }, { "match": "danb", "policy": "deny", "format": "glob" }, { "match": "dan*", "policy": "allow", "format": "exact" }, ], "policy": "deny" }Quoted 5 lines
This sets up an authorization rule that allows 'fred', 'bob' and anyone whose name starts with 'dan', except for 'danb'. Everyone unmatched is denied.
The object can be loaded on the comand line using
s/comand/command/
Quoted 2 lines
-object authz-list-file,id=authz0,filename=/etc/qemu/vnc.acl,refresh=yes
Double dash, for the sake of qemu-img
Quoted 17 lines
Signed-off-by Daniel P. Berrangé <[email protected]>---
+/**
+ * QAuthZListFile:
+ *
+ * This authorization driver provides a file mechanism
+ * for granting access by matching user names against a
+ * file of globs. Each match rule has an associated policy
+ * and a catch all policy applies if no rule matches
+ *
+ * To create an instance of this class via QMP:
+ *
+ * {
+ * "execute": "object-add",
+ * "arguments": {Quoted 6 lines
+ * "qom-type": "authz-list-file", + * "id": "authz0", + * "parameters": {+ * "filename": "
/etc/qemu/myvm-vnc.acl",
+ * "refresh": "yes"
+ * }
Quoted 7 lines
If you change the commit message to use bool, also change this comment to match.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH v2 08/11] authz: add QAuthZList object type for an access control list
In reply to Daniel P. BerrangéQuoted 16 lines · Daniel P. Berrangé
Quoted 15 lines · Eric Blake
Quoted 13 lines · Daniel P. Berrangé
From: "Daniel P. Berrange" <[email protected]>
Add a QAuthZList object type that implements the QAuthZ interface. This built-in implementation maintains a trivial access control list with a sequence of match rules and a final default policy. This replicates the functionality currently provided by the
qemu_aclmodule.It is not currently possible to create this via -object, since there is no syntax supported to specify non-scalar properties for objects. This is likely to be addressed by later support for using JSON with -object, or an equivalent approach.
Quoted 5 lines
Quoted 2 lines
Is this statement slightly stale, since we have JSON support with --object already?
That's news to me if we do. Markus did a PoC but AFAIK it was never proposed for merge so far.
Correct. Can finish the job if there's a need.
[...]
Re: [Qemu-devel] [PATCH v2 08/11] authz: add QAuthZList object type for an access control list
Quoted 21 lines · Markus Armbruster
Quoted 19 lines · Daniel P. Berrangé
Quoted 17 lines · Eric Blake
Quoted 9 lines · Daniel P. Berrangé
From: "Daniel P. Berrange" <[email protected]>
Add a QAuthZList object type that implements the QAuthZ interface. This built-in implementation maintains a trivial access control list with a sequence of match rules and a final default policy. This replicates the functionality currently provided by the
qemu_aclmodule.Quoted 4 lines
It is not currently possible to create this via -object, since there is no syntax supported to specify non-scalar properties for objects. This is likely to be addressed by later support for using JSON with -object, or an equivalent approach.
Is this statement slightly stale, since we have JSON support with --object already?
Quoted 6 lines
Quoted 2 lines
That's news to me if we do. Markus did a PoC but AFAIK it was never proposed for merge so far.
Correct. Can finish the job if there's a need.
[...]
I'm not hugely bothered by it - this QAuthZList impl serves two core purposes - a replacement for the HMP monitor commands I deprecated, an an engine for the QAuthZListFile which stores QAuthZList objects in external json files. The latter is what I think we'll use in practice, as it lets us auto-refresh on the fly via inotify which is much more convenient than having libvirt do object_add/object_del.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|