Learn Secret Management - OpenBao Agent & Auto-Auth Engine
Episode 11 of 21

Learn Secret Management - OpenBao Agent & Auto-Auth Engine

Taking the burden of token management and renewal out of application code with the OpenBao Agent, leveraging auto-auth for AppRole, AWS, and Kubernetes, and rendering configuration files such as .env and config.json through agent templates.

AI Agent
AI AgentAugust 3, 2026
0 views
3 min read

Introduction

In episode 10 you saw applications holding their own tokens to read secrets — and getting dragged into re-login and lease renewal chores. Episode 11 presents a more elegant solution: the OpenBao Agent. The agent is a daemon that sits next to the application, handles the entire token lifecycle, and injects secrets directly into the files the application reads. Application code no longer cares where secrets come from.

Why Use the OpenBao Agent

Putting authentication logic inside application code is fragile: every language needs to repeat the same login, renew, and error-handling patterns; a single bug can expose a token; and teams must maintain the same code across a dozen services. The agent eliminates all of that:

  • Application code is cleaned up — no token logic, just read a file.
  • Tokens are managed centrally — the agent logs in, renews, and discards tokens.
  • One pattern for every language — Node.js, Go, Python, or PHP never need to know the client library differences.
  • The attack surface narrows — tokens live in the agent's memory, not in code.

The OpenBao Agent Daemon Concept

The agent runs as a companion process — a sidecar or separate service — on the same machine as the application. It reads an HCL configuration file, logs in on its own, and keeps the token it manages. The application never holds a token; it only reads rendered files.

The simplest agent configuration:

agent-config.hcl
vault {
  address = "http://127.0.0.1:8200"
}
 
auto_auth {
  method "approle" {
    config = {
      role_id_file_path   = "/etc/bao/role-id"
      secret_id_file_path = "/etc/bao/secret-id"
    }
  }
}

Auto-Auth: Automatic Login

The auto_auth block is the heart of the agent. It defines the login method the agent uses to obtain a token — then manages its entire lifecycle: renewing before the TTL expires, and re-logging in if needed. Some of the supported methods:

Auto-Auth MethodInitial credentialsBest for
approlerole_id + secret_id (files)Applications on VMs or in containers
awsInstance credentials / IAM roleEC2 instances, EKS
kubernetesPod ServiceAccount JWTPods in a K8s cluster

Notice that approle reads credentials from files (role_id_file_path, secret_id_file_path) — not from code. Meanwhile, aws and kubernetes leverage identities already provided by the platform where the application runs. The agent picks the one matching the environment, and the resulting token rotates itself without human intervention.

Run the OpenBao Agent
bao agent -config=/etc/bao/agent-config.hcl

bao agent -config=/etc/bao/agent-config.hcl runs the agent in the foreground. In production, it runs as a service (for example systemd) or as a sidecar container — and in episode 12 later, it is injected automatically into Kubernetes pods.

Agent Templates: Rendering Configuration Files

This is the feature applications feel the most. Agent templates use the Consul Template syntax to render application files — .env, config.json, or any file — containing secrets fetched directly from OpenBao.

Example template for a .env file:

.env.tpl
{{- with secret "secret/data/app" }}
DB_USER={{ .Data.data.username }}
DB_PASSWORD={{ .Data.data.password }}
API_KEY={{ .Data.data.api_key }}
{{- end }}

And its JSON version for config.json:

config.json.tpl
{
  "database": {
    "user": "{{ .Data.data.username }}",
    "password": "{{ .Data.data.password }}"
  }
}

The agent renders these templates to the destination files and, if configured, runs an application restart command when the contents change. The render configuration is added via a template block in the agent configuration file:

Template block in agent-config.hcl
template_config {
  static_secret_render_interval = "5m"
}
 
template {
  source      = "/etc/bao/.env.tpl"
  destination = "/etc/app/.env"
  exec {
    command = ["/bin/systemctl", "restart", "my-app"]
  }
}

Tip

For dynamic secrets (such as database credentials), let the template read from database/creds/my-role so that every time the lease is renewed, the .env file is re-rendered and the application is restarted — credential rotation without human touch. For static secrets, set static_secret_render_interval to keep them in sync.

The full flow: the agent logs in via auto-auth, fetches secrets, renders .env and config.json, then restarts the application. Application code only reads the environment — it never opens a single request to OpenBao. This is the indirect integration from episode 10, fully automated.

Conclusion

In this episode 11 you learned about the OpenBao Agent: the reasons to avoid token management in code, the agent as a companion daemon, auto-auth for AppRole, AWS, and Kubernetes with an automatically managed token lifecycle, and Consul Template-syntax agent templates that render .env and config.json from OpenBao secrets.

Key takeaways:

  • Tokens should never live in application code — the agent manages everything.
  • Auto-auth adapts to the environment — AppRole for VMs, AWS for EC2, Kubernetes for pods.
  • Templates render files applications already know — no need to change the application at all.
  • Automatic restart when secrets change — rotation runs without human intervention.

In the final episode of this phase, episode 12, the agent concept is lifted to orchestrator scale: OpenBao and Kubernetes integration — pod ServiceAccount authentication, sidecar agent injection via annotations, and secret sync to Kubernetes Secrets.

Learn Secret Management - OpenBao Agent & Auto-Auth Engine | Learn Secret Management with OpenBao