Skip to content
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

Secrets owned by non-root users are no longer readable by that user #69

Closed
chvp opened this issue Nov 20, 2021 · 6 comments · Fixed by #71
Closed

Secrets owned by non-root users are no longer readable by that user #69

chvp opened this issue Nov 20, 2021 · 6 comments · Fixed by #71

Comments

@chvp
Copy link

chvp commented Nov 20, 2021

Since 0.10 / #27

Relevant namei -l output:

drwxr-xr-x root root /
drwxr-xr-x root root run
lrwxrwxrwx root root agenix -> /run/agenix.d/2
drwxr-xr-x root root   /
drwxr-xr-x root root   run
drwxr-x--- root keys   agenix.d
                       2 - Permission denied

Even if I set symlink = false this doesn't work, since even if the secrets are decrypted to /run/agenix, they are actually decrypted to /run/agenix.d/2, since /run/agenix is already a symlink to /run/agenix.d/2 at that point. (Which kind of defeats the point of symlink = false IIUC. Maybe this should be a separate issue?)

I can add the relevant user(s) to the keys group to fix this behaviour, but this is not documented anywhere.

@ryantm
Copy link
Owner

ryantm commented Nov 20, 2021

Thanks for the report! I've confirmed this is a problem for me too with:

  age.secrets.test-user-file = {
    owner = "ryantm";
    group = "users";
    file = ../secrets/test-user-file.age;
  };
$ sudo ls -la /run/agenix/
total 16
drwxr-x--- 2 root   keys     0 Nov 20 12:03 .
drwxr-x--- 3 root   keys     0 Nov 20 12:03 ..
-r-------- 1 ryantm users   12 Nov 20 12:03 test-user-file

[ryantm@home2:~/p/nixfiles]$ sudo ls -la /run/agenix.d/3
total 16
drwxr-x--- 2 root   keys     0 Nov 20 12:03 .
drwxr-x--- 3 root   keys     0 Nov 20 12:03 ..
-r-------- 1 ryantm users   12 Nov 20 12:03 test-user-file

$ whoami
ryantm

$ cat /run/agenix/test-user-file
cat: /run/agenix/test-user-file: Permission denied

cc @cole-h

@ryantm
Copy link
Owner

ryantm commented Nov 20, 2021

If I change permissions with:

chmod o+x /run/agenix.d
chmod o+x /run/agenix.d/3

then it works.

@ryantm
Copy link
Owner

ryantm commented Nov 20, 2021

ryantm added a commit that referenced this issue Nov 20, 2021
@cole-h
Copy link
Collaborator

cole-h commented Nov 20, 2021

Ah, this was not an issue for me since my user is in the keys group. Sorry about that! 🙇

@ryantm
Copy link
Owner

ryantm commented Nov 20, 2021

Released https://github.com/ryantm/agenix/releases/tag/0.10.1 to fix this. Thanks again.

@cole-h
Copy link
Collaborator

cole-h commented Nov 20, 2021

Even if I set symlink = false this doesn't work, since even if the secrets are decrypted to /run/agenix, they are actually decrypted to /run/agenix.d/2, since /run/agenix is already a symlink to /run/agenix.d/2 at that point. (Which kind of defeats the point of symlink = false IIUC. Maybe this should be a separate issue?)

If you set symlink = false;, the idea is that you also set the path to where the secret should be located. So your secret would look like:

{
  age.secrets.test = {
    path = "/var/lib/some/path/that/cannot/be/a/symlink";
    symlink = false;
  };
}

And then your secret will be decrypted to /var/lib/some/path/that/cannot/be/a/symlink.

Secrets are decrypted to "${config.age.secrets.<secret>.path}.tmp", as you can see in these places:

_truePath="${secretType.path}"

TMP_FILE="$_truePath.tmp"

LANG=${config.i18n.defaultLocale} ${ageBin} --decrypt ${identities} -o "$TMP_FILE" "${secretType.file}"

mv -f "$TMP_FILE" "$_truePath"

But the default path is /run/agenix/<secret>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants