|
| 1 | +--- |
| 2 | +title: Enable Authentication |
| 3 | +description: Secure your Agent Control server with API key authentication for shared and production deployments. |
| 4 | +icon: "lock" |
| 5 | +--- |
| 6 | + |
| 7 | +Authentication is disabled by default so you can get started quickly in local development. Before sharing your server or deploying to production, enable API key authentication to protect the control plane from unauthorized access. |
| 8 | + |
| 9 | +## How It Works |
| 10 | + |
| 11 | +Agent Control uses a two-tier API key model: |
| 12 | + |
| 13 | +| Key type | Environment variable | What it can do | |
| 14 | +|----------|---------------------|----------------| |
| 15 | +| **Regular** | `AGENT_CONTROL_API_KEYS` | Register agents, evaluate controls, read controls and agents | |
| 16 | +| **Admin** | `AGENT_CONTROL_ADMIN_API_KEYS` | Everything above **plus** create/update/delete controls and manage agent-control associations | |
| 17 | + |
| 18 | +The `/health` endpoint is always public and requires no authentication. |
| 19 | + |
| 20 | +<Tip> |
| 21 | +Give your agent runtime a **regular** key. Reserve **admin** keys for setup scripts, CI pipelines, and the UI dashboard. |
| 22 | +</Tip> |
| 23 | + |
| 24 | +## Step-by-Step Setup |
| 25 | + |
| 26 | +<Steps> |
| 27 | +<Step title="Start the server with authentication enabled"> |
| 28 | + |
| 29 | +Pass the authentication environment variables when starting the server: |
| 30 | + |
| 31 | +```bash |
| 32 | +curl -L https://raw.githubusercontent.com/agentcontrol/agent-control/refs/heads/main/docker-compose.yml \ |
| 33 | + | AGENT_CONTROL_API_KEY_ENABLED=true \ |
| 34 | + AGENT_CONTROL_API_KEYS="my-runtime-key" \ |
| 35 | + AGENT_CONTROL_ADMIN_API_KEYS="my-admin-key" \ |
| 36 | + AGENT_CONTROL_SESSION_SECRET="some-long-random-string" \ |
| 37 | + CORS_ORIGINS="http://localhost:4000" \ |
| 38 | + docker compose -f - up -d |
| 39 | +``` |
| 40 | + |
| 41 | +<Warning> |
| 42 | +Replace the placeholder key values above with strong, unique secrets before any shared or production deployment. |
| 43 | +</Warning> |
| 44 | + |
| 45 | +</Step> |
| 46 | + |
| 47 | +<Step title="Pass the API key from the SDK"> |
| 48 | + |
| 49 | +The SDK reads the `AGENT_CONTROL_API_KEY` environment variable by default, or you can pass it explicitly: |
| 50 | + |
| 51 | +```python |
| 52 | +from agent_control import AgentControlClient |
| 53 | + |
| 54 | +# Option 1: Environment variable (recommended) |
| 55 | +# export AGENT_CONTROL_API_KEY="my-runtime-key" |
| 56 | +async with AgentControlClient() as client: |
| 57 | + await client.health_check() |
| 58 | + |
| 59 | +# Option 2: Explicit constructor argument |
| 60 | +async with AgentControlClient(api_key="my-runtime-key") as client: |
| 61 | + await client.health_check() |
| 62 | +``` |
| 63 | + |
| 64 | +</Step> |
| 65 | + |
| 66 | +<Step title="Use an admin key for control management"> |
| 67 | + |
| 68 | +Operations that modify controls or agent-control associations require an admin key. This keeps your control plane locked down even if a runtime key is compromised. |
| 69 | + |
| 70 | +```python |
| 71 | +# setup.py — run with an admin key |
| 72 | +async with AgentControlClient(api_key="my-admin-key") as client: |
| 73 | + await controls.create_control(client, name="block-ssn", data={...}) |
| 74 | + await agents.add_agent_control(client, agent_name="my-agent", control_id="...") |
| 75 | +``` |
| 76 | + |
| 77 | +</Step> |
| 78 | + |
| 79 | +<Step title="Include the key in direct API calls"> |
| 80 | + |
| 81 | +If calling the REST API directly, include the key in the `X-API-Key` header: |
| 82 | + |
| 83 | +```bash |
| 84 | +curl -H "X-API-Key: my-runtime-key" \ |
| 85 | + http://localhost:8000/api/v1/agents |
| 86 | +``` |
| 87 | + |
| 88 | +</Step> |
| 89 | +</Steps> |
| 90 | + |
| 91 | +## Key Rotation |
| 92 | + |
| 93 | +Agent Control accepts multiple comma-separated keys per variable, making zero-downtime rotation straightforward: |
| 94 | + |
| 95 | +1. Add the new key alongside the old one: `AGENT_CONTROL_API_KEYS="old-key,new-key"` |
| 96 | +2. Redeploy the server |
| 97 | +3. Update all clients to use the new key |
| 98 | +4. Remove the old key: `AGENT_CONTROL_API_KEYS="new-key"` |
| 99 | +5. Redeploy again |
| 100 | + |
| 101 | +## Troubleshooting |
| 102 | + |
| 103 | +**401 Unauthorized** — check these in order: |
| 104 | + |
| 105 | +1. Authentication is enabled (`AGENT_CONTROL_API_KEY_ENABLED=true`) |
| 106 | +2. Your key is present in the correct variable (`AGENT_CONTROL_API_KEYS` for regular, `AGENT_CONTROL_ADMIN_API_KEYS` for admin operations) |
| 107 | +3. The `X-API-Key` header (or SDK `api_key` argument) matches exactly — no trailing whitespace or quotes |
| 108 | + |
| 109 | +See the [Authentication reference](/core/reference#authentication) for the full configuration table. |
0 commit comments