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