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