]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: propagate SSH authorized keys when binding user into contaier via --bind...
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Aug 2024 15:29:15 +0000 (17:29 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 28 Aug 2024 16:13:48 +0000 (17:13 +0100)
This means the host user typically can just log into his own account
bound into the container via SSH.

src/nspawn/nspawn-bind-user.c

index 91f90e1d023a031035eb640ab0acd06e2f5a24c6..1668656dabf5f0dc1948fbd2724957f0e37fca6f 100644 (file)
@@ -88,7 +88,7 @@ static int convert_user(
         _cleanup_(group_record_unrefp) GroupRecord *converted_group = NULL;
         _cleanup_(user_record_unrefp) UserRecord *converted_user = NULL;
         _cleanup_free_ char *h = NULL;
-        sd_json_variant *p, *hp = NULL;
+        sd_json_variant *p, *hp = NULL, *ssh = NULL;
         int r;
 
         assert(u);
@@ -115,8 +115,10 @@ static int convert_user(
 
         /* Acquire the source hashed password array as-is, so that it retains the JSON_VARIANT_SENSITIVE flag */
         p = sd_json_variant_by_key(u->json, "privileged");
-        if (p)
+        if (p) {
                 hp = sd_json_variant_by_key(p, "hashedPassword");
+                ssh = sd_json_variant_by_key(p, "sshAuthorizedKeys");
+        }
 
         r = user_record_build(
                         &converted_user,
@@ -127,8 +129,9 @@ static int convert_user(
                                         SD_JSON_BUILD_PAIR_CONDITION(u->disposition >= 0, "disposition", SD_JSON_BUILD_STRING(user_disposition_to_string(u->disposition))),
                                         SD_JSON_BUILD_PAIR("homeDirectory", SD_JSON_BUILD_STRING(h)),
                                         SD_JSON_BUILD_PAIR("service", JSON_BUILD_CONST_STRING("io.systemd.NSpawn")),
-                                        SD_JSON_BUILD_PAIR_CONDITION(!strv_isempty(u->hashed_password), "privileged", SD_JSON_BUILD_OBJECT(
-                                                                                  SD_JSON_BUILD_PAIR("hashedPassword", SD_JSON_BUILD_VARIANT(hp))))));
+                                        SD_JSON_BUILD_PAIR("privileged", SD_JSON_BUILD_OBJECT(
+                                                                           SD_JSON_BUILD_PAIR_CONDITION(!strv_isempty(u->hashed_password), "hashedPassword", SD_JSON_BUILD_VARIANT(hp)),
+                                                                           SD_JSON_BUILD_PAIR_CONDITION(!!ssh, "sshAuthorizedKeys", SD_JSON_BUILD_VARIANT(ssh))))));
         if (r < 0)
                 return log_error_errno(r, "Failed to build container user record: %m");