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.
This commit is contained in:
@@ -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="))) {
|
||||
|
||||
Reference in New Issue
Block a user