Skip to content

Commit adaff8e

Browse files
committed
machined: use different polkit actions for registering and creating a machine
The difference between these two operations are large: one is relatively superficial: for "registration" all resources remain associated with the invoking user, only the cgroup is reported to machined which then keeps track of the machine, too. OTOH "creation" a scope is allocated in system context, hence the invoked code will be owned by the system, and its resource usage charged against the system. Hence, use two distinct polkit actions for this, so that we can relax access to registration, but keep access to creation tough.
1 parent 276d200 commit adaff8e

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/machine/machine-varlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ int vl_method_register(sd_varlink *link, sd_json_variant *parameters, sd_varlink
155155
r = varlink_verify_polkit_async(
156156
link,
157157
manager->bus,
158-
"org.freedesktop.machine1.create-machine",
158+
machine->allocate_unit ? "org.freedesktop.machine1.create-machine" : "org.freedesktop.machine1.register-machine",
159159
(const char**) STRV_MAKE("name", machine->name,
160160
"class", machine_class_to_string(machine->class)),
161161
&manager->polkit_registry);

src/machine/machined-dbus.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ static int method_list_machines(sd_bus_message *message, void *userdata, sd_bus_
228228
static int method_create_or_register_machine(
229229
Manager *manager,
230230
sd_bus_message *message,
231+
const char *polkit_action,
231232
bool read_network,
232233
Machine **ret,
233234
sd_bus_error *error) {
@@ -318,7 +319,7 @@ static int method_create_or_register_machine(
318319

319320
r = bus_verify_polkit_async(
320321
message,
321-
"org.freedesktop.machine1.create-machine",
322+
polkit_action,
322323
details,
323324
&manager->polkit_registry,
324325
error);
@@ -378,7 +379,7 @@ static int method_create_machine_internal(sd_bus_message *message, bool read_net
378379

379380
assert(message);
380381

381-
r = method_create_or_register_machine(manager, message, read_network, &m, error);
382+
r = method_create_or_register_machine(manager, message, "org.freedesktop.machine1.create-machine", read_network, &m, error);
382383
if (r < 0)
383384
return r;
384385
if (r == 0)
@@ -416,7 +417,7 @@ static int method_register_machine_internal(sd_bus_message *message, bool read_n
416417

417418
assert(message);
418419

419-
r = method_create_or_register_machine(manager, message, read_network, &m, error);
420+
r = method_create_or_register_machine(manager, message, "org.freedesktop.machine1.register-machine", read_network, &m, error);
420421
if (r < 0)
421422
return r;
422423
if (r == 0)

src/machine/org.freedesktop.machine1.policy

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@
9999
<allow_inactive>auth_admin</allow_inactive>
100100
<allow_active>auth_admin_keep</allow_active>
101101
</defaults>
102-
<annotate key="org.freedesktop.policykit.imply">org.freedesktop.login1.shell org.freedesktop.login1.login</annotate>
102+
<annotate key="org.freedesktop.policykit.imply">org.freedesktop.login1.shell org.freedesktop.login1.login org.freedesktop.machine1.register-machine</annotate>
103+
</action>
104+
105+
<action id="org.freedesktop.machine1.register-machine">
106+
<description gettext-domain="systemd">Register a local virtual machine or container</description>
107+
<message gettext-domain="systemd">Authentication is required to register a local virtual machine or container.</message>
108+
<defaults>
109+
<allow_any>auth_admin</allow_any>
110+
<allow_inactive>auth_admin</allow_inactive>
111+
<allow_active>yes</allow_active>
112+
</defaults>
103113
</action>
104114

105115
<action id="org.freedesktop.machine1.manage-images">

0 commit comments

Comments
 (0)