Skip to content

RFE: allow service credentials to be updated during service runtime #21099

Closed

Description

@voanhduy1512

Is your feature request related to a problem? Please describe.
I am using LoadCredential to pass credential, tls cert and key, into my service.
This service can receive HUP signal and reload it config, without restart the whole process. Before using LoadCredential, I can point the service to credential location directly, have ExecReload=/bin/kill --signal HUP $MAINPID in service unit and systemctl reload servicename to ask it to reload when the credential change.
With LoadCredential, I can't find any document or way to make it pick up new credential and make it available to the service unless I do a full restart with systemctl restart service

Describe the solution you'd like
systemctl reload service would trigger update credential

Describe alternatives you've considered
Have a separated command systemctl reload-credential or something like that

The systemd version you checked that didn't have the feature you are asking for

systemd 249 (249.4)
+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 +BZIP2 +LZ4 +XZ +ZLIB -ZSTD -XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified

Activity

  1. poettering commented on Oct 26, 2021

    @poettering
    Member

    credentials are immutable: once loaded the remain entirely static until the service goes down. This is explicitly documented and by design.

    Changing this comes with all kinds of issue, i.e. the replacement couldn't be atomic for example.

  2. added
    RFE 🎁
    on Oct 26, 2021
  3. changed the title [-]Reload to update credential when using LoadCredential [/-] [+]RFE: allow service credentials to be updated during service runtime[/+] on Oct 26, 2021
  4. mikroskeem commented on Oct 31, 2021

    @mikroskeem

    Technically you can:

    1. Remount /run/credentials/<x> as read-write temporarily (to follow the idea of keeping credentials immutable for the service, consider doing so in a separate mount namespace)
    2. Fetch new desired credentials and write them into temporary file /run/credentials/<x>/.<credname>.<random>
    3. Replace them atomically using rename(temp, orig) (atomic only in a single file context however)

    Not ideal nor not the cleanest solution, but if 3rd point is not an issue, then that'll avoid bringing down the service and causing disruptions (for example
    nginx process serving thousands of clients).

    That being said, could credentials immutability be reconsidered?

  5. flokli commented on Feb 22, 2022

    @flokli
    Contributor

    The reload of credentials was already flagged in #15778 (comment), and #16568 explicitly marked as an initial implementation.

    I also still think being able to renew credentials makes a lot of sense - one good example are indeed SSL certificates.

  6. tashian commented on Aug 9, 2022

    @tashian

    I'm in the PKI world and I spend a lot of time looking at issues of certificate management in production.

    I want to give this a +1 because I think the immutability of credentials should be reconsidered in the case where a service is being reloaded.

    The way I see it, it's good security hygiene to use short-lived certificates and renew them every few days.

    So, while it's convenient to treat certs as immutable config, they are not like other config data. Certs expire. And, most services support reloading their certificate files on demand.

    The AF_UNIX credential functionality has such great potential as a hook for a certificate management service. I'm sure you had this use case in mind when building it. But, the fact that credentials are treated as immutable makes this very difficult to put into practice without @mikroskeem's workaround.

  7. mikroskeem commented on Oct 2, 2022

    @mikroskeem
  8. arianvp commented on Jun 8, 2024

    @arianvp
    Contributor

    This is how Kubernetes atomically replaces secrets mounted into a pod:

    https://pkg.go.dev/k8s.io/kubernetes/pkg/volume/util#AtomicWriter

    by using two levels of symlinks they're able to replace the credentials directory atomically with a new directory containing the new set of credentials.

    This seems to work pretty well for them.

    More explained here: https://ahmet.im/blog/kubernetes-inotify/

  9. arianvp commented on Jun 8, 2024

    @arianvp
    Contributor

    The only caveat is that if you're using inotify or the likes you should handle IN_DELETE_SELF

  10. flokli commented on Jun 10, 2024

    @flokli
    Contributor

    Thanks for linking to this! I think going with this approach is better than not doing any rotation at all. Sure, some userspace might not do their credential rotation properly, and depending on how the source to the credentials is provided it might be hard to update it atomically on the source, but that shouldn't prevent us from not supporting any updates at all.

    In case this comes up: yes, applications could be rewritten to use socket activation, store and serialize all other state and then zero-downtime-restart into their new config, but very frequently they don't do that, but do support watching for file changes, sometimes in combination with a signal to reload.

    credentials are immutable: once loaded the remain entirely static until the service goes down. This is explicitly documented and by design.

    The rotation topic was explicitly raised in the initial RFE for credentials, and left out for the initial implementation.

    I'd very much prefer this could be changed, and not stay immutable forever. Secret rotation is something that should be supported. If this is considered a breaking change, it could be gated behind a MutableCredentials=yes option.

  11. poettering commented on Jun 10, 2024

    @poettering
    Member

    So, with today's kernels we could make this reasonably atomic, by using MOVE_MOUNT_BENATH. i.e. we could prepare all creds in a fresh mount, and then atomically replace the old mount with the new mount, so that apps either see the old or the new mount, in all immutability, and fully atomic.

  12. arianvp commented on Jun 19, 2024

    @arianvp
    Contributor

    For AF_UNIX credential reloading I guess what we can do is close() the socket and then reconnect()

  13. added a commit that references this issue on Dec 15, 2025
    c866e71
  14. 17 remaining items

  15. added 2 commits that reference this issue on Dec 21, 2025
    fc4bdaf
    ea5e647
  16. added a commit that references this issue on Jan 18, 2026
    82a7cfe
  17. added a commit that references this issue on Jan 30, 2026
    7a13431
  18. added 9 commits that reference this issue on Feb 10, 2026
    cbfd16c
    37fc0b2
    9415b3d
    1c84464
    80ad0e2
    b317860
    ee9dcd0
    c73c795
    fff07be
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

    RFE 🎁credspid1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions