Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
make run IDs unique, bound the pod start wait, and return the agent's exit code
Jake Hulbergc012422b408d
diff --git a/docs/documentation/platform/agent-vault/guides/kubernetes-setup.mdx b/docs/documentation/platform/agent-vault/guides/kubernetes-setup.mdxindex 269e30ef05..d6639c2e80 100644--- a/docs/documentation/platform/agent-vault/guides/kubernetes-setup.mdx+++ b/docs/documentation/platform/agent-vault/guides/kubernetes-setup.mdx@@ -20,7 +20,7 @@ For why each piece runs where it does, and how to choose between the standard ru- Permission to create namespaces and RBAC roles in the cluster with `kubectl`- An image for your agent that runs as a non-root user- An orchestrator to start agent runs, such as a script, a CI or job runner job, or a Kubernetes controller (Step 5 includes a script you can start from)-- [`curl`](https://curl.se) and [`jq`](https://jqlang.org) on the machine that runs your orchestrator+- [`curl`](https://curl.se), [`jq`](https://jqlang.org), and [`openssl`](https://openssl-library.org) on the machine that runs your orchestrator- If you want agents to run on gVisor or Kata Containers, a RuntimeClass for that runtime in the cluster (see [Choose an isolation level](/documentation/platform/agent-vault/guides/kubernetes#choose-an-isolation-level))## Step 1: Set up Agent Vault@@ -224,7 +224,14 @@ If the fingerprints match, store the certificate in a ConfigMap that agent podskubectl -n agents create configmap agent-vault-ca --from-file=ca.pem```-If you [rotate the proxy's token](/documentation/platform/agent-vault/proxies#rotate-a-proxy’s-token), the proxy gets a new certificate authority, so download the certificate and update the ConfigMap again.+If you [rotate the proxy's token](/documentation/platform/agent-vault/proxies#rotate-a-proxy’s-token), the proxy gets a new certificate authority, so download the certificate again and replace the ConfigMap:++```bash+kubectl -n agents create configmap agent-vault-ca --from-file=ca.pem --dry-run=client -o yaml \+ | kubectl replace -f -+```++Agent pods started after that use the new certificate.## Step 4: Set up your orchestrator@@ -268,7 +275,7 @@ For each agent run, your orchestrator creates a session, puts the session token### Define the agent's pod-Save this manifest as `agent-pod.yaml`. Replace `<agent-image>` and `<agent-command>` with your agent's image and command, and keep `<run-id>`, which the script in the next step fills in. The script gives each run an ID, the current Unix time, and uses it in the names of the run's pod and Secret and in its session's label:+Save this manifest as `agent-pod.yaml`. Replace `<agent-image>` with your agent's image, and set `command` to the command that starts your agent, with each argument as its own list item, such as `["claude", "-p", "Fix the failing test"]`. Keep `<run-id>`, which the script in the next step fills in. The script gives each run a unique ID and uses it in the names of the run's pod and Secret and in its session's label:```yaml expandableapiVersion: v1@@ -291,7 +298,7 @@ spec:containers:- name: agentimage: <agent-image>- args: ["<agent-command>"]+ command: ["<agent-command>", "<argument>"]# HTTPS_PROXY and HTTP_PROXY, with the session token in the proxy URL.envFrom:- secretRef:@@ -343,7 +350,8 @@ set -euo pipefailINFISICAL_URL=https://app.infisical.comACCESS_TOKEN=<access-token>-RUN_ID=$(date +%s)+# Unique per run, so runs started at the same time don't share names.+RUN_ID=$(date +%s)-$(openssl rand -hex 3)echo "Run ID: $RUN_ID"# One session per run. The ttl outlasts the pod's 30-minute deadline, so the@@ -371,13 +379,19 @@ printf 'HTTPS_PROXY=%s\nHTTP_PROXY=%s\n' "$PROXY_URL" "$PROXY_URL" \sed "s/<run-id>/$RUN_ID/g" agent-pod.yaml | kubectl apply -f -# Wait up to 2 minutes for the container to start, then follow its output until# the agent exits.-for attempt in $(seq 60); do- kubectl -n agents logs -f "agent-$RUN_ID" 2>/dev/null && exit 0- sleep 2+if ! kubectl -n agents logs -f --pod-running-timeout=2m "agent-$RUN_ID"; then+ echo "The agent's pod didn't start:" >&2+ kubectl -n agents get pod "agent-$RUN_ID" -o jsonpath='{.status.phase} {.status.containerStatuses[0].state.waiting.reason} {.status.containerStatuses[0].state.waiting.message}{.status.conditions[?(@.reason=="Unschedulable")].message}{"\n"}' >&2+ exit 1+fi++# Exit with the agent's exit code.+EXIT_CODE=""+until [ -n "$EXIT_CODE" ]; do+ sleep 1+ EXIT_CODE=$(kubectl -n agents get pod "agent-$RUN_ID" -o jsonpath='{.status.containerStatuses[0].state.terminated.exitCode}')done-echo "The agent's pod didn't start:" >&2-kubectl -n agents describe pod "agent-$RUN_ID" | tail -n 15 >&2-exit 1+exit "$EXIT_CODE"```The script calls [the endpoint that creates a session](/api-reference/endpoints/agent-vault-sessions/create) and, when it exits, [the endpoint that revokes a session](/api-reference/endpoints/agent-vault-sessions/revoke). Your orchestrator can make the same calls in any language (see [Create sessions with the API](/documentation/platform/agent-vault/sessions-api)).