]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
service: setup credentials for ExecCondition
authorMaximilian Bosch <maximilian@mbosch.me>
Sat, 8 Nov 2025 18:16:50 +0000 (19:16 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 9 Nov 2025 20:27:00 +0000 (05:27 +0900)
Closes #35788

This gives access to credentials within ExecCondition=. As described in
ticket #35788, I do have a use-case for this and as noted in the
commit that dropped this[1], this is OK to be revisited if there are
use-cases.

[1] a145623bc403e410f41808a8e5cb31d29a52567c

src/core/service.c
test/units/TEST-54-CREDS.sh

index 7b446351943cc2b3f4943117f200ecda7fcdebc5..c92fb450857d9d7ddb438f4e6dd34891a4a425b9 100644 (file)
@@ -1692,6 +1692,8 @@ static ExecFlags service_exec_flags(ServiceExecCommand command_id, ExecFlags cre
         /* All start phases get access to credentials. ExecStartPre= gets a new credential store upon
          * every invocation, so that updating credential files through it works. When the first main process
          * starts, passed creds become stable. Also see 'cred_flag'. */
+        if (command_id == SERVICE_EXEC_CONDITION)
+                flags |= EXEC_SETUP_CREDENTIALS;
         if (command_id == SERVICE_EXEC_START_PRE)
                 flags |= EXEC_SETUP_CREDENTIALS_FRESH;
         if (command_id == SERVICE_EXEC_START_POST)
index 7024adace45f7e791d1dc4e250d4524eb4e57612..479417dea00f1099f7469400e42b1f1373ceb1c4 100755 (executable)
@@ -446,6 +446,13 @@ systemd-run -p DynamicUser=yes -p 'LoadCredential=os:/etc/os-release' \
             --service-type=oneshot --wait --pipe \
             true | cmp /etc/os-release
 
+# https://github.com/systemd/systemd/issues/35788
+systemd-run -p DynamicUser=yes -p 'LoadCredential=os:/etc/os-release' \
+            -p 'ExecCondition=systemd-creds cat os' \
+            --unit=test-54-exec-condition.service \
+            --service-type=oneshot --wait --pipe \
+            true | cmp /etc/os-release
+
 # https://github.com/systemd/systemd/pull/24734#issuecomment-1925440546
 # Also ExecStartPre= should be able to update creds
 dd if=/dev/urandom of=/tmp/cred-huge bs=600K count=1