Add agentvault seed-oauth for oauth2-proxy credentials
Seeding an oauth2-proxy secret by hand means an agent shell-plumbing a client secret and a cookie secret, which the classifier blocks. seed-oauth does it in one self-contained invocation: it reads the KV path, fills in only the keys that are missing, preserves everything else and prints key names and the new version, never a value. - Add SeedOAuth in internal/agent: read-modify-write of the client_id, client_secret and cookie_secret keys with per-key created/kept/rotated actions and a no-op when nothing changed. - Generate secrets from 32 crypto/rand bytes; cookie_secret is base64url so it decodes to exactly the 32 bytes oauth2-proxy requires. - Add ReadKVOptional (missing secret = empty) and WriteKVAny (non-string fields survive a round trip) to the KV-v2 client. - Wire the seed-oauth subcommand and document it in README and AGENTS.md. - Cover fresh create, patch-preserves-client_secret, other-key preservation, --rotate, idempotence, denial errors and secret leakage.
This commit is contained in:
@@ -162,6 +162,42 @@ Errors name the failing stage: AppRole login, KV read denied (policy not
|
||||
applied), outpost not found (terraform not applied), `view_key` failure, or KV
|
||||
write denied.
|
||||
|
||||
### seed-oauth
|
||||
|
||||
Make a Vault KV-v2 path hold a complete oauth2-proxy credential set. It is a
|
||||
read-modify-write: `client_id` is set from the flag, `client_secret` and
|
||||
`cookie_secret` are generated (32 bytes from `crypto/rand`) only when missing,
|
||||
every other key on the path is written back untouched, and nothing is written
|
||||
at all when the secret is already correct. `cookie_secret` is base64url so it
|
||||
decodes to exactly the 32 bytes oauth2-proxy requires.
|
||||
|
||||
```bash
|
||||
agentvault seed-oauth \
|
||||
--path kubernetes/namespace/repospawner/default/oauth-credentials \
|
||||
--client-id 4f1c…
|
||||
```
|
||||
|
||||
```
|
||||
path: kv/kubernetes/namespace/repospawner/default/oauth-credentials
|
||||
keys: client_id, client_secret, cookie_secret
|
||||
client_id: created
|
||||
client_secret: kept
|
||||
cookie_secret: created
|
||||
version: 4
|
||||
```
|
||||
|
||||
That is the common case: the provider's `client_secret` already lives on the
|
||||
path, so only the missing keys are added. A run with nothing to do prints
|
||||
`version: unchanged` and issues no write.
|
||||
|
||||
Flags: `--path` and `--client-id` are required; `--kv-mount` (default `kv`) and
|
||||
`--rotate` override the rest. `--rotate` regenerates both secrets — only use it
|
||||
when the IdP provider's secret is being rotated alongside, since a rotated
|
||||
`client_secret` no longer matches the provider.
|
||||
|
||||
Errors name the failing stage: AppRole login, KV read denied, or KV write
|
||||
denied. Only key names, actions and the KV version are printed.
|
||||
|
||||
## Build & package
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user