Skip to content

Conversation

@yuwata
Copy link
Member

@yuwata yuwata commented Aug 8, 2017

If AmbientCapabilities= is prefixed by '-' and the ambient capability is not supported by the kernel, then the listed ambient capabilities are ignored and the commands are executed by root.
On top of the options, networkd, resolved, and timesyncd drop the capabilities in the following commits.

yuwata added 6 commits August 8, 2017 12:29
If AmbientCapabilities= is prefixed by '-' and the ambient capability
is not supported by the kernel, then the listed ambient capabilities
are ignored and the commands are executed by root.
@Siosm
Copy link

Siosm commented Aug 8, 2017

As far as I'm concerned, this looks good to me as it appears to fix all issues raised in previous discussions. I've closed my previous PR.

I think there are three minor points:

  • you should create the /run/systemd/resolved folder using tmpfiles (in commit "resolved: support to run by non-root user"):
diff --git a/tmpfiles.d/systemd.conf.m4 b/tmpfiles.d/systemd.conf.m4
@@ -21,6 +21,9 @@ d /run/systemd/netif 0755 systemd-network systemd-network -
 d /run/systemd/netif/links 0755 systemd-network systemd-network -
 d /run/systemd/netif/leases 0755 systemd-network systemd-network -
 )m4_dnl
+m4_ifdef(`ENABLE_RESOLVED',
+d /run/systemd/resolve 0755 systemd-resolve systemd-resolve -
+)m4_dnl
 
 d /run/log 0755 root root -
 
  • commit "timesyncd: support to run by non-root user" might require packaging glue to move the previous 'clock' file to the new location during upgrades.
  • Should there be a warning during unit spawning that would remind administrators that the user/group has not been changed for the process if ambient capabilities are not available? This warning would then be dismissable by explicitly overriding AmbientCapabilities/User/Group options in the units.

@yuwata
Copy link
Member Author

yuwata commented Aug 9, 2017

@Siosm Thank you for the comments.

you should create the /run/systemd/resolved folder using tmpfiles (in commit "resolved: support to run by non-root user"):

Is it necessary? The service runs with RuntimeDirectory=systemd/resolve... Unlike /run/systemd/netif, the directory is not inotified, I think. Is it true?

commit "timesyncd: support to run by non-root user" might require packaging glue to move the previous 'clock' file to the new location during upgrades.

OK. I will document it.

Should there be a warning during unit spawning that would remind administrators that the user/group has not been changed for the process if ambient capabilities are not available? This warning would then be dismissable by explicitly overriding AmbientCapabilities/User/Group options in the units.

Hmm, the user/group setting is ignored only if AmbientCapabilities= is prefixed. So, I do not think such warning is necessary.

Also this moves the location of clock file to /var/lib/systemd/timesync.
@yuwata
Copy link
Member Author

yuwata commented Aug 9, 2017

Updated.

SystemCallArchitectures=native
ReadWritePaths=/var/lib/systemd
StateDirectory=systemd/timesync
User=systemd-timesync
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor personal preference: Could you move the User option near the top of the Service section and add Group option even if it is implied by the User option?


* clock file is now moved to /var/lib/systemd/timesync/clock.
Distributors should change the location of the file if it is packaged.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this file is packaged with systemd. The minor issue here would happen during a restart after an upgrade as the old timesyncd would use the old path and the new timsyncd the new path thus loosing the recorded timestamp. This will also leave an used file in place.

I would suggest:
The file /var/lib/systemd/clock used by systemd-timesyncd to remember the last known good clock value has been moved to /var/lib/systemd/timesync/clock. Distributors should either remove the previous file after the service has been restarted or move the current file to the new directory once the old daemon has been stopped and before the new daemon startup.

But this may be to much of a hassle for such a minor issue / minor gain.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. I will update the NEWS entry based on that.

I don't think this file is packaged with systemd.

For example, http://pkgs.fedoraproject.org/rpms/systemd/blob/master/f/systemd.spec#_688

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The %ghost directive means that the file will be removed when the package is removed/updated. But this file will be written to by systemd-timesyncd when it is stopped. Thus this is still relevant I think.

@Siosm
Copy link

Siosm commented Aug 9, 2017

Is it necessary? The service runs with RuntimeDirectory=systemd/resolve... Unlike /run/systemd/netif, the directory is not inotified, I think. Is it true?

This "double" setup was also suggested to ease debugging (#6393 (comment)), but is not strictly necessary I agree.

poettering added a commit to poettering/systemd that referenced this pull request Aug 9, 2017
This patch adds two new special character prefixes to ExecStart= and
friends, in addition to the existing "-", "@" and "+":

"!"  → much like "+", except with a much reduced effect as it only
       disables the actual setresuid()/setresgid()/setgroups() calls, but
       leaves all other security features on, including namespace
       options. This is very useful in combination with
       RuntimeDirectory= or DynamicUser= and similar option, as a user
       is still allocated and used for the runtime directory, but the
       actual UID/GID dropping is left to the daemon process itself.
       This should make RuntimeDirectory= a lot more useful for daemons
       which insist on doing their own privilege dropping.

"!!" → Similar to "!", but on systems supporting ambient caps this
       becomes a NOP. This makes it relatively straightforward to write
       unit files that make use of ambient capabilities to let systemd
       drop all privs while retaining compatibility with systems that
       lack ambient caps, where priv dropping is the left to the daemon
       codes themselves.

This is an alternative approach to systemd#6564 and related PRs.
@poettering
Copy link
Member

Heya, sorry for not being more responsive on the whole ambient caps/user dropping stuff. I go sidetracked by other stuff for a while. Anyway, a few weeks ago I started working on #6577 which I now filed, which tries to solve the same issue in a different way, and I think in a slightly nicer way...

Any chance you can have a look at that, so that we can find some common ground we can all agree on?

poettering added a commit to poettering/systemd that referenced this pull request Aug 9, 2017
This patch adds two new special character prefixes to ExecStart= and
friends, in addition to the existing "-", "@" and "+":

"!"  → much like "+", except with a much reduced effect as it only
       disables the actual setresuid()/setresgid()/setgroups() calls, but
       leaves all other security features on, including namespace
       options. This is very useful in combination with
       RuntimeDirectory= or DynamicUser= and similar option, as a user
       is still allocated and used for the runtime directory, but the
       actual UID/GID dropping is left to the daemon process itself.
       This should make RuntimeDirectory= a lot more useful for daemons
       which insist on doing their own privilege dropping.

"!!" → Similar to "!", but on systems supporting ambient caps this
       becomes a NOP. This makes it relatively straightforward to write
       unit files that make use of ambient capabilities to let systemd
       drop all privs while retaining compatibility with systems that
       lack ambient caps, where priv dropping is the left to the daemon
       codes themselves.

This is an alternative approach to systemd#6564 and related PRs.
poettering added a commit to poettering/systemd that referenced this pull request Aug 10, 2017
This patch adds two new special character prefixes to ExecStart= and
friends, in addition to the existing "-", "@" and "+":

"!"  → much like "+", except with a much reduced effect as it only
       disables the actual setresuid()/setresgid()/setgroups() calls, but
       leaves all other security features on, including namespace
       options. This is very useful in combination with
       RuntimeDirectory= or DynamicUser= and similar option, as a user
       is still allocated and used for the runtime directory, but the
       actual UID/GID dropping is left to the daemon process itself.
       This should make RuntimeDirectory= a lot more useful for daemons
       which insist on doing their own privilege dropping.

"!!" → Similar to "!", but on systems supporting ambient caps this
       becomes a NOP. This makes it relatively straightforward to write
       unit files that make use of ambient capabilities to let systemd
       drop all privs while retaining compatibility with systems that
       lack ambient caps, where priv dropping is the left to the daemon
       codes themselves.

This is an alternative approach to systemd#6564 and related PRs.
@yuwata
Copy link
Member Author

yuwata commented Aug 12, 2017

Closing this in favor of #6577.

@yuwata yuwata closed this Aug 12, 2017
andir pushed a commit to andir/systemd that referenced this pull request Sep 7, 2017
This patch adds two new special character prefixes to ExecStart= and
friends, in addition to the existing "-", "@" and "+":

"!"  → much like "+", except with a much reduced effect as it only
       disables the actual setresuid()/setresgid()/setgroups() calls, but
       leaves all other security features on, including namespace
       options. This is very useful in combination with
       RuntimeDirectory= or DynamicUser= and similar option, as a user
       is still allocated and used for the runtime directory, but the
       actual UID/GID dropping is left to the daemon process itself.
       This should make RuntimeDirectory= a lot more useful for daemons
       which insist on doing their own privilege dropping.

"!!" → Similar to "!", but on systems supporting ambient caps this
       becomes a NOP. This makes it relatively straightforward to write
       unit files that make use of ambient capabilities to let systemd
       drop all privs while retaining compatibility with systems that
       lack ambient caps, where priv dropping is the left to the daemon
       codes themselves.

This is an alternative approach to systemd#6564 and related PRs.
andir pushed a commit to andir/systemd that referenced this pull request Sep 22, 2017
This patch adds two new special character prefixes to ExecStart= and
friends, in addition to the existing "-", "@" and "+":

"!"  → much like "+", except with a much reduced effect as it only
       disables the actual setresuid()/setresgid()/setgroups() calls, but
       leaves all other security features on, including namespace
       options. This is very useful in combination with
       RuntimeDirectory= or DynamicUser= and similar option, as a user
       is still allocated and used for the runtime directory, but the
       actual UID/GID dropping is left to the daemon process itself.
       This should make RuntimeDirectory= a lot more useful for daemons
       which insist on doing their own privilege dropping.

"!!" → Similar to "!", but on systems supporting ambient caps this
       becomes a NOP. This makes it relatively straightforward to write
       unit files that make use of ambient capabilities to let systemd
       drop all privs while retaining compatibility with systems that
       lack ambient caps, where priv dropping is the left to the daemon
       codes themselves.

This is an alternative approach to systemd#6564 and related PRs.
@yuwata yuwata deleted the ambient-prefix branch November 12, 2017 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants