Skip to content

Credentials only accessible to very first ExecStartPre= when using sandboxing (mount namespace) #27275

Closed

Description

@veehaitch

systemd version the issue has been seen with

252.5

Used distribution

NixOS unstable

Linux kernel version used

6.1.15

CPU architectures issue was seen on

x86_64

Component

systemd

Expected behaviour you didn't see

I'd expect that the service credentials (provisioned through, e.g., LoadCredential=) are accessible from any ExecStartPre= command line regardless of its position. Therefore, I'd expect that the following command prints the contents of /etc/os-release and then exits successfully:

systemd-run -P --wait \
  -p 'DynamicUser=yes' \
  -p 'LoadCredential=os:/etc/os-release' \
  -p 'ExecStartPre=systemctl --version' \
  -p 'ExecStartPre=systemd-creds cat os' \
  true

Unexpected behaviour you saw

The command above yields the following output:

Running as unit: run-u127.service
systemd 252 (252.5)
+PAM +AUDIT -SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT -GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD +BPF_FRAMEWORK -XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified
Failed to open credentials directory '/run/credentials/run-u127.service': Permission denied
Failed to open credentials directory: Permission denied
Finished with result: exit-code
Service runtime: 74ms
CPU time consumed: 33ms
IP traffic received: 0B
IP traffic sent: 0B
IO bytes read: 0B
IO bytes written: 0B

Swapping the position of the two ExecStartPre= command lines works as expected:

systemd-run -P --wait \
  -p 'DynamicUser=yes' \
  -p 'LoadCredential=os:/etc/os-release' \
  -p 'ExecStartPre=systemd-creds cat os' \
  -p 'ExecStartPre=systemctl --version' \
  true

Output:

Running as unit: run-u128.service
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
BUILD_ID="23.05.20230308.c90c402"
DOCUMENTATION_URL="https://nixos.org/learn.html"
HOME_URL="https://nixos.org/"
ID=nixos
LOGO="nix-snowflake"
NAME=NixOS
PRETTY_NAME="NixOS 23.05 (Stoat)"
SUPPORT_URL="https://nixos.org/community.html"
VERSION="23.05 (Stoat)"
VERSION_CODENAME=stoat
VERSION_ID="23.05"
systemd 252 (252.5)
+PAM +AUDIT -SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT -GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD +BPF_FRAMEWORK -XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified
Finished with result: success
Main processes terminated with: code=exited/status=0
Service runtime: 111ms
CPU time consumed: 46ms
IP traffic received: 0B
IP traffic sent: 0B
IO bytes read: 0B
IO bytes written: 0B

Steps to reproduce the problem

See above.

Additional program output to the terminal or log subsystem illustrating the issue

No response

Activity

  1. added
    bug 🐛
    on Apr 14, 2023
  2. changed the title [-]Credentials only accessible to very first `ExecStartPre=`[/-] [+]Credentials only accessible to very first `ExecStartPre=` when using sandboxing (mount namespace)[/+] on Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛credspid1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions