]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfiles: automatically provision /etc/issue.d/ + /etc/motd.d/ + /etc/hosts from... 24014/head
authorLennart Poettering <lennart@poettering.net>
Fri, 15 Jul 2022 14:33:20 +0000 (16:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 Jul 2022 22:06:22 +0000 (00:06 +0200)
test/TEST-54-CREDS/test.sh
test/units/testsuite-54.sh
tmpfiles.d/meson.build
tmpfiles.d/provision.conf [new file with mode: 0644]
units/systemd-tmpfiles-setup.service

index ac6777be3112af53e8653637399ced990cd6d63a..5269eaa437e632b9522332e047af00b2af84b590 100755 (executable)
@@ -3,9 +3,29 @@
 set -e
 
 TEST_DESCRIPTION="test credentials"
-NSPAWN_ARGUMENTS="${NSPAWN_ARGUMENTS:-} --set-credential=mynspawncredential:strangevalue"
-QEMU_OPTIONS="${QEMU_OPTIONS:-} -fw_cfg name=opt/io.systemd.credentials/myqemucredential,string=othervalue -smbios type=11,value=io.systemd.credential:smbioscredential=magicdata -smbios type=11,value=io.systemd.credential.binary:binarysmbioscredential=bWFnaWNiaW5hcnlkYXRh -smbios type=11,value=io.systemd.credential.binary:sysusers.extra=dSBjcmVkdGVzdHVzZXIK -smbios type=11,value=io.systemd.credential.binary:tmpfiles.extra=ZiAvdG1wL3NvdXJjZWRmcm9tY3JlZGVudGlhbCAtIC0gLSAtIHRtcGZpbGVzc2VjcmV0Cg=="
-KERNEL_APPEND="${KERNEL_APPEND:-} systemd.set_credential=kernelcmdlinecred:uff systemd.set_credential=sysctl.extra:kernel.domainname=sysctltest rd.systemd.import_credentials=no"
+
+NSPAWN_CREDS=(
+    "--set-credential=mynspawncredential:strangevalue"
+)
+NSPAWN_ARGUMENTS="${NSPAWN_ARGUMENTS:-} ${NSPAWN_CREDS[*]}"
+
+QEMU_CREDS=(
+    "-fw_cfg name=opt/io.systemd.credentials/myqemucredential,string=othervalue"
+    "-smbios type=11,value=io.systemd.credential:smbioscredential=magicdata"
+    "-smbios type=11,value=io.systemd.credential.binary:binarysmbioscredential=bWFnaWNiaW5hcnlkYXRh"
+    "-smbios type=11,value=io.systemd.credential.binary:sysusers.extra=dSBjcmVkdGVzdHVzZXIK"
+    "-smbios type=11,value=io.systemd.credential.binary:tmpfiles.extra=ZiAvdG1wL3NvdXJjZWRmcm9tY3JlZGVudGlhbCAtIC0gLSAtIHRtcGZpbGVzc2VjcmV0Cg=="
+)
+QEMU_OPTIONS="${QEMU_OPTIONS:-} ${QEMU_CREDS[*]}"
+
+KERNEL_CREDS=(
+    "systemd.set_credential=kernelcmdlinecred:uff"
+    "systemd.set_credential=sysctl.extra:kernel.domainname=sysctltest"
+    "systemd.set_credential=login.motd:hello"
+    "systemd.set_credential=login.issue:welcome"
+    "rd.systemd.import_credentials=no"
+)
+KERNEL_APPEND="${KERNEL_APPEND:-} ${KERNEL_CREDS[*]}"
 
 # shellcheck source=test/test-functions
 . "${TEST_BASE_DIR:?}/test-functions"
index 8eff47028d77b3e9189cd7cb9c2db80dd784398f..dc0c5f554f15cd454e55b712e5b8d2731aa363c4 100755 (executable)
@@ -46,6 +46,8 @@ elif [ -d /sys/firmware/qemu_fw_cfg/by_name ]; then
 
     # Verify that writing a file via tmpfiles worked
     [ "$(cat /tmp/sourcedfromcredential)" = "tmpfilessecret" ]
+    [ "$(cat /etc/motd.d/50-provision.conf)" = "hello" ]
+    [ "$(cat /etc/issue.d/50-provision.conf)" = "welcome" ]
 else
     echo "qemu_fw_cfg support missing in kernel. Sniff!"
     expected_credential=""
index 454616969443e022c4b1c86c9715beec76fee49a..ca1abbf3fecf5cc0eba940b690e33d18a1a17de6 100644 (file)
@@ -14,6 +14,7 @@ files = [['README',               ''],
          ['systemd-tmp.conf',     ''],
          ['tmp.conf',             ''],
          ['x11.conf',             ''],
+         ['provision.conf',       ''],
         ]
 
 foreach pair : files
diff --git a/tmpfiles.d/provision.conf b/tmpfiles.d/provision.conf
new file mode 100644 (file)
index 0000000..9a47838
--- /dev/null
@@ -0,0 +1,17 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+# See tmpfiles.d(5) for details
+
+# Provision additional loging messages from credentials, if they are set. Note
+# that these lines are NOPs if the credentials are not set or if the files
+# already exist.
+f^ /etc/motd.d/50-provision.conf - - - - login.motd
+f^ /etc/issue.d/50-provision.conf - - - - login.issue
+
+# Provision a /etc/hosts file from credentials.
+f^ /etc/hosts - - - - network.hosts
index 6c1ee91a403abbe2c1ae5964a5d90638f79c73b8..fc6a4a0e0be2b03f02791600f439d7a5314a4270 100644 (file)
@@ -22,3 +22,6 @@ RemainAfterExit=yes
 ExecStart=systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev
 SuccessExitStatus=DATAERR CANTCREAT
 LoadCredential=tmpfiles.extra
+LoadCredential=login.motd
+LoadCredential=login.issue
+LoadCredential=network.hosts