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

Agenix Line 162: unbound variable #288

Open
Supermarcel10 opened this issue Sep 14, 2024 · 2 comments
Open

Agenix Line 162: unbound variable #288

Supermarcel10 opened this issue Sep 14, 2024 · 2 comments

Comments

@Supermarcel10
Copy link

Issue

It seems like there is an issue with how agenix might be retrieving the $EDITOR variable as superuser.

Line 162 seems to be referring to the following line of code:

[ -t 0 ] || EDITOR='cp /dev/stdin'

$EDITOR "$CLEARTEXT_FILE" # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

if [ ! -f "$CLEARTEXT_FILE" ]
then
  warn "$FILE wasn't created."
  return
fi

Terminal

[marcel@marcel-pc:/etc/nixos/secrets]$ agenix -e github-token.age
mv: cannot move '/tmp/tmp.TB9tizadZX/github-token.age' to 'github-token.age': Permission denied

[marcel@marcel-pc:/etc/nixos/secrets]$ sudo !!
sudo agenix -e github-token.age
/run/current-system/sw/bin/agenix: line 162: EDITOR: unbound variable

[marcel@marcel-pc:/etc/nixos/secrets]$ sudo echo $EDITOR
nano

[marcel@marcel-pc:/etc/nixos/secrets]$ echo $EDITOR
nano
@ccalhoun1999
Copy link

I am running into the same issue. Is there any workaround for this?

@Supermarcel10
Copy link
Author

Supermarcel10 commented Oct 31, 2024

@ccalhoun1999

So by the looks of it, the permissions agenix has are very specific, but I haven't seen it documented anywhere clearly and definitively.

As far as my testing goes, because of the error you'd be tempted to normally try running as sudo user but this is actually not the intended way to do it.

For my setup I have the following:
etc/nixos/secrets containing:

  • secrets.nix:
    Note: You might have to comment out the line with example.age when building for the first time.
let
  username = "age1..."
in
{
  "example1.age".publicKeys = [ username ];
  ...
}
  • example1.age
  • example2.age
  • ...

In terms of the permissions I've set the entire secrets directory as 775, owned by root, with a custom user group for managing it (but the default "users" is sufficient).

This will allow anyone to read all files within it, and execute on them, and only root and the user group can edit them (add new secrets, edit them, etc)

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

No branches or pull requests

2 participants