diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-05-11 20:18:56 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-06-21 17:38:23 +0200 |
commit | 38a7666df317b26a355a8c2e0332bd79312f30f6 (patch) | |
tree | 60d1f2b22a5df929b60e4cd9d28d34fd932c3d70 | |
parent | cryptsetup: minor coding style tweaks (diff) | |
download | systemd-38a7666df317b26a355a8c2e0332bd79312f30f6.tar.xz systemd-38a7666df317b26a355a8c2e0332bd79312f30f6.zip |
machined: allow unprivileged registration of VMs/containers
Now that we have a concept of unprivileged VMs and containers, let's
allow unprivileged clients to register with machined too – subject to
Polkit permissions.
-rw-r--r-- | src/machine/machine-varlink.c | 12 | ||||
-rw-r--r-- | src/machine/machined-varlink.c | 2 | ||||
-rw-r--r-- | src/machine/org.freedesktop.machine1.policy | 11 | ||||
-rw-r--r-- | src/shared/varlink-io.systemd.Machine.c | 4 | ||||
-rw-r--r-- | src/vmspawn/vmspawn-register.c | 3 | ||||
-rw-r--r-- | src/vmspawn/vmspawn.c | 3 |
6 files changed, 29 insertions, 6 deletions
diff --git a/src/machine/machine-varlink.c b/src/machine/machine-varlink.c index 6f437c06c4..ea300d71de 100644 --- a/src/machine/machine-varlink.c +++ b/src/machine/machine-varlink.c @@ -5,6 +5,7 @@ #include "sd-id128.h" #include "sd-json.h" +#include "bus-polkit.h" #include "hostname-util.h" #include "json-util.h" #include "machine-varlink.h" @@ -136,6 +137,7 @@ int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethod { "vSockCid", SD_JSON_VARIANT_UNSIGNED, machine_cid, offsetof(Machine, vsock_cid), 0 }, { "sshAddress", SD_JSON_VARIANT_STRING, sd_json_dispatch_string, offsetof(Machine, ssh_address), SD_JSON_STRICT }, { "sshPrivateKeyPath", SD_JSON_VARIANT_STRING, json_dispatch_path, offsetof(Machine, ssh_private_key_path), 0 }, + VARLINK_DISPATCH_POLKIT_FIELD, {} }; @@ -147,6 +149,16 @@ int vl_method_register(Varlink *link, sd_json_variant *parameters, VarlinkMethod if (r != 0) return r; + r = varlink_verify_polkit_async( + link, + manager->bus, + "org.freedesktop.machine1.create-machine", + (const char**) STRV_MAKE("name", machine->name, + "class", machine_class_to_string(machine->class)), + &manager->polkit_registry); + if (r <= 0) + return r; + if (!pidref_is_set(&machine->leader)) { r = varlink_get_peer_pidref(link, &machine->leader); if (r < 0) diff --git a/src/machine/machined-varlink.c b/src/machine/machined-varlink.c index dc35877c49..bd092bb282 100644 --- a/src/machine/machined-varlink.c +++ b/src/machine/machined-varlink.c @@ -433,7 +433,7 @@ static int manager_varlink_init_machine(Manager *m) { if (m->varlink_machine_server) return 0; - r = varlink_server_new(&s, VARLINK_SERVER_ROOT_ONLY|VARLINK_SERVER_INHERIT_USERDATA); + r = varlink_server_new(&s, VARLINK_SERVER_ACCOUNT_UID|VARLINK_SERVER_INHERIT_USERDATA); if (r < 0) return log_error_errno(r, "Failed to allocate varlink server object: %m"); diff --git a/src/machine/org.freedesktop.machine1.policy b/src/machine/org.freedesktop.machine1.policy index f031e4e480..fe125ed0db 100644 --- a/src/machine/org.freedesktop.machine1.policy +++ b/src/machine/org.freedesktop.machine1.policy @@ -91,6 +91,17 @@ <annotate key="org.freedesktop.policykit.imply">org.freedesktop.login1.shell org.freedesktop.login1.login</annotate> </action> + <action id="org.freedesktop.machine1.create-machine"> + <description gettext-domain="systemd">Create a local virtual machine or container</description> + <message gettext-domain="systemd">Authentication is required to create a local virtual machine or container.</message> + <defaults> + <allow_any>auth_admin</allow_any> + <allow_inactive>auth_admin</allow_inactive> + <allow_active>auth_admin_keep</allow_active> + </defaults> + <annotate key="org.freedesktop.policykit.imply">org.freedesktop.login1.shell org.freedesktop.login1.login</annotate> + </action> + <action id="org.freedesktop.machine1.manage-images"> <description gettext-domain="systemd">Manage local virtual machine and container images</description> <message gettext-domain="systemd">Authentication is required to manage local virtual machine and container images.</message> diff --git a/src/shared/varlink-io.systemd.Machine.c b/src/shared/varlink-io.systemd.Machine.c index 2d25a345d7..76eaf7d13c 100644 --- a/src/shared/varlink-io.systemd.Machine.c +++ b/src/shared/varlink-io.systemd.Machine.c @@ -14,7 +14,9 @@ static VARLINK_DEFINE_METHOD( VARLINK_DEFINE_INPUT(ifIndices, VARLINK_INT, VARLINK_ARRAY|VARLINK_NULLABLE), VARLINK_DEFINE_INPUT(vSockCid, VARLINK_INT, VARLINK_NULLABLE), VARLINK_DEFINE_INPUT(sshAddress, VARLINK_STRING, VARLINK_NULLABLE), - VARLINK_DEFINE_INPUT(sshPrivateKeyPath, VARLINK_STRING, VARLINK_NULLABLE)); + VARLINK_DEFINE_INPUT(sshPrivateKeyPath, VARLINK_STRING, VARLINK_NULLABLE), + VARLINK_FIELD_COMMENT("Whether to allow interactive authentication on this operation."), + VARLINK_DEFINE_INPUT(allowInteractiveAuthentication, VARLINK_BOOL, VARLINK_NULLABLE)); static VARLINK_DEFINE_ERROR(MachineExists); diff --git a/src/vmspawn/vmspawn-register.c b/src/vmspawn/vmspawn-register.c index 2140bba9cd..2130fd9108 100644 --- a/src/vmspawn/vmspawn-register.c +++ b/src/vmspawn/vmspawn-register.c @@ -70,7 +70,8 @@ int register_machine( SD_JSON_BUILD_PAIR_CONDITION(VSOCK_CID_IS_REGULAR(cid), "vSockCid", SD_JSON_BUILD_UNSIGNED(cid)), SD_JSON_BUILD_PAIR_CONDITION(!!directory, "rootDirectory", SD_JSON_BUILD_STRING(directory)), SD_JSON_BUILD_PAIR_CONDITION(!!address, "sshAddress", SD_JSON_BUILD_STRING(address)), - SD_JSON_BUILD_PAIR_CONDITION(!!key_path, "sshPrivateKeyPath", SD_JSON_BUILD_STRING(key_path))); + SD_JSON_BUILD_PAIR_CONDITION(!!key_path, "sshPrivateKeyPath", SD_JSON_BUILD_STRING(key_path)), + SD_JSON_BUILD_PAIR_CONDITION(isatty(STDIN_FILENO), "allowInteractiveAuthentication", SD_JSON_BUILD_BOOLEAN(true))); } int unregister_machine(sd_bus *bus, const char *machine_name) { diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 73e165fead..971844e10c 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -2229,9 +2229,6 @@ static int verify_arguments(void) { if (!strv_isempty(arg_initrds) && !arg_linux) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Option --initrd= cannot be used without --linux=."); - if (arg_register && !arg_privileged) - return log_error_errno(SYNTHETIC_ERRNO(EPERM), "--register= requires root privileges, refusing."); - return 0; } |