]> git.ipfire.org Git - thirdparty/systemd.git/blob - docs/USER_RECORD.md
hwdb: Lenovo IdeaPad Z500 Touchpad Toggle (#33039)
[thirdparty/systemd.git] / docs / USER_RECORD.md
1 ---
2 title: JSON User Records
3 category: Users, Groups and Home Directories
4 layout: default
5 SPDX-License-Identifier: LGPL-2.1-or-later
6 ---
7
8 # JSON User Records
9
10 systemd optionally processes user records that go beyond the classic UNIX (or glibc NSS) `struct passwd`.
11 Various components of systemd are able to provide and consume records in a more extensible format of a dictionary of key/value
12 pairs, encoded as JSON.
13
14 Specifically:
15
16 1. [`systemd-homed.service`](https://www.freedesktop.org/software/systemd/man/systemd-homed.service.html)
17 manages `human` user home directories and embeds these JSON records
18 directly in the home directory images
19 (see [Home Directories](/HOME_DIRECTORY) for details).
20
21 2. [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
22 processes these JSON records for users that log in, and applies various
23 settings to the activated session, including environment variables, nice
24 levels and more.
25
26 3. [`systemd-logind.service`](https://www.freedesktop.org/software/systemd/man/systemd-logind.service.html)
27 processes these JSON records of users that log in, and applies various
28 resource management settings to the per-user slice units it manages.
29 This allows setting global limits on resource consumption by a specific user.
30
31 4. [`nss-systemd`](https://www.freedesktop.org/software/systemd/man/nss-systemd.html)
32 is a glibc NSS module that synthesizes classic NSS records from these JSON
33 records, providing full backwards compatibility with the classic UNIX APIs
34 both for look-up and enumeration.
35
36 5. The service manager (PID 1) exposes dynamic users (i.e. users synthesized as
37 effect of `DynamicUser=` in service unit files) as these advanced JSON
38 records, making them discoverable to the rest of the system.
39
40 6. [`systemd-userdbd.service`](https://www.freedesktop.org/software/systemd/man/systemd-userdbd.service.html)
41 is a small service that can translate UNIX/glibc NSS records to these JSON user records.
42 It also provides a unified [Varlink](https://varlink.org/) API for querying and enumerating records of this type,
43 optionally acquiring them from various other services.
44
45 JSON user records may contain various fields that are not available in `struct
46 passwd`, and are extensible for other applications.
47 For example, the record may contain information about:
48
49 1. Additional security credentials (PKCS#11 security token information,
50 biometrical authentication information, SSH public key information)
51
52 2. Additional user metadata, such as a picture, email address, location string,
53 preferred language or timezone
54
55 3. Resource Management settings (such as CPU/IO weights, memory and tasks
56 limits, classic UNIX resource limits or nice levels)
57
58 4. Runtime parameters such as environment variables or the `nodev`, `noexec`,
59 `nosuid` flags to use for the home directory
60
61 5. Information about where to mount the home directory from
62
63 And various other things. The record is intended to be extensible, for example
64 the following extensions are envisioned:
65
66 1. Windows network credential information
67
68 2. Information about default IMAP, SMTP servers to use for this user
69
70 3. Parental control information to enforce on this user
71
72 4. Default parameters for backup applications and similar
73
74 Similar to JSON User Records there are also
75 [JSON Group Records](/GROUP_RECORD) that encapsulate UNIX groups.
76
77 JSON User Records are not suitable for storing all identity information about
78 the user, such as binary data or large unstructured blobs of text. These parts
79 of a user's identity should be stored in the [Blob Directories](/USER_RECORD_BLOB_DIRS).
80
81 JSON User Records may be transferred or written to disk in various protocols
82 and formats. To inquire about such records defined on the local system use the
83 [User/Group Lookup API via Varlink](/USER_GROUP_API). User/group records may
84 also be dropped in number of drop-in directories as files. See
85 [`nss-systemd(8)`](https://www.freedesktop.org/software/systemd/man/nss-systemd.html)
86 for details.
87
88 ## Why JSON?
89
90 JSON is nicely extensible and widely used.
91 In particular it's easy to synthesize and process with numerous programming languages.
92 It's particularly popular in the web communities, which hopefully should make it easy to link
93 user credential data from the web and from local systems more closely together.
94
95 Please note that this specification assumes that JSON numbers may cover the full
96 integer range of -2^63 … 2^64-1 without loss of precision (i.e. INT64_MIN … UINT64_MAX).
97 Please read, write and process user records as defined by this specification only with JSON implementations that provide this number range.
98
99 ## General Structure
100
101 The JSON user records generated and processed by systemd follow a general
102 structure, consisting of seven distinct "sections". Specifically:
103
104 1. Various fields are placed at the top-level of user record (the `regular` section).
105 These are generally fields that shall apply unconditionally to the
106 user in all contexts, are portable and not security sensitive.
107
108 2. A number of fields are located in the `privileged` section (a sub-object of the user record).
109 Fields contained in this object are security sensitive,
110 i.e. contain information that the user and the administrator should be able to see, but other users should not.
111 In many ways this matches the data stored in `/etc/shadow` in classic Linux user accounts, i.e. includes
112 password hashes and more.
113 Algorithmically, when a user record is passed to an untrusted client, by monopolizing such sensitive records in a single
114 object field we can easily remove it from view.
115
116 3. A number of fields are located in objects inside the `perMachine` section
117 (an array field of the user record).
118 Primarily these are resource management-related fields, as those tend to make sense on a specific system
119 only, e.g. limiting a user's memory use to 1G only makes sense on a specific
120 system that has more than 1G of memory.
121 Each object inside the `perMachine` array comes with a `matchMachineId` or `matchHostname` field which indicate
122 which systems to apply the listed settings to.
123 Note that many fields accepted in the `perMachine` section can also be set at the top level (the
124 `regular` section), where they define the fallback if no matching object in `perMachine` is found.
125
126 4. Various fields are located in the `binding` section (a sub-sub-object of the
127 user record; an intermediary object is inserted which is keyed by the
128 machine ID of the host).
129 Fields included in this section "bind" the object to a specific system.
130 They generally include non-portable information about paths or UID assignments,
131 that are true on a specific system, but not
132 necessarily on others, and which are managed automatically by some user
133 record manager (such as `systemd-homed`).
134 Data in this section is considered part of the user record only in the local context, and is generally not
135 ported to other systems.
136 Due to that it is not included in the reduced user record the cryptographic signature defined in the `signature` section is calculated on.
137 In `systemd-homed` this section is also removed when the user's record is stored in the `~/.identity` file in the home directory,
138 so that every system with access to the home directory can manage these
139 `binding` fields individually.
140 Typically, the binding section is persisted to the local disk.
141
142 5. Various fields are located in the `status` section (a sub-sub-object of the
143 user record, also with an intermediary object between that is keyed by the
144 machine ID, similar to the way the `binding` section is organized).
145 This section is augmented during runtime only, and never persisted to disk.
146 The idea is that this section contains information about current runtime
147 resource usage (for example: currently used disk space of the user), that
148 changes dynamically but is otherwise immediately associated with the user
149 record and for many purposes should be considered to be part of the user
150 record.
151
152 6. The `signature` section contains one or more cryptographic signatures of a
153 reduced version of the user record.
154 This is used to ensure that only user records defined by a specific source are accepted on a system, by validating
155 the signature against the set of locally accepted signature public keys.
156 The signature is calculated from the JSON user record with all sections removed,
157 except for `regular`, `privileged`, `perMachine`. Specifically, `binding`,
158 `status`, `signature` itself and `secret` are removed first and thus not covered by the signature.
159 This section is optional, and is only used when cryptographic validation of user records is required
160 (as it is by `systemd-homed.service` for example).
161
162 7. The `secret` section contains secret user credentials, such as password or PIN information.
163 This data is never persisted, and never returned when user records are inquired by a client, privileged or not.
164 This data should only be included in a user record very briefly, for example when certain very specific operations are executed.
165 For example, in tools such as `systemd-homed` this section may be included in user records, when creating
166 a new home directory, as passwords and similar credentials need to be
167 provided to encrypt the home directory with.
168
169 Here's a tabular overview of the sections and their properties:
170
171 | Section | Included in Signature | Persistent | Security Sensitive | Contains Host-Specific Data |
172 |------------|-----------------------|------------|--------------------|-----------------------------|
173 | regular | yes | yes | no | no |
174 | privileged | yes | yes | yes | no |
175 | perMachine | yes | yes | no | yes |
176 | binding | no | yes | no | yes |
177 | status | no | no | no | yes |
178 | signature | no | yes | no | no |
179 | secret | no | no | yes | no |
180
181 Note that services providing user records to the local system are free to
182 manage only a subset of these sections and never include the others in them.
183 For example, a service that has no concept of signed records (for example
184 because the records it manages are inherently trusted anyway) does not have to
185 bother with the `signature` section.
186 A service that only defines records in a strictly local context and without signatures doesn't have to deal with the
187 `perMachine` or `binding` sections and can include its data exclusively in the regular section.
188 A service that uses a separate, private channel for authenticating users (or that doesn't have a concept of authentication at all)
189 does not need to be concerned with the `secret` section of user records, as
190 the fields included therein are only useful when executing authentication
191 operations natively against JSON user records.
192
193 The `systemd-homed` manager uses all seven sections for various purposes.
194 Inside the home directories (and if the LUKS2 backend is used, also
195 in the LUKS2 header) a user record containing the `regular`, `privileged`,
196 `perMachine` and `signature` sections is stored. `systemd-homed` also stores a
197 version of the record on the host, with the same four sections and augmented
198 with an additional, fifth `binding` section.
199 When a local client enquires about a user record managed by `systemd-homed` the service will add in some
200 additional information about the user and home directory in the `status`
201 section — this version is only transferred via IPC and never written to disk.
202 Finally the `secret` section is used during authentication operations via
203 IPC to transfer the user record along with its authentication tokens in one go.
204
205 ## Fields in the `regular` section
206
207 As mentioned, the `regular` section's fields are placed at the top level object.
208 The following fields are currently defined:
209
210 `userName` → The UNIX user name for this record.
211 Takes a string with a valid UNIX user name.
212 This field is the only mandatory field, all others are optional.
213 Corresponds with the `pw_name` field of `struct passwd` and the `sp_namp` field of `struct spwd` (i.e. the shadow user record stored in `/etc/shadow`).
214 See [User/Group Name Syntax](/USER_NAMES)
215 for the (relaxed) rules the various systemd components enforce on user/group names.
216
217 `realm` → The "realm" a user is defined in.
218 This concept allows distinguishing users with the same name that originate in different organizations or installations.
219 This should take a string in DNS domain syntax, but doesn't have
220 to refer to an actual DNS domain (though it is recommended to use one for this).
221 The idea is that the user `lpoetter` in the `redhat.com` realm might be
222 distinct from the same user in the `poettering.hq` realm.
223 User records for the same user name that have different realm fields are considered referring to different users.
224 When updating a user record it is required that any new version has to match in both `userName` and `realm` field.
225 This field is optional, when unset the user should not be considered part of any realm.
226 A user record with a realm set is never compatible (for the purpose of updates,
227 see above) with a user record without one set, even if the `userName` field matches.
228
229 `blobDirectory` → The absolute path to a world-readable copy of the user's blob
230 directory. See [Blob Directories](/USER_RECORD_BLOB_DIRS) for more details.
231
232 `blobManifest` → An object, which maps valid blob directory filenames (see
233 [Blob Directories](/USER_RECORD_BLOB_DIRS) for requirements) to SHA256 hashes
234 formatted as hex strings. This exists for the purpose of including the contents
235 of the blob directory in the record's signature. Managers that support blob
236 directories and utilize signed user records (like `systemd-homed`) should use
237 this field to verify the contents of the blob directory whenever appropriate.
238
239 `realName` → The real name of the user, a string. This should contain the
240 user's real ("human") name, and corresponds loosely to the GECOS field of classic UNIX user records.
241 When converting a `struct passwd` to a JSON user record this field is initialized from GECOS (i.e. the `pw_gecos` field), and
242 vice versa when converting back.
243 That said, unlike GECOS this field is supposed to contain only the real name and no other information.
244 This field must not contain control characters (such as `\n`) or colons (`:`), since those are used
245 as record separators in classic `/etc/passwd` files and similar formats.
246
247 `emailAddress` → The email address of the user, formatted as string.
248 [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
249 initializes the `$EMAIL` environment variable from this value for all login
250 sessions.
251
252 `iconName` → The name of an icon picked by the user, for example for the
253 purpose of an avatar.
254 This must be a string, and should follow the semantics defined in the
255 [Icon Naming Specification](https://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html).
256
257 `location` → A free-form location string describing the location of the user, if that is applicable.
258 It's probably wise to use a location string processable by geo-location subsystems, but this is not enforced nor required.
259 Example: `Berlin, Germany` or `Basement, Room 3a`.
260
261 `disposition` → A string, one of `intrinsic`, `system`, `dynamic`, `regular`,
262 `container`, `reserved`. If specified clarifies the disposition of the user,
263 i.e. the context it is defined in.
264 For regular, "human" users this should be `regular`, for system users (i.e. users that system services run under, and similar) this should be `system`.
265 The `intrinsic` disposition should be used only for the two users that have special meaning to the OS kernel itself,
266 i.e. the `root` and `nobody` users.
267 The `container` string should be used for users that are used by an OS container, and hence will show up in `ps` listings
268 and such, but are only defined in container context.
269 Finally `reserved` should be used for any users outside of these use-cases.
270 Note that this property is entirely optional and applications are assumed to be able to derive the
271 disposition of a user automatically from a record even in absence of this
272 field, based on other fields, for example the numeric UID. By setting this
273 field explicitly applications can override this default determination.
274
275 `lastChangeUSec` → An unsigned 64-bit integer value, referring to a timestamp in µs
276 since the epoch 1970, indicating when the user record (specifically, any of the
277 `regular`, `privileged`, `perMachine` sections) was last changed.
278 This field is used when comparing two records of the same user to identify the newer one, and
279 is used for example for automatic updating of user records, where appropriate.
280
281 `lastPasswordChangeUSec` → Similar, also an unsigned 64-bit integer value,
282 indicating the point in time the password (or any authentication token) of the user was last changed.
283 This corresponds to the `sp_lstchg` field of `struct spwd`, i.e. the matching field in the user shadow database `/etc/shadow`,
284 though provides finer resolution.
285
286 `shell` → A string, referring to the shell binary to use for terminal logins of this user.
287 This corresponds with the `pw_shell` field of `struct passwd`, and should contain an absolute file system path.
288 For system users not suitable for terminal log-in this field should not be set.
289
290 `umask` → The `umask` to set for the user's login sessions.
291 Takes an integer. Note that usually on UNIX the umask is noted in octal, but JSON's
292 integers are generally written in decimal, hence in this context we denote it umask in decimal too.
293 The specified value should be in the valid range for umasks, i.e. 0000…0777 (in octal as typical in UNIX), or 0…511 (in decimal, how
294 it actually appears in the JSON record).
295 This `umask` is automatically set by [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
296 for all login sessions of the user.
297
298 `environment` → An array of strings, each containing an environment variable
299 and its value to set for the user's login session, in a format compatible with
300 [`putenv()`](https://man7.org/linux/man-pages/man3/putenv.3.html). Any
301 environment variable listed here is automatically set by
302 [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
303 for all login sessions of the user.
304 `timeZone` → A string indicating a preferred timezone to use for the user. When
305 logging in
306 [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
307 will automatically initialize the `$TZ` environment variable from this
308 string.
309 The string should be a `tzdata` compatible location string, for example: `Europe/Berlin`.
310
311 `preferredLanguage` → A string indicating the preferred language/locale for the
312 user. It is combined with the `additionalLanguages` field to initialize the `$LANG`
313 and `$LANGUAGE` environment variables on login; see below for more details. This string
314 should be in a format compatible with the `$LANG` environment variable, for example:
315 `de_DE.UTF-8`.
316
317 `additionalLanguages` → An array of strings indicating the preferred languages/locales
318 that should be used in the event that translations for the `preferredLanguage` are
319 missing, listed in order of descending priority. This allows multi-lingual users to
320 specify all the languages that they know, so software lacking translations in the user's
321 primary language can try another language that the user knows rather than falling back to
322 the default English. All entries in this field must be valid locale names, compatible with
323 the `$LANG` variable, for example: `de_DE.UTF-8`. When logging in
324 [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
325 will prepend `preferredLanguage` (if set) to this list (if set), remove duplicates,
326 and then automatically initialize the `$LANGUAGE` variable with the resulting list.
327 It will also initialize `$LANG` variable with the first entry in the resulting list.
328
329 `niceLevel` → An integer value in the range -20…19. When logging in
330 [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
331 will automatically initialize the login process' nice level to this value with,
332 which is then inherited by all the user's processes, see
333 [`setpriority()`](https://man7.org/linux/man-pages/man2/setpriority.2.html) for
334 more information.
335 `resourceLimits` → An object, where each key refers to a Linux resource limit
336 (such as `RLIMIT_NOFILE` and similar).
337 Their values should be an object with two keys `cur` and `max` for the soft and hard resource limit.
338 When logging in
339 [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
340 will automatically initialize the login process' resource limits to these
341 values, which is then inherited by all the user's processes, see
342 [`setrlimit()`](https://man7.org/linux/man-pages/man2/setrlimit.2.html) for more
343 information.
344
345 `locked` → A boolean value. If true, the user account is locked, the user may
346 not log in. If this field is missing it should be assumed to be false,
347 i.e. logins are permitted.
348 This field corresponds to the `sp_expire` field of `struct spwd` (i.e. the `/etc/shadow` data for a user) being set to zero or one.
349
350 `notBeforeUSec` → An unsigned 64-bit integer value, indicating a time in µs since
351 the UNIX epoch (1970) before which the record should be considered invalid for
352 the purpose of logging in.
353
354 `notAfterUSec` → Similar, but indicates the point in time *after* which logins
355 shall not be permitted anymore.
356 This corresponds to the `sp_expire` field of `struct spwd`, when it is set to a value larger than one, but provides finer granularity.
357
358 `storage` → A string, one of `classic`, `luks`, `directory`, `subvolume`,
359 `fscrypt`, `cifs`.
360 Indicates the storage mechanism for the user's home directory. If `classic` the home directory is a plain directory as in classic
361 UNIX. When `directory`, the home directory is a regular directory, but the
362 `~/.identity` file in it contains the user's user record, so that the directory
363 is self-contained. Similar, `subvolume` is a `btrfs` subvolume that also
364 contains a `~/.identity` user record; `fscrypt` is an `fscrypt`-encrypted
365 directory, also containing the `~/.identity` user record; `luks` is a per-user
366 LUKS volume that is mounted as home directory, and `cifs` a home directory mounted from a Windows File Share.
367 The five latter types are primarily used by `systemd-homed` when managing home directories, but may be used if other
368 managers are used too. If this is not set, `classic` is the implied default.
369
370 `diskSize` → An unsigned 64-bit integer, indicating the intended home directory
371 disk space in bytes to assign to the user.
372 Depending on the selected storage type this might be implemented differently:
373 for `luks` this is the intended size of the file system and LUKS volume, while for the others this likely translates
374 to classic file system quota settings.
375
376 `diskSizeRelative` → Similar to `diskSize` but takes a relative value, but
377 specifies a fraction of the available disk space on the selected storage medium to assign to the user.
378 This unsigned integer value is normalized to 2^32 = 100%.
379
380 `skeletonDirectory` → Takes a string with the absolute path to the skeleton
381 directory to populate a new home directory from.
382 This is only used when a home directory is first created, and defaults to `/etc/skel` if not defined.
383
384 `accessMode` → Takes an unsigned integer in the range 0…511 indicating the UNIX
385 access mask for the home directory when it is first created.
386
387 `tasksMax` → Takes an unsigned 64-bit integer indicating the maximum number of
388 tasks the user may start in parallel during system runtime.
389 This counts all tasks (i.e. threads, where each process is at least one thread) the user starts or that are
390 forked from these processes even if the user identity is changed (for example by setuid binaries/`su`/`sudo` and similar).
391 [`systemd-logind.service`](https://www.freedesktop.org/software/systemd/man/systemd-logind.service.html)
392 enforces this by setting the `TasksMax` slice property for the user's slice
393 `user-$UID.slice`.
394
395 `memoryHigh`/`memoryMax` → These take unsigned 64-bit integers indicating upper
396 memory limits for all processes of the user (plus all processes forked off them
397 that might have changed user identity),
398 in bytes. Enforced by
399 [`systemd-logind.service`](https://www.freedesktop.org/software/systemd/man/systemd-logind.service.html),
400 similar to `tasksMax`.
401
402 `cpuWeight`/`ioWeight` → These take unsigned integers in the range 1…10000
403 (defaults to 100) and configure the CPU and IO scheduling weights for the
404 user's processes as a whole.
405 Also enforced by
406 [`systemd-logind.service`](https://www.freedesktop.org/software/systemd/man/systemd-logind.service.html),
407 similar to `tasksMax`, `memoryHigh` and `memoryMax`.
408
409 `mountNoDevices`/`mountNoSuid`/`mountNoExecute` → Three booleans that control
410 the `nodev`, `nosuid`, `noexec` mount flags of the user's home
411 directories.
412 Note that these booleans are only honored if the home directory is managed by a subsystem such as `systemd-homed.service` that automatically
413 mounts home directories on login.
414
415 `cifsDomain` → A string indicating the Windows File Sharing domain (CIFS) to use.
416 This is generally useful, but particularly when `cifs` is used as storage
417 mechanism for the user's home directory, see above.
418
419 `cifsUserName` → A string indicating the Windows File Sharing user name (CIFS)
420 to associate this user record with.
421 This is generally useful, but particularly useful when `cifs` is used as storage mechanism for the user's home directory, see above.
422
423 `cifsService` → A string indicating the Windows File Share service (CIFS) to
424 mount as home directory of the user on login.
425 Should be in format `//<host>/<service>/<directory/…>`.
426 The directory part is optional. If missing the top-level directory of the CIFS share is used.
427
428 `cifsExtraMountOptions` → A string with additional mount options to pass to
429 `mount.cifs` when mounting the home directory CIFS share.
430
431 `imagePath` → A string with an absolute file system path to the file, directory
432 or block device to use for storage backing the home directory.
433 If the `luks` storage is used, this refers to the loopback file or block device node to store the LUKS volume on.
434 For `fscrypt`, `directory`, `subvolume` this refers to the directory to bind mount as home directory on login.
435 Not defined for `classic` or `cifs`.
436
437 `homeDirectory` → A string with an absolute file system path to the home directory.
438 This is where the image indicated in `imagePath` is mounted to on login and thus indicates the application facing home directory while the home
439 directory is active, and is what the user's `$HOME` environment variable is set to during log-in.
440 It corresponds to the `pw_dir` field of `struct passwd`.
441
442 `uid` → An unsigned integer in the range 0…4294967295: the numeric UNIX user ID (UID) to use for the user.
443 This corresponds to the `pw_uid` field of `struct passwd`.
444
445 `gid` → An unsigned integer in the range 0…4294967295: the numeric UNIX group ID (GID) to use for the user.
446 This corresponds to the `pw_gid` field of `struct passwd`.
447
448 `memberOf` → An array of strings, each indicating a UNIX group this user shall be a member of.
449 The listed strings must be valid group names, but it is not required that all groups listed exist in all contexts: any entry for which no
450 group exists should be silently ignored.
451
452 `fileSystemType` → A string, one of `ext4`, `xfs`, `btrfs` (possibly others) to
453 use as file system for the user's home directory.
454 This is primarily relevant when the storage mechanism used is `luks` as a file system to use inside the
455 LUKS container must be selected.
456
457 `partitionUuid` → A string containing a lower-case, text-formatted UUID, referencing
458 the GPT partition UUID the home directory is located in.
459 This is primarily relevant when the storage mechanism used is `luks`.
460
461 `luksUuid` → A string containing a lower-case, text-formatted UUID, referencing
462 the LUKS volume UUID the home directory is located in. This is primarily
463 relevant when the storage mechanism used is `luks`.
464
465 `fileSystemUuid` → A string containing a lower-case, text-formatted UUID,
466 referencing the file system UUID the home directory is located in. This is
467 primarily relevant when the storage mechanism used is `luks`.
468
469 `luksDiscard` → A boolean. If true and `luks` storage is used, controls whether
470 the loopback block devices, LUKS and the file system on top shall be used in
471 `discard` mode, i.e. erased sectors should always be returned to the underlying storage.
472 If false and `luks` storage is used turns this behavior off.
473 In addition, depending on this setting an `FITRIM` or `fallocate()` operation is
474 executed to make sure the image matches the selected option.
475
476 `luksOfflineDiscard` → A boolean. Similar to `luksDiscard`, it controls whether
477 to trim/allocate the file system/backing file when deactivating the home
478 directory.
479
480 `luksExtraMountOptions` → A string with additional mount options to append to
481 the default mount options for the file system in the LUKS volume.
482
483 `luksCipher` → A string, indicating the cipher to use for the LUKS storage mechanism.
484
485 `luksCipherMode` → A string, selecting the cipher mode to use for the LUKS storage mechanism.
486
487 `luksVolumeKeySize` → An unsigned integer, indicating the volume key length in
488 bytes to use for the LUKS storage mechanism.
489
490 `luksPbkdfHashAlgorithm` → A string, selecting the hash algorithm to use for
491 the PBKDF operation for the LUKS storage mechanism.
492
493 `luksPbkdfType` → A string, indicating the PBKDF type to use for the LUKS storage mechanism.
494
495 `luksPbkdfForceIterations` → An unsigned 64-bit integer, indicating the intended
496 number of iterations for the PBKDF operation, when LUKS storage is used.
497
498 `luksPbkdfTimeCostUSec` → An unsigned 64-bit integer, indicating the intended
499 time cost for the PBKDF operation, when the LUKS storage mechanism is used, in
500 µs. Ignored when `luksPbkdfForceIterations` is set.
501
502 `luksPbkdfMemoryCost` → An unsigned 64-bit integer, indicating the intended
503 memory cost for the PBKDF operation, when LUKS storage is used, in bytes.
504
505 `luksPbkdfParallelThreads` → An unsigned 64-bit integer, indicating the intended
506 required parallel threads for the PBKDF operation, when LUKS storage is used.
507
508 `luksSectorSize` → An unsigned 64-bit integer, indicating the sector size to use for the LUKS storage mechanism, in bytes.
509 Must be a power of two between 512 and 4096.
510
511 `autoResizeMode` → A string, one of `off`, `grow`, `shrink-and-grow`.
512 Unless set to `off`, controls whether the home area shall be grown automatically to
513 the size configured in `diskSize` automatically at login time.
514 If set to `shrink-and-grown` the home area is also shrunk to the minimal size possible
515 (as dictated by used disk space and file system constraints) on logout.
516
517 `rebalanceWeight` → An unsigned integer, `null` or a boolean.
518 Configures the free disk space rebalancing weight for the home area.
519 The integer must be in the range 1…10000 to configure an explicit weight.
520 If unset, or set to `null` or `true` the default weight of 100 is implied.
521 If set to 0 or `false` rebalancing is turned off for this home area.
522
523 `service` → A string declaring the service that defines or manages this user record.
524 It is recommended to use reverse domain name notation for this.
525 For example, if `systemd-homed` manages a user a string of `io.systemd.Home` is used for this.
526
527 `rateLimitIntervalUSec` → An unsigned 64-bit integer that configures the
528 authentication rate limiting enforced on the user account.
529 This specifies a timer interval (in µs) within which to count authentication attempts.
530 When the counter goes above the value configured n `rateLimitIntervalBurst` log-ins are
531 temporarily refused until the interval passes.
532
533 `rateLimitIntervalBurst` → An unsigned 64-bit integer, closely related to
534 `rateLimitIntervalUSec`, that puts a limit on authentication attempts within
535 the configured time interval.
536
537 `enforcePasswordPolicy` → A boolean.
538 Configures whether to enforce the system's password policy when creating the home directory for the user or changing the user's password.
539 By default the policy is enforced, but if this field is false it is bypassed.
540
541 `autoLogin` → A boolean.
542 If true the user record is marked as suitable for auto-login.
543 Systems are supposed to automatically log in a user marked this way during boot, if there's exactly one user on it defined this way.
544
545 `preferredSessionType` → A string that indicates the user's preferred session type
546 (i.e. `x11`, `wayland`, or other values valid for `$XDG_SESSION_TYPE`). This should
547 be used by the display manager to pre-select the correct environment to log into.
548
549 `preferredSessionLauncher` → A string that indicates the user's preferred session launcher
550 desktop entry file (i.e. `gnome`, `gnome-classic`, `plasma`, `kodi`, or others that appear
551 in `/usr/share/xsessions/` or `/usr/share/wayland-sessions/`). This should be used by the
552 display manager to pre-select the correct environment to launch when the user logs in.
553
554 `stopDelayUSec` → An unsigned 64-bit integer, indicating the time in µs the
555 per-user service manager is kept around after the user fully logged out. This
556 value is honored by
557 [`systemd-logind.service`](https://www.freedesktop.org/software/systemd/man/systemd-logind.service.html). If
558 set to zero the per-user service manager is immediately terminated when the
559 user logs out, and longer values optimize high-frequency log-ins as the
560 necessary work to set up and tear down a log-in is reduced if the service manager stays running.
561
562 `killProcesses` → A boolean.
563 If true all processes of the user are automatically killed when the user logs out.
564 This is enforced by
565 [`systemd-logind.service`](https://www.freedesktop.org/software/systemd/man/systemd-logind.service.html).
566 If false any processes left around when the user logs out are left running.
567
568 `passwordChangeMinUSec`/`passwordChangeMaxUSec` → An unsigned 64-bit integer,
569 encoding how much time has to pass at least/at most between password changes of the user.
570 This corresponds with the `sp_min` and `sp_max` fields of `struct spwd` (i.e. the `/etc/shadow` entries of the user), but offers finer granularity.
571
572 `passwordChangeWarnUSec` → An unsigned 64-bit integer, encoding how much time to
573 warn the user before their password expires, in µs.
574 This corresponds with the `sp_warn` field of `struct spwd`.
575
576 `passwordChangeInactiveUSec` → An unsigned 64-bit integer, encoding how much
577 time has to pass after the password expired that the account is deactivated.
578 This corresponds with the `sp_inact` field of `struct spwd`.
579
580 `passwordChangeNow` → A boolean.
581 If true the user has to change their password on next login.
582 This corresponds with the `sp_lstchg` field of `struct spwd` being set to zero.
583
584 `pkcs11TokenUri` → An array of strings, each with an RFC 7512 compliant PKCS#11
585 URI referring to security token (or smart card) of some form, that shall be
586 associated with the user and may be used for authentication.
587 The URI is used to search for an X.509 certificate and associated private key that may be used to
588 decrypt an encrypted secret key that is used to unlock the user's account (see below).
589 It's undefined how precise the URI is: during log-in it is tested against all plugged in security tokens and if there's exactly one matching
590 private key found with it it is used.
591
592 `fido2HmacCredential` → An array of strings,each with a Base64-encoded FIDO2
593 credential ID that shall be used for authentication with FIDO2 devices that implement the `hmac-secret` extension.
594 The salt to pass to the FIDO2 device is found in `fido2HmacSalt`.
595
596 `recoveryKeyType` → An array of strings, each indicating the type of one recovery key.
597 The only supported recovery key type at the moment is `modhex64`, for details see the description of `recoveryKey` below.
598 An account may have any number of recovery keys defined, and the array should have one entry for each.
599
600 `privileged` → An object, which contains the fields of the `privileged` section
601 of the user record, see below.
602
603 `perMachine` → An array of objects, which contain the `perMachine` section of
604 the user record, and thus fields to apply on specific systems only, see below.
605
606 `binding` → An object, keyed by machine IDs formatted as strings, pointing
607 to objects that contain the `binding` section of the user record,
608 i.e. additional fields that bind the user record to a specific machine, see
609 below.
610
611 `status` → An object, keyed by machine IDs formatted as strings, pointing to
612 objects that contain the `status` section of the user record, i.e. additional
613 runtime fields that expose the current status of the user record on a specific
614 system, see below.
615
616 `signature` → An array of objects, which contain cryptographic signatures of
617 the user record, i.e. the fields of the `signature` section of the user record,
618 see below.
619
620 `secret` → An object, which contains the fields of the `secret` section of the
621 user record, see below.
622
623 ## Fields in the `privileged` section
624
625 As mentioned, the `privileged` section is encoded in a sub-object of the user
626 record top-level object, in the `privileged` field.
627 Any data included in this object shall only be visible to the administrator and the user themselves,
628 and be suppressed implicitly when other users get access to a user record.
629 It thus takes the role of the `/etc/shadow` records for each user, which has similarly restrictive access semantics.
630 The following fields are currently defined:
631
632 `passwordHint` → A user-selected password hint in free-form text.
633 This should be a string like "What's the name of your first pet?", but is entirely for the user to choose.
634
635 `hashedPassword` → An array of strings, each containing a hashed UNIX password
636 string, in the format
637 [`crypt(3)`](https://man7.org/linux/man-pages/man3/crypt.3.html) generates.
638 This corresponds with `sp_pwdp` field of `struct spwd` (and in a way the `pw_passwd`
639 field of `struct passwd`).
640
641 `sshAuthorizedKeys` → An array of strings, each listing an SSH public key that
642 is authorized to access the account.
643 The strings should follow the same format as the lines in the traditional `~/.ssh/authorized_keys` file.
644
645 `pkcs11EncryptedKey` → An array of objects.
646 Each element of the array should be an object consisting of three string fields: `uri` shall contain a PKCS#11
647 security token URI, `data` shall contain a Base64-encoded encrypted key and
648 `hashedPassword` shall contain a UNIX password hash to test the key against.
649 Authenticating with a security token against this account shall work
650 as follows: the encrypted secret key is converted from its Base64
651 representation into binary, then decrypted with the PKCS#11 `C_Decrypt()`
652 function of the PKCS#11 module referenced by the specified URI, using the private key found on the same token.
653 The resulting decrypted key is then Base64-encoded and tested against the specified UNIX hashed password.
654 The Base64-encoded decrypted key may also be used to unlock further resources
655 during log-in, for example the LUKS or `fscrypt` storage backend.
656 It is generally recommended that for each entry in `pkcs11EncryptedKey` there's also
657 a matching one in `pkcs11TokenUri` and vice versa, with the same URI, appearing
658 in the same order, but this should not be required by applications processing
659 user records.
660
661 `fido2HmacSalt` → An array of objects, implementing authentication support with
662 FIDO2 devices that implement the `hmac-secret` extension.
663 Each element of the array should be an object consisting of three string fields: `credential`,
664 `salt`, `hashedPassword`, and three boolean fields: `up`, `uv` and `clientPin`.
665 The first two string fields shall contain Base64-encoded binary
666 data: the FIDO2 credential ID and the salt value to pass to the FIDO2 device.
667 During authentication this salt along with the credential ID is sent to
668 the FIDO2 token, which will HMAC hash the salt with its internal secret key and return the result.
669 This resulting binary key should then be Base64-encoded and used as string password for the further layers of the stack.
670 The `hashedPassword` field of the `fido2HmacSalt` field shall be a UNIX password
671 hash to test this derived secret key against for authentication.
672 The `up`, `uv` and `clientPin` booleans map to the FIDO2 concepts of the same name and encode
673 whether the `uv`/`up` options are enabled during the authentication, and whether a PIN shall be required.
674 It is generally recommended that for each entry in `fido2HmacSalt` there's also a matching one in `fido2HmacCredential`,
675 and vice versa, with the same credential ID, appearing in the same order,
676 but this should not be required by applications processing user records.
677
678 `recoveryKey`→ An array of objects, each defining a recovery key.
679 The object has two mandatory fields: `type` indicates the type of recovery key.
680 The only currently permitted value is the string `modhex64`.
681 The `hashedPassword` field contains a UNIX password hash of the normalized recovery key.
682 Recovery keys are in most ways similar to regular passwords, except that they are generated by
683 the computer, not chosen by the user, and are longer.
684 Currently, the only supported recovery key format is `modhex64`, which consists of 64
685 [modhex](https://developers.yubico.com/yubico-c/Manuals/modhex.1.html)
686 characters (i.e. 256bit of information), in groups of 8 chars separated by
687 dashes,
688 e.g. `lhkbicdj-trbuftjv-tviijfck-dfvbknrh-uiulbhui-higltier-kecfhkbk-egrirkui`.
689 Recovery keys should be accepted wherever regular passwords are.
690 The `recoveryKey` field should always be accompanied by a `recoveryKeyType` field (see above), and each
691 entry in either should map 1:1 to an entry in the other, in the same order and
692 matching the type. When accepting a recovery key it should be brought
693 automatically into normalized form, i.e. the dashes inserted when missing, and
694 converted into lowercase before tested against the UNIX password hash, so that
695 recovery keys are effectively case-insensitive.
696
697 ## Fields in the `perMachine` section
698
699 As mentioned, the `perMachine` section contains settings that shall apply to specific systems only.
700 This is primarily interesting for resource management properties as they tend to require a per-system focus,
701 however they may be used for other purposes too.
702
703 The `perMachine` field in the top-level object is an array of objects.
704 When processing the user record first the various fields on the top-level object should be parsed.
705 Then, the `perMachine` array should be iterated in order, and
706 the various settings within each contained object should be applied that match
707 either the indicated machine ID or host name, overriding any corresponding
708 settings previously parsed from the top-level object.
709 There may be multiple array entries that match a specific system, in which case all settings should be applied.
710 If the same option is set in the top-level object as in a
711 per-machine object then the per-machine setting wins and entirely undoes the
712 setting in the top-level object (i.e. no merging of properties that are arrays is done).
713 If the same option is set in multiple per-machine objects the one
714 specified later in the array wins (and here too no merging of individual fields
715 is done, the later field always wins in full).
716 To summarize, the order of application is (last one wins):
717
718 1. Settings in the top-level object
719 2. Settings in the first matching `perMachine` array entry
720 3. Settings in the second matching `perMachine` array entry
721 4. …
722 5. Settings in the last matching `perMachine` array entry
723
724 The following fields are defined in this section:
725
726 `matchMachineId` → An array of strings that are formatted 128-bit IDs in hex.
727 If any of the specified IDs match the system's local machine ID
728 (i.e. matches `/etc/machine-id`) the fields in this object are honored.
729 (As a special case, if only a single machine ID is listed this field may be a single
730 string rather than an array of strings.)
731
732 `matchHostname` → An array of strings that are valid hostnames.
733 If any of the specified hostnames match the system's local hostname, the fields in this object are honored.
734 If both `matchHostname` and `matchMachineId` are used within the same array entry, the object is honored when either match succeeds,
735 i.e. the two match types are combined in OR, not in AND.
736 (As a special case, if only a single hostname is listed this field may be a single string rather than an array of strings.)
737
738 These two are the only two fields specific to this section.
739 All other fields that may be used in this section are identical to the equally named ones in the
740 `regular` section (i.e. at the top-level object). Specifically, these are:
741
742 `blobDirectory`, `blobManifest`, `iconName`, `location`, `shell`, `umask`, `environment`, `timeZone`,
743 `preferredLanguage`, `additionalLanguages`, `niceLevel`, `resourceLimits`, `locked`, `notBeforeUSec`,
744 `notAfterUSec`, `storage`, `diskSize`, `diskSizeRelative`, `skeletonDirectory`,
745 `accessMode`, `tasksMax`, `memoryHigh`, `memoryMax`, `cpuWeight`, `ioWeight`,
746 `mountNoDevices`, `mountNoSuid`, `mountNoExecute`, `cifsDomain`,
747 `cifsUserName`, `cifsService`, `cifsExtraMountOptions`, `imagePath`, `uid`,
748 `gid`, `memberOf`, `fileSystemType`, `partitionUuid`, `luksUuid`,
749 `fileSystemUuid`, `luksDiscard`, `luksOfflineDiscard`, `luksCipher`,
750 `luksCipherMode`, `luksVolumeKeySize`, `luksPbkdfHashAlgorithm`,
751 `luksPbkdfType`, `luksPbkdfForceIterations`, `luksPbkdfTimeCostUSec`, `luksPbkdfMemoryCost`,
752 `luksPbkdfParallelThreads`, `luksSectorSize`, `autoResizeMode`, `rebalanceWeight`,
753 `rateLimitIntervalUSec`, `rateLimitBurst`, `enforcePasswordPolicy`,
754 `autoLogin`, `preferredSessionType`, `preferredSessionLauncher`, `stopDelayUSec`, `killProcesses`,
755 `passwordChangeMinUSec`, `passwordChangeMaxUSec`, `passwordChangeWarnUSec`,
756 `passwordChangeInactiveUSec`, `passwordChangeNow`, `pkcs11TokenUri`,
757 `fido2HmacCredential`.
758
759 ## Fields in the `binding` section
760
761 As mentioned, the `binding` section contains additional fields about the user record, that bind it to the local system.
762 These fields are generally used by a local user manager (such as `systemd-homed.service`) to add in fields that make
763 sense in a local context but not necessarily in a global one.
764 For example, a user record that contains no `uid` field in the regular section is likely
765 extended with one in the `binding` section to assign a local UID if no global
766 UID is defined.
767
768 All fields in the `binding` section only make sense in a local context and are
769 suppressed when the user record is ported between systems.
770 The `binding` section is generally persisted on the system but not in the home directories themselves
771 and the home directory is supposed to be fully portable and thus not contain
772 the information that `binding` is supposed to contain that binds the portable
773 record to a specific system.
774
775 The `binding` sub-object on the top-level user record object is keyed by the
776 machine ID the binding is intended for, which point to an object with the fields of the bindings.
777 These fields generally match fields that may also be defined in the `regular` and `perMachine` sections, however override both.
778 Usually, the `binding` value should not contain settings different from
779 those set via `regular` or `perMachine`, however this might happen if some
780 settings are not supported locally (think: `fscrypt` is recorded as intended
781 storage mechanism in the `regular` section, but the local kernel does not
782 support `fscrypt`, hence `directory` was chosen as implicit fallback), or have
783 been changed in the `regular` section through updates (e.g. a home directory
784 was created with `luks` as storage mechanism but later the user record was
785 updated to prefer `subvolume`, which however doesn't change the actual storage
786 used already which is pinned in the `binding` section).
787
788 The following fields are defined in the `binding` section.
789 They all have an identical format and override their equally named counterparts in the `regular`
790 and `perMachine` sections:
791
792 `blobDirectory`, `imagePath`, `homeDirectory`, `partitionUuid`, `luksUuid`,
793 `fileSystemUuid`, `uid`, `gid`, `storage`, `fileSystemType`, `luksCipher`,
794 `luksCipherMode`, `luksVolumeKeySize`.
795
796 ## Fields in the `status` section
797
798 As mentioned, the `status` section contains additional fields about the user
799 record that are exclusively acquired during runtime, and that expose runtime
800 metrics of the user and similar metadata that shall not be persisted but are
801 only acquired "on-the-fly" when requested.
802
803 This section is arranged similarly to the `binding` section: the `status`
804 sub-object of the top-level user record object is keyed by the machine ID,
805 which points to the object with the fields defined here.
806 The following fields are defined:
807
808 `diskUsage` → An unsigned 64-bit integer.
809 The currently used disk space of the home directory in bytes.
810 This value might be determined in different ways, depending on the selected storage mechanism.
811 For LUKS storage this is the file size of the loopback file or block device size.
812 For the directory/subvolume/fscrypt storage this is the current disk space used as
813 reported by the file system quota subsystem.
814
815 `diskFree` → An unsigned 64-bit integer, denoting the number of "free" bytes in
816 the disk space allotment, i.e. usually the difference between the disk size as
817 reported by `diskSize` and the used already as reported in `diskFree`, but
818 possibly skewed by metadata sizes, disk compression and similar.
819
820 `diskSize` → An unsigned 64-bit integer, denoting the disk space currently
821 allotted to the user, in bytes. Depending on the storage mechanism this can mean different things (see above).
822 In contrast to the top-level field of the same (or the one in the `perMachine` section),
823 this field reports the current size allotted to the user, not the intended one.
824 The values may differ when user records are updated without the home directory being re-sized.
825
826 `diskCeiling`/`diskFloor` → Unsigned 64-bit integers indicating upper and lower
827 bounds when changing the `diskSize` value, in bytes.
828 These values are typically derived from the underlying data storage, and indicate in which range the home
829 directory may be re-sized in, i.e. in which sensible range the `diskSize` value should be kept.
830
831 `state` → A string indicating the current state of the home directory.
832 The precise set of values exposed here are up to the service managing the home
833 directory to define (i.e. are up to the service identified with the `service` field below).
834 However, it is recommended to stick to a basic vocabulary here:
835 `inactive` for a home directory currently not mounted, `absent` for a home
836 directory that cannot be mounted currently because it does not exist on the
837 local system, `active` for a home directory that is currently mounted and
838 accessible.
839
840 `service` → A string identifying the service that manages this user record.
841 For example `systemd-homed.service` sets this to `io.systemd.Home` to all user records it manages.
842 This is particularly relevant to define clearly the context in which `state` lives, see above.
843 Note that this field also exists on the top-level object (i.e. in the `regular` section), which it overrides.
844 The `regular` field should be used if conceptually the user record can only be managed by the specified service,
845 and this `status` field if it can conceptually be managed by different managers, but currently is managed by the
846 specified one.
847
848 `signedLocally` → A boolean.
849 If true indicates that the user record is signed by a public key for which the private key is available locally.
850 This means that the user record may be modified locally as it can be re-signed with the private key.
851 If false indicates that the user record is signed by a public key recognized by the local manager but whose private key is not available locally.
852 This means the user record cannot be modified locally as it couldn't be signed afterwards.
853
854 `goodAuthenticationCounter` → An unsigned 64-bit integer.
855 This counter is increased by one on every successful authentication attempt, i.e. an
856 authentication attempt where a security token of some form was presented and it was correct.
857
858 `badAuthenticationCounter` → An unsigned 64-bit integer.
859 This counter is increased by one on every unsuccessfully authentication attempt, i.e. an
860 authentication attempt where a security token of some form was presented and it
861 was incorrect.
862
863 `lastGoodAuthenticationUSec` → An unsigned 64-bit integer, indicating the time
864 of the last successful authentication attempt in µs since the UNIX epoch (1970).
865
866 `lastBadAuthenticationUSec` → Similar, but the timestamp of the last
867 unsuccessfully authentication attempt.
868
869 `rateLimitBeginUSec` → An unsigned 64-bit integer: the µs timestamp since the
870 UNIX epoch (1970) where the most recent rate limiting interval has been
871 started, as configured with `rateLimitIntervalUSec`.
872
873 `rateLimitCount` → An unsigned 64-bit integer, counting the authentication
874 attempts in the current rate limiting interval, see above.
875 If this counter grows beyond the value configured in `rateLimitBurst` authentication attempts are temporarily refused.
876
877 `removable` → A boolean value.
878 If true the manager of this user record determined the home directory being on removable media.
879 If false it was determined the home directory is in internal built-in media.
880 (This is used by `systemd-logind.service` to automatically pick the right default value for
881 `stopDelayUSec` if the field is not explicitly specified: for home directories
882 on removable media the delay is selected very low to minimize the chance the
883 home directory remains in unclean state if the storage device is removed from
884 the system by the user).
885
886 `accessMode` → The access mode currently in effect for the home directory
887 itself.
888
889 `fileSystemType` → The file system type backing the home directory: a short
890 string, such as "btrfs", "ext4", "xfs".
891
892 `fallbackShell`, `fallbackHomeDirectory` → These fields have the same contents
893 and format as the `shell` and `homeDirectory` fields (see above). When the
894 `useFallback` field (see below) is set to true, the data from these fields
895 should override the fields of the same name without the `fallback` prefix.
896
897 `useFallback` → A boolean that allows choosing between the regular `shell` and
898 `homeDirectory` fields or the fallback fields of the same name (see above). If
899 `true` the fallback fields should be used in place of the regular fields, if
900 `false` or unset the regular fields should be used. This mechanism is used for
901 enable subsystems such as SSH to allow logins into user accounts, whose homed
902 directories need further unlocking (because the SSH native authentication
903 cannot release a suitabable disk encryption key), which the fallback shell
904 provides.
905
906 ## Fields in the `signature` section
907
908 As mentioned, the `signature` section of the user record may contain one or
909 more cryptographic signatures of the user record.
910 Like all others, this section is optional, and only used when cryptographic validation of user records shall be used.
911 Specifically, all user records managed by `systemd-homed.service` will carry such signatures and the service refuses managing user records that come
912 without signature or with signatures not recognized by any locally defined public key.
913
914 The `signature` field in the top-level user record object is an array of objects.
915 Each object encapsulates one signature and has two fields: `data` and `key` (both are strings).
916 The `data` field contains the actual signature, encoded in Base64, the `key` field contains a copy of the public key whose
917 private key was used to make the signature, in PEM format.
918 Currently only signatures with Ed25519 keys are defined.
919
920 Before signing the user record should be brought into "normalized" form,
921 i.e. the keys in all objects should be sorted alphabetically.
922 All redundant white-space and newlines should be removed and the JSON text then signed.
923
924 The signatures only cover the `regular`, `perMachine` and `privileged` sections
925 of the user records, all other sections (include `signature` itself), are
926 removed before the signature is calculated.
927
928 Rationale for signing and threat model: while a multi-user operating system
929 like Linux strives for being sufficiently secure even after a user acquired a
930 local login session reality tells us this is not the case.
931 Hence it is essential to restrict carefully which users may gain access to a system and which ones shall not.
932 A minimal level of trust must be established between system,
933 user record and the user themselves before a log-in request may be permitted.
934 In particular if the home directory is provided in its own LUKS2 encapsulated file system
935 it is essential this trust is established before the user logs in (and hence the file system mounted),
936 since file system implementations on Linux are well known to be relatively vulnerable to rogue disk images.
937 User records and home directories in many context are expected to be something shareable between multiple systems,
938 and the transfer between them might not happen via exclusively trusted channels.
939 Hence it's essential that the user record is not manipulated between uses.
940 Finally, resource management (which may be done by the various fields of the user record) is security
941 sensitive, since it should forcefully lock the user into the assigned resource usage and not allow them to use more.
942 The requirement of being able to trust the user record data combined with the potential transfer over untrusted
943 channels suggest a cryptographic signature mechanism where only user records
944 signed by a recognized key are permitted to log in locally.
945
946 Note that other mechanisms for establishing sufficient trust exist too, and are perfectly valid as well.
947 For example, systems like LDAP/ActiveDirectory generally insist on user record transfer from trusted servers via encrypted TLS channels only.
948 Or traditional UNIX users created locally in `/etc/passwd` never exist outside of the local trusted system,
949 hence transfer and trust in the source are not an issue.
950 The major benefit of operating with signed user records is that they are self-sufficiently trusted,
951 not relying on a secure channel for transfer, and thus being compatible with a more distributed model
952 of home directory transfer, including on USB sticks and such.
953
954 ## Fields in the `secret` section
955
956 As mentioned, the `secret` section of the user record should never be persisted
957 nor transferred across machines.
958 It is only defined in short-lived operations, for example when a user record is first created or registered, as the secret
959 key data needs to be available to derive encryption keys from and similar.
960
961 The `secret` field of the top-level user record contains the following fields:
962
963 `password` → an array of strings, each containing a plain text password.
964
965 `tokenPin` → an array of strings, each containing a plain text PIN, suitable
966 for unlocking security tokens that require that.
967 (The field `pkcs11Pin` should be considered a compatibility alias for this field, and merged with `tokenPin`
968 in case both are set.)
969
970 `pkcs11ProtectedAuthenticationPathPermitted` → a boolean.
971 If set to true allows the receiver to use the PKCS#11 "protected authentication path" (i.e. a
972 physical button/touch element on the security token) for authenticating the user.
973 If false or unset, authentication this way shall not be attempted.
974
975 `fido2UserPresencePermitted` → a boolean.
976 If set to true allows the receiver to use the FIDO2 "user presence" flag.
977 This is similar to the concept of `pkcs11ProtectedAuthenticationPathPermitted`,
978 but exposes the FIDO2 "up" concept behind it.
979 If false or unset authentication this way shall not be attempted.
980
981 `fido2UserVerificationPermitted` → a boolean. If set to true allows the
982 receiver to use the FIDO2 "user verification" flag.
983 This is similar to the concept of `pkcs11ProtectedAuthenticationPathPermitted`,
984 but exposes the FIDO2 "uv" concept behind it.
985 If false or unset authentication this way shall not be attempted.
986
987 ## Mapping to `struct passwd` and `struct spwd`
988
989 When mapping classic UNIX user records (i.e. `struct passwd` and `struct spwd`)
990 to JSON user records the following mappings should be applied:
991
992 | Structure | Field | Section | Field | Condition |
993 |-----------------|-------------|--------------|------------------------------|----------------------------|
994 | `struct passwd` | `pw_name` | `regular` | `userName` | |
995 | `struct passwd` | `pw_passwd` | `privileged` | `password` | (See notes below) |
996 | `struct passwd` | `pw_uid` | `regular` | `uid` | |
997 | `struct passwd` | `pw_gid` | `regular` | `gid` | |
998 | `struct passwd` | `pw_gecos` | `regular` | `realName` | |
999 | `struct passwd` | `pw_dir` | `regular` | `homeDirectory` | |
1000 | `struct passwd` | `pw_shell` | `regular` | `shell` | |
1001 | `struct spwd` | `sp_namp` | `regular` | `userName` | |
1002 | `struct spwd` | `sp_pwdp` | `privileged` | `password` | (See notes below) |
1003 | `struct spwd` | `sp_lstchg` | `regular` | `lastPasswordChangeUSec` | (if `sp_lstchg` > 0) |
1004 | `struct spwd` | `sp_lstchg` | `regular` | `passwordChangeNow` | (if `sp_lstchg` == 0) |
1005 | `struct spwd` | `sp_min` | `regular` | `passwordChangeMinUSec` | |
1006 | `struct spwd` | `sp_max` | `regular` | `passwordChangeMaxUSec` | |
1007 | `struct spwd` | `sp_warn` | `regular` | `passwordChangeWarnUSec` | |
1008 | `struct spwd` | `sp_inact` | `regular` | `passwordChangeInactiveUSec` | |
1009 | `struct spwd` | `sp_expire` | `regular` | `locked` | (if `sp_expire` in [0, 1]) |
1010 | `struct spwd` | `sp_expire` | `regular` | `notAfterUSec` | (if `sp_expire` > 1) |
1011
1012 At this time almost all Linux machines employ shadow passwords, thus the
1013 `pw_passwd` field in `struct passwd` is set to `"x"`, and the actual password
1014 is stored in the shadow entry `struct spwd`'s field `sp_pwdp`.
1015
1016 ## Extending These Records
1017
1018 User records following this specifications are supposed to be extendable for various applications.
1019 In general, subsystems are free to introduce their own keys, as long as:
1020
1021 * Care should be taken to place the keys in the right section, i.e. the most
1022 appropriate for the data field.
1023
1024 * Care should be taken to avoid namespace clashes.
1025 Please prefix your fields with a short identifier of your project to avoid ambiguities and
1026 incompatibilities.
1027
1028 * This specification is supposed to be a living specification.
1029 If you need additional fields, please consider submitting them upstream for inclusion in this specification.
1030 If they are reasonably universally useful, it would be best to list them here.
1031
1032 ## Examples
1033
1034 The shortest valid user record looks like this:
1035
1036 ```json
1037 {
1038 "userName" : "u"
1039 }
1040 ```
1041
1042 A reasonable user record for a system user might look like this:
1043
1044 ```json
1045 {
1046 "userName" : "httpd",
1047 "uid" : 473,
1048 "gid" : 473,
1049 "disposition" : "system",
1050 "locked" : true
1051 }
1052 ```
1053
1054 A fully featured user record associated with a home directory managed by
1055 `systemd-homed.service` might look like this:
1056
1057 ```json
1058 {
1059 "autoLogin" : true,
1060 "binding" : {
1061 "15e19cf24e004b949ddaac60c74aa165" : {
1062 "fileSystemType" : "ext4",
1063 "fileSystemUuid" : "758e88c8-5851-4a2a-b88f-e7474279c111",
1064 "gid" : 60232,
1065 "homeDirectory" : "/home/grobie",
1066 "blobDirectory" : "/var/cache/systemd/homed/grobie/",
1067 "imagePath" : "/home/grobie.home",
1068 "luksCipher" : "aes",
1069 "luksCipherMode" : "xts-plain64",
1070 "luksUuid" : "e63581ba-79fb-4226-b9de-1888393f7573",
1071 "luksVolumeKeySize" : 32,
1072 "partitionUuid" : "41f9ce04-c827-4b74-a981-c669f93eb4dc",
1073 "storage" : "luks",
1074 "uid" : 60232
1075 }
1076 },
1077 "blobManifest" : {
1078 "avatar" : "c0636851d25a62d817ff7da4e081d1e646e42c74d0ecb53425f75fcf1ba43b52",
1079 "login-background" : "da7ad0222a6edbc6cd095149c72d38d92fd3114f606e4b57469857ef47fade18"
1080 },
1081 "disposition" : "regular",
1082 "enforcePasswordPolicy" : false,
1083 "lastChangeUSec" : 1565950024279735,
1084 "memberOf" : [
1085 "wheel"
1086 ],
1087 "privileged" : {
1088 "hashedPassword" : [
1089 "$6$WHBKvAFFT9jKPA4k$OPY4D4TczKN/jOnJzy54DDuOOagCcvxxybrwMbe1SVdm.Bbr.zOmBdATp.QrwZmvqyr8/SafbbQu.QZ2rRvDs/"
1090 ]
1091 },
1092 "signature" : [
1093 {
1094 "data" : "LU/HeVrPZSzi3MJ0PVHwD5m/xf51XDYCrSpbDRNBdtF4fDVhrN0t2I2OqH/1yXiBidXlV0ptMuQVq8KVICdEDw==",
1095 "key" : "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA/QT6kQWOAMhDJf56jBmszEQQpJHqDsGDMZOdiptBgRk=\n-----END PUBLIC KEY-----\n"
1096 }
1097 ],
1098 "userName" : "grobie",
1099 "status" : {
1100 "15e19cf24e004b949ddaac60c74aa165" : {
1101 "goodAuthenticationCounter" : 16,
1102 "lastGoodAuthenticationUSec" : 1566309343044322,
1103 "rateLimitBeginUSec" : 1566309342340723,
1104 "rateLimitCount" : 1,
1105 "state" : "inactive",
1106 "service" : "io.systemd.Home",
1107 "diskSize" : 161118667776,
1108 "diskCeiling" : 190371729408,
1109 "diskFloor" : 5242880,
1110 "signedLocally" : true
1111 }
1112 }
1113 }
1114 ```
1115
1116 When `systemd-homed.service` manages a home directory it will also include a
1117 version of the user record in the home directory itself in the `~/.identity` file.
1118 This version lacks the `binding` and `status` sections which are used for
1119 local management of the user, but are not intended to be portable between
1120 systems. It would hence look like this:
1121
1122 ```json
1123 {
1124 "autoLogin" : true,
1125 "disposition" : "regular",
1126 "enforcePasswordPolicy" : false,
1127 "lastChangeUSec" : 1565950024279735,
1128 "memberOf" : [
1129 "wheel"
1130 ],
1131 "privileged" : {
1132 "hashedPassword" : [
1133 "$6$WHBKvAFFT9jKPA4k$OPY4D4TczKN/jOnJzy54DDuOOagCcvxxybrwMbe1SVdm.Bbr.zOmBdATp.QrwZmvqyr8/SafbbQu.QZ2rRvDs/"
1134 ]
1135 },
1136 "signature" : [
1137 {
1138 "data" : "LU/HeVrPZSzi3MJ0PVHwD5m/xf51XDYCrSpbDRNBdtF4fDVhrN0t2I2OqH/1yXiBidXlV0ptMuQVq8KVICdEDw==",
1139 "key" : "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA/QT6kQWOAMhDJf56jBmszEQQpJHqDsGDMZOdiptBgRk=\n-----END PUBLIC KEY-----\n"
1140 }
1141 ],
1142 "userName" : "grobie",
1143 }
1144 ```