Add castle secret CLI and fail-loud unresolved-secret apply gate
Writing a secret by hand meant knowing the active backend and its layout;
getting it wrong (a file write on an OpenBao fleet) left the value where the
resolver never reads it, so ${secret:NAME} silently degraded to the literal
<MISSING_SECRET:NAME> placeholder that a service then used as its credential.
- `castle secret {list|set|get|rm}` reads/writes the ACTIVE backend, so there's
no wrong store to pick. `set NAME` with no value reads a hidden prompt / stdin.
- `castle apply` (and --plan) now refuses to converge any deployment whose
${secret:...} refs don't resolve in the active backend: exits non-zero, writes
nothing, and names each deployment + secret + the `castle secret set` fix.
- New helpers in core/config.py: active_secret_backend(), active_backend_name(),
secret_refs(). Gate impl: deploy._unresolved_secrets() + ApplyResult.blocked.
- Tests: test_deploy_secret_gate.py, TestSecretRefs, test_secret.py. Docs: AGENTS.md.
This commit is contained in:
@@ -12,6 +12,7 @@ from castle_core.config import (
|
||||
resolve_env_split,
|
||||
resolve_env_vars,
|
||||
save_config,
|
||||
secret_refs,
|
||||
)
|
||||
from castle_core.manifest import ProgramSpec, SystemdDeployment
|
||||
|
||||
@@ -182,6 +183,22 @@ class TestResolveEnvVars:
|
||||
assert resolved["API_KEY"] == "<MISSING_SECRET:NONEXISTENT>"
|
||||
|
||||
|
||||
class TestSecretRefs:
|
||||
"""Tests for extracting ${secret:NAME} references (the apply-gate input)."""
|
||||
|
||||
def test_none_when_no_refs(self) -> None:
|
||||
assert secret_refs("plain") == []
|
||||
assert secret_refs("${port}/${data_dir}") == []
|
||||
|
||||
def test_single_and_composite(self) -> None:
|
||||
assert secret_refs("${secret:API_KEY}") == ["API_KEY"]
|
||||
assert secret_refs("neo4j/${secret:NEO4J_PW}") == ["NEO4J_PW"]
|
||||
|
||||
def test_multiple_deduped_in_order(self) -> None:
|
||||
value = "${secret:A}:${secret:B}:${secret:A}"
|
||||
assert secret_refs(value) == ["A", "B"]
|
||||
|
||||
|
||||
class TestResolveEnvSplit:
|
||||
"""Tests for the secret/plain partition used to keep secrets out of units."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user