You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RFE: allow service credentials to be updated during service runtime #21099
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
changed the title [-]Reload to update credential when using LoadCredential [/-][+]RFE: allow service credentials to be updated during service runtime[/+]on Oct 26, 2021
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)
Fetch new desired credentials and write them into temporary file /run/credentials/<x>/.<credname>.<random>
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?
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.
Reacted by Herman Slatman, Florian Klink, Võ Anh Duy, Laurens Duijvesteijn, clacknya, Gary Guo, Simon Menke, Poscat, Joshua Peek, Gunni and 1 more
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.
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.
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.
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.
Reacted by Florian Klink, Sarah Brofeldt, Arian van Putten, Erik Skytthe, Mark Vainomaa, Charles Hall, Martin Weinelt, Ryan Lahfa, Simon Menke, Ilan Joselevich and 6 more
Activity
poettering commentedon Oct 26, 2021
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.
[-]Reload to update credential when using LoadCredential [/-][+]RFE: allow service credentials to be updated during service runtime[/+]mikroskeem commentedon Oct 31, 2021
Technically you can:
/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)/run/credentials/<x>/.<credname>.<random>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
nginxprocess serving thousands of clients).That being said, could credentials immutability be reconsidered?
flokli commentedon Feb 22, 2022
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.
tashian commentedon Aug 9, 2022
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_UNIXcredential 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.mikroskeem commentedon Oct 2, 2022
I've released https://github.com/ZentriaMC/syringe which features described logic for credentials updating
arianvp commentedon Jun 8, 2024
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/
arianvp commentedon Jun 8, 2024
The only caveat is that if you're using inotify or the likes you should handle
IN_DELETE_SELFflokli commentedon Jun 10, 2024
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.
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=yesoption.poettering commentedon Jun 10, 2024
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.
arianvp commentedon Jun 19, 2024
For
AF_UNIXcredential reloading I guess what we can do isclose()the socket and then reconnect()core/service: support credential refreshing on reload
17 remaining items
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credential refreshing on reload
core/service: support credentials refreshing on reload (#40093)