Skip to main content

Why IaC for auth

Auth config drifts in ways application code doesn’t. An agent spun up by hand in a dashboard has no peer review, no version history, and no automated rollback. When the production incident happens and you need to know why an agent had write access to the deploy tool, “someone added it last Tuesday” is not an audit trail. Treating agents and permissions as Terraform resources fixes this. Every grant goes through a pull request. Every change is versioned in git. Destroying a staging environment tears down the access alongside the infrastructure, no orphaned tokens floating around.

Installation

The provider requires Go 1.21 to build.
1
Clone the repository and build the binary:
2
Install into the local plugin cache:
3
Declare the provider in your Terraform configuration:

Provider setup

Both arguments can be set via environment variables, which is preferred in CI:
string
default:"KAVACHOS_BASE_URL env var"
Base URL of your KavachOS deployment.
string
default:"KAVACHOS_TOKEN env var"
API token for authenticating with KavachOS.

Resources

kavachos_agent

Manages an agent identity, the primary entity in KavachOS.
The token attribute is computed on creation and marked sensitive. Read it with:
The raw token is only returned once, at creation time. KavachOS does not store it in recoverable form. If you lose it, rotate the agent’s token via the API or dashboard.
string
required
ID of the user who owns this agent.
string
required
Human-readable name.
"autonomous" | "delegated" | "service"
required
Agent type: autonomous, delegated, or service.
block[]
One or more permission grant blocks.
string
RFC 3339 expiry timestamp.
Permission block arguments
string
required
Resource pattern, e.g. mcp:github:* or mcp:deploy:production.
string[]
required
Allowed actions, e.g. [“read”] or [“execute”].
block
Optional block limiting usage.
Constraints block arguments
bool
default:"false"
Require human approval before the action executes.
number
Rate limit: maximum calls allowed per hour.
string[]
Glob patterns restricting allowed argument values.
string[]
CIDR blocks from which this permission may be used.

kavachos_permission

Grants a single permission to an existing agent from a separate module. If you control both the agent and all its permissions in one place, use inline permission blocks on kavachos_agent instead.
string
required
ID of the target agent.
string
required
Resource pattern.
string[]
required
Allowed actions.
bool
default:"false"
Require human approval.
number
Rate limit per hour.
string[]
Glob patterns for argument values.
string[]
CIDR blocks allowed to exercise the permission.

kavachos_api_key

Manages an API key for server-to-server requests.
Valid scopes: agents:read, agents:write, audit:read, delegation:read, delegation:write, organizations:read, organizations:write, admin.
The key attribute is only populated immediately after creation. Read it with terraform output -raw ci_key and store it in your secret manager before the session ends.

kavachos_organization

Manages an organization for multi-tenant isolation.
slug is immutable after creation. Change it by deleting and recreating the organization.

Data sources

kavachos_agent

Reads an agent that was not created by this Terraform configuration.

kavachos_agents

Lists agents, optionally filtered.
Filter arguments: owner_id, status (active | revoked | expired), type (autonomous | delegated | service).

Import existing state

Resources provisioned outside Terraform can be brought under management:
After importing, run terraform plan. Terraform will show a diff for any attributes that differ from your configuration. Update the HCL to match, or let Terraform converge.
Importing an API key restores the ID and metadata but not the raw key value, that was only available at creation time.

GitOps workflow

Manage KavachOS configuration alongside your application infrastructure:
A minimal GitHub Actions workflow:
Every permission change ships as a pull request diff. The plan output shows exactly what will change before it’s applied. The apply only runs on merge to main. This means the same controls you use for code changes, required reviewers, branch protection, signed commits, apply to auth config changes too.
Last modified on April 18, 2026