systemd can load a credential into a unit-specific, read-only directory and provide its location through CREDENTIALS_DIRECTORY. The daemon can read that file without placing the secret value directly in a unit Environment line or command argument. This does not protect a compromised process that is allowed to read the credential, and root or the service owner can still be within the trust boundary. Sandboxing options such as a read-only system tree and a managed state directory reduce incidental write access, but each option must be checked against the daemon's actual filesystem needs. Credential rotation usually requires a unit restart or explicit reload path that opens the new material.
systemd service credentials: pass files through a narrow runtime boundary
Operational decision
A webhook dispatcher uses a signing key stored in a protected host file. Its unit loads that file as a named credential, runs under a dedicated unprivileged identity, writes only to a managed state directory, and reads the key from the credential directory at startup. The operator verifies file ownership, the process's effective user, and the permissions of the material presented to the unit. They rotate the source key, restart or reload through the supported path, and verify a newly signed synthetic request while an old-key overlap window is still valid. A failed reload must leave an explicit alarm, not a silent mixture of signatures from old and new workers.
[Service]
User=webhook-dispatch
LoadCredential=signing-key:/etc/secure/webhook/signing-key
ProtectSystem=strict
StateDirectory=webhook-dispatch
ExecStart=/opt/webhook/bin/dispatcher
Application reads: $CREDENTIALS_DIRECTORY/signing-keyCost and verification
Credential loading adds a per-service file lifecycle and requires a tested renewal path. A strict filesystem sandbox may break runtime writes to unexpected directories, so inspect actual file access during a disposable rollout. Secret values should not enter process arguments, unit files, or logs. Rotate the underlying credential before it expires and measure from source update to every process using the new generation. A credential copied to an unprotected host path is still vulnerable even if the unit references it through LoadCredential.
Common Mistakes
- Do not put a signing key value in Environment or ExecStart.
- Do not assume a running service reloads a changed credential automatically.
- Do not enable a strict sandbox without testing required write paths.
Connected lessons
- DevOps: delivery, infrastructure, and reliable operations
- Secret rotation rollout: update the issuer, consumer, and active connections
- Service account tokens: mount only when the workload needs Kubernetes API access
- Configuration pairs: prevent mixed policy and credential generations
- systemd dependencies: separate unit ordering from application readiness
- systemd restarts: bound crash loops and preserve evidence before resetting failures
