Commit adef4a4
fix(security): P2-8 AES-256-GCM encryption-at-rest for on-disk secrets (#55)
* fix(security): P2-8 AES-256-GCM encryption-at-rest for on-disk secrets
Secrets written to disk by gearbox-agent (API key, webhook secret) are
now protected with AES-256-GCM envelope encryption when
GEARBOX_AGENT_ENCRYPTION_KEY is set.
Key changes:
- aead.go: KeyProvider interface, EnvKeyProvider (reads 32-byte hex key
from GEARBOX_AGENT_ENCRYPTION_KEY), encryptSecret/decryptSecret using
AES-256-GCM, magic bytes GBE1 for auto-detection of encrypted files.
- keys.go: loadOrCreateSecret and readSecret auto-detect and decrypt;
auto-migrate existing plaintext files to encrypted on first boot with
key set; hard-fail (ErrKeyRequired) if encrypted file found but no key
is configured. New WriteAPIKey() for the --rotate-api-key path.
- main.go: --rotate-api-key uses crypto.WriteAPIKey (respects encryption);
startup warning when no encryption key is configured.
Backward compatible: no GEARBOX_AGENT_ENCRYPTION_KEY → plaintext as before.
Tier 2 KMS providers tracked in issue #54.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(security): address P2-8 Copilot review nits
- aead.go: docstring no longer claims "lowercase hex" only; hex.DecodeString
accepts both cases, and constraining the wire form would just be a foot-gun.
- aead.go: ErrKeyRequired message no longer points to --generate-webhook-secret
as the recovery path. That flag won't overwrite an existing file, so it
wouldn't actually unblock recovery for an encrypted webhook secret. The
doc comment for ErrKeyRequired explains this; the message itself just
says "delete the file and re-generate the secret".
- main.go: plaintext-encryption warning moved out of the one-shot CLI
handler region (was firing before --show-api-key etc., polluting their
stdout). Now only emitted on normal startup. Malformed-key validation
still runs early so any subcommand that needs to decrypt fails cleanly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(crypto): mark deterministic test fixtures gitleaks:allow
The gitleaks "generic-api-key" rule was matching three hard-coded test
fixtures in aead_test.go (lines 249, 355, 378):
plainSecret := "abcdef0123456789..." // 64 hex chars
apiKey := "abcdef1234567890..." // 64 hex chars (x2)
These are deterministic fixtures used to exercise the secret-file
round-trip, not real credentials — but they trip the rule because the
variable names include "secret"/"key" and the values are 32+ chars of
[a-z0-9]. Added //gitleaks:allow inline comments rather than broadening
the global path allowlist so future test files don't get an accidental
free pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(gitleaks): allowlist commit 96bd383 (P2-8 test fixtures)
gitleaks-action scans the full PR diff range, so even after inline
//gitleaks:allow comments were added to aead_test.go in commit 5477bd8,
the historical commit 96bd383 (where the fixtures were introduced)
continues to trip the generic-api-key rule.
Adding the commit SHA to the existing allowlist (same pattern used for
2fdb5ba). The fixtures themselves are deterministic 64-hex-char values
used to exercise the encryption-at-rest round-trip — not real secrets.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ff336e2 commit adef4a4
5 files changed
Lines changed: 632 additions & 21 deletions
File tree
- gearbox-agent
- cmd/gearbox-agent
- internal/framework/crypto
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
76 | 80 | | |
77 | 81 | | |
| 82 | + | |
78 | 83 | | |
79 | 84 | | |
80 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
95 | 103 | | |
96 | 104 | | |
97 | 105 | | |
| |||
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
112 | | - | |
| 120 | + | |
113 | 121 | | |
114 | 122 | | |
115 | 123 | | |
| |||
169 | 177 | | |
170 | 178 | | |
171 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
172 | 189 | | |
173 | 190 | | |
174 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
0 commit comments