Repository navigation
Closed
Description
systemd version the issue has been seen with
251.3
Used distribution
NixOS Unstable 22.11.20220808.39d7f92
Linux kernel version used
5.15.59
CPU architectures issue was seen on
x86_64
Component
systemd
Expected behaviour you didn't see
When running a oneshot service with multiple ExecStart command lines and DynamicUser=true, credentials should be available to each command line.
Unexpected behaviour you saw
Credentials were only available to the first command line. The second one got Permission denied. But if you don't enable DynamicUser, then both command lines will have access as expected.
Steps to reproduce the problem
# foo.service
[Unit]
[Service]
Environment="LOCALE_ARCHIVE=/nix/store/mhbhiykjxvl5cn0f4g0zxcii4shz4rq8-glibc-locales-2.35-163/lib/locale/locale-archive"
Environment="PATH=/nix/store/xp5z3k851fs7haqbcwqax1hh4pynzla9-coreutils-9.1/bin:/nix/store/b1c0270m7fcppqpga49fqy7n8hj3vbw2-findutils-4.9.0/bin:/nix/store/74lg75l5wdxkiab73pc7x3983lcppk86-gnugrep-3.7/bin:/nix/store/cr41h6cg093d7z6w0nnaiqpsfc2fxd54-gnused-4.8/bin:/nix/store/yzycn28101y9v6disd23r86g1q3n4dsj-systemd-251.3/bin:/nix/store/xp5z3k851fs7haqbcwqax1hh4pynzla9-coreutils-9.1/sbin:/nix/store/b1c0270m7fcppqpga49fqy7n8hj3vbw2-findutils-4.9.0/sbin:/nix/store/74lg75l5wdxkiab73pc7x3983lcppk86-gnugrep-3.7/sbin:/nix/store/cr41h6cg093d7z6w0nnaiqpsfc2fxd54-gnused-4.8/sbin:/nix/store/yzycn28101y9v6disd23r86g1q3n4dsj-systemd-251.3/sbin"
Environment="TZDIR=/nix/store/3m1aakciplbv5mymyl9dmis35kw71fib-tzdata-2022a/share/zoneinfo"
DynamicUser=true
ExecStart=/nix/store/xp5z3k851fs7haqbcwqax1hh4pynzla9-coreutils-9.1/bin/stat ${CREDENTIALS_DIRECTORY}/foo
ExecStart=/nix/store/xp5z3k851fs7haqbcwqax1hh4pynzla9-coreutils-9.1/bin/stat ${CREDENTIALS_DIRECTORY}/foo
LoadCredential=foo:/etc/shadow
Type=oneshot
You can disregard all the /nix/store/* noise and replace it with /usr to replicate on other distros.
This service will fail when you start it. The first stat command has access, but the second one doesn't.
Additional program output to the terminal or log subsystem illustrating the issue
Aug 11 21:13:12 nixos systemd[1]: Starting foo.service...
Aug 11 21:13:12 nixos stat[926]: File: /run/credentials/foo.service/foo
Aug 11 21:13:12 nixos stat[926]: Size: 802 Blocks: 8 IO Block: 4096 regular file
Aug 11 21:13:12 nixos stat[926]: Device: 0,45 Inode: 19325 Links: 1
Aug 11 21:13:12 nixos stat[926]: Access: (0400/-r--------) Uid: (63016/ foo) Gid: ( 0/ root)
Aug 11 21:13:12 nixos stat[926]: Access: 2022-08-11 21:13:12.448000000 +0000
Aug 11 21:13:12 nixos stat[926]: Modify: 2022-08-11 21:13:12.448000000 +0000
Aug 11 21:13:12 nixos stat[926]: Change: 2022-08-11 21:13:12.448000000 +0000
Aug 11 21:13:12 nixos stat[926]: Birth: -
Aug 11 21:13:12 nixos stat[928]: /nix/store/xp5z3k851fs7haqbcwqax1hh4pynzla9-coreutils-9.1/bin/stat: cannot statx '/run/credentials/foo.service/foo': Permission denied
Aug 11 21:13:12 nixos systemd[1]: foo.service: Main process exited, code=exited, status=1/FAILURE
Aug 11 21:13:12 nixos systemd[1]: foo.service: Failed with result 'exit-code'.
Aug 11 21:13:12 nixos systemd[1]: Failed to start foo.service.
Activity
ElvishJerricco commentedon Aug 12, 2022
I also reproduced this on Arch Linux with systemd 251.4
I also tried this on Debian Bullseye with systemd 247 and did not see the bug.
ElvishJerricco commentedon Aug 13, 2022
I've bisected the issue down to a631cbf by @poettering, though to be honest it looks like that is just exposing a separate problem. I can't imagine why adding
&& FLAGS_SET(params->flags, EXEC_WRITE_CREDENTIALS)would be a problem unless the flags were somehow incorrect.jiphex commentedon May 18, 2023
I have also seen this on Rocky9 (systemd v252-13.el9_2)
This works (the
catis able to read the credential), but thelsgets permission denied. If I move thecatcommand to be anything but the first command executed, it is unable to read the credential.YHNdnzj commentedon May 18, 2023
Already fixed in #27279.
Gunni commentedon Feb 11, 2025
NACK? Works without
DynamicUser=yes...Does not work with
DynamicUser=yes...Works with
DynamicUser=yesif the first command uses the credential...Systemd 252