Systemd/src/libsystemd
Lennart Poettering b3415f5dae core: store the invocation ID in the per-service keyring
Let's store the invocation ID in the per-service keyring as a root-owned key,
with strict access rights. This has the advantage over the environment-based ID
passing that it also works from SUID binaries (as they key cannot be overidden
by unprivileged code starting them), in contrast to the secure_getenv() based
mode.

The invocation ID is now passed in three different ways to a service:

- As environment variable $INVOCATION_ID. This is easy to use, but may be
  overriden by unprivileged code (which might be a bad or a good thing), which
  means it's incompatible with SUID code (see above).

- As extended attribute on the service cgroup. This cannot be overriden by
  unprivileged code, and may be queried safely from "outside" of a service.
  However, it is incompatible with containers right now, as unprivileged
  containers generally cannot set xattrs on cgroupfs.

- As "invocation_id" key in the kernel keyring. This has the benefit that the
  key cannot be changed by unprivileged service code, and thus is safe to
  access from SUID code (see above). But do note that service code can replace
  the session keyring with a fresh one that lacks the key. However in that case
  the key will not be owned by root, which is easily detectable. The keyring is
  also incompatible with containers right now, as it is not properly namespace
  aware (but this is being worked on), and thus most container managers mask
  the keyring-related system calls.

Ideally we'd only have one way to pass the invocation ID, but the different
ways all have limitations. The invocation ID hookup in journald is currently
only available on the host but not in containers, due to the mentioned
limitations.

How to verify the new invocation ID in the keyring:

 # systemd-run -t /bin/sh
 Running as unit: run-rd917366c04f847b480d486017f7239d6.service
 Press ^] three times within 1s to disconnect TTY.
 # keyctl show
 Session Keyring
  680208392 --alswrv      0     0  keyring: _ses
  250926536 ----s-rv      0     0   \_ user: invocation_id
 # keyctl request user invocation_id
 250926536
 # keyctl read 250926536
 16 bytes of data in key:
 9c96317c ac64495a a42b9cd7 4f3ff96b
 # echo $INVOCATION_ID
 9c96317cac64495aa42b9cd74f3ff96b
 # ^D

This creates a new transient service runnint a shell. Then verifies the
contents of the keyring, requests the invocation ID key, and reads its payload.
For comparison the invocation ID as passed via the environment variable is also
displayed.
2016-12-13 20:59:36 +01:00
..
sd-bus Merge pull request #4618 from grawity/signal-direction 2016-11-10 13:52:15 -05:00
sd-daemon tree-wide: htonl() is weird, let's use htobe32() instead (#3538) 2016-06-15 01:26:01 +02:00
sd-device tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853) 2016-12-09 10:04:30 +01:00
sd-event sd-event: fix sd_event_source_get_priority() (#4712) 2016-11-21 19:21:00 -05:00
sd-hwdb sd-hwdb: drop caching of search string 2016-11-30 15:51:08 -05:00
sd-id128 core: store the invocation ID in the per-service keyring 2016-12-13 20:59:36 +01:00
sd-login tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853) 2016-12-09 10:04:30 +01:00
sd-netlink networkd: handle MTU field in IPv6 RA (#4719) 2016-11-23 22:32:19 +01:00
sd-network tree-wide: make invocations of extract_first_word more uniform (#4627) 2016-11-11 18:58:41 +01:00
sd-path tree-wide: drop NULL sentinel from strjoin 2016-10-23 11:43:27 -04:00
sd-resolve sd-resolve: use close_many() (#3643) 2016-07-02 08:17:26 -07:00
sd-utf8 tree-wide: remove Emacs lines from all files 2016-02-10 13:41:57 +01:00
.gitignore libsystemd: remove list of symbols to export only in the future 2015-06-17 16:21:13 +02:00
libsystemd.pc.in Adjust pkgconfig files to point at rootlibdir (#4584) 2016-11-08 09:36:41 +01:00
libsystemd.sym sd-id128: add new sd_id128_get_machine_app_specific() API 2016-11-29 15:13:00 +01:00
Makefile libsystemd-bus: rename to libsystemd 2014-01-13 18:54:19 +01:00