ocfox / den

Simply, but firmly
https://ocfox.me/
MIT License
13 stars 1 forks source link

anti-pattern use of agenix for factorio credentials #3

Closed Kreyren closed 9 months ago

Kreyren commented 10 months ago

https://github.com/ocfox/den/blob/3e33c09639fa2701e1e98a14469c1c4798631fc3/hosts/whitefox/nixpkgs.nix#L12

See: https://github.com/ryantm/agenix#builtinsreadfile-anti-pattern

This can cause the cleartext to be placed into the world-readable Nix store. Instead, have your services read the cleartext path at runtime.

ocfox commented 10 months ago

Thanks, but I am thinking about how to get this token during building.

Kreyren commented 10 months ago

Refer to https://github.com/ryantm/agenix#installation

In short it's declaring a file like this:

# Standalone ragenix secret declaration

let
    user = "ssh-ed25519 your-key";

    system-host = "ssh-ed25519 content of /etc/ssh/ssh_host_ed25519_key.pub without host@domain.tld"; 
in {
    "./path/to/your/file.age".publicKeys = [
        user system-host # users and systems who are allowed to decrypt the file.age
    ];
}

I keep this file in ./secrets.nix as it's standalone from flakes

Then invoke agenix -e ./path/to/your/file.age if you didn't already

and declare the secret in your configuration:

   services.gitea.enable = true; # Example
   ...
   age.secrets.file.file = ../secrets/file.age;
   ...

and then you can refer it it with e.g.

{ config, ... }:
{
  users.users.YOUR_USER.hashedPasswordFile = config.age.secrets.kreyren-user-password.path;
}

Upon deployment it will place the file in /run/agenix/somewhere

Let me know if you need help or ideally ask in https://matrix.to/#/%23agenix:nixos.org

oluceps commented 9 months ago

Here is a pattern that may help for avoiding impure eval and global readable:

inputs.private-repo.url = "git+ssh://git@github.com/${username}/${private-repo}";

Place credentials under another flake and import then.

 token = inputs.private-repo.token; 
ocfox commented 9 months ago

I like this approach. - Thank you!