Skip to contentSkip to conversation

systemd the userspace object manager

RFC Christopher J. PeBenito 3 participants 8 messages Nov 18, 2014 – Nov 21, 2014 SELinux security module

lore
Share & tools
lore
#0 lore raw

Systemd currently mixes userspace permissions into a kernel class (system). This came up on the refpolicy list a few months ago[1], but there has been no decision or progress[2][3] that I'm aware of, so I'd like to reach a decision on the direction here.

Based on what was proposed for upstreaming into refpolicy, it looks like all of the service class permissions were duplicated into system, in addition to "halt" and "reboot". This conflates kernel functions with systemd functions. With the current systemd implementation, I think a minimum change should be:

class init_system
{
halt
reboot
}

class init_service
{
start
stop
status
reload
enable
disable
}

(init_ prefix added for naming convention consistency with other userspace classes in refpolicy)

Since we are discussing the enforcement, I'd like to review all of systemd's enforcement. Right now there are checks against unit files and processes, both for the service object class. I think this has problems as it conflates units (as service configurations) with services (the daemon processes). In an ideal world (I don't know if the systemd code could easily support this), I think the classes should be:

class init_system
{
halt
reboot
}

class init_unit
{
enable
disable
reload
}

class init_service
{
start
stop
status
}

Then init_system checks would always be against systemd's type (i.e. init_t), init_unit would always check against the unit file type, and init_service would always check against the daemon process type (which systemd should be able to calculate since it does that for socket activation).

[1] http://oss.tresys.com/pipermail/refpolicy/2014-July/007229.html
[2] https://bugs.freedesktop.org/show_bug.cgi?id=81105
[3] https://bugzilla.redhat.com/show_bug.cgi?id=1132933

Signature · 3 lines
Chris PeBenito
Tresys Technology, LLC
www.tresys.com | oss.tresys.com
#1 lore raw
Quoted 17 lines · Christopher J. PeBenito

Systemd currently mixes userspace permissions into a kernel class (system). This came up on the refpolicy list a few months ago[1], but there has been no decision or progress[2][3] that I'm aware of, so I'd like to reach a decision on the direction here.

Based on what was proposed for upstreaming into refpolicy, it looks like all of the service class permissions were duplicated into system, in addition to "halt" and "reboot". This conflates kernel functions with systemd functions. With the current systemd implementation, I think a minimum change should be:

class init_system
{
halt
reboot
}

Quoted 9 lines

class init_service
{
start
stop
status
reload
enable
disable
}

With some sleuthing help from a few people in the IRC channel, we found that reload permission is used in the system class to mediate at least the "systemctl daemon-reload", which reloads all unit files. I'll amend my suggestions to add a more specific permission, "reload_all_units", to the init_system class above and below for daemon-reload, under the assumption that a change to check the reload permission on all units would be rejected by systemd maintainers.

Quoted 41 lines

(init_ prefix added for naming convention consistency with other userspace classes in refpolicy)

Since we are discussing the enforcement, I'd like to review all of systemd's enforcement. Right now there are checks against unit files and processes, both for the service object class. I think this has problems as it conflates units (as service configurations) with services (the daemon processes). In an ideal world (I don't know if the systemd code could easily support this), I think the classes should be:

class init_system
{
halt
reboot
}

class init_unit
{
enable
disable
reload
}

class init_service
{
start
stop
status
}

Then init_system checks would always be against systemd's type (i.e. init_t), init_unit would always check against the unit file type, and init_service would always check against the daemon process type (which systemd should be able to calculate since it does that for socket activation).

[1] http://oss.tresys.com/pipermail/refpolicy/2014-July/007229.html
[2] https://bugs.freedesktop.org/show_bug.cgi?id=81105
[3] https://bugzilla.redhat.com/show_bug.cgi?id=1132933

Signature · 3 lines
Chris PeBenito
Tresys Technology, LLC
www.tresys.com | oss.tresys.com
#2 lore raw
In reply to Christopher J. PeBenito
Quoted 8 lines

class init_service
{
start
stop
status
}

I cannot really substantiate but it look like these are also used to start/stop/get status of systemd (session) daemons, so i suppose start_init, stop_init, get_status_init

I suspect this is mainly for starting the systemd session daemons. Logind uses these i believe.

so to start a systemd session daemon: allow ARG init_t:init start_init; or something maybe?

#3 lore raw
Quoted 9 lines · Dominick Grift
Quoted 8 lines

class init_service
{
start
stop
status
}

Quoted 5 lines

I cannot really substantiate but it look like these are also used to start/stop/get status of systemd (session) daemons, so i suppose start_init, stop_init, get_status_init

I suspect this is mainly for starting the systemd session daemons. Logind uses these i believe.

so to start a systemd session daemon: allow ARG init_t:init start_init; or something maybe?

Why would those daemons need to be treated specially? In the end they're still services; they may have special system features, but in that case you don't allow just anyone to stop/start them.

Signature · 3 lines
Chris PeBenito
Tresys Technology, LLC
www.tresys.com | oss.tresys.com
#4 lore raw
Quoted 5 lines · Christopher J. PeBenito

Why would those daemons need to be treated specially? In the end they're still services; they may have special system features, but in that case you don't allow just anyone to stop/start them.

You're probably right. It looks that way, but i suppose the only way to be determine is to view the code.

Signature · 1 line
Dominick Grift
#5 lore raw
In reply to Christopher J. PeBenito
Quoted 10 lines · Christopher J. PeBenito
Quoted 9 lines · Dominick Grift
Quoted 7 lines

class init_service
{
start
stop
status
}

I cannot really substantiate but it look like these are also used to start/stop/get status of systemd (session) daemons, so i suppose start_init, stop_init, get_status_init

Quoted 8 lines
Quoted 3 lines

I suspect this is mainly for starting the systemd session daemons. Logind uses these i believe.

so to start a systemd session daemon: allow ARG init_t:init start_init; or something maybe?

Why would those daemons need to be treated specially? In the end they're still services; they may have special system features, but in that case you don't allow just anyone to stop/start them.

I can see why you'd want someone to be able to restart apache but not everything. Certainly having specific permissions is not the way to accomplish that.

The rule above is kind of strange, permissions should not be equivalence classes, types should be, so it should be more like:

allow <domain requesting restart> <derived service label> : init {start stop}

right?

#6 lore raw
Quoted 5 lines · Joshua Brindle

I can see why you'd want someone to be able to restart apache but not everything. Certainly having specific permissions is not the way to accomplish that.

Quoted 7 lines

The rule above is kind of strange, permissions should not be equivalence classes, types should be, so it should be more like:

allow <domain requesting restart> <derived service label> : init {start stop}

right?

If only it were that simple. Here is my take on the whole thing:

Generally services are managed by "service" access checks on unit file types

allow webadmin webserverunitfile:service {start stop};

However these is also a concept of transient (in-memory) unit files, managing a service through a transient unit would work like:

allow user self:service {start stop};

or in the case of transient systemd units:

allow user systemd:service {stop start};

Then there is the system(d) class which also has the start, stop permissions associated with it (it is yet to be determined for what exactly)

In my policy systemd-logind does the following:

allow logind_t systemd:system(d) { start stop };

I suspect that this is required to spawn the systemd session daemon (at least) It may or may not also be required for kexec (not sure as i havent tested that yet)

This is pretty much just all speculation though, in the sense that this is broadly what i see happening in the system, and it might not be the same as what *should* be happening Instead its probably better to just read the systemd object manager code

Signature · 1 line
Dominick Grift
#7 lore raw
Quoted 31 lines · Dominick Grift
Quoted 11 lines · Joshua Brindle

I can see why you'd want someone to be able to restart apache but not everything. Certainly having specific permissions is not the way to accomplish that.

The rule above is kind of strange, permissions should not be equivalence classes, types should be, so it should be more like:

allow<domain requesting restart> <derived service label> : init {start stop}

right?

If only it were that simple. Here is my take on the whole thing:

Generally services are managed by "service" access checks on unit file types

allow webadmin webserverunitfile:service {start stop};

However these is also a concept of transient (in-memory) unit files, managing a service through a transient unit would work like:

allow user self:service {start stop};

or in the case of transient systemd units:

allow user systemd:service {stop start};

Then there is the system(d) class which also has the start, stop permissions associated with it (it is yet to be determined for what exactly)

In my policy systemd-logind does the following:

Quoted 8 lines

allow logind_t systemd:system(d) { start stop };

I suspect that this is required to spawn the systemd session daemon (at least) It may or may not also be required for kexec (not sure as i havent tested that yet)

This is pretty much just all speculation though, in the sense that this is broadly what i see happening in the system, and it might not be the same as what *should* be happening Instead its probably better to just read the systemd object manager code

I don't think we are saying different things. Note my rule above specifically says the object label is derived. I never speculated about how it would be derived, though it could be based on label mapping or type_trans calculations. In the cases above it would seem like there are some transient labels that need to be derived without the luxury of an object on-disk so you could either using a labeling file:

user_u:user_r:user_t:s0 user_u:user_r:user_service_t:s0

or a type_transition using the systemd or service object class:

type_transition user_t systemd_t service:user_service_t

Both of these has been done for various other userspace object classes, I haven't yet seen anything that makes systemd 'special'.