Rendering secrets into config files with OpenBao Agent templates

OpenBao Agent templates use consul-template syntax to write secrets into application config files, renew leases and run restart commands. This page covers how the feature works, the configuration choices, and what to confirm before rollout.

On this page

Why teams render OpenBao secrets into config files with Agent templates

Many applications expect their secrets in a file: a YAML document, an INI file or a Java properties file that the process reads at startup. When the vendor or the in-house code base cannot be changed to call OpenBao directly, OpenBao Agent templates fill that gap. Templates use consul-template syntax to read secrets from OpenBao and write them into the target file, so the application keeps reading the file it already knows. The rendered output is a plain file on disk, which means the team also owns its permissions, ownership and cleanup.

This approach usually fits better than direct API calls when the application is closed or costly to change, when several services share one configuration format, or when a platform team wants to keep OpenBao client logic out of application code. Direct calls suit applications that can authenticate and renew leases themselves and that need secrets only in memory. Templates trade some control for simplicity: the file exists on disk for as long as it is present, so the reader must decide where it lives, who can read it and how it is removed. Confirm the Agent feature set, the template functions available and the exact syntax against the OpenBao documentation for the version you plan to run, since template behavior is the part most likely to differ from older Vault-era examples.

Before committing, ask your team to list each application that needs file-based secrets, the format it reads, and whether it reloads on change or requires a restart. Those answers decide the render destination, the command Agent runs after a write and how much effort goes into testing the rendered output. The OpenBao documentation is the starting point for confirming which Agent behaviors apply to your chosen release.

How the Agent moves a secret from OpenBao into a config file

The flow starts on the application host, where OpenBao Agent authenticates to the OpenBao server through auto-auth and writes the resulting token to a token sink. The Agent reads the template file, requests the secret, and renders the config file. A restart command then runs so the application loads the new values. Check that the token sink and rendered file are readable only by the service account, and that the restart command runs only when the rendered content changes.

Secret flow from the OpenBao server through Agent templates into a rendered config file on the host.

How template rendering, leases and renewal work together

The template-to-file cycle runs in a fixed order. OpenBao Agent first authenticates to the cluster using its configured auto-auth method, then reads each template named in its configuration, fetches the secrets those templates reference, writes the rendered output to the destination path, and watches the data it read so it can render again when a value changes. Before go-live, confirm in the OpenBao agent documentation exactly which template fields trigger a command after a write, because the restart behavior your application depends on follows from that setting, not from the file write itself. Also confirm the file permissions and ownership that Agent applies to rendered output, since a config file that is world-readable defeats the purpose of keeping secrets out of source control.

Static secrets and leased dynamic secrets need different renewal logic. A static key/value secret has no expiry of its own, so Agent re-renders it when the stored value changes and the rendering cadence is a question of how quickly your team needs to see a rotation. A leased dynamic secret, such as a database credential, carries a lease that expires unless it is renewed or the credential is fetched again. For these, Agent must keep the lease alive while the application runs, and a template that reads a dynamic secret should be reviewed against the lease duration the secrets engine issues. Ask your team which secrets engines will be rendered this way and whether each one issues renewable leases.

Plan for renewal failure before it happens. If Agent cannot renew a lease, for example because the auto-auth token expired, the policy changed or the cluster was unreachable, the rendered credential will eventually stop working and the application will fail at the database or service layer rather than at OpenBao. Test this path deliberately: revoke or let expire a test lease in a non-production environment, observe what Agent logs, whether it re-fetches a new credential, and whether your restart command runs. Confirm with the documentation how Agent reports renewal errors so that your monitoring can alert on them. The result of this test should decide whether your application can tolerate a brief gap, which is the question that sets the rendering design.

Template configuration options and when each fits

This table compares the main settings in an OpenBao Agent template stanza and the situations where each one fits. Read it as a checklist: settle the source and destination first, then decide how the file should be permissioned, reloaded and rendered. Confirm exact key names and defaults for your OpenBao version before you write configuration.

SettingWhat it controlsWhen it fits
sourcePath to the template file containing consul-template syntax and secret referencesAny config file with several secrets or a layout you want reviewed in version control
destinationPath where the rendered file is writtenPoint it at a location only the application's service account can read
permsFile mode applied to the rendered fileRestrictive modes for files holding credentials. Confirm the expected value format for your version
commandRuns after each successful render, often to reload or restart the serviceApplications that read config only at startup or have no reload signal
error_on_missing_keyFails the render when a referenced key is absentWhen a stale file is safer than a partially written one. Confirm the default in your version
wait (min and max)Delays rendering so bursts of secret changes produce one render and one command runSecret paths that change in bursts, or rotations that touch many keys at once
static_secret_render_intervalRe-renders static KV secrets on a fixed interval, since they have no lease to trackKV secrets that change occasionally and must reach the file without restarting the agent
Lease-aware renewalRenews leases and re-renders when a new dynamic credential is issuedDatabase and other dynamic credentials. Confirm lease behavior for each secrets engine you use

Decisions to make before writing the first template

Each template decision changes what lands on disk, who can read it and what has to happen when a secret changes. Settle these questions with the application owner and the platform team before the first template is written, because they determine the file layout, the reload path and the review process.

Static versus leased secrets

Decide which values are static, such as a third-party API key stored in KV, and which are leased, such as database credentials issued by a dynamic engine with a lifetime. Static values need a render interval and a change trigger. Leased values need the template to re-render before the lease expires, and the application must tolerate a new credential appearing mid-run. Ask the application team whether it reads the file once at startup or watches it for changes.

OpenBao HA docs

File permissions and ownership

Rendered files contain plaintext secrets, so the owner, group and mode must match the account the application runs under and nothing broader. Set the file mode in the template configuration and confirm the directory that holds the file is not world-readable. Check that the Agent process can write to the target path and that a rename-based write does not break file ownership expected by the service.

Which process reloads and how

A rendered file does nothing until the application reads it. Decide whether the application re-reads its configuration on a signal, on an HTTP call, or only at restart, and whether a reload command is safe to run while requests are in flight. Keep the command in the template configuration, test it against a staging copy, and confirm what happens when the command fails and the old file must stay in place.

Splitting secrets across files

Decide whether all secrets go into one file or are separated by owner, sensitivity or rotation schedule. Separate files let you give a database password to one service and a signing key to another, and let a rotation touch only the file it affects. The cost is more templates to version and more reload hooks. Map each secret to a consumer before you choose the layout.

Secrets that must not reach disk

Some values, such as a private key used only for a single request, should not be written to a file at all. Decide whether the application can take the value from an environment variable or a socket instead. If a file is unavoidable, plan a tmpfs or memory-backed location and confirm that logs, crash dumps and backup jobs exclude it. Process supervisor mode and other delivery methods are alternatives to evaluate for these values.

Versioning templates with the application

Templates reference secret paths, field names and file formats that the application depends on, so they should live in the same repository and go through the same review as the application config. Record which template version shipped with which application release, and test template changes in a staging environment that uses the same Agent version as production. Confirm the template syntax is compatible with the Agent release you run before you deploy.

OpenBao storage docs

How to set up an Agent template for one application

This sequence takes one application from an unconfigured host to a template-rendered config file that is written with the right permissions, refreshed when secrets change and reloaded safely. Each step ends with a check so you know the previous step is solid before moving on.

  1. Confirm the auto-auth method and token sink

    Decide how the Agent on this host will authenticate to OpenBao, following the auth method your team chose for servers. OpenBao recommends AppRole for servers, so confirm that the role exists, its secret ID delivery path is defined, and the token sink is a file readable only by the Agent's service account. Confirm the policy attached to the role grants read access only to the secret paths this application needs. Check: run the Agent once in a test configuration and confirm it writes a token sink file and that the token can read one test secret path with the expected policy.

  2. Write the template with consul-template syntax

    Create a template file that uses consul-template syntax to read secrets from the paths you confirmed and places them into the structure your application expects, such as a properties, YAML or JSON config. Keep one template per output file, and avoid writing secrets into logs or comments. Keep the template in version control so changes are reviewed. Check: render the template by hand against a test secret and confirm every placeholder resolves to a value and nothing is left as raw template text.

  3. Configure the destination path and permissions

    In the Agent configuration, set the destination path for the rendered file and the file mode, owner and group so that only the application's service account can read it. Create the parent directory ahead of time with restrictive permissions, and avoid world-readable locations. Confirm that the Agent process can write to that path without running with broader rights than it needs. Check: after one render, list the file and confirm its owner, group and mode match your plan and that another local user cannot read it.

  4. Set the restart or reload command

    Add an exec or command hook that tells the application to reload or restart after the file changes, so new secrets take effect. Prefer a reload signal or an application-supported reload command where one exists, and restart the service only when reload is not supported. Test the command by hand first so you know its exit status and effects. Check: change a test secret, trigger a render, and confirm the command runs once and the application reports that it loaded the new value.

  5. Start the Agent in a test environment

    Run the Agent with this configuration on a non-production host or staging environment that mirrors the application's runtime. Watch the Agent logs during startup to confirm auto-auth succeeds, the template is rendered on first start and the lease or renewal activity is recorded. Confirm the Agent is managed by a service supervisor so it restarts after a crash. Check: the Agent runs continuously for the test period without authentication errors and the application starts reading the rendered file.

  6. Verify the rendered file and restart behavior

    Confirm that the rendered output is correct and that updates behave as intended. Rotate or change a test secret in OpenBao and confirm the file updates, the reload or restart command runs, and the application picks up the change. Also confirm that renewal of the token and any leased secret continues over time, and that the Agent handles an application restart without losing its template state. Check: record the file hash before and after the change, and keep the Agent log entries that show the render and command execution as evidence.

  7. Promote the configuration to production

    Move the reviewed template, Agent configuration, role and policy definitions into production through your normal change process, with the production secret paths and the same permissions and command settings. Confirm the production role uses its own secret ID and that no test tokens or test paths are carried over. Keep a rollback plan that restores the previous config file. Check: after promotion, confirm the production application reads the rendered file, the Agent reports successful renewals, and a single test change in production propagates as tested.

Security considerations for rendered secret files

A rendered template turns a secret that lived in OpenBao into a file that sits on a host. The cards below cover the controls that decide whether that file stays as private as the secret it carries, from permissions and storage to cleanup and the template itself.

File permissions and umask

Every rendered file inherits the owner, group and mode the Agent sets, and the process that writes it can be affected by its umask. Set the mode explicitly in each template stanza so that only the application's service account can read the file, and confirm the directory above it is not world-readable. Check the result with ls -l after a render, because a file that looks private in the template can still be readable through a permissive parent directory.

Tmpfs or encrypted destination paths

Rendered secrets written to a normal disk can persist in filesystem journals and backups after the file is removed. Point destination paths at a tmpfs mount or an encrypted volume where the platform allows it, and confirm that backup jobs exclude those paths. On Kubernetes, ask whether an in-memory emptyDir fits the workload, since its memory use counts against the pod's limits.

Token and policy scope for the Agent

The Agent's token decides which secrets it can render, so a broad policy turns one compromised host into a source of every secret that host's templates reference. Write a policy per Agent identity that lists only the paths its templates read, and keep the token time-limited so renewal failures stop reads. Review which auth method the Agent uses and who can change its configuration file, because the template is only as protected as the config that loads it.

Audit of secret reads

Each render is a read from OpenBao, and the audit device records it, but only if audit logging is enabled on the cluster and someone reviews the entries. Confirm which paths and identities appear in the audit log for a test render, then set alerts for reads from unexpected identities or at unusual frequency. Ask the team to document which log sink holds these entries and how long it keeps them.

Cleanup of stale files

A file left behind after a template is removed, a service is retired, or a secret path is renamed keeps its contents on disk indefinitely. Maintain an inventory of destination paths per host, and include removal of retired files in the decommissioning checklist. Test what happens when the Agent stops or a template is deleted, since behavior on shutdown determines whether files persist after the process exits.

Protection of the template source

The template file names the secret paths and the layout of the destination, which helps an attacker target a host even when the secrets are safe. Store templates under version control with restricted write access, and deploy them with the same review process as application code. Keep template files readable only by the Agent's account, and avoid putting literal secret values inside a template, since that moves the secret into a file that is easier to copy.

Namespaces docs

Questions teams ask before rendering secrets into config files

What does it cost to render OpenBao secrets into config files?

The cost is mostly the time spent mapping each config file to its secret paths, policies and restart behavior, and then testing those renders in a non-production environment. OpenBao itself is open source under MPL-2.0, so the license adds no fee, but you still pay for the people who build, test and operate the setup. Effort rises with the number of applications, the number of distinct config formats, and how many services need a restart when a secret changes. Ask any partner for a quote built from a written scope that lists each application, its config files, its secret paths and its restart procedure. Separate one-time build work from recurring work such as template changes and upgrade testing.

How long does a first OpenBao Agent template take to validate?

Validation time depends on how many moving parts the first template touches, not on the template syntax itself. A simple static secret written to one file in a test host is quick to check, while a config file that needs an OpenBao auth method, a policy, a restart hook and a rollback path takes longer. Confirm the timeline against your own environment and change process, including how long your team needs for review and approval. Any duration a partner quotes should come from the written scope, not from a general figure.

What must our team provide before a template engagement starts?

Gather four inputs before work starts:

  • An inventory of application config files, their formats and the processes that read them
  • The OpenBao secret paths each file needs and who owns each secret
  • The policies and auth method each host or workload will use to read its secrets
  • The restart or reload procedure for each application, including health checks and rollback

If any of these are missing, the first weeks of work go to discovery. Access to a non-production OpenBao cluster and a staging copy of each application also shortens validation. Confirm these prerequisites in writing with whoever you hire.

Can our internal team set up OpenBao Agent templates without a partner?

Yes, a team with OpenBao operations experience and access to the application owners can build templates in-house. The work is manageable when the number of applications is small and the restart behavior is well understood. Risk rises when templates write secrets to files that other processes read, when a restart touches production traffic, or when no one owns the policies behind each path. A partner is most useful for the first few templates, for a documented pattern your team can repeat, or for a review of how files are permissioned and rotated. Decide based on your team's capacity and the number of applications in scope.

How do lease-aware renewal and restart commands behave with dynamic secrets?

Dynamic secrets carry leases, so Agent must re-render the file before the lease expires and, depending on your configuration, run a command after each render. Confirm the exact renewal and command behavior against the OpenBao Agent documentation for your version, and test what happens when OpenBao is unreachable. Static secrets use a render interval instead, so the file changes only when the source value changes. Plan restart commands so they run only when the rendered content actually changed, and so a failed command does not leave an application in a broken state.

Do rendered secret files need specific permissions and ownership?

Yes. A rendered file contains plaintext secrets, so it should be readable only by the account that runs the application, with the directory also restricted. Set the file owner, group and mode in the template configuration, and verify them after each render on the target OS. On Windows, check the equivalent access control entries instead. Document where each file lives, who can read it and how it is removed when a host is retired. Auditors and security reviewers often ask for this evidence, so keep the permission checks in your test plan.

How do templates change when we upgrade OpenBao or the applications?

Template syntax and Agent behavior can change between OpenBao releases, so each upgrade needs a regression test of every template against a staging cluster. The OpenBao migration guide describes in-place replacement of the Vault server process with configuration and endpoints unchanged, but it was tested only against Vault 1.14.1 community edition, so confirm your own path before relying on it. Application upgrades can also change the config format a template writes, which requires a template update in the same release window. Keep templates in version control, pin the Agent version, and record which template version each host runs.

Operating rendered templates after go-live

Treat render failures as production incidents from the first day. An Agent template that stops updating usually fails quietly: the config file on disk keeps the last good value, the application keeps running on it, and nobody notices until a credential expires. Plan for Agent logs to be collected centrally and for alerts on render errors, failed template evaluations and auth failures. Confirm with your OpenBao version's documentation which Agent log lines and metrics report template rendering, since the exact messages and any metrics endpoint should come from the release you run, not from memory. Record the owner of each rendered file so that someone is accountable when a render fails.

Rotating auth material is the recurring task most likely to break rendering. When an AppRole secret ID, a certificate, a JWT source or a token file is replaced, the Agent auto-auth configuration must be updated on every host that uses it, and the old material must be removed only after the Agent has authenticated with the new one. Schedule these rotations as change windows, and test them on a non-production host first. Review the template itself whenever a secret path moves, because a renamed KV path or a changed field key produces an empty or stale value without a hard error in some setups. Compare each template against the current secret layout during every path change review.

Restart handling and renewal failure need deliberate tests, not assumptions. Confirm that the command action runs only after the rendered file has changed, that the restart is idempotent, and that a failed restart is logged and visible. For renewal, simulate the failure modes you expect: revoke a test token, make the OpenBao endpoint unreachable for a short period, and let a lease expire. Observe whether the Agent re-authenticates, whether the file keeps its last good content, and whether the application recovers after restart. Repeat these drills after each OpenBao upgrade, and document the expected behavior so that on-call engineers know whether a stale file is an expected state or an incident.

How DeployOpen scopes and delivers OpenBao Agent template work

The sequence turns a set of secrets and application config files into a written scope, a tested template configuration running in your infrastructure, and documentation your teams can operate after handover.

  1. Inventory the config files and secrets

    DeployOpen works with your application owners to list every config file that needs a secret, the secret paths it reads from OpenBao, the file format and permissions each application expects, and which values change often enough to need a render interval. The output is an inventory that maps each file to its consumers, its owner and the restart behavior the application tolerates. Your teams confirm the list before any template is written.

  2. Agree the auth method and restart behavior

    The team confirms how OpenBao Agent will authenticate on each host, which token sink and file permissions apply, and what happens when a lease renews or a secret changes. Restart commands, reload signals and any health checks run after rendering are agreed per application. DeployOpen records these choices in the written scope, so the auth method, template targets and restart rules are reviewed together rather than separately.

  3. Confirm the written fixed scope

    DeployOpen issues a written scope that lists the templates, applications, hosts, auth method, restart commands, verification steps and handover documents. Scope, deliverables and timelines are agreed in writing before work starts, and any change to the inventory goes through the same written process. Your procurement and security teams sign off on the scope, which becomes the reference for the quote.

  4. Build templates in your infrastructure

    DeployOpen writes the consul-template syntax templates, Agent configuration and restart hooks inside your own accounts, data centers or air-gapped networks. Values are read from OpenBao at runtime and written to files with the permissions the scope sets, with no secret copied into source control or tickets. Each template is checked against its application's expected format before it goes into a shared environment.

  5. Verify renewal, rendering and restarts

    Your engineers and DeployOpen test the setup together. Checks cover a first render at boot, a secret rotation that triggers a re-render, lease renewal before expiry, a failed read that must not leave a partial file, and the restart or reload that follows. The step closes when each test case in the scope has a recorded result and any defects are fixed and retested.

  6. Hand over runbooks and documentation

    DeployOpen delivers documentation covering the template inventory, auth configuration, file paths and permissions, restart rules, troubleshooting steps and the procedure for adding a new template. Your operators walk through the runbook and confirm they can perform a rotation and a rollback on their own. The handover is complete when your team has the documents and has run the procedures in a test environment.

  7. Continue upgrades and reviews by retainer

    After handover, optional retainers cover OpenBao and Agent upgrades, template changes as applications evolve, and continuous review of rendering and restart behavior. Retainer terms, scope and frequency are agreed in writing, separately from the initial fixed-scope work. Ask for the retainer terms in the quote so recurring costs are visible alongside the one-time implementation fee.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.