Context
A service needs an API token, but putting the token in a unit's environment creates an awkward exposure and rotation problem. systemd credentials provide a file-based handoff between the service manager and a service process. They are useful when the application can read a secret file or accepts a path through ordinary configuration.
Start with an application-owned test account, a supported systemd release and an approved source for the secret. Confirm that the operator can manage the unit without receiving unnecessary access to secret values. Credential support varies by systemd version, so read the local manual before adapting examples from newer releases.
Design the handoff
- Identify the application's secret-file interface. A setting named
TOKEN_FILEis useful only if the application actually opens that path. Merely renaming a token environment variable does not change application behavior. Decide whether the process reads once at startup or supports an explicit refresh, and record what happens if the file is missing. - Review
LoadCredential=in the installedsystemd.execdocumentation. Its identifier names the credential made available to the service; its source path identifies material read by the service manager. Use a harmless staging value to prove the handoff. Keep the source protected and avoid printing it during troubleshooting. A local credential file does not automatically provide a centralized secret inventory or approval process. - Configure the application to locate the delivered file through the supported credentials-directory interface. Inspect
systemctl cat example.servicefor the declaration andsystemctl show example.service -p Userfor the runtime identity. Validate that the application can read the file through its own redacted health check. Do not replace this test with an administrator reading the file as root.
An illustrative rotation problem
In an illustrative integration service, the source token changes successfully but the next outbound request still uses the old token. The service loaded its credential at startup and retained an in-memory client. This is a lifecycle mismatch, not proof that the file permissions are wrong. A planned service restart or supported application refresh must be part of that integration's rotation procedure.
| Symptom | Evidence to collect | Decision |
|---|---|---|
| Credential identifier missing | Unit declaration and installed feature support | Correct configuration or compatibility |
| File present, login rejected | Secret version identifier and upstream test | Validate material without displaying it |
| New source, old behavior | Process start time and application refresh contract | Activate a new credential lifecycle |
| Root test succeeds only | Service identity and actual application read | Inspect the intended runtime access |
Correct the demonstrated boundary
Separate the source's protection from the delivered credential's protection. systemd documents a read-only per-unit location accessible to the service identity and superuser. That is a scoped delivery mechanism; it cannot prevent an application from logging the token or transmitting it to an unintended endpoint. Review those application behaviors independently.
Apply the smallest correction in staging first. Preserve the previous valid credential through the agreed rollback window, following the provider's rotation rules. Avoid synchronizing two unrelated changes, such as a token rotation and a service-account migration, unless the acceptance plan covers both.
Verify a fresh service lifecycle, one legitimate upstream request and the expected failure when the credential is intentionally absent in the test environment. Confirm logs show only a credential version or success state. The acceptance evidence should never contain the token itself.
Operate the secret lifecycle
The operating procedure should name the source owner, consuming unit, refresh method, rotation trigger and recovery contact. Monitor authentication failures separately from unit status, because an active service can have unusable credentials. Rehearse expiration and rollback using non-production material. Clouvenix server hardening can help define that handoff without embedding secret values in support records.
Technical reference
systemd credential delivery interfaces. Match available directives to the deployed release.