Automatic certificate renewal with OpenBao Agent templates

How to use OpenBao Agent pkiCert and secret template functions to render and renew TLS certificates for services, and how to reload each service safely after renewal.

On this page

How OpenBao Agent templates keep service certificates current

OpenBao Agent can render a service's TLS certificate and private key to files on disk and keep those files current, so a service with short-lived certificates does not depend on someone remembering to renew it. Teams need this when certificate lifetimes are shorter than a manual renewal cycle can reliably cover, or when many hosts carry certificates that must be replaced on a predictable schedule. Manual renewal can work for a handful of long-lived certificates, but each renewal then becomes a ticket, a copy operation and a restart, and any one of them can be missed. The Agent moves that work onto the host, where it runs the same way every time.

The mechanism rests on two template functions. The pkiCert function requests a certificate from a PKI role on your OpenBao cluster and makes the certificate and key available for rendering into files. The secret function reads other values, such as a stored key or passphrase, when a template needs them. Templates are rendered by the Agent, which re-renders them as the certificate approaches expiry. Confirm the exact function signatures, the output fields and the renewal trigger against the documentation for your OpenBao version before you write templates, because those details determine what your files contain and when they change.

The Agent does not restart or reload the service. A renewed file on disk has no effect on a process that already loaded the old certificate into memory, so the reload step belongs to your team. Plan it explicitly: check whether your Agent version can run a command after rendering, or use your service manager's reload, a signal the service handles gracefully, or a rolling restart across a cluster. Test the reload on a staging copy, and decide what happens if it fails, because a renewed file on disk paired with an old certificate in memory can hide the problem from anyone who only checks the file.

What Agent can render and renew

OpenBao Agent turns certificates and secrets into files that services can read. Each card covers one part of that path, from the PKI request to the reload that makes a renewed certificate take effect.

pkiCert requests from the PKI mount

The pkiCert function asks a PKI mount for a certificate and makes the issued certificate, private key and chain available to templates. It is the entry point for TLS renewal, so every service starts here. Check that the Agent token can call the issuing role on the correct mount path, and confirm that the role's maximum TTL fits the renewal window you planned for the service. Ask your platform team which intermediate signs the leaf certificates.

Generic secret template functions

Secret template functions read values from key/value and other secrets engines and write them into rendered files. Use them for material that pkiCert does not produce, such as a database password in a configuration file or a CA bundle stored as a secret. Keep template sources free of literal secrets, and confirm which secret paths the Agent token may read before the first render. Test each template against a non-production secret first.

Rendered files and permissions

Each template writes a file to a path you choose, and that file may contain a private key. Set the owner, group and file mode on every output so that only the service account that needs the key can read it. Check the parent directory as well, because a readable directory can expose a key even when the file itself is locked down. Confirm the exact permission settings in the Agent configuration reference for your release before you rely on them.

Template lifecycle and re-rendering

Agent keeps each template under management, re-renders it when its source changes or its lease nears expiry, and then runs any command attached to it. A render can fail, for example when the PKI backend is unreachable during renewal. Test whether the previous files stay on disk after a failed render, so a service keeps its last valid certificate until the next successful attempt. Confirm this behavior for your Agent version.

Reloading services after renewal

A new certificate on disk does not change what a running process serves until the process reloads it. Attach a command to the template so that Agent triggers a reload after each successful render. Use the graceful reload the service documents so existing connections finish cleanly. Verify on a staging listener that the served certificate serial changes after renewal, and ask the service owner which reload signal or endpoint applies.

Renewal timing for each service

Renewal does not happen at one fixed point for every service, because each certificate has its own TTL, issuing role and consumer. Services with long-lived connections, such as load balancers, need enough margin for the reload to complete. Batch jobs may read the certificate only at startup, so their renewal matters mainly for the next run. Record the TTL, renewal point and reload behavior for each service in one table so the platform team can review them together.

Renewal options for each service type

This table compares how a renewed certificate reaches four kinds of service: one that reloads from disk, one that needs a restart, one that cannot be reloaded, and one behind a load balancer. Read each row against the service you run, then check the downtime, file ownership and rollback notes before you choose a pattern. The main takeaway is that the renewal itself is the same in every case, and the reload step is what decides the risk.

Service typeWhen this option fitsDowntime and file ownershipRollback and what to confirm
Reloads certificate from diskService supports a signal, API call or config reload that re-reads the certificate and key filesUsually no connection drop, but the agent and service must agree on file ownership and permissionsKeep the previous files until the reload succeeds. Confirm the reload command and whether existing connections keep the old certificate
Needs a restartService loads TLS material only at startup and has no documented reload pathBrief interruption per instance. Restart timing must be scheduled, and file ownership must match the service userRetain prior certificate and key for a manual rollback. Confirm the restart command and health checks that gate it
Cannot be reloadedService has no reload or restart hook you can automate, or certificate material is embedded in its own storeRenewal may need a vendor procedure or a rebuild. Ownership of the store is often outside the agent's controlTreat as a manual or change-controlled process. Confirm with the vendor how the certificate store is replaced and rolled back
Behind a load balancerSeveral instances serve traffic and the balancer holds or terminates TLSRolling updates keep service up if one node is updated at a time. File ownership is per node, so each node needs its own renderDrain each node before reload, and confirm the balancer re-checks health before moving on. Keep the previous certificate on each node until all pass

How renewal differs between services

Renewal behavior is not the same across services, so one template and one reload action will not fit every workload. The first question for each service is whether it reads its certificate and key only at startup, can reload them while running, or validates a trust chain against a file it loads once. A web server such as NGINX or Apache HTTP Server can often reload its configuration without dropping connections, while many database servers and some internal APIs read TLS material only when the process starts. Agent-rendered files therefore need a per-service reload step, and that step has to be written down before the first renewal fires.

Chain files and private keys create the most common failures. Some services expect the leaf certificate and intermediates in one PEM file, others want the chain in a separate CA bundle, and a few reject a file where the key and certificate are in the wrong order. Confirm each service's documented format and whether it verifies the chain on load. Keep the private key file readable only by the service account, and check that the template output permissions and ownership match. If your PKI issues from a new intermediate during a CA rotation, the chain a client trusts may change, so the chain file must be updated together with the leaf.

Test each service against a renewed certificate in a non-production environment before rollout. Use a short-lived test certificate, trigger the template and reload action, then check the live handshake, client trust and logs for errors. Record the reload method per service, including whether it needs a signal, a restart or an API call, and whether connections are interrupted. Confirm these details with each vendor's documentation and your own configuration rather than assuming the behavior from a similar product.

Set up pkiCert renewal and a safe service reload

This sequence takes a service from a PKI role and token policy to a renewed certificate that is checked before it goes live and reloads the service only when the new files pass. Each stage ends with a check you can run before moving on.

  1. Confirm the PKI role and token policy

    The platform or PKI team confirms that the PKI secrets engine mount, the role the service will request certificates from, and the allowed common names and alternative names match what the service needs. The Agent's token policy should grant only create on that role's issue path and read on the auth token it uses. Run a test issuance with the same token, using a short TTL, and confirm the response contains the leaf certificate, the issuing CA and the chain. Done when the test succeeds and the token cannot read other paths or issue from other roles.

  2. Write the Agent configuration and template

    Create the Agent configuration with the auth method the host uses, a sink for the token, and a template stanza whose contents use the pkiCert function against your role, such as pkiCert "pki/issue/your-role" "common_name=svc.example.internal". Set destination to a staging path, not the live certificate location, and set file permissions so the private key is readable only by the service account. Ask the team that owns the service which files it reads, whether it expects a combined PEM, and whether it needs the chain in a separate file. Done when the Agent starts in the foreground and writes a file to staging without errors in its log.

  3. Render the certificate to a staging path

    Let the Agent render the certificate and key into the staging directory and leave the live files untouched. Confirm the file names, ownership and modes match the service's expectations. Check the certificate's subject, the SAN entries and the not-before and not-after dates with a standard X.509 inspection tool, and confirm the key matches the certificate by comparing their public key digests. Done when the staged key and certificate pair match and the expiry is the one you expected from the role's TTL.

  4. Validate the certificate and chain

    Verify that the staged leaf certificate chains to the intended issuer by running a chain verification against the root you trust, using the CA file that your clients already use. Confirm the chain order matches what the service presents and that the issuer is the one you expect if your PKI uses more than one issuer. Test the new bundle in a non-production copy of the service or in a test client where possible. Done when verification passes and the test client completes a TLS handshake with the staged files.

  5. Promote the files and run a reload check

    Keep the current live files as a dated backup, then move the staged files into their live locations in one step, such as an atomic rename within the same filesystem. Before sending the reload signal, run the service's own configuration check, for example its syntax or config test command, against the new files. Only if that check passes, send the reload command your service documents. Done when the reload command exits with success and the service logs a clean start with the new certificate.

  6. Confirm the live endpoint and set the rollback path

    Connect to the live endpoint from outside the host and confirm it presents the new serial number and expiry, and that existing clients still complete their handshakes. Write the rollback as a documented step: restore the backed-up files, run the same config check against them, and reload. Rehearse this in a test environment before production. Done when the endpoint shows the renewed certificate and the rollback procedure has been tested once.

  7. Schedule renewal and watch for failures

    Confirm with your PKI owner that the Agent will renew before the certificate expires, and check the Agent's own documentation for how it decides when to re-render. Add monitoring for the Agent process, the reload exit status and the days remaining on the live certificate, and alert on failures to render or reload. Ask the service owner which reload failures should page someone and which should only log. Done when a deliberately failed reload in a test environment produces the alert you configured.

How a renewal moves from PKI to a reloaded service

The renewal starts at the OpenBao PKI mount, which issues a new certificate when the Agent asks for one. The Agent authenticates to OpenBao from the host, renders the certificate and key to disk through its template, and runs a validation step before anything changes. Only after validation passes does the Agent run the service reload command, so the service picks up the new files. The trust boundary sits between OpenBao and the host: the private key is generated and stored on the host, so check file permissions and what the reload step is allowed to touch.

Certificate renewal from the OpenBao PKI mount to a reloaded service, with the trust boundary on the host.

Security and operational risks to control

Renewal automation moves private keys onto disks, into process environments and into service reloads, so each step creates a new place for a secret to leak or a service to fail quietly. The cards below cover the risks that matter most for OpenBao Agent certificate renewal and the control that addresses each one. Confirm each control against your own file layout, service manager and monitoring stack before go-live.

Private key file permissions

Agent writes rendered certificates and private keys to files that the service reads at startup. If the destination directory or file is readable by other local users, any process on the host can copy the key and impersonate the service until the certificate expires. Check that the key file is owned by the service account, that its mode excludes group and other read access, and that parent directories are not world-writable. Confirm the same rules hold after every re-render, because some template or file-write settings can recreate files with different modes.

OpenBao docs

Agent token and auth scope

The Agent authenticates to OpenBao with an auth method, and the policy attached to that identity decides which PKI roles it can issue from. A broad policy lets a compromised host request certificates for names it should never serve. Grant the Agent identity update on only the specific pki/issue/<role> paths it needs, keep the role's allowed domains narrow, and use AppRole or a similar machine method with a secret-zero delivery plan. Ask your team who can read the Agent's auth material on each host.

Keys exposed in logs and environment

Keys can leak through places other than the file system. Logging a rendered template, passing key material as an environment variable, or printing Agent debug output can place a private key in journald, container logs or CI output, where retention is often longer than expected. Keep key material in files only, avoid template actions that echo full output to logs, and set Agent log levels to what operations needs. Review your log pipeline for patterns that match PEM headers before the first renewal runs.

Reload failures on expired certificates

Renewal can succeed while the service keeps serving the old certificate because the reload command failed, timed out or ran before the new files were complete. The service then continues until the previous certificate expires, and the outage looks sudden. Test each reload command by hand, use a command action that returns a non-zero exit on failure, and confirm the service picks up the new certificate by checking the presented chain. Write down the rollback path if a new certificate is rejected by clients.

Monitoring renewal success

A renewal job that fails without an alert is one of the most common causes of certificate outages. Track the time each certificate expires, the time of its last successful render and reload, and any Agent errors in its logs. Alert well before expiry rather than at expiry, and treat a missing renewal event as a failure, not as silence. Confirm with your monitoring team which metric or log source will carry these signals, since the Agent alone does not send them to your alerting system.

Questions teams ask before automating certificate renewal

How many services can one renewal setup cover before it becomes hard to manage?

There is no fixed number. The count matters less than how many distinct certificate shapes and reload actions you have. Each service needs its own Agent template or template group, its own certificate role or common name set, and its own file ownership and permissions. A fleet of identical web servers behind one pattern is cheap to cover, while ten services with different key formats, chains and restart rules each need separate design and testing. Ask any partner to list every service in a scope document, with its certificate type, reload method and owner, before quoting. That list is the main driver of effort on this topic.

What makes the reload step harder than the renewal itself?

Rendering a new certificate is usually straightforward. Reloading the service so it actually uses the new certificate is where work accumulates. Some services reload gracefully on a signal, some need a full restart, some cache certificates in memory with no reload hook, and some load a bundle that must be assembled in a particular order. Load balancers and clusters add a rolling sequence so that not every node drops at once. Each variant needs a tested command, a health check afterward and a rollback path. Budget more attention for services that cannot reload without interrupting users.

What does the testing for automatic certificate renewal include?

Testing should prove that a certificate renews before expiry, lands at the right path with the right permissions, the service serves it, and the old certificate stops being used. In practice that means a staging run per service, a forced renewal ahead of the normal window, a check that the chain validates against the trust store clients use, and a failure test where the CA or the Agent is unreachable. Ask whether the scope includes a renewal drill in a non-production environment and whether results are written down. Testing is often the largest cost item after service count, because it cannot be skipped without moving risk into production.

What does our team need to provide for the engagement?

Your team supplies access and decisions. Expect to provide a list of services and owners, the hosts where they run, network paths from those hosts to the OpenBao cluster, and an authentication method for the Agent that fits your policy. Someone must approve which certificate roles and common names each service may request, and who signs off on maintenance windows for reloads. Security and platform staff also need to confirm where private keys may be stored on disk and which users can read them. If those owners are not named before work starts, timelines slip, so ask the partner to include a discovery step that captures them.

Can our own engineers build this without outside help?

Yes, if your team already runs OpenBao, understands its PKI engine and can test service reloads safely. The Agent documentation and template syntax are learnable, and a single well-tested service is a reasonable first project. The difficulty grows with the number of services, the variety of reload behaviors and the need to keep the setup running after the original builder moves on. Teams often do one pilot internally, then decide whether the rest justifies outside help. A partner's value is usually in the repeatable pattern, the test evidence and the documentation your operators can maintain.

What should a written scope for certificate renewal include?

A written scope should name each service, its certificate type, the OpenBao PKI role or mount it uses, the Agent host and template files, and the reload action with its health check. It should state the rollback method, the test environments, the acceptance criteria for a successful renewal and who performs each step. Ask for a list of deliverables such as template files, runbooks, test records and a handover session. Confirm whether the work is one-time or includes ongoing support, since renewals keep running after the project ends. DeployOpen plans and implements these engagements under a fixed scope agreed in writing before work starts, and a quote follows from that document.

What recurring work does automatic renewal create after launch?

Automation shifts work from expiry events to ongoing care. Recurring tasks include reviewing templates when a service changes its file layout, updating reload commands after upgrades, rotating Agent credentials, and checking that renewals still succeed after OpenBao upgrades. Each new service added later needs the same design and test steps. Ask any partner whether ongoing support is a separate retainer and what it covers, and confirm who watches renewal failures and alerts. Without an owner for these tasks, a setup that worked at launch can quietly stop renewing.

What are the main risks of automating renewal, and how do we confirm they are covered?

The main risks are a service that keeps serving an expired or wrong certificate, a reload that causes an outage, private keys written with overly broad permissions, and an Agent whose access to PKI is wider than needed. Confirm that the design limits each Agent to the roles it needs, that key files have restricted ownership, and that a failed renewal raises an alert before expiry. Ask for evidence from a test run and a documented rollback. Those controls also give compliance and audit teams material to review, although DeployOpen prepares evidence and does not issue audit reports or certifications.

How DeployOpen scopes and delivers certificate renewal

DeployOpen treats automatic certificate renewal with OpenBao Agent templates as a defined piece of work inside your infrastructure. We agree the services, certificate paths, renewal triggers and reload actions in writing, then build and test them against your own environment before handover.

How we scope

  • Inventory each service that consumes a TLS certificate, including its certificate path, key format and reload method.
  • Agree in writing which PKI roles, mount paths and template functions the Agent configuration will use.
  • Confirm which services need a reload, a signal or a restart, and who owns the change window for each.

How we build

  • Write Agent templates for each service and test rendering against a non-production OpenBao PKI mount.
  • Verify renewal timing with forced short-lived certificates, and confirm the service picks up the new certificate.
  • Test failure paths, including an unreachable OpenBao endpoint and a rejected reload, before any production cutover.

How we hand over

  • Deliver the Agent configuration, templates, reload hooks and file permissions as versioned, documented artifacts.
  • Document the renewal sequence per service, including what happens to in-flight connections during reload.
  • Provide a runbook covering alerting on failed renewals, rollback steps and how to add a new service.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.
  • Retainers can cover Agent version upgrades and re-testing when a service or its TLS library changes.
  • Ask your DeployOpen contact to confirm the support scope and response terms in the written agreement.

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.