]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
import-creds: don't try to import VM creds in a container
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Dec 2022 16:57:56 +0000 (17:57 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 22 Dec 2022 23:46:41 +0000 (00:46 +0100)
If we run in a container we shouldn#t try to import creds passed in from
a VMM, as they are not for us, but for the VM itself.

src/core/import-creds.c

index 0bcd407e682fb5e8e17f49df5d800a53c9a725bf..1f5a15f73b40cac3b5f84f249c0e5f8bf34376a5 100644 (file)
@@ -20,6 +20,7 @@
 #include "proc-cmdline.h"
 #include "recurse-dir.h"
 #include "strv.h"
+#include "virt.h"
 
 /* This imports credentials passed in from environments higher up (VM manager, boot loader, …) and rearranges
  * them so that later code can access them using our regular credential protocol
@@ -370,6 +371,9 @@ static int import_credentials_qemu(ImportCredentialContext *c) {
 
         assert(c);
 
+        if (detect_container() > 0) /* don't access /sys/ in a container */
+                return 0;
+
         source_dir_fd = open(QEMU_FWCFG_PATH, O_RDONLY|O_DIRECTORY|O_CLOEXEC);
         if (source_dir_fd < 0) {
                 if (errno == ENOENT) {
@@ -561,6 +565,9 @@ static int import_credentials_smbios(ImportCredentialContext *c) {
 
         /* Parses DMI OEM strings fields (SMBIOS type 11), as settable with qemu's -smbios type=11,value=… switch. */
 
+        if (detect_container() > 0) /* don't access /sys/ in a container */
+                return 0;
+
         for (unsigned i = 0;; i++) {
                 struct dmi_field_header {
                         uint8_t type;