Chapter 10 of 16 · Application/workload user · orders-api

Vault Agent for Applications

Use Vault Agent auto-auth and templates to separate token lifecycle from application code while preserving a clear reload contract.

Chapter contract

Persona: Application/workload user · orders-apiPhase: Applications and pipelinesEstimated time: 50 minutes

Prerequisites:

Chapter 7 complete, AppRole inputs present, and the Compose Agent profile available.

User-visible outcome:

orders-api receives an Agent-rendered file and proves freshness, permissions, and reload signaling.

Learning objectives

Consumer flow

Auto-authstep 1Token lifecyclestep 2Template renderstep 3Application reloadstep 4

Ownership boundary

OwnerConsumer-facing responsibility
You ownDefines consumption, validation, reload, and stop-using behavior.
Platform team ownsProvides trusted runtime identity, protected delivery, network, and telemetry.
Vault ownsOperates auth mounts, policies, engines, audit, and recovery.

Core concepts

Auto-auth

Agent obtains and renews a token through a configured auth method.

Template

A controlled rendering of selected Vault data.

Token sink

Protected token output; omit it unless another process needs it.

Reload command

A bounded hook run only after successful render.

Commands and configuration

cd learn-vault/labs/bootstrap
docker compose --profile agent up -d vault-agent
cd ../vault-agent
./wait-for-render.sh
./inspect-render.sh

Secret-safety stop

Stop: Agent reduces custom token code; it does not make rendered files non-secret. Protect destinations, backups, process access, and cleanup.

Failure drill

SymptomThe app keeps old configuration while Agent is running.
Likely causesTemplate error, policy denial, renewal failure, rename mismatch, or reload hook failure.
Inspect safelyCheck Agent state, render mtime, error class, reload marker, and KV version.
Do not printRendered content, token sink, SecretID, or Agent environment.

Break it / fix it

Break it: Stop Agent after the first render and let the file become stale.

Show diagnosis and fix

Fix it: Restore auto-auth, require a successful new render, then verify the application reload marker.

Escalate with time, endpoint, auth path, role, mount, namespace when relevant, status code, request ID, and sanitized error class. Never attach a credential or response body.

Try it

Bootstrap boundary

labs/bootstrap owns the disposable server, auth mounts, policies, roles, and engines; learner actions begin after setup.

Cost:

$0; local containers only

Starting state:

Run labs/bootstrap/setup.sh and source .runtime/learner.env unless the chapter lab says AppRole alone is sufficient.

User actions:

Start the Agent profile, wait for a protected render and reload marker, then inspect mode, mtime, and schema keys only.

cd learn-vault/labs/bootstrap
docker compose --profile agent up -d vault-agent
cd ../vault-agent
./wait-for-render.sh
./inspect-render.sh
test -f ../../.runtime/reload.request
./cleanup.sh

Success criteria:

Complete every item in the Verify section using metadata-only evidence; no secret value appears in terminal output or tracked files.

Troubleshooting:

Use the Failure drill and Break it / fix it evidence fields. Stop before broadening policy, weakening identity or TLS checks, or copying secret-bearing diagnostics.

Verify

  1. The render exists with mode 0600.
  2. Inspection reports expected keys without values.
  3. The reload marker follows a successful render.
Evidence rule: retain only status, policy names, TTLs, versions, timestamps, fingerprints, and error classes. Never retain secret values.

Cleanup

Stop the Agent profile and remove renders and markers; keep core services if continuing.

Project Lockbox increment

orders-api receives KV configuration through an Agent file-and-reload contract and exposes render age only.

Quick check

What does Agent remove from app code?

Token acquisition, renewal, and template retrieval mechanics.

Who owns reload correctness?

The application contract.

Is a token sink mandatory?

No. Omit it when no separate process needs the token.

What should health inspect?

Agent state, freshness, schema validity, and app acceptance.

Gotchas

Recap and next

Agent is a lifecycle sidecar, not an ownership shortcut: the app still defines valid, fresh, and reloadable.

Primary references

Continue →