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.

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.
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:
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:
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"
}
}
}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 Method | Initial credentials | Best for |
|---|---|---|
approle | role_id + secret_id (files) | Applications on VMs or in containers |
aws | Instance credentials / IAM role | EC2 instances, EKS |
kubernetes | Pod ServiceAccount JWT | Pods 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.
bao agent -config=/etc/bao/agent-config.hclbao 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.
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:
{{- 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:
{
"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_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.
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:
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.