]> git.ipfire.org Git - thirdparty/systemd.git/blame - docs/USERDB_AND_DESKTOPS.md
firstboot: Update help string with --root-shell options
[thirdparty/systemd.git] / docs / USERDB_AND_DESKTOPS.md
CommitLineData
b05e1220
LP
1---
2title: systemd-homed and JSON User/Group Record Support in Desktop Environments
5fe63895 3category: Users, Groups and Home Directories
b05e1220
LP
4layout: default
5---
6
7# `systemd-homed` and JSON User/Group Record Support in Desktop Environments
8
9Starting with version 245, systemd supports a new subsystem
10[`systemd-homed.service`](https://www.freedesktop.org/software/systemd/man/systemd-homed.service.html)
11for managing regular ("human") users and their home directories. Along with it
12a new concept `userdb` got merged that brings rich, extensible JSON user/group
13records, extending the classic UNIX/glibc NSS `struct passwd`/`struct group`
14structures. Both additions are added in a fully backwards compatible way,
15accessible through `getpwnam()`/`getgrnam()`/… (i.e. libc NSS) and PAM as
16usual, meaning that for basic support no changes in the upper layers of the
17stack (in particular desktop environments, such as GNOME or KDE) have to be
18made. However, for better support a number of changes to desktop environments
19are recommended. A few areas where that applies are discussed below.
20
21Before reading on, please read up on the basic concepts, specifically:
22
23* [Home Directories](https://systemd.io/HOME_DIRECTORY)
24* [JSON User Records](https://systemd.io/USER_RECORD)
25* [JSON Group Records](https://systemd.io/GROUP_RECORD)
26* [User/Group Record Lookup API via Varlink](https://systemd.io/USER_GROUP_API)
27
28## Support for Suspending Home Directory Access during System Suspend
29
30One key feature of `systemd-homed` managed encrypted home directories is the
31ability that access to them can be suspended automatically during system sleep,
32removing any cryptographic key material from memory while doing so. This is
33important in a world where most laptop users seldom shut down their computers
34but most of the time just suspend them instead. Previously, the encryption keys
35for the home directories remained in memory during system suspend, so that
36sufficiently equipped attackers could read them from there and gain full access
37to the device. By removing the key material from memory before suspend, and
38re-requesting it on resume this attack vector can be closed down effectively.
39
40Supporting this mechanism requires support in the desktop environment, since
41the encryption keys (i.e. the user's login password) need to be reacquired on
42system resume, from a lock screen or similar. This lock screen must run in
43system context, and cannot run in the user's own context, since otherwise it
44might end up accessing the home directory of the user even though access to it
45is temporarily suspended and thus will hang if attempted.
46
47It is suggested that desktop environments that implement lock screens run them
48from system context, for example by switching back to the display manager, and
49only revert back to the session after re-authentication via this system lock
50screen (re-authentication in this case refers to passing the user's login
51credentials to the usual PAM authentication hooks). Or in other words, when
52going into system suspend it is recommended that GNOME Shell switches back to
53the GNOME Display Manager login screen which now should double as screen lock,
54and only switches back to the shell's UI after the user re-authenticated there.
55
56Note that this change in behavior is a good idea in any case, and does not
57create any dependencies on `systemd-homed` or systemd-specific APIs. It's
58simply a change of behavior regarding use of existing APIs, not a suggested
59hook-up to a any new API.
60
61A display manager which supports this kind of out-of-context screen lock
62operation needs to inform systemd-homed about this so that systemd-homed knows
63that it is safe to suspend the user's home directory on suspend. This is done
64via the `suspend=` argument to the
65[`pam_systemd_home`](https://www.freedesktop.org/software/systemd/man/pam_systemd_home.html)
66PAM module. A display manager should hence change its PAM stack configuration
67to set this parameter to on. `systemd-homed` will not suspend home directories
68if there's at least one active session of the user that does not support
69suspending, as communicated via this parameter.
70
71## User Management UIs
72
73The rich user/group records `userdb` and `systemd-homed` support carry various
74fields of relevance to UIs that manage the local user database or parts
75thereof. In particular, most of the metadata `accounts-daemon` (also see below)
76supports is directly available in these JSON records. Hence it makes sense for
77any user management UI to expose them directly.
78
79`systemd-homed` exposes APIs to add, remove and make changes to local users via
98ab0dae
ZJS
80D-Bus, with full [polkit](https://www.freedesktop.org/software/polkit/docs/latest/)
81hook-up. On the command line this is exposed via the
b05e1220
LP
82`homectl` command. A graphical UI that exposes similar functionality would be
83very useful, exposing the various new account settings, and in particular
84providing a stream-lined UI for enrolling new-style authentication tokens such
85as PKCS#11/YubiKey-style devices. (Ideally, if the user plugs in an
86uninitialized YubiKey during operation it might be nice if the Desktop would
87automatically ask if a key pair shall be written to it and the local account be
88bound to it, `systemd-homed` provides enough YubiKey/PKCS#11 support to make
89this a reality today; except that it will not take care of token
90initialization).
91
92A strong point of `systemd-homed` is per-user resource management. In
93particular disk space assignments are something that most likely should be
94exposed in a user management UI. Various metadata fields are supplied allowing
95exposure of disk space assignment "slider" UI. Note however that the file system
96back-ends of `systemd-homed.service` have different feature sets. Specifically,
97only btrfs has online file system shrinking support, ext4 only offline file
98system shrinking support, and xfs no shrinking support at all (all three file
99systems support online file system growing however). This means if the LUKS
100back-end is used, disk space assignment cannot be instant for logged in users,
101unless btrfs is used.
102
103Note that only `systemd-homed` provides an API for modifying/creating/deleting
104users. The generic `userdb` subsystem (which might have other back-ends, besides
105`systemd-homed`, for example LDAP or Windows) exclusively provides a read-only
106interface. (This is unlikely to change, as the other back-ends might have very
107different concepts of adding or modifying users, i.e. might not even have any
108local concept for that at all). This means any user management UI that intends
109to change (and not just view) user accounts should talk directly to
110`systemd-homed` to make use of its features; there's no abstraction available
111to support other back-ends under the same API.
112
113Unfortunately there's currently no documentation for the `systemd-homed` D-Bus
114API. Consider using the `homectl` sources as guidelines for implementing a user
115management UI. The JSON user/records are well documented however, see above,
116and the D-Bus API provides limited introspection.
117
118## Relationship to `accounts-daemon`
119
120For a long time `accounts-daemon` has been included in Linux distributions
121providing richer user accounts. The functionality of this daemon overlaps in
122many areas with the functionality of `systemd-homed` or `userdb`, but there are
123systematic differences, which means that `systemd-homed` cannot replace
124`accounts-daemon` fully. Most importantly: `accounts-daemon` provides
125"side-car" metadata for *any* type of user account, while `systemd-homed` only
126provides additional metadata for the users it defines itself. In other words:
127`accounts-daemon` will augment foreign accounts; `systemd-homed` cannot be used
128to augment users defined elsewhere, for example in LDAP or as classic
129`/etc/passwd` records.
130
131This probably means that for the time being, a user management UI (or other UI)
132that wants to support rich user records with compatibility with the status quo
133ante should probably talk to both `systemd-homed` and `accounts-daemon` at the
134same time, and ignore `accounts-daemon`'s records if `systemd-homed` defines
135them. While I (Lennart) personally believe in the long run `systemd-homed` is
136the way to go for rich user records, any UI that wants to manage and support
137rich records for classic records has to support `accounts-daemon` in parallel
138for the time being.
139
140In the short term, it might make sense to also expose the `userdb` provided
141records via `accounts-daemon`, so that clients of the latter can consume them
142without changes. However, I think in the long run `accounts-daemon` should
143probably be removed from the general stack, hence this sounds like a temporary
144solution only.
145
146In case you wonder, there's no automatic mechanism for converting existing
147users registered in `/etc/passwd` or LDAP to users managed by
148`systemd-homed`. There's documentation for doing this manually though, see
149[Converting Existing Users to systemd-homed managed
150Users](https://systemd.io/CONVERTING_TO_HOMED).
151
152## Future Additions
153
154JSON user/group records are extensible, hence we can easily add any additional
155fields desktop environments require. For example pattern-based authentication
156is likely very useful on touch-based devices, and the user records should hence
157learn them natively. Fields for other authentication mechanisms, such as
158fingerprint authentication should be provided as well, eventually.
159
160It is planned to extend the `userdb` Varlink API to support look-ups by partial
161user name and real name (GECOS) data, so that log-in screens can optionally
162implement simple complete-as-you-type login screens.
163
164It is planned to extend the `systemd-homed` D-Bus API to instantly inform clients
165about hardware associated with a specific user being plugged in, to which login
166screens can listen in order to initiate authentication. Specifically, any
167YubiKey-like security token plugged in that is associated with a local user
168record should initiate authentication for that user, making typing in of the
169username unnecessary.