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