feat(security): integrate sops-nix for declarative secret management

- Add 'sops-nix' to flake inputs and lockfile.
- Define age public keys and path regex rules in `sops.yaml` for the
  desktop host.
- Provide comprehensive documentation in `docs/secrets-management.md`
  detailing key generation, rotation, and systemd runtime decryption.
This commit is contained in:
kiskaadee committed 2026-06-23 21:56:58 -05:00
1 parent cb67770e44
commit ebb6c48663
4 files changed
+121

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
keys:
- &kiskaadee age16nr2t9jrw09kakuxy2vtvtgtwa9jvy5dmtge25rzlqelf5cjy4es46alu9
- &desktop age18q3lr2z4yeg2f86my42ym4hx0dvcwgjshmchyhdkgwvf4k37dsyq3mcjse
creation_rules:
- path_regex: hosts/desktop/secrets\.yaml$
key_groups:
- pgp: []
age:
- *kiskaadee
- *desktop
+82
View File
@@ -0,0 +1,82 @@
# 🔒 Secrets Management via sops-nix
This repository utilizes **`sops-nix`** (integrated with Mozilla SOPS and `age`) to manage all sensitive information (passwords, tokens, API keys) declaratively and securely.
Secrets are stored encrypted directly in the Git repository, and decrypted dynamically at boot into memory (`/run/secrets/`), ensuring no credentials leak into the public-readable Nix store.
---
## 🛠️ Bootstrapping Secrets on a Recreated Server
If you are setting up a new host or rebuilding the system from scratch, follow these steps to configure your secrets key structure.
### Step 1: Generate a User age Key Pair
To encrypt and decrypt files on your local machine, generate a native `age` key pair:
```bash
# Create the standard config directory
mkdir -p ~/.config/sops/age
# Generate the age key pair
nix-shell -p age --run "age-keygen -o ~/.config/sops/age/keys.txt"
# Lock down key permissions
chmod 600 ~/.config/sops/age/keys.txt
```
To print your public key for configuration, run:
```bash
grep "public key" ~/.config/sops/age/keys.txt
```
### Step 2: Convert the Host SSH Public Key to age
To allow systemd to decrypt secrets automatically at boot time, obtain the host's SSH public key converted to `age` format:
```bash
nix run nixpkgs#ssh-to-age -- -i /etc/ssh/ssh_host_ed25519_key.pub
```
*Note: The private key counterpart `/etc/ssh/ssh_host_ed25519_key` is automatically read by `sops-nix` at boot with root privileges.*
### Step 3: Configure Public Keys in `.sops.yaml`
Add both the user `age` public key and the host `age` public key to the [.sops.yaml](file:///home/kiskaadee/Config/.sops.yaml) configuration file at the root of the repository:
```yaml
keys:
- &kiskaadee age1...your_user_age_key...
- &desktop age1...your_host_age_key...
creation_rules:
- path_regex: hosts/desktop/secrets\.yaml$
key_groups:
- pgp: []
age:
- *kiskaadee
- *desktop
```
---
## ✏️ Editing and Managing Secrets
Because `sops` automatically reads from your local `~/.config/sops/age/keys.txt` keyfile, you can manage secrets using simple commands:
### Create/Edit an Encrypted File
```bash
nix-shell -p sops --run "sops hosts/desktop/secrets.yaml"
```
This decrypts the file, opens it in your editor defined by `$EDITOR`, and automatically re-encrypts the values when you save and exit.
### Structure of `secrets.yaml`
Provide your keys and values as standard YAML:
```yaml
dynu_user: your-username
dynu_domain: your-domain.dynu.net
dynu_password: your-secret-password-or-hash
```
---
## 🔄 Runtime Decryption
At boot time, `sops-nix` performs the following steps:
1. Systemd runs the `sops-install-secrets` activation script.
2. The script reads `/etc/ssh/ssh_host_ed25519_key` to decrypt `hosts/desktop/secrets.yaml`.
3. The values are exposed under `/run/secrets/` as individual files (or templates) with strict user/group ownership (typically restricted to `root`).
4. Services read these paths at startup, keeping secrets secure and decoupled from the world-readable `/nix/store`.
Generated
+21
View File
@@ -160,9 +160,30 @@
"dms": "dms",
"home-manager": "home-manager",
"nixpkgs": "nixpkgs",
"sops-nix": "sops-nix",
"zen-browser": "zen-browser"
}
},
"sops-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1782165805,
"narHash": "sha256-478kKQBvK6SYTOdN2h9jhKJv94nbXRbFMfuL1WshErg=",
"owner": "Mic92",
"repo": "sops-nix",
"rev": "56b24064fdcaedca53553b1a6d607fd23b613a24",
"type": "github"
},
"original": {
"owner": "Mic92",
"repo": "sops-nix",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
+7
View File
@@ -31,6 +31,12 @@
inputs.nixpkgs.follows = "nixpkgs";
};
## Cryptographic Secrets management
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# Antigravity CLI - coding companion and local AI agent helper
antigravity = {
url = "github:jacopone/antigravity-nix";
@@ -51,6 +57,7 @@
modules = [
./hosts/desktop/hardware-configuration.nix # Autogenerated hardware/disk/CPU module
./hosts/desktop/configuration.nix # Desktop environment / system package settings
inputs.sops-nix.nixosModules.sops # Import Sops module
home-manager.nixosModules.home-manager {
home-manager.useGlobalPkgs = true;