buzz ssl
This commit is contained in:
1 parent
6411069dbc
commit
dd6d071c34
15 files changed
+270
-42
No files matched your search
+24
-21
@@ -11,32 +11,35 @@ bin/
|
||||
├── temp-monitor # NuShell script: collect CPU/GPU temps to CSV + optional graph
|
||||
├── TEMP_MONITOR_README.md # Usage docs for temp-monitor
|
||||
└── lib/
|
||||
├── cmds.nu # All subcommand implementations (NuShell — source of truth)
|
||||
├── cmds.nu # All subcommand implementations (NuShell — source of truth); commands only
|
||||
├── helpers.nu # Shared helpers: REPO_ROOT const + internal functions used by commands
|
||||
├── profile.nu # Profile helpers and tab-completion data
|
||||
└── types.nu # Type definitions
|
||||
└── types.nu # Type definitions
|
||||
```
|
||||
|
||||
## Key Commands
|
||||
|
||||
| Command | Description |
|
||||
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `skyg os switch` | Rebuild and switch local system |
|
||||
| `skyg remote switch <host>` | Deploy to a remote host |
|
||||
| `skyg remote install <host>` | Fresh-install a remote host via nixos-anywhere, using `hosts/<profile>.disko.nix`. Always wipes the disks in that file. Aborts if the file is missing, if the host already boots NixOS from disk (unless `--force-wipe`), or if you do not type the short hostname. |
|
||||
| `skyg hm switch` | Apply Home Manager config |
|
||||
| `skyg update [input]` | Update flake inputs |
|
||||
| `skyg build-image iso | pi1 | pi2` | Build bootable image — ISO (`iso`) or Pi SD card image (`pi1`, `pi2`) |
|
||||
| `skyg openwrt` | Deploy OpenWrt config |
|
||||
| `skyg rollback` | Roll back to previous generation |
|
||||
| `skyg profiles` | List valid local/remote profiles |
|
||||
| `skyg check` | Run `nix flake check --no-build` |
|
||||
| `skyg check-flake-versions` | Verify NixOS release version consistency in flake.nix |
|
||||
| `skyg remote boot-all` | Boot all remote hosts (builds on `fwdesk`) |
|
||||
| `skyg remote status` | Check status of all remote hosts |
|
||||
| `skyg secrets` | List known secret names |
|
||||
| `skyg decrypt <secret>` | Decrypt a secret to `.tmp/unencrypted-<secret>` |
|
||||
| `skyg encrypt <secret> [--yaml]` | Encrypt a working copy back into the secret |
|
||||
| `skyg compare-secret <secret>` | Diff the working copy against the stored secret |
|
||||
| Command | Description |
|
||||
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `skyg os switch` | Rebuild and switch local system |
|
||||
| `skyg remote switch <host>` | Deploy to a remote host |
|
||||
| `skyg remote install <host>` | Fresh-install a remote host via nixos-anywhere, using `hosts/<profile>.disko.nix`. Always wipes the disks in that file. Aborts if the file is missing, if the host already boots NixOS from disk (unless `--force-wipe`), or if you do not type the short hostname. |
|
||||
| `skyg hm switch` | Apply Home Manager config |
|
||||
| `skyg update [input]` | Update flake inputs |
|
||||
| `skyg build-image iso | pi1 | pi2` | Build bootable image — ISO (`iso`) or Pi SD card image (`pi1`, `pi2`) |
|
||||
| `skyg openwrt` | Deploy OpenWrt config |
|
||||
| `skyg rollback` | Roll back to previous generation |
|
||||
| `skyg profiles` | List valid local/remote profiles |
|
||||
| `skyg check` | Run `nix flake check --no-build` |
|
||||
| `skyg check-flake-versions` | Verify NixOS release version consistency in flake.nix |
|
||||
| `skyg remote boot-all` | Boot all remote hosts (builds on `fwdesk`) |
|
||||
| `skyg remote status` | Check status of all remote hosts |
|
||||
| `skyg secrets` | List known secret names |
|
||||
| `skyg decrypt <secret>` | Decrypt a secret to `.tmp/unencrypted-<secret>` |
|
||||
| `skyg encrypt <secret> [--yaml]` | Encrypt a working copy back into the secret |
|
||||
| `skyg compare-secret <secret>` | Diff the working copy against the stored secret |
|
||||
| `skyg ca init` | Generate the lab root CA: key → `secrets/lab-ca-key.age`, cert → `configs/pki/lab-ca.crt` (see `configs/pki/ABOUTME.md`) |
|
||||
| `skyg ca issue <domain> --for <host>` | Mint a TLS leaf cert signed by the lab CA: cert → `configs/pki/<domain>.crt`, key → `secrets/<name>-tls-key.age`. Auto-registers missing `secrets.nix` entries. |
|
||||
|
||||
## Agent Note
|
||||
|
||||
|
||||
+72
-2
@@ -1,7 +1,6 @@
|
||||
use types.nu *
|
||||
use profile.nu *
|
||||
|
||||
const REPO_ROOT = path self | path dirname | path dirname | path dirname
|
||||
use helpers.nu *
|
||||
|
||||
export def skyg [] {
|
||||
print $REPO_ROOT
|
||||
@@ -473,3 +472,74 @@ export def "skyg compare-secret" [secret: string] {
|
||||
|
||||
rm -f $temp_decrypted
|
||||
}
|
||||
|
||||
# Generate the lab root CA: key encrypted to secrets/lab-ca-key.age,
|
||||
# public cert written to configs/pki/lab-ca.crt. Run once, before `ca issue`.
|
||||
export def "skyg ca init" [
|
||||
--days: int = 3650 # CA lifetime in days
|
||||
] {
|
||||
cd $REPO_ROOT
|
||||
let cert = "configs/pki/lab-ca.crt"
|
||||
let key_secret = "secrets/lab-ca-key.age"
|
||||
if ($cert | path exists) {
|
||||
error make {msg: $"($cert) already exists — refusing to overwrite the CA. Delete it manually to rotate."}
|
||||
}
|
||||
ensure-secret-entry $key_secret ["ari"]
|
||||
mkdir .tmp configs/pki
|
||||
let tmp_key = ".tmp/lab-ca-key.pem"
|
||||
(openssl req -x509 -newkey rsa:4096 -sha256 -days $days -nodes
|
||||
-keyout $tmp_key -out $cert
|
||||
-subj "/CN=Skyg Lab CA"
|
||||
-addext "basicConstraints=critical,CA:TRUE"
|
||||
-addext "keyUsage=critical,keyCertSign,cRLSign")
|
||||
^cat $tmp_key | agenix -e $key_secret
|
||||
rm -f $tmp_key
|
||||
print $"✅ CA cert: ($cert) — commit this"
|
||||
print $"✅ CA key encrypted: ($key_secret)"
|
||||
print "Next: skyg ca issue <domain> --for <host>"
|
||||
}
|
||||
|
||||
# Issue a TLS cert for a domain, signed by the lab CA.
|
||||
# Writes configs/pki/<domain>.crt; encrypts the key to secrets/<name>-tls-key.age.
|
||||
export def "skyg ca issue" [
|
||||
domain: string # e.g. buzz.app.internal
|
||||
--for: string # secrets.nix key name allowed to decrypt the leaf key (e.g. minipc1)
|
||||
--days: int = 825 # leaf lifetime (825 = browser max)
|
||||
--name: string # secret slug override (default: first DNS label)
|
||||
] {
|
||||
cd $REPO_ROOT
|
||||
let ca_cert = "configs/pki/lab-ca.crt"
|
||||
let ca_key_secret = "secrets/lab-ca-key.age"
|
||||
if not ($ca_cert | path exists) {
|
||||
error make {msg: "No CA found — run `skyg ca init` first"}
|
||||
}
|
||||
let key_names = (^cat secrets.nix | parse --regex '(\w+) = "ssh-' | get capture0)
|
||||
if ($for not-in $key_names) {
|
||||
error make {msg: $"Unknown recipient '($for)'. Known: ($key_names | str join ', ')"}
|
||||
}
|
||||
let slug = $name | default ($domain | split row "." | first)
|
||||
let secret = $"secrets/($slug)-tls-key.age"
|
||||
let cert = $"configs/pki/($domain).crt"
|
||||
if ($cert | path exists) {
|
||||
error make {msg: $"($cert) already exists — delete it manually to re-issue."}
|
||||
}
|
||||
ensure-secret-entry $secret ["ari" $for]
|
||||
mkdir .tmp configs/pki
|
||||
let ca_key = ".tmp/lab-ca-key.pem"
|
||||
agenix -d $ca_key_secret | save -f $ca_key
|
||||
let leaf_key = $".tmp/($slug)-tls-key.pem"
|
||||
let csr = $".tmp/($slug).csr"
|
||||
let ext = $".tmp/($slug)-ext.cnf"
|
||||
$"basicConstraints=critical,CA:FALSE\nkeyUsage=critical,digitalSignature,keyEncipherment\nextendedKeyUsage=serverAuth\nsubjectAltName=DNS:($domain)\n" | save -f $ext
|
||||
(openssl req -newkey rsa:2048 -nodes
|
||||
-keyout $leaf_key -out $csr
|
||||
-subj $"/CN=($domain)")
|
||||
(openssl x509 -req -in $csr
|
||||
-CA $ca_cert -CAkey $ca_key -CAcreateserial
|
||||
-out $cert -days $days -sha256 -extfile $ext)
|
||||
^cat $leaf_key | agenix -e $secret
|
||||
rm -f $ca_key $leaf_key $csr $ext
|
||||
print $"✅ Cert: ($cert) — commit this"
|
||||
print $"✅ Key encrypted: ($secret)"
|
||||
print $"Wire it up: age.secrets.($slug)-tls-key.file = ../($secret);"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
export const REPO_ROOT = path self | path dirname | path dirname | path dirname
|
||||
|
||||
# Insert a secrets.nix entry for the given secret path if missing.
|
||||
export def ensure-secret-entry [secret_path: string, recipients: list<string>] {
|
||||
let file = "secrets.nix"
|
||||
# Read via external cat — `open` type-guessing on .nix files is unreliable.
|
||||
let content = (^cat $file)
|
||||
if ($content | str contains $secret_path) {
|
||||
return
|
||||
}
|
||||
let entry = $' "($secret_path)".publicKeys = [ ($recipients | str join " ") ];'
|
||||
let lines = ($content | lines)
|
||||
# Insert before the final top-level closing brace.
|
||||
let closing = ($lines | enumerate | where item == "}" | last)
|
||||
if $closing == null {
|
||||
error make {msg: $"Could not find the final '}' in ($file) — refusing to edit"}
|
||||
}
|
||||
let new_lines = ($lines | insert $closing.index $entry)
|
||||
($new_lines | str join "\n") + "\n" | save -f $file
|
||||
print $"📝 Registered ($secret_path) in secrets.nix — review with git diff"
|
||||
}
|
||||
Reference in new issue
Block a user