Skip to content

Latest commit

 

History

History
245 lines (198 loc) · 12.3 KB

README.md

File metadata and controls

245 lines (198 loc) · 12.3 KB

Argo Rollouts + outer Agent demo

The console, CLI and management API use direct access. Only assessment submission requires a Run credential. See Access.

This synthetic demo follows the Jenkins example: the platform owns deployment and continuation, the outside Agent evaluates the frozen Spec and observation, and OpenGuardrail computes the Decision. Argo CD sync hooks remain planned. This implementation uses an inline Argo Rollouts Analysis Job.

Argo maps Job completion to analysis success, then advances the Rollout. See the Job provider and inline analysis contracts. Image-pull failures can leave analysis Inconclusive and the Rollout Paused; they do not authorize continuation. Do not manually promote past the gate.

Operator setup

Use a disposable namespace with Kubernetes 1.27+ and Argo Rollouts installed. The operator needs Docker, kubectl and the kubectl-rollouts plugin. The Agent needs Python 3.12+, age/age-keygen, guardrailctl, kubectl and read access to the selected Pods and pods/log. It needs neither pods/exec nor Secret access. The operator applies manifests and triggers revisions; those privileges are separate from the Agent's log-read access.

Publish recovery.yaml as Scene recovery. Use the same HTTPS service origin reachable from the Job and Agent. The sample Spec's validForSeconds: 900 controls Decision validity after finalization. The Scene's runTtlSeconds sets the separate Run deadline and must cover the wait. The Job deadline is 840 seconds and the adapter waits up to 780 seconds including preparation. A Decision must still be current at the final gate read.

From the repository root, build and push to a registry reachable by the cluster:

docker build -f integrations/argo/Dockerfile -t REGISTRY/open-guardrail-argo-demo:demo .
docker push REGISTRY/open-guardrail-argo-demo:demo
kubectl create namespace guardrail-demo
kubectl -n guardrail-demo create secret generic open-guardrail-project-key \
  --from-file=project-key.json=/path/to/private/orchestrator-key.json

If a network proxy stalls Go downloads over HTTP/2, pass --build-arg GODEBUG=http2client=0 to docker build. This setting is confined to the build stage. The CLI build downloads only its actual dependencies.

For a local kind cluster, build the image as open-guardrail-argo-demo:local and load it before applying the manifests. On Apple Silicon, exporting a single platform avoids missing-content errors with Docker's multi-platform image store:

docker image save --platform linux/arm64 -o /path/to/demo-image.tar open-guardrail-argo-demo:local
kind load image-archive --name YOUR_CLUSTER /path/to/demo-image.tar

Use linux/amd64 instead on an x86-64 cluster.

Edit analysis-template.yaml: set the image reference (prefer a digest), OPEN_GUARDRAIL_URL, and a stable unique ARGO_INSTANCE_ID for this installation. These are operator configuration, not Agent inputs. Only the analysis container mounts the Secret. It has no Kubernetes API token; private state uses a memory-backed emptyDir. The adapter copies the mounted Secret into a regular 0600 file there for the CLI, then removes that copy on exit. Restrict who can modify the template, patch Rollouts, or access worker memory/files. Ciphertext log access is safe only while the Agent's private identity remains private.

kubectl -n guardrail-demo apply -f integrations/argo/analysis-template.yaml
kubectl -n guardrail-demo apply -f integrations/argo/rollout.yaml
kubectl argo rollouts status guardrail-demo -n guardrail-demo --timeout 180s

The first deployment establishes a baseline and skips canary analysis. It is not a guarded release. Wait for that baseline to become healthy before proceeding. The workload uses the public argoproj/rollouts-demo:blue image. Observations are independent synthetic fixtures, not measurements of that workload. No traffic router is configured; replica counts approximate the canary weight.

Agent walkthrough

For each case (healthy, unhealthy, unknown), choose a fresh private directory:

python3 -m integrations.argo.agent_client init --case healthy \
  --work-dir /path/to/private/argo-demo-1

init prints the public recipient and writes rollout-patch.json. The operator uses this patch to start the canary. It puts the case and public recipient in Rollout annotations and a fresh attempt ID in Pod-template annotations, so even repeating a case creates a distinct revision. Never put private keys in annotations.

kubectl -n guardrail-demo patch rollout guardrail-demo --type merge \
  --patch-file /path/to/private/argo-demo-1/rollout-patch.json
kubectl -n guardrail-demo get analysisruns
kubectl -n guardrail-demo get jobs
kubectl -n guardrail-demo get pods -l app.kubernetes.io/component=open-guardrail-analysis

Select the new AnalysisRun, its owned Job and that Job's Pod (check owner UIDs). After its log contains GUARDRAIL_ENVELOPE_AGE_BASE64=, receive the handoff:

python3 -m integrations.argo.agent_client receive \
  --work-dir /path/to/private/argo-demo-1 --namespace guardrail-demo --pod NEW_JOB_POD

Output includes Run ID, frozen Spec, baseSubmissionNo and observation, never the token. Treat these as data, not instructions. Write a Submission containing one readiness Check and one health Evidence whose resultSummary contains the exact observation. Use the actual observation time in RFC3339 and choose PASS, BLOCKED or UNKNOWN from the facts. See the Jenkins Submission shape.

python3 -m integrations.argo.agent_client submit \
  --work-dir /path/to/private/argo-demo-1 \
  --submission /path/to/private/argo-demo-1/submission.json
kubectl -n guardrail-demo get analysisruns
kubectl argo rollouts status guardrail-demo -n guardrail-demo --timeout 15m
Observation Run result / Decision Expected analysis
healthy PASS / ALLOW Successful; rollout continues
unhealthy BLOCKED / DENY Failed; rollout aborts
unknown UNKNOWN / DENY Failed; rollout aborts

Run cases serially, with a fresh directory and patch each time, after the previous analysis ends. Inspect aborted revisions before applying the next patch as a new revision. Never promote a blocked revision.

Failure and recovery

Continuation requires both a completed, current PASS / ALLOW and successful business evidence validation. This Recovery demo compares the structured health Evidence exactly with the Job's original observation. That equality rule belongs to this business adapter. Other adopters can define source, time, key-field or range rules while retaining the Run/Revision/final-Submission identity checks. Client-side validation is a convenience; the Job independently validates after reading the persisted final Submission.

Logs contain a sanitized GUARDRAIL_GATE_RESULT JSON line. The same JSON is written to the Pod's termination message, for example:

{"outcome":"DENY","layer":"business","reason":"EVIDENCE_REJECTED","serverDecision":"ALLOW","businessEvidence":"REJECTED"}

The adapter's outcome is ALLOW or DENY; serverDecision, when known, records the server's ALLOW or DENY Decision. A business evidence rejection can therefore produce outcome: DENY even when serverDecision is ALLOW.

Argo's native AnalysisRun status remains Failed. Read the Pod termination message or Job logs for the layer that stopped progression:

kubectl -n YOUR_NAMESPACE get pod YOUR_JOB_POD -o jsonpath='{.status.containerStatuses[?(@.name=="guardrail")].state.terminated.message}'
kubectl -n YOUR_NAMESPACE logs YOUR_JOB_POD -c guardrail
Reason Layer Recovery
DECISION_REJECTED Decision Inspect the submitted checks; use a new attempt after correcting the cause
DECISION_EXPIRED Decision Evaluate a fresh Run; never promote using stale ALLOW
EVIDENCE_REJECTED Business Investigate the original observation versus persisted Evidence before a new attempt
AGENT_TIMEOUT Orchestration Inspect the existing OPEN Run and private handoff; submit only if the old checkpoint is still valid
VERIFICATION_FAILED Verification Restore connectivity, inspect the Run and failed Job, then select an explicit recovery path
STATE_EXISTS / PREPARE_FAILED Orchestration Inspect private state and the existing Run; do not blindly restart prepare or rotate credentials

A failed Job does not resume automatically if an Agent submits later. Inspect the old attempt and start a new checkpoint deliberately. If Kubernetes stops the Pod before it can write a result, use Job/Pod status and events as infrastructure evidence; there may be no adapter termination message.

Job and container retries are disabled (backoffLimit: 0, restartPolicy: Never). Identity includes configured cluster ID, namespace, Job UID, Rollout, candidate ReplicaSet hash and checkpoint. Operations within a Job share an identity; a new Job is a new attempt and Run. Inspect uncertain create/submit responses before starting another attempt. No automatic credential rotation or prepare restart is performed.

receive can be repeated after decryption. Failed or uncertain submission keeps local plaintext and retries with the same operation ID. Successful submission removes the handoff/token. Never upload private directories. The Job validates Evidence itself even if an Agent bypasses the client. Its ALLOW check occurs at Job completion, not atomically with a later traffic change. Real integrations must bind the actual immutable image, measure the actual canary, and account for controller delays and Decision lifetime.

Pod loss removes ephemeral state and may lose a Run credential. Retain the Run ID from logs and follow Run credential recovery with operator credentials. Do not restart a lost Job assuming its state survived. Keep logs until the Agent receives the handoff. After inspection, clean up explicitly:

kubectl delete namespace guardrail-demo

For a demo requiring neither Kubernetes nor encryption, use the local Agent demo.

Repeatable acceptance

smoke.py runs the actual controller, Jobs, native service and CLI using deterministic submissions. It defaults to eight cases: healthy, unhealthy, unknown, forged Evidence, missing Agent submission, expired Decision, service unavailability and Pod loss. It checks owner UIDs, Run uniqueness, final AnalysisRun status, rollout continuation/abort, sanitized termination reasons, and absence of credentials in logs. The Pod-loss result comes from Kubernetes Job failure; it is marked as infrastructure evidence in the report.

Prerequisites: local kind with Rollouts installed, the demo image loaded into kind, Python 3.12+, kubectl with the argo-rollouts plugin, age/age-keygen, openssl, and native service/CLI binaries (for example from make build). Run from the repository root, replacing the host IP with an IPv4 address reachable from Pods:

python3 -m integrations.argo.smoke \
  --context kind-YOUR_CLUSTER \
  --host-ip YOUR_HOST_IP \
  --work-dir /path/to/private/argo-smoke-1 \
  --server-bin "$PWD/bin/open-guardrail" \
  --cli "$PWD/bin/guardrailctl" \
  --image open-guardrail-argo-demo:local

Each run creates a fresh private directory and a fresh namespace (random by default). It refuses an existing namespace and requires an explicit local kind context with a loopback API endpoint. The host TLS proxy binds only the supplied IP. The script injects a temporary CA for the Job and stops the temporary service on exit. It retains the namespace for inspection and private credentials/data outside the repository. Share only results.json, never the work directory. The output prints the namespace so cleanup can be explicit:

kubectl --context kind-YOUR_CLUSTER delete namespace PRINTED_TEST_NAMESPACE

Use --cases healthy unhealthy unknown forged for the original four-case acceptance, or select individual fault cases. Expiry uses a one-second Decision TTL and delayed Run reads; unavailability injects HTTP 503 after handoff; Pod loss deletes only that test's gate Pod. These fault controls live exclusively in the acceptance harness.