-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can Systemd 247 "credentials" logic solve secret management for us? #102397
Comments
I thought about the issue for 7 minutes.
Then the credentials won't have to be state and the configuration is reproducible again. Related: |
also related: #93659 |
Also related: Mic92/sops-nix#39 (review) |
I did some testing with a conf akin to the following
having the /run/secrets being populated with agenix.
I'm not sure how to proceed next. I'm interested in testing if anybody has ideas. |
@happysalada you could ask upstream (systemd) how the feature should be used in this case if the documentation is not clear. maybe something is still missing which they can add |
submitted systemd/systemd#19604 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
just to give a summary of what happened. the systemd people advise not using environment variables for secrets at all. Meaning that any application written to get secrets (database password for example) from environment variables should be modified to read it from a file instead. To me it seems that this is going to need some work with upstream packages to change the behavior. It seems that some settings like db passwords are most often read from env vars, while things from cert files is most often a file. I'm curious to see how upstream maintainers will react to those proposed changes. Regarding usage it's a little odd to me, but it seems the way to use this will be pass a file coming from run/secrets. Meaning doing traditional secret management to have secrets be available in Please correct me, If you feel I misunderstood something. |
That is very common in Docker, maybe they made it popular. it might be OK inside a container, but we should use files thank you for bringing this topic forward! |
At least with current systemd in unstable (systemd-247.6), It doesn't seem to be broken anymore. I created
|
very silly question, how do you pass several credentials ? |
You can assign a list
|
It is still broken. The systemd version hasn't changed since I posted systemd/systemd#19604 (comment). |
@dotlambda you can't reproduce the command output I posted in my comments (here and here)? I think your issue is that in your example you want systemd to do the substitution, not a wrapper script. |
@flokli Please read my comment. You have to use |
Let's carry the discussion over to systemd/systemd#19604 (comment) - that's unrelated to whether systemd 247's credential logic can be used to solve secret management. It can, as demonstrated in #102397 (comment), it just requires some wrapper scripts for services not supporting reading secrets from files, and assembling these files with environment variables passed at runtime - so closing this issue. |
How about we leave it open until we manage to use it somewhere in nixpkgs ? |
Just an additional note that I tried to run this on the systemd 247.6 without DynamicUser. ExecStartPre and LoadCredentials seem to be enough to trigger the bug (for me). |
Systemd update to 249.4 just landed on unstable. The gotchas are
I was thinking of writing some documentation for it, but I don't know at all where it would belong. If people know, I'm interested. PS: working on a PR in nixpkgs that uses that. However it needs a bit more work. I will update when it's close to merging |
A systemd section in the nixos manual might be worth it? If that's too high
of a bar we could create a nixos.wiki page
…On Tue, 5 Oct 2021, 06:49 Raphael Megzari, ***@***.***> wrote:
Systemd update to 249.4 just landed on unstable.
There are a couple of gotchas with using LoadCredentials but my simple
testing reveal it to work well.
The gotchas are
- credentials are not available in ExecPreStart
- if used inside ExecStart the environment variable
$CREDENTIALS_DIRECTORY should be used between {} like
${CREDENTIALS_DIRECTORY}/my_credential. Since in systemd unlike in
bash / is not a variable separator.
I was thinking of writing some documentation for it, but I don't know at
all where it would belong. If people know, I'm interested.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#102397 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEZNIZUASFLEOA3RH4WFPDUFJ7UFANCNFSM4TGZHCAQ>
.
|
@happysalada @arianvp NixOS manual should be better for discoverability. I'd be more than happy to review a PR for this. There's already quite some markdown files in |
I couldn't find the |
Ok, very early design for a systemd section, feedback welcome |
How is this going to work on non-NixOS hosts? |
Non-NixOS hosts are not affected by this. We render systemd units only for NixOS machines. The systemd credentials system simply exposes files in a |
I think this can be closed now? (Note that unfortunately we cannot access credentials in ExecStartPre yet: systemd/systemd#19604) |
I agree, I think this can be closed. the credentials logic has been implemented in several modules. |
@happysalada could you link to some of them? |
plausible.nix and lemmy.nix are two of them. |
So just out of interest because I'm window-shopping for a secrets solution: now that the issue is closed, can we get a summary?
|
If you search for loadcrediential in nixpkgs youll see where it s used. The one problem you might run into though is that if upstream us just putting secets in env vars. Then there isnt any point in using loadcredential, whatever you do it will end up in the nix store. The best is if upstream enables loading a secret through a path, then loadcredential is the perfect solution for it. If you are packaging your own software, then using env vars that read a path is the way to go. |
It would be great to have the best practices of credential handling in nixos modules documented und used in all where it is possible, to have a consistent experience. |
@arianvp recently also mentioned the concept of If you don't specify an absolute path to the secret, but only an identifier, that's where systemd credentials logic looks things up. Maybe we could align our recommendations towards that? Is someone willing to take over @happysalada 's PR at #142282 (or at least the credentials-related parts)? |
Issue description
Configuring credentials in NixOS is an unsolved problem, since saving them in the nix store is a bad idea (it is world-readable on a system).
A solution would be to store it outside the nix store, as state on disk (like linux user passwords), in best case with permissions, so only the service that needs it can access it.
Maybe the new "credentials" logic from Systemd 247 can solve it for us?
Source: https://github.com/systemd/systemd/blob/6706384a89ae0c462e7172588c80667190c4d9e2/NEWS#L320
Update: Turns out this feature was added because of the discussions in NixOS/rfcs#59 (comment). So the answer is probably yes!
cc @flokli @Mic92 @aanderse @arianvp @edolstra @shlevy @d-goldin @globin
Thanks to @poettering for making this possible!
Related:
The text was updated successfully, but these errors were encountered: