Import QEMU upstream snapshot d2e570c
Upstream: https://gitlab.com/qemu-project/qemu.git Upstream-Commit: d2e570cc0f97b936902a5b1b86b73c0f5998b475
This commit is contained in:
commit
cf256aa081
11315 files changed
+3598369
No files matched your search
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* QEMU authorization framework base class
|
||||
*
|
||||
* Copyright (c) 2018 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QAUTHZ_BASE_H
|
||||
#define QAUTHZ_BASE_H
|
||||
|
||||
#include "qapi/error.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
|
||||
#define TYPE_QAUTHZ "authz"
|
||||
|
||||
OBJECT_DECLARE_TYPE(QAuthZ, QAuthZClass,
|
||||
QAUTHZ)
|
||||
|
||||
|
||||
/**
|
||||
* QAuthZ:
|
||||
*
|
||||
* The QAuthZ class defines an API contract to be used
|
||||
* for providing an authorization driver for services
|
||||
* with user identities.
|
||||
*/
|
||||
|
||||
struct QAuthZ {
|
||||
Object parent_obj;
|
||||
};
|
||||
|
||||
|
||||
struct QAuthZClass {
|
||||
ObjectClass parent_class;
|
||||
|
||||
bool (*is_allowed)(QAuthZ *authz,
|
||||
const char *identity,
|
||||
Error **errp);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* qauthz_is_allowed:
|
||||
* @authz: the authorization object
|
||||
* @identity: the user identity to authorize
|
||||
* @errp: pointer to a NULL initialized error object
|
||||
*
|
||||
* Check if a user @identity is authorized. If an error
|
||||
* occurs this method will return false to indicate
|
||||
* denial, as well as setting @errp to contain the details.
|
||||
* Callers are recommended to treat the denial and error
|
||||
* scenarios identically. Specifically the error info in
|
||||
* @errp should never be fed back to the user being
|
||||
* authorized, it is merely for benefit of administrator
|
||||
* debugging.
|
||||
*
|
||||
* Returns: true if @identity is authorized, false if denied or if
|
||||
* an error occurred.
|
||||
*/
|
||||
bool qauthz_is_allowed(QAuthZ *authz,
|
||||
const char *identity,
|
||||
Error **errp);
|
||||
|
||||
|
||||
/**
|
||||
* qauthz_is_allowed_by_id:
|
||||
* @authzid: ID of the authorization object
|
||||
* @identity: the user identity to authorize
|
||||
* @errp: pointer to a NULL initialized error object
|
||||
*
|
||||
* Check if a user @identity is authorized. If an error
|
||||
* occurs this method will return false to indicate
|
||||
* denial, as well as setting @errp to contain the details.
|
||||
* Callers are recommended to treat the denial and error
|
||||
* scenarios identically. Specifically the error info in
|
||||
* @errp should never be fed back to the user being
|
||||
* authorized, it is merely for benefit of administrator
|
||||
* debugging.
|
||||
*
|
||||
* Returns: true if @identity is authorized, false if denied or if
|
||||
* an error occurred.
|
||||
*/
|
||||
bool qauthz_is_allowed_by_id(const char *authzid,
|
||||
const char *identity,
|
||||
Error **errp);
|
||||
|
||||
#endif /* QAUTHZ_BASE_H */
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* QEMU list authorization driver
|
||||
*
|
||||
* Copyright (c) 2018 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QAUTHZ_LIST_H
|
||||
#define QAUTHZ_LIST_H
|
||||
|
||||
#include "authz/base.h"
|
||||
#include "qapi/qapi-types-authz.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
#define TYPE_QAUTHZ_LIST "authz-list"
|
||||
|
||||
OBJECT_DECLARE_SIMPLE_TYPE(QAuthZList,
|
||||
QAUTHZ_LIST)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* QAuthZList:
|
||||
*
|
||||
* This authorization driver provides a list mechanism
|
||||
* for granting access by matching user names against a
|
||||
* list 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": {
|
||||
* "qom-type": "authz-list",
|
||||
* "id": "authz0",
|
||||
* "props": {
|
||||
* "rules": [
|
||||
* { "match": "fred", "policy": "allow", "format": "exact" },
|
||||
* { "match": "bob", "policy": "allow", "format": "exact" },
|
||||
* { "match": "danb", "policy": "deny", "format": "exact" },
|
||||
* { "match": "dan*", "policy": "allow", "format": "glob" }
|
||||
* ],
|
||||
* "policy": "deny"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
struct QAuthZList {
|
||||
QAuthZ parent_obj;
|
||||
|
||||
QAuthZListPolicy policy;
|
||||
QAuthZListRuleList *rules;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
QAuthZList *qauthz_list_new(const char *id,
|
||||
QAuthZListPolicy policy,
|
||||
Error **errp);
|
||||
|
||||
ssize_t qauthz_list_append_rule(QAuthZList *auth,
|
||||
const char *match,
|
||||
QAuthZListPolicy policy,
|
||||
QAuthZListFormat format,
|
||||
Error **errp);
|
||||
|
||||
ssize_t qauthz_list_insert_rule(QAuthZList *auth,
|
||||
const char *match,
|
||||
QAuthZListPolicy policy,
|
||||
QAuthZListFormat format,
|
||||
size_t index,
|
||||
Error **errp);
|
||||
|
||||
ssize_t qauthz_list_delete_rule(QAuthZList *auth,
|
||||
const char *match);
|
||||
|
||||
|
||||
#endif /* QAUTHZ_LIST_H */
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* QEMU list file authorization driver
|
||||
*
|
||||
* Copyright (c) 2018 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QAUTHZ_LISTFILE_H
|
||||
#define QAUTHZ_LISTFILE_H
|
||||
|
||||
#include "authz/list.h"
|
||||
#include "qemu/filemonitor.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
#define TYPE_QAUTHZ_LIST_FILE "authz-list-file"
|
||||
|
||||
OBJECT_DECLARE_SIMPLE_TYPE(QAuthZListFile,
|
||||
QAUTHZ_LIST_FILE)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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": {
|
||||
* "qom-type": "authz-list-file",
|
||||
* "id": "authz0",
|
||||
* "props": {
|
||||
* "filename": "/etc/qemu/myvm-vnc.acl",
|
||||
* "refresh": true
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* If 'refresh' is 'yes', inotify is used to monitor for changes
|
||||
* to the file and auto-reload the rules.
|
||||
*
|
||||
* The myvm-vnc.acl file should contain the parameters for
|
||||
* the QAuthZList object in JSON format:
|
||||
*
|
||||
* {
|
||||
* "rules": [
|
||||
* { "match": "fred", "policy": "allow", "format": "exact" },
|
||||
* { "match": "bob", "policy": "allow", "format": "exact" },
|
||||
* { "match": "danb", "policy": "deny", "format": "exact" },
|
||||
* { "match": "dan*", "policy": "allow", "format": "glob" }
|
||||
* ],
|
||||
* "policy": "deny"
|
||||
* }
|
||||
*
|
||||
* The object can be created on the command line using
|
||||
*
|
||||
* -object authz-list-file,id=authz0,\
|
||||
* filename=/etc/qemu/myvm-vnc.acl,refresh=on
|
||||
*
|
||||
*/
|
||||
struct QAuthZListFile {
|
||||
QAuthZ parent_obj;
|
||||
|
||||
QAuthZ *list;
|
||||
char *filename;
|
||||
bool refresh;
|
||||
QFileMonitor *file_monitor;
|
||||
int64_t file_watch;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
QAuthZListFile *qauthz_list_file_new(const char *id,
|
||||
const char *filename,
|
||||
bool refresh,
|
||||
Error **errp);
|
||||
|
||||
#endif /* QAUTHZ_LISTFILE_H */
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* QEMU PAM authorization driver
|
||||
*
|
||||
* Copyright (c) 2018 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QAUTHZ_PAMACCT_H
|
||||
#define QAUTHZ_PAMACCT_H
|
||||
|
||||
#include "authz/base.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
|
||||
#define TYPE_QAUTHZ_PAM "authz-pam"
|
||||
|
||||
OBJECT_DECLARE_SIMPLE_TYPE(QAuthZPAM,
|
||||
QAUTHZ_PAM)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* QAuthZPAM:
|
||||
*
|
||||
* This authorization driver provides a PAM mechanism
|
||||
* for granting access by matching user names against a
|
||||
* list 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": {
|
||||
* "qom-type": "authz-pam",
|
||||
* "id": "authz0",
|
||||
* "parameters": {
|
||||
* "service": "qemu-vnc-tls"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* The driver only uses the PAM "account" verification
|
||||
* subsystem. The above config would require a config
|
||||
* file /etc/pam.d/qemu-vnc-tls. For a simple file
|
||||
* lookup it would contain
|
||||
*
|
||||
* account requisite pam_listfile.so item=user sense=allow \
|
||||
* file=/etc/qemu/vnc.allow
|
||||
*
|
||||
* The external file would then contain a list of usernames.
|
||||
* If x509 cert was being used as the username, a suitable
|
||||
* entry would match the distinguish name:
|
||||
*
|
||||
* CN=laptop.berrange.com,O=Berrange Home,L=London,ST=London,C=GB
|
||||
*
|
||||
* On the command line it can be created using
|
||||
*
|
||||
* -object authz-pam,id=authz0,service=qemu-vnc-tls
|
||||
*
|
||||
*/
|
||||
struct QAuthZPAM {
|
||||
QAuthZ parent_obj;
|
||||
|
||||
char *service;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
QAuthZPAM *qauthz_pam_new(const char *id,
|
||||
const char *service,
|
||||
Error **errp);
|
||||
|
||||
#endif /* QAUTHZ_PAMACCT_H */
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* QEMU simple authorization driver
|
||||
*
|
||||
* Copyright (c) 2018 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QAUTHZ_SIMPLE_H
|
||||
#define QAUTHZ_SIMPLE_H
|
||||
|
||||
#include "authz/base.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
#define TYPE_QAUTHZ_SIMPLE "authz-simple"
|
||||
|
||||
OBJECT_DECLARE_SIMPLE_TYPE(QAuthZSimple,
|
||||
QAUTHZ_SIMPLE)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* QAuthZSimple:
|
||||
*
|
||||
* This authorization driver provides a simple mechanism
|
||||
* for granting access based on an exact matched username.
|
||||
*
|
||||
* To create an instance of this class via QMP:
|
||||
*
|
||||
* {
|
||||
* "execute": "object-add",
|
||||
* "arguments": {
|
||||
* "qom-type": "authz-simple",
|
||||
* "id": "authz0",
|
||||
* "props": {
|
||||
* "identity": "fred"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Or via the command line
|
||||
*
|
||||
* -object authz-simple,id=authz0,identity=fred
|
||||
*
|
||||
*/
|
||||
struct QAuthZSimple {
|
||||
QAuthZ parent_obj;
|
||||
|
||||
char *identity;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
QAuthZSimple *qauthz_simple_new(const char *id,
|
||||
const char *identity,
|
||||
Error **errp);
|
||||
|
||||
|
||||
#endif /* QAUTHZ_SIMPLE_H */
|
||||
Reference in new issue
Block a user