Learn how to add Zero Trust access for AI agents with Terraform or Helm while keeping enrollment credentials out of state and source control.

Zero Trust access for an AI agent should be declared as three separate things: the agent’s workload identity, the services that identity may reach, and the credential used to enroll it.

Terraform or Helm can manage the first two and the deployment wiring. They should not turn a long-lived enrollment secret into source code or saved state. Build the policy around a named agent and named services, then make every change pass a plan, render, and connectivity check.

Start with an identity and a deny-by-default policy

An AI agent needs its own non-human identity, not the same key as its operator or every other agent. NetFoundry’s AI security architecture describes this as a cryptographic identity for each agent, LLM, and MCP server, with policy authorizing the connection before a routable path exists.

NetFoundry AI security page

Before writing Terraform or Helm, record the access contract:

FieldExampleWhy it matters
Agent identityagent-repo-review-prodSeparates this workload from its operator and other agents
Allowed destinationsmcp-search, llm-privateLimits reachability to named services
Allowed actionRead repository metadata and call approved toolsPrevents a network rule from becoming broad application access
EnvironmentproductionKeeps test and production identities separate
Retirement signalAgent deployment removed or policy owner revokes itMakes removal an explicit lifecycle event

The destination names in this table are examples, not universal NetFoundry service names. Use the exact resource names from the provider or chart version you have verified. Do not paste a command from an older provider or chart into production without checking its current schema.

The useful boundary is service-level reachability. A policy that grants an agent access to an entire subnet is not least privilege just because the subnet is private. The agent should reach the MCP server or model endpoint it needs, and nothing else.

For background, Zero Trust API security covers the same authenticate-before-connect idea for service access. The implementation below applies that boundary to an agent deployed through infrastructure as code.

Model the agent in Terraform

Terraform should own durable intent: the agent identity, its destination policy, and the relationship between them. The resource names below are illustrative because the correct blocks depend on the provider you use.

variable "agent_name" {
  type        = string
  description = "Stable identity name for this agent deployment"
}

variable "allowed_services" {
  type        = set(string)
  description = "Exact service names this agent may reach"
}

resource "example_agent_identity" "reviewer" {
  name        = var.agent_name
  environment = "production"
}

resource "example_service_policy" "reviewer_access" {
  name       = "${var.agent_name}-services"
  identity   = example_agent_identity.reviewer.id
  services   = var.allowed_services
  action     = "dial"
  default    = "deny"
}

Replace example_agent_identity and example_service_policy with the resources in the current provider documentation. Keep the interface stable even if the provider’s resource names change: an identity input, an explicit service set, and a deny-by-default policy are the parts your review should preserve.

Use separate variables for the identity and service set so a destination change is visible in the plan. A reviewer should be able to answer, “Which agent gained access to which service?” without reading a generated JSON document or guessing from an IP address.

Pin the provider version and commit the lock file. Run terraform fmt, terraform validate, and terraform plan in CI. Review the plan for four changes:

  1. A new identity is created only for the intended agent.
  2. The policy adds only the named services.
  3. No unrelated identity loses access.
  4. A removed agent produces a policy and identity deletion, or an explicit revocation step required by the provider.

Terraform state is part of the security boundary. HashiCorp’s state documentation says state maps configuration to real resources and warns against placing it in version control or storage without locking and access controls. Use a protected remote backend, encryption at rest, access controls, and audit logs.

Keep enrollment credentials out of Terraform state

Marking a Terraform variable sensitive hides it from normal CLI output, but it does not automatically remove its value from state. HashiCorp’s sensitive-data guidance makes that distinction explicit.

Prefer this pattern:

variable "enrollment_token" {
  type      = string
  sensitive = true
  ephemeral = true
}

provider "example" {
  enrollment_token = var.enrollment_token
}

The ephemeral argument requires a Terraform version and provider context that support it. Check both before using it. If your provider cannot consume an ephemeral value, inject the credential at runtime through the CI secret store or a workload identity exchange, and keep the value out of .tfvars, Git, plan artifacts, and logs.

Do not output the enrollment token. Do not put it in a local, a rendered manifest, a Helm values file, or a Terraform resource argument that the provider records in state. If an API requires a durable credential, let the provider write it to a dedicated secret manager and grant the agent only the permission to read its own secret.

Package the agent with Helm

Helm should package the agent, its connector or sidecar, the identity name, and the allowed service names. It should not package a live enrollment token in values.yaml.

Keep the chart values explicit:

agent:
  name: agent-repo-review-prod
  services:
    - mcp-search
    - llm-private
  identityMode: workload

enrollment:
  existingSecret: agent-enrollment
  tokenKey: token

This values file describes references and policy, not secret material. The chart template can mount the existing Kubernetes Secret into the connector or pass a reference through the deployment environment, depending on the chart’s documented interface. The exact key names are chart-specific.

Helm’s values guidance recommends documented values, clear types, and structures that are easy to override. Apply the same rule to security values: name the identity and each destination clearly, quote strings when YAML coercion could change their type, and document which fields are references rather than credentials.

Kubernetes Secrets are not a complete secret-management strategy. The Kubernetes documentation on Secrets explains how Secret objects provide a way to hold sensitive data, but access to them still depends on cluster authorization and storage protections. Restrict get and list permissions, enable encryption at rest, and prefer an external secret manager or short-lived identity when the platform supports it.

Render and inspect the chart before applying it:

helm lint ./charts/agent
helm template agent-repo-review ./charts/agent \
  --namespace agents \
  --values values-prod.yaml > rendered.yaml

Review rendered.yaml for three leaks: the token itself, a public listener that the agent does not need, and a destination list broader than the Terraform policy. Run a secret scanner against the chart, rendered output, and CI logs. Keep the rendered file as a short-lived review artifact, not a committed manifest.

Make Terraform and Helm agree

Use one source of truth for the access contract. A common split is Terraform for the identity and service policy, and Helm for the workload that consumes that identity. Pass the stable identity name and approved service set into the chart from the same environment configuration used by Terraform.

The two tools should agree on:

CheckTerraform ownsHelm consumes
IdentityStable agent name and environmentIdentity reference or enrollment mode
ReachabilityExact allowed service setConnector and agent configuration
Credential pathRuntime injection mechanismExisting Secret or identity socket reference
LifecycleCreate, update, revokeDeploy, roll back, terminate
EvidencePlan and policy diffRendered manifest and release history

Do not let Helm silently add a destination that Terraform never approved. Add a CI test that compares the rendered service list with the Terraform input. If the provider exposes a policy read API, query the applied policy and compare it with the reviewed plan after deployment.

Detect manual changes and test the real path

IaC only helps when you detect drift. A scheduled Terraform plan can identify changes made outside the configuration. A provider refresh or API inspection can show whether the identity still exists and whether its policy has changed. The plan is evidence of a difference, not proof that the agent can or cannot connect.

Test both allowed and denied paths:

  1. Run the agent’s normal request to an approved MCP service or model endpoint.
  2. Attempt a request to an unlisted service and expect a denial.
  3. Confirm the decision is tied to the agent identity, not only the node or pod IP.
  4. Check that the connection log identifies the agent and destination.
  5. Delete the Helm release or remove the identity from Terraform, then verify the old identity cannot reconnect.

NetFoundry’s SPIRE integration overview describes a useful two-layer check: SPIRE issues a short-lived workload identity, the network policy uses that identity for connectivity, and the MCP server verifies it again with mutual TLS. If your environment uses SPIFFE or SPIRE, keep the network authorization and application authorization distinct. Passing one check should not grant every tool call.

Change access safely

Treat an access change as a policy change, not a firewall exception. Add one destination, test it, and record why the agent needs it. When the agent no longer needs that service, remove it from the set and verify the denied path.

For a production change, require:

When retiring an agent, revoke first, then remove deployment resources. Deleting the pod without deleting the identity leaves an authorization object that someone can accidentally reuse. Remove the identity, policy binding, secret reference, and monitoring rule together. Check the provider’s behavior for deleted identities and clean up any external certificate or enrollment record it does not remove automatically.

FAQ

Can Terraform manage Zero Trust access for an AI agent?

Yes. Terraform can manage the agent identity, the explicit service allowlist, and the policy binding when the selected provider exposes those resources. It should also manage the lifecycle change that revokes access when the agent is removed. Confirm the provider’s current resource schema before applying the example.

Can Helm create Zero Trust access for AI agents?

Helm can configure the deployed agent and its connector, including the identity reference and allowed service names. The chart should consume a runtime credential or workload identity and should not store a long-lived enrollment token in values.yaml. Keep the chart’s policy values separate from secret delivery.

Does sensitive = true keep a Terraform secret out of state?

No. sensitive redacts values from normal CLI output, but Terraform can still store them in state and plan files. Use an ephemeral value where the Terraform version and provider support it, or inject the credential at runtime through a protected identity or secret-management path. Protect any state that still contains sensitive values.

How do I stop an AI agent from reaching an unapproved tool?

Give the agent an identity-based policy containing only the approved tool services and set the default behavior to deny. Test a request to an unlisted service and verify that the denial is logged against the agent identity. A private network alone does not create this service-level boundary.

Should an AI agent use a shared API key for MCP access?

No. A shared API key cannot distinguish one agent from another and is difficult to revoke without affecting every consumer. Use a short-lived, cryptographically verifiable workload identity and make the MCP server perform its own authorization check. This keeps network access and tool authorization tied to the same workload.

What should happen when an AI agent is retired?

Revoke its policy and identity before deleting its deployment. Then remove its secret reference, certificate or enrollment record, and monitoring configuration, and verify that the old identity cannot reconnect. Deleting only the pod can leave a reusable authorization object behind.

Sources & References