diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-07-30 16:16:26 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-07-31 15:52:27 +0200 |
commit | 831f208783aeac443e6f2fc2efc3119535a032ef (patch) | |
tree | 8ba1bf30dcd20d9e4d0a56ecd084fa4d3ddcc39c /src/core/execute-serialize.c | |
parent | exec-credential: Skip duplicate credentials in load_credential_glob() (diff) | |
download | systemd-831f208783aeac443e6f2fc2efc3119535a032ef.tar.xz systemd-831f208783aeac443e6f2fc2efc3119535a032ef.zip |
core: Add support for renaming credentials with ImportCredential=
This allows for "per-instance" credentials for units. The use case
is best explained with an example. Currently all our getty units
have the following stanzas in their unit file:
"""
ImportCredential=agetty.*
ImportCredential=login.*
"""
This means that setting agetty.autologin=root as a system credential
will make every instance of our all our getty units autologin as the
root user. This prevents us from doing autologin on /dev/hvc0 while
still requiring manual login on all other ttys.
To solve the issue, we introduce support for renaming credentials with
ImportCredential=. This will allow us to add the following to e.g.
serial-getty@.service:
"""
ImportCredential=tty.serial.%I.agetty.*:agetty.
ImportCredential=tty.serial.%I.login.*:login.
"""
which for serial-getty@hvc0.service will make the service manager read
all credentials of the form "tty.serial.hvc0.agetty.xxx" and pass them
to the service in the form "agetty.xxx" (same goes for login). We can
apply the same to each of the getty units to allow setting agetty and
login credentials for individual ttys instead of globally.
Diffstat (limited to 'src/core/execute-serialize.c')
-rw-r--r-- | src/core/execute-serialize.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/core/execute-serialize.c b/src/core/execute-serialize.c index 69f79984a5..2381662769 100644 --- a/src/core/execute-serialize.c +++ b/src/core/execute-serialize.c @@ -2554,13 +2554,14 @@ static int exec_context_serialize(const ExecContext *c, FILE *f) { return r; } - if (!set_isempty(c->import_credentials)) { - char *ic; - SET_FOREACH(ic, c->import_credentials) { - r = serialize_item(f, "exec-context-import-credentials", ic); - if (r < 0) - return r; - } + ExecImportCredential *ic; + ORDERED_SET_FOREACH(ic, c->import_credentials) { + r = serialize_item_format(f, "exec-context-import-credentials", "%s%s%s", + ic->glob, + ic->rename ? " " : "", + strempty(ic->rename)); + if (r < 0) + return r; } r = serialize_image_policy(f, "exec-context-root-image-policy", c->root_image_policy); @@ -3688,11 +3689,15 @@ static int exec_context_deserialize(ExecContext *c, FILE *f) { if (r < 0) return r; } else if ((val = startswith(l, "exec-context-import-credentials="))) { - r = set_ensure_allocated(&c->import_credentials, &string_hash_ops); + _cleanup_free_ char *glob = NULL, *rename = NULL; + + r = extract_many_words(&val, " ", EXTRACT_DONT_COALESCE_SEPARATORS, &glob, &rename); if (r < 0) return r; + if (r == 0) + return -EINVAL; - r = set_put_strdup(&c->import_credentials, val); + r = exec_context_put_import_credential(c, glob, rename); if (r < 0) return r; } else if ((val = startswith(l, "exec-context-root-image-policy="))) { |