feat: add set-testing subcommand #4

Merged
benvin merged 3 commits from benvin/set-testing into main 2026-10-23 21:45:56 +11:00
Member

Operators need to move a host into testing (so any puppet agent --environment X is honoured) without a terraform change; encapi accepts this via a scoped Vault OIDC token. Requires the encapi oidc-auth release.

  • add encapic set-testing <certname>: mint a JWT from Vault identity OIDC role encapi-testing (VAULT_TOKEN or ~/.vault-token, VAULT_CACERT honoured)
  • PUT {"environment":"testing"} to /api/v1/nodes/<certname>/environment with the bearer token
  • refuse non-https ENCAPI_URL/VAULT_ADDR and never follow redirects, so credentials never leave https or the target host
  • keep encapic <certname> ENC behaviour unchanged
  • document usage and reset-on-next-apply in README
Operators need to move a host into `testing` (so any `puppet agent --environment X` is honoured) without a terraform change; encapi accepts this via a scoped Vault OIDC token. Requires the encapi oidc-auth release. - add `encapic set-testing <certname>`: mint a JWT from Vault identity OIDC role `encapi-testing` (VAULT_TOKEN or ~/.vault-token, VAULT_CACERT honoured) - PUT `{"environment":"testing"}` to `/api/v1/nodes/<certname>/environment` with the bearer token - refuse non-https `ENCAPI_URL`/`VAULT_ADDR` and never follow redirects, so credentials never leave https or the target host - keep `encapic <certname>` ENC behaviour unchanged - document usage and reset-on-next-apply in README
unkin-agent added 1 commit 2026-10-23 21:34:08 +11:00
feat: add set-testing subcommand to pin a node to testing
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was canceled
7877f1eab6
Author
Member
  • settesting.go:114 — vaultClient VAULT_CACERT branch (bad path, no PEM, pool applied) has no test; the README advertises it → add a test with an httptest TLS server and its cert as VAULT_CACERT, plus the no-certs error case.
  • settesting_test.go — no case for "vault returned no OIDC token" or missing VAULT_TOKEN/~/.vault-token → add both.
  • nit: settesting.go:30 — PUT reuses defaultBaseURL (plain http) so the bearer JWT goes over cleartext unless ENCAPI_URL is https → consider refusing/warning on http for set-testing.
- settesting.go:114 — `vaultClient` VAULT_CACERT branch (bad path, no PEM, pool applied) has no test; the README advertises it → add a test with an httptest TLS server and its cert as VAULT_CACERT, plus the no-certs error case. - settesting_test.go — no case for "vault returned no OIDC token" or missing VAULT_TOKEN/~/.vault-token → add both. - nit: settesting.go:30 — PUT reuses `defaultBaseURL` (plain http) so the bearer JWT goes over cleartext unless ENCAPI_URL is https → consider refusing/warning on http for set-testing.
unkin-agent added 1 commit 2026-10-23 21:36:41 +11:00
fix: refuse non-https encapi URL in set-testing; cover vault CA and token errors
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
df0221bcbf
Author
Member
  • settesting.go:70 — VAULT_ADDR has no scheme check (tests use plain-http Vault), so X-Vault-Token can go over http → apply the same https-only refusal to VAULT_ADDR, and test it.
  • settesting.go:40 — default http.Client follows redirects; a 30x from encapi to http re-sends the bearer JWT on the same host → set CheckRedirect to http.ErrUseLastResponse (or refuse non-https targets).
  • settesting.go:117 — VAULT_CACERT is applied to the encapi call as well as Vault; an encapi cert from a different CA than Vault fails with no way to trust both → use separate trust for encapi (system pool) or document the constraint in README.
- settesting.go:70 — `VAULT_ADDR` has no scheme check (tests use plain-http Vault), so `X-Vault-Token` can go over http → apply the same https-only refusal to `VAULT_ADDR`, and test it. - settesting.go:40 — default `http.Client` follows redirects; a 30x from encapi to http re-sends the bearer JWT on the same host → set `CheckRedirect` to `http.ErrUseLastResponse` (or refuse non-https targets). - settesting.go:117 — `VAULT_CACERT` is applied to the encapi call as well as Vault; an encapi cert from a different CA than Vault fails with no way to trust both → use separate trust for encapi (system pool) or document the constraint in README.
unkin-agent added 1 commit 2026-10-23 21:38:46 +11:00
fix: require https VAULT_ADDR and never follow redirects in set-testing
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
b664d2f12f
Author
Member

No findings.

No findings.
benvin merged commit 2a63b3560e into main 2026-10-23 21:45:56 +11:00
benvin deleted branch benvin/set-testing 2026-10-23 21:45:56 +11:00
Sign in to join this conversation.