Add secret and certificate lifecycle lab
This commit is contained in:
parent
ef60a6ec4e
commit
dd99af4f58
|
|
@ -0,0 +1,64 @@
|
|||
# Secrets and certificate lifecycle lab
|
||||
|
||||
This opt-in lab uses External Secrets Operator (ESO) to copy a demo value from
|
||||
an in-memory Vault development server into a Kubernetes Secret. A separate
|
||||
cert-manager self-signed Issuer issues a short-lived demo certificate. Jeannie
|
||||
creates Argo CD applications for the controllers and the lab resources. Both
|
||||
controllers and their CRDs are cluster-wide, although the demo resources and
|
||||
Vault service are confined to the `secrets-lab` namespace. Existing controllers
|
||||
are not adopted automatically.
|
||||
|
||||
Vault dev mode uses an automatically generated root token in a Kubernetes
|
||||
Secret and HTTP inside the cluster. It has no durable storage; a Vault restart
|
||||
loses its contents. This setup is only for disposable values, not real
|
||||
passwords, production secrets, or a backup of your existing secrets. The demo
|
||||
certificate is self-signed and is not trusted by browsers. Neither Dex nor OCI
|
||||
edge certificates are changed.
|
||||
|
||||
Your SOPS workflow stores encrypted values in Git and decrypts them when needed.
|
||||
This lab instead stores the value in Vault, and ESO periodically synchronizes a
|
||||
Kubernetes Secret. The generated Kubernetes Secret still exists in the cluster;
|
||||
ESO does not eliminate the need to protect Kubernetes secrets, access, or
|
||||
backups. A real secret-manager deployment would need durable storage, access
|
||||
policies, TLS, token management, and recovery planning.
|
||||
|
||||
## Run
|
||||
|
||||
Push the commit first; Argo CD reads the configured GitOps repository's `main`
|
||||
branch. On Debian, with the desired Jeannie profile selected:
|
||||
|
||||
```sh
|
||||
cd ~/my-homelab-configs
|
||||
git pull --ff-only gitea main
|
||||
./jeannie secrets-lab plan
|
||||
./jeannie secrets-lab apply
|
||||
./jeannie secrets-lab test
|
||||
```
|
||||
|
||||
The first apply downloads two charts and waits for their CRDs and the Vault
|
||||
deployment. Argo CD may need additional time to synchronize the demo resources.
|
||||
No secret values are printed. Check progress with `./jeannie secrets-lab status`.
|
||||
|
||||
## Exercises
|
||||
|
||||
```sh
|
||||
# Write a new random demo value to Vault and verify ESO copied it.
|
||||
./jeannie secrets-lab rotate
|
||||
|
||||
# If the disposable Vault restarted, create a replacement only if needed.
|
||||
./jeannie secrets-lab recover
|
||||
|
||||
# Delete only the lab TLS Secret and verify cert-manager reissues it.
|
||||
./jeannie secrets-lab recover-cert
|
||||
```
|
||||
|
||||
Certificate reissuance is a recovery exercise. The Certificate also has a 24-hour
|
||||
duration and an eight-hour renewal window so you can inspect automatic renewal
|
||||
using `kubectl describe certificate -n secrets-lab secrets-lab-demo` with the
|
||||
selected cluster's kubeconfig. Removing the demo TLS Secret changes its private
|
||||
key; no other TLS Secret is touched. Vault recovery creates a new value if the
|
||||
in-memory database was lost; it cannot restore the old value.
|
||||
|
||||
The chart versions are pinned for the homelab's Kubernetes 1.31 compatibility.
|
||||
That Kubernetes release and these controller versions require an upgrade plan;
|
||||
do not treat this lab as a supported production secret-management deployment.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- vault.yaml
|
||||
- resources.yaml
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
apiVersion: external-secrets.io/v1beta1
|
||||
kind: SecretStore
|
||||
metadata:
|
||||
name: secrets-lab-vault
|
||||
namespace: secrets-lab
|
||||
spec:
|
||||
provider:
|
||||
vault:
|
||||
server: http://secrets-lab-vault.secrets-lab.svc:8200
|
||||
path: secret
|
||||
version: v2
|
||||
auth:
|
||||
tokenSecretRef: {name: secrets-lab-vault-token, key: token}
|
||||
---
|
||||
apiVersion: external-secrets.io/v1beta1
|
||||
kind: ExternalSecret
|
||||
metadata:
|
||||
name: secrets-lab-demo
|
||||
namespace: secrets-lab
|
||||
spec:
|
||||
refreshInterval: 30s
|
||||
secretStoreRef: {name: secrets-lab-vault, kind: SecretStore}
|
||||
target:
|
||||
name: secrets-lab-demo
|
||||
creationPolicy: Owner
|
||||
data:
|
||||
- secretKey: value
|
||||
remoteRef: {key: demo, property: value}
|
||||
---
|
||||
apiVersion: cert-manager.io/v1
|
||||
kind: Issuer
|
||||
metadata:
|
||||
name: secrets-lab-selfsigned
|
||||
namespace: secrets-lab
|
||||
spec:
|
||||
selfSigned: {}
|
||||
---
|
||||
apiVersion: cert-manager.io/v1
|
||||
kind: Certificate
|
||||
metadata:
|
||||
name: secrets-lab-demo
|
||||
namespace: secrets-lab
|
||||
spec:
|
||||
secretName: secrets-lab-demo-tls
|
||||
duration: 24h
|
||||
renewBefore: 8h
|
||||
privateKey:
|
||||
rotationPolicy: Always
|
||||
commonName: secrets-lab.local
|
||||
dnsNames: [secrets-lab.local]
|
||||
issuerRef: {name: secrets-lab-selfsigned, kind: Issuer}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: secrets-lab-vault
|
||||
namespace: secrets-lab
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels: {app: secrets-lab-vault}
|
||||
template:
|
||||
metadata:
|
||||
labels: {app: secrets-lab-vault}
|
||||
spec:
|
||||
automountServiceAccountToken: false
|
||||
containers:
|
||||
- name: vault
|
||||
image: hashicorp/vault:1.18.5
|
||||
args: ["server", "-dev", "-dev-listen-address=0.0.0.0:8200"]
|
||||
env:
|
||||
- name: VAULT_DEV_ROOT_TOKEN_ID
|
||||
valueFrom:
|
||||
secretKeyRef: {name: secrets-lab-vault-token, key: token}
|
||||
- {name: VAULT_ADDR, value: "http://127.0.0.1:8200"}
|
||||
- name: VAULT_TOKEN
|
||||
valueFrom:
|
||||
secretKeyRef: {name: secrets-lab-vault-token, key: token}
|
||||
ports:
|
||||
- {name: http, containerPort: 8200}
|
||||
readinessProbe:
|
||||
httpGet: {path: /v1/sys/health, port: http}
|
||||
initialDelaySeconds: 3
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
capabilities: {drop: [ALL]}
|
||||
resources:
|
||||
requests: {cpu: 25m, memory: 64Mi}
|
||||
limits: {memory: 256Mi}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: secrets-lab-vault
|
||||
namespace: secrets-lab
|
||||
spec:
|
||||
selector: {app: secrets-lab-vault}
|
||||
ports:
|
||||
- {name: http, port: 8200, targetPort: http}
|
||||
15
jeannie
15
jeannie
|
|
@ -64,6 +64,7 @@ Base, Inventory, And Planning
|
|||
Review pinned cluster identity and scoped state.
|
||||
preflight Run non-mutating infrastructure preflight checks.
|
||||
gateway-lab {plan|apply|status|test} Manage the isolated Gateway API and FastAPI lab.
|
||||
secrets-lab {plan|apply|status|test|rotate|recover|recover-cert} Practice secret and certificate lifecycle.
|
||||
doctor-preapply Run deeper pre-apply safety checks.
|
||||
plan [all|provisioning|cluster|platform|apps|edge]
|
||||
Run OpenTofu plans without applying changes.
|
||||
|
|
@ -255,6 +256,7 @@ case "${1:-}" in
|
|||
up|cluster|platform|apps|start-cluster) runtime_pipeline=true ;;
|
||||
start) [[ "${2:-plan}" != apply ]] || runtime_pipeline=true ;;
|
||||
gateway-lab) [[ "${2:-plan}" != apply ]] || runtime_pipeline=true ;;
|
||||
secrets-lab) case "${2:-plan}" in apply|test|rotate|recover|recover-cert) runtime_pipeline=true ;; esac ;;
|
||||
esac
|
||||
if "${runtime_pipeline}"; then
|
||||
if [[ "${JEANNIE_RUNTIME_PIPELINE_LOCK:-}" != "${LAB_CLUSTER_PROFILE}" ||
|
||||
|
|
@ -276,6 +278,9 @@ case "${1:-}" in
|
|||
gateway-lab)
|
||||
if [[ "${2:-plan}" == apply ]]; then cluster_runtime_require || exit 1; fi
|
||||
;;
|
||||
secrets-lab)
|
||||
case "${2:-plan}" in apply|test|rotate|recover|recover-cert) cluster_runtime_require || exit 1 ;; esac
|
||||
;;
|
||||
__up-task)
|
||||
cluster_runtime_require || exit 1
|
||||
;;
|
||||
|
|
@ -306,6 +311,16 @@ case "${1:-}" in
|
|||
esac
|
||||
|
||||
case "${1:-}" in
|
||||
secrets-lab)
|
||||
[[ $# -le 2 ]] || { echo "Usage: ./jeannie secrets-lab {plan|apply|status|test|rotate|recover|recover-cert}" >&2; exit 2; }
|
||||
case "${2:-plan}" in
|
||||
plan|apply|status|test|rotate|recover|recover-cert) ;;
|
||||
*) echo "Usage: ./jeannie secrets-lab {plan|apply|status|test|rotate|recover|recover-cert}" >&2; exit 2 ;;
|
||||
esac
|
||||
if [[ "${2:-plan}" != plan ]]; then cluster_context_require || exit 1; fi
|
||||
case "${2:-plan}" in apply|rotate|recover|recover-cert) record_change_journal "secrets-lab" "$@" ;; esac
|
||||
KUBECONFIG="${KUBECONFIG_PATH}" python3 "${REPO_ROOT}/scripts/secrets-lab.py" "${2:-plan}"
|
||||
;;
|
||||
gateway-lab)
|
||||
[[ $# -le 2 ]] || { echo "Usage: ./jeannie gateway-lab {plan|apply|status|test}" >&2; exit 2; }
|
||||
case "${2:-plan}" in
|
||||
|
|
|
|||
|
|
@ -0,0 +1,191 @@
|
|||
#!/usr/bin/env python3
|
||||
"""A disposable Vault, External Secrets and cert-manager learning environment."""
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
OWNER = "homelab.dev/secrets-lab"
|
||||
NAMESPACE = "secrets-lab"
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
CONTROLLERS = {
|
||||
"secrets-lab-external-secrets": ("https://charts.external-secrets.io", "external-secrets", "0.12.1", "externalsecrets.external-secrets.io", {"installCRDs": True}),
|
||||
"secrets-lab-cert-manager": ("https://charts.jetstack.io", "cert-manager", "v1.19.6", "certificates.cert-manager.io", {"crds": {"enabled": True}}),
|
||||
}
|
||||
|
||||
|
||||
def command(args, data=None, check=True):
|
||||
result = subprocess.run(args, input=data, text=True, capture_output=True)
|
||||
if check and result.returncode:
|
||||
raise RuntimeError(result.stderr.strip() or f"{args[0]} failed")
|
||||
return result
|
||||
|
||||
|
||||
def kubectl(*args, data=None, check=True):
|
||||
return command(["kubectl", *args], data, check)
|
||||
|
||||
|
||||
def get(kind, name, namespace=None):
|
||||
args = ["get", kind, name, "--ignore-not-found", "-o", "json"]
|
||||
if namespace:
|
||||
args += ["-n", namespace]
|
||||
output = kubectl(*args).stdout.strip()
|
||||
return json.loads(output) if output else None
|
||||
|
||||
|
||||
def owned(obj):
|
||||
return obj and obj.get("metadata", {}).get("labels", {}).get(OWNER) == "true"
|
||||
|
||||
|
||||
def ensure_available(kind, name, namespace=None):
|
||||
obj = get(kind, name, namespace)
|
||||
if obj and not owned(obj):
|
||||
raise RuntimeError(f"{kind}/{name} exists and is not owned by this lab")
|
||||
return obj
|
||||
|
||||
|
||||
def apply_json(obj):
|
||||
kubectl("apply", "-f", "-", data=json.dumps(obj))
|
||||
|
||||
|
||||
def application(name, source, namespace):
|
||||
return {"apiVersion": "argoproj.io/v1alpha1", "kind": "Application", "metadata": {"name": name, "namespace": "argocd", "labels": {OWNER: "true"}}, "spec": {"project": "default", "source": source, "destination": {"server": "https://kubernetes.default.svc", "namespace": namespace}, "syncPolicy": {"automated": {"prune": True, "selfHeal": True}, "syncOptions": ["CreateNamespace=true", "ServerSideApply=true"]}}}
|
||||
|
||||
|
||||
def ensure_controller(name, config):
|
||||
repo, chart, version, crd, values = config
|
||||
app = ensure_available("application", name, "argocd")
|
||||
if not app and get("crd", crd):
|
||||
raise RuntimeError(f"{crd} already exists; refusing to install a second controller. Review existing ownership first")
|
||||
source = {"repoURL": repo, "chart": chart, "targetRevision": version, "helm": {"valuesObject": values}}
|
||||
apply_json(application(name, source, name))
|
||||
|
||||
|
||||
def wait_crd(name):
|
||||
for _ in range(150):
|
||||
if get("crd", name):
|
||||
kubectl("wait", f"crd/{name}", "--for=condition=Established", "--timeout=120s")
|
||||
return
|
||||
time.sleep(2)
|
||||
raise RuntimeError(f"{name} was not created; inspect the Argo CD controller application")
|
||||
|
||||
|
||||
def vault(*args, data=None, check=True):
|
||||
return kubectl("-n", NAMESPACE, "exec", "deployment/secrets-lab-vault", "--", "vault", *args, data=data, check=check)
|
||||
|
||||
|
||||
def seed(overwrite=False):
|
||||
# A successful list distinguishes an absent key from an inaccessible Vault.
|
||||
result = vault("kv", "list", "-format=json", "secret/", check=False)
|
||||
if result.returncode and "No value found" not in result.stderr:
|
||||
raise RuntimeError("Could not inspect the demo Vault; check its health and token")
|
||||
keys = json.loads(result.stdout) if result.returncode == 0 else []
|
||||
if "demo" not in keys or overwrite:
|
||||
value = secrets.token_urlsafe(32)
|
||||
vault("kv", "put", "secret/demo", "-", data=json.dumps({"value": value}))
|
||||
return "rotated" if overwrite else "created"
|
||||
return "preserved"
|
||||
|
||||
|
||||
def install():
|
||||
namespace = ensure_available("namespace", NAMESPACE)
|
||||
ensure_available("application", "secrets-lab", "argocd")
|
||||
for name, config in CONTROLLERS.items():
|
||||
app = ensure_available("application", name, "argocd")
|
||||
if not app and get("crd", config[3]):
|
||||
raise RuntimeError(f"{config[3]} already exists; refusing a second controller")
|
||||
if not app and get("namespace", name):
|
||||
raise RuntimeError(f"Namespace {name} already exists; refusing to adopt it")
|
||||
if not namespace:
|
||||
apply_json({"apiVersion": "v1", "kind": "Namespace", "metadata": {"name": NAMESPACE, "labels": {OWNER: "true"}}})
|
||||
token = ensure_available("secret", "secrets-lab-vault-token", NAMESPACE)
|
||||
if not token:
|
||||
obj = {"apiVersion": "v1", "kind": "Secret", "metadata": {"name": "secrets-lab-vault-token", "namespace": NAMESPACE, "labels": {OWNER: "true"}}, "type": "Opaque", "stringData": {"token": secrets.token_urlsafe(32)}}
|
||||
kubectl("create", "-f", "-", data=json.dumps(obj))
|
||||
for name, config in CONTROLLERS.items():
|
||||
ensure_controller(name, config)
|
||||
for config in CONTROLLERS.values():
|
||||
wait_crd(config[3])
|
||||
repo = os.environ.get("TF_VAR_gitops_repo_url") or os.environ.get("LAB_GITOPS_REPO_URL") or "ssh://git@192.168.100.73:32222/jv/my-homelab-configs.git"
|
||||
apply_json(application("secrets-lab", {"repoURL": repo, "targetRevision": "main", "path": "apps/secrets-lab"}, NAMESPACE))
|
||||
for _ in range(150):
|
||||
if get("deployment", "secrets-lab-vault", NAMESPACE):
|
||||
break
|
||||
time.sleep(2)
|
||||
else:
|
||||
raise RuntimeError("Vault deployment was not created; inspect Argo CD application secrets-lab")
|
||||
kubectl("-n", NAMESPACE, "rollout", "status", "deployment/secrets-lab-vault", "--timeout=300s")
|
||||
print(f"Demo Vault secret: {seed()}; no values were printed.")
|
||||
print("Run ./jeannie secrets-lab test to check synchronization and certificate issuance.")
|
||||
|
||||
|
||||
def sync_check():
|
||||
kubectl("-n", NAMESPACE, "annotate", "externalsecret/secrets-lab-demo", f"force-sync={time.time_ns()}", "--overwrite")
|
||||
expected = json.loads(vault("kv", "get", "-format=json", "secret/demo").stdout)["data"]["data"]["value"]
|
||||
for _ in range(90):
|
||||
obj = get("secret", "secrets-lab-demo", NAMESPACE)
|
||||
if obj and base64.b64decode(obj.get("data", {}).get("value", "")).decode() == expected:
|
||||
return
|
||||
time.sleep(2)
|
||||
raise RuntimeError("ExternalSecret did not synchronize the Vault value within 180 seconds")
|
||||
|
||||
|
||||
def test():
|
||||
sync_check()
|
||||
kubectl("-n", NAMESPACE, "wait", "certificate/secrets-lab-demo", "--for=condition=Ready", "--timeout=180s")
|
||||
tls = get("secret", "secrets-lab-demo-tls", NAMESPACE)
|
||||
if not tls or not all(tls.get("data", {}).get(key) for key in ("tls.crt", "tls.key")):
|
||||
raise RuntimeError("Demo certificate secret is missing certificate or key")
|
||||
print("Vault and Kubernetes demo secret match; demo certificate is Ready. Secret values were not printed.")
|
||||
|
||||
|
||||
def recover_cert():
|
||||
old = get("secret", "secrets-lab-demo-tls", NAMESPACE)
|
||||
if not old:
|
||||
raise RuntimeError("Demo TLS secret is missing already; run test to observe recovery")
|
||||
old_uid = old["metadata"]["uid"]
|
||||
kubectl("-n", NAMESPACE, "delete", "secret", "secrets-lab-demo-tls", "--wait=true")
|
||||
for _ in range(90):
|
||||
new = get("secret", "secrets-lab-demo-tls", NAMESPACE)
|
||||
if new and new["metadata"]["uid"] != old_uid and all(new.get("data", {}).get(k) for k in ("tls.crt", "tls.key")):
|
||||
kubectl("-n", NAMESPACE, "wait", "certificate/secrets-lab-demo", "--for=condition=Ready", "--timeout=120s")
|
||||
print("Demo TLS secret recreated and certificate is Ready.")
|
||||
return
|
||||
time.sleep(2)
|
||||
raise RuntimeError("Demo TLS secret was not recreated; inspect the Certificate and Issuer")
|
||||
|
||||
|
||||
def main():
|
||||
action = sys.argv[1] if len(sys.argv) > 1 else "plan"
|
||||
if action == "plan":
|
||||
print(json.dumps({"profile": os.environ.get("LAB_CLUSTER_PROFILE"), "scope": "disposable namespace and cluster-wide controllers", "controllers": {name: config[2] for name, config in CONTROLLERS.items()}, "vault": "in-memory development server; demo data disappears on restart", "certificate": "self-signed demo only"}, indent=2))
|
||||
elif action == "apply":
|
||||
install()
|
||||
elif action == "rotate":
|
||||
print(f"Demo secret {seed(overwrite=True)} in Vault; waiting for synchronization.")
|
||||
sync_check()
|
||||
print("Rotation synchronized successfully; no secret values were printed.")
|
||||
elif action == "recover":
|
||||
print(f"Demo Vault secret {seed()}; waiting for synchronization.")
|
||||
sync_check()
|
||||
print("Demo secret synchronized; no secret values were printed.")
|
||||
elif action == "test":
|
||||
test()
|
||||
elif action == "recover-cert":
|
||||
recover_cert()
|
||||
elif action == "status":
|
||||
print(kubectl("-n", NAMESPACE, "get", "deployments,secretstores,externalsecrets,issuers,certificates", "--ignore-not-found").stdout)
|
||||
else:
|
||||
raise RuntimeError("Usage: ./jeannie secrets-lab {plan|apply|status|test|rotate|recover|recover-cert}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except (RuntimeError, ValueError, OSError, KeyError) as exc:
|
||||
print(f"Secrets lab: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
|
@ -108,6 +108,7 @@ validate_unit_tests() {
|
|||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_doctor_dex_drift.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_opentelemetry_lab.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_gateway_lab.py'
|
||||
python3 -m unittest discover -s "${REPO_ROOT}/tests/jeannie" -p 'test_secrets_lab.py'
|
||||
}
|
||||
|
||||
main() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
import importlib.util
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
spec = importlib.util.spec_from_file_location("secrets_lab", ROOT / "scripts/secrets-lab.py")
|
||||
lab = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(lab)
|
||||
|
||||
|
||||
class SecretsLabTest(unittest.TestCase):
|
||||
def test_existing_secret_is_preserved_on_recovery(self):
|
||||
with mock.patch.object(lab, "vault", return_value=SimpleNamespace(returncode=0, stdout='["demo"]', stderr="")) as vault:
|
||||
self.assertEqual(lab.seed(), "preserved")
|
||||
self.assertEqual(vault.call_count, 1)
|
||||
|
||||
def test_rotation_writes_new_value_without_returning_it(self):
|
||||
result = SimpleNamespace(returncode=0, stdout='["demo"]', stderr="")
|
||||
with mock.patch.object(lab, "vault", return_value=result) as vault:
|
||||
self.assertEqual(lab.seed(overwrite=True), "rotated")
|
||||
self.assertEqual(vault.call_count, 2)
|
||||
self.assertIn("value", vault.call_args.kwargs["data"])
|
||||
|
||||
def test_empty_vault_gets_a_demo_value(self):
|
||||
result = SimpleNamespace(returncode=2, stdout="", stderr="No value found at secret/metadata")
|
||||
with mock.patch.object(lab, "vault", return_value=result) as vault:
|
||||
self.assertEqual(lab.seed(), "created")
|
||||
self.assertEqual(vault.call_count, 2)
|
||||
|
||||
def test_vault_error_never_overwrites(self):
|
||||
result = SimpleNamespace(returncode=2, stdout="", stderr="permission denied")
|
||||
with mock.patch.object(lab, "vault", return_value=result) as vault:
|
||||
with self.assertRaisesRegex(RuntimeError, "inspect"):
|
||||
lab.seed()
|
||||
self.assertEqual(vault.call_count, 1)
|
||||
|
||||
def test_existing_unowned_resource_is_refused(self):
|
||||
with mock.patch.object(lab, "get", return_value={"metadata": {}}):
|
||||
with self.assertRaisesRegex(RuntimeError, "not owned"):
|
||||
lab.ensure_available("namespace", "secrets-lab")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue