DocsAgent SetupAgent Enrollment & mTLS

Agent Enrollment & mTLS

Enroll new agents with expiring enrollment tokens, migrate agents that use zone (environment) keys, and require mutual TLS with a certificate fingerprint bound to each agent, either with the automatic platform CA or with your own CA behind nginx.


Why Enrollment Tokens

An environment key (an agent API key not bound to an agent) used to register any new agent_id in its zone automatically: if the key leaked, anyone could register arbitrary agents. New agents now enroll with an enrollment token: a short-lived, limited-use secret that the agent exchanges once for its own API key, bound to its agent_id.

  • Tokens have a name, a discovery zone, an expiry (1 to AGENT_ENROLLMENT_TOKEN_MAX_HOURS hours, default 24, max 720) and a maximum number of uses (1 to 1000, default 1).
  • The token is shown once at creation and stored only as a SHA-256 hash; the list shows its prefix, state, uses (n/max), expiry, last use and creator.
  • States: active, expired, exhausted (uses reached max uses) and revoked. A token that is not active is rejected with 401 "Invalid or expired enrollment token".
  • Revoking a token (Revoke, or DELETE /api/v1/agent/enrollment-tokens/{id}/) never affects agents already enrolled: they keep their own API key.

Creating a Token

Managers open the Agents page (Discovery section) and click "Enrollment tokens" on the zone. Enter a name, the validity in hours and the maximum number of uses, then click "Create token" and copy the token from the dialog: it is shown once. Viewers can list tokens but not create or revoke them.

# Same operation through the API (JWT of a manager)
curl -X POST https://idp.example.com/api/v1/agent/enrollment-tokens/ \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"name": "rollout-dc1", "environment": 3, "expires_in_hours": 24, "max_uses": 20}'
Agents with status, version and mTLS certificate

Configuring the Agent

Leave api_key empty and set enrollment_token (or IDP_ENROLLMENT_TOKEN). On start the agent looks for its key in this order: api_key from the config or IDP_API_KEY, then the content of api_key_file, then enrollment. After a successful enrollment the key is written atomically to api_key_file (mode 0600, directory 0700) and every later restart reuses it, so the token can expire or be revoked.

  • Network errors, 5xx, 408 and 429 are retried with the exponential backoff until the agent is stopped; other 4xx answers (invalid token, agent already enrolled, disabled agent) stop the agent with a clear error.
  • If api_key_file cannot be written, the agent logs an error and keeps the key in memory: after a restart it needs a new enrollment token.
  • No enrollment happens with -output or -dry-run. The token is never written to the logs (only the key prefix is).
  • Once the key is stored, remove enrollment_token / IDP_ENROLLMENT_TOKEN from the host configuration. Use an https:// backend_url: the token travels in the request body.
  • To re-enroll an agent after revoking its key, also delete api_key_file on the host: otherwise the agent keeps using the stored, revoked key.
  • The enrollment endpoint is POST /api/v1/agent/enroll/ with {"agent_id", "token"}; it is unauthenticated and rate limited (THROTTLE_AGENT_ENROLL_RATE, default 20/minute).
agent_id: "web-01"
backend_url: "https://idp.example.com"
api_key: ""
enrollment_token: "idpe_..."            # IDP_ENROLLMENT_TOKEN
api_key_file: "/var/lib/idp-agent/api_key" # IDP_API_KEY_FILE; Windows: C:\ProgramData\idp-agent\api_key

Environment Keys and AGENT_ALLOW_ENV_KEY_ENROLLMENT

By default (AGENT_ALLOW_ENV_KEY_ENROLLMENT=false) an environment key can no longer register a new agent_id: the request gets 401 "Auto-registration with environment keys is disabled; enroll the agent with an enrollment token". Agents already registered keep authenticating with the environment key as before, so existing installations keep working without changes.

Warning: Setting AGENT_ALLOW_ENV_KEY_ENROLLMENT=true restores the old auto-registration and shows a warning to managers on the Settings page. Use it only during a transition.

Migrating Existing Agents

An agent registered with an environment key can be moved to its own key with an enrollment token of the same zone: set enrollment_token, clear api_key and restart it. The enrollment issues a key for the existing agent (its data and history are kept) and from then on the environment key can no longer authenticate it.

  • An agent that already has an active key of its own gets 409: revoke that key first if it must re-enroll, and delete api_key_file on the host.
  • An agent_id registered in another zone gets 409; a disabled agent gets 403; a token of an inactive zone gets 403.
  • With mTLS, the enrollment also binds the certificate fingerprint of the agent (see below).
  • With the automatic mTLS (mtls.auto, on by default) the agent sends a CSR together with the token and receives its client certificate in the same response (see Automatic Agent mTLS, /docs/agent/mtls).

Requiring mTLS

With AGENT_REQUIRE_MTLS=true every agent request must present a verified client certificate bound to the agent. Two front ends can verify it: the Traefik router of the agents host with the platform CA (the automatic mode, see Automatic Agent mTLS, /docs/agent/mtls), or the nginx server of docker/nginx/agent-mtls.conf with a CA of your own, described here. An enrollment that carries a CSR (automatic mode) does not need a certificate yet: the one-use token is the credential. The nginx server listens on 8443, accepts only client certificates signed by the agent CA (ssl_verify_client on, ssl_client_certificate /etc/nginx/certs/agent-ca.crt), exposes only /api/v1/agent/ and forwards X-SSL-Client-Verify and X-SSL-Client-Cert. The backend computes the SHA-256 fingerprint of the certificate and compares it with the one registered for the agent; a missing or different fingerprint gets 401.

  • Mount server.crt, server.key and agent-ca.crt under /etc/nginx/certs/ and include agent-mtls.conf next to nginx.conf (it reuses its backend upstream). The plain server clears the X-SSL-Client-* headers on /api/v1/agent/ so they cannot be injected.
  • On the agent set tls_cert_file and tls_key_file (client certificate) and, for a private server CA, tls_ca_file; point backend_url to https://<host>:8443.
  • An existing agent without a registered fingerprint is rejected until a manager sets it or the agent enrolls again with a token.
  • agent-mtls.conf configures no CRL: to revoke an agent certificate, clear or replace its cert_fingerprint (the agent is then rejected until the new fingerprint is set).

Trusted Proxies

The backend trusts the X-SSL-Client-* headers only from the addresses in AGENT_MTLS_TRUSTED_PROXIES (comma-separated CIDRs, default 127.0.0.1/32,::1/128). The backend is also reachable directly (port 8100 in Docker Compose), so without this check anyone with an API key could forge the headers. List only the address of the nginx container itself (a /32): give nginx a fixed IP on the compose network. Never list the whole Docker subnet: connections to a published backend port arrive from the Docker gateway (e.g. 172.18.0.1), which is inside that subnet, and could inject the headers and bypass mTLS.

Warning: With AGENT_REQUIRE_MTLS=true do not publish the backend port (8100), or bind it to 127.0.0.1 only (e.g. "127.0.0.1:8100:8000"), so agents can reach the backend only through nginx.

AGENT_REQUIRE_MTLS=true
# Fixed IP of the nginx container on the compose network (a /32, not the subnet)
AGENT_MTLS_TRUSTED_PROXIES=172.18.0.10/32
# optional
AGENT_ENROLLMENT_TOKEN_MAX_HOURS=720
THROTTLE_AGENT_ENROLL_RATE=20/minute

Setting the Certificate Fingerprint

The fingerprint is the SHA-256 of the DER certificate, the value printed by openssl. It is saved automatically when an agent enrolls (or auto-registers) with a verified certificate; a manager can also set it on the agent with PATCH /api/v1/agent/agents/{id}/ and the cert_fingerprint field. Hex with or without ":" and in any case is accepted and stored lowercase without separators; an empty string clears it.

Note: nginx's $ssl_client_fingerprint is SHA-1, so nginx forwards the whole certificate ($ssl_client_escaped_cert) and the backend computes the SHA-256 itself. With a certificate of your own CA, set the new fingerprint (or re-enroll) before switching to a renewed certificate; certificates of the platform CA are re-bound automatically at every renewal.

openssl x509 -in agent.crt -noout -fingerprint -sha256
# SHA256 Fingerprint=AB:CD:...

curl -X PATCH https://idp.example.com/api/v1/agent/agents/42/ \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"cert_fingerprint": "AB:CD:..."}'

Checking the Configuration

Managers see an "Agent channel security" card on the Settings page (Platform section): a warning while AGENT_ALLOW_ENV_KEY_ENROLLMENT is enabled and whether mTLS is required. The same flags are returned by GET /api/v1/agent/security-settings/ ({"env_key_enrollment_allowed", "mtls_required"}).