Vault Agent and Consul Template for Secret Delivery. This is the mechanism that lets your applications stop storing passwords and database connections in plain text files and start receiving them live from Vault, just as they need them. For the VA-003 exam, you need to know not just that these tools exist, but exactly how they differ from each other and how they automate the flow of secrets from Vault to an application.
Jump to a section
A simple way to picture Vault Agent and Consul Template for Secret Delivery
The head chef at a busy restaurant kitchen is the central figure here. She needs the daily specials board, the wine list, and the prep schedule to run the kitchen. The problem is she can't be running to the owner's office every time a waiter asks about the special. She needs those documents delivered to her station, automatically, the moment they change.
Her solution is twofold. First, she hires a dedicated receptionist. This receptionist's only job is to sit at the owner's office door. Every time the owner updates the specials, the receptionist grabs the new list and walks it straight to the chef. The chef never has to ask again. Second, she creates a pre-printed, fill-in-the-blanks template for the prep schedule. Whenever the receptionist delivers a new ingredient delivery note, the chef simply plugs the quantities into her template, and the updated schedule prints out automatically. The template itself never changes, only the numbers inside it.
The chef is your application. The owner's office is Vault, the central secret store. The specials list is a database password — something that changes. The receptionist is the Vault Agent, the secure babysitter that fetches the password automatically and keeps renewing it. The fill-in-the-blanks prep schedule template is the Consul Template, a configuration file that waits for a new secret and then rewrites your app's config file. The chef never touches the owner's office; she just uses what the receptionist and the template deliver. This eliminates the risk of the chef leaving her station (your app being exposed to a static password) and ensures she always has the correct, live version of the specials board.
To understand Vault Agent and Consul Template, you first need to understand the problem they solve. Without them, if you wanted your application to use a database password stored in Vault, you had two bad options.
The first bad option: you embed the password directly in your application's configuration file. This is terrible security. If an attacker gets the file, they have the password forever. Also, if the password rotates (changes), you have to manually update the file and restart the app.
The second bad option: you write your own custom script inside the application that talks to Vault's API (Application Programming Interface, which is a set of rules for how two software programs can talk to each other). This is complex error-prone code. You have to handle authentication, token renewal, network timeouts, and the file rewriting logic yourself. Every application team ends up writing the same messy code.
Vault Agent and Consul Template exist to get rid of both bad options. They are secondary tools that sit between Vault and your application, handling all the complex secret fetching and file rewriting so your application code stays simple and secure.
What is Vault Agent?
Vault Agent is a daemon (a background process that runs continuously on a server, like a heartbeat). Its job is to authenticate to Vault on behalf of a client. It manages the lifecycle of a Vault token, which is a temporary credential that proves the application's identity to Vault. The Agent automatically renews that token before it expires. More importantly, Vault Agent can fetch secrets from Vault and, if you configure it to do so, write those secrets into a file that your application can read. This is called a 'sidecar' pattern because the Agent runs alongside your application, much like a motorcycle sidecar rides alongside the main bike. The application never directly calls Vault; it only reads a local file that the Agent keeps fresh.
What is Consul Template?
Consul Template is a separate tool that came from the Consul ecosystem (Consul is another HashiCorp tool for service discovery), but it works perfectly with Vault. It does one thing very well: it watches for changes in data from a source (Vault, Consul, or a local file) and automatically rewrites template files. A template is a configuration file with placeholder variables, like '{{ with secret "database/creds/my-role" }}' or '{{ .Data.password }}'. When the underlying secret changes, Consul Template sees the change, re-executes the template with the new values, and writes out a fresh configuration file. It can also run a command after writing the file, like 'systemctl restart my-app', so the application picks up the new secret immediately.
How they work together (the most common exam scenario):
A fully automated setup uses both tools. Vault Agent handles the authentication and token lifecycle. Consul Template handles the template rendering and file rewriting. Here is the flow:
1. You configure Vault Agent with the necessary auth method (how the server identifies itself to Vault, like an AWS IAM role or a static token). The Agent starts up, authenticates to Vault, and receives a token.
2. You configure Consul Template with the address of Vault and a template file. That template file looks like a normal configuration file but with Vault placeholders, for example: 'DB_PASSWORD={{ with secret "database/creds/my-app-role" }}{{ .Data.password }}{{ end }}'.
3. Consul Template starts up. It knows it needs to talk to Vault to get the password. But Vault requires a valid token. So Consul Template is configured to use a 'vault_agent_token_file' or similar parameter that points to the file where Vault Agent writes its current token.
4. Consul Template reads the token from the Agent's file, calls Vault with that token, and fetches the secret. It then fills in the template and writes the finished configuration file to disk (like '/etc/my-app/config.env').
5. If the secret rotates or the token gets renewed, the Agent updates its token file, Consul Template detects the change, re-fetches the secret, and rewrites the config file. Your application sees a new, valid password without being restarted or manually touched.
Why bother?
This replaces the old manual method of storing secrets in plain text config files. It replaces the fragile method of having every application write its own Vault client code. It provides zero-touch secret rotation, meaning passwords can change every hour and your application will always get the latest version automatically. For the VA-003 exam, the key distinction is: Vault Agent manages authentication and token lifecycle (it is the 'who are you' part), while Consul Template manages template rendering and file rewriting (it is the 'what gets written to disk' part). They are often used together, but they are separate products that do different jobs.
Configure Vault Agent Authentication
Set up the 'auto_auth' block in the Vault Agent configuration with a chosen method, such as AWS IAM, AppRole, or a token file. This block tells the Agent how to prove its identity to Vault and receive a token. Without this, the Agent cannot fetch any secrets.
Define the Sink for the Agent Token
Add a 'sink' configuration that tells the Agent where to write the current token. Most commonly it is a file path, like '/opt/vault/agent-token'. This file will be read by Consul Template later. If the sink is not defined, the token exists only in the Agent's memory and is not accessible to other tools.
Create the Consul Template Configuration File
Write a template file (e.g., 'app.tpl') that contains the desired output format with Vault template directives, like '{{ with secret "database/creds/my-role" }}{{ .Data.password }}{{ end }}'. This file is the blueprint for the final configuration file that your application will read.
Point Consul Template to the Agent Token
In the Consul Template configuration, set the 'vault_agent_token_file' parameter to the path of the sink file from Step 2. This tells Consul Template to read the agent's token for authentication. Without this, Consul Template would need its own separate token.
Set the Output Destination and Post-Command
Configure Consul Template to write the rendered file to a location your application expects (e.g., '/etc/myapp/config.json'). Optionally, add a 'command' parameter to execute a script or restart the application so it picks up the new secret immediately.
Run Both Daemons and Test Rotation
Start the Vault Agent and Consul Template as background services. Trigger a secret rotation in Vault (by renewing a dynamic secret, for example) and verify that the Agent renews its token, Consul Template detects the change, the config file is updated, and the application uses the new value.
A mid-sized company called 'FinFlow' runs a payment processing application on a fleet of fifty Linux servers. The application needs to connect to a PostgreSQL database to read transaction data. The database password is stored in Vault and is set to rotate every 30 days as a security policy. Previously, an engineer named Priya had to manually copy the new password from the Vault UI into a file on each server every month, then restart the application. This process took her four hours and was prone to human error. Once, she missed updating three servers, causing a partial outage.
FinFlow decides to implement Vault Agent and Consul Template. Here is exactly what the IT team does, step by step:
Step 1: Provision a Vault Agent configuration file on each server. The file specifies the 'vault' address, the 'auto_auth' method (in this case, using the server's AWS IAM role), and a 'sink' that writes the token to a specific file at '/opt/vault/agent-token'. The team uses a configuration management tool like Ansible to push this file to all fifty servers.
Step 2: Start the Vault Agent as a systemd service. The team writes a systemd unit file that starts the Vault Agent at boot time and keeps it running. They test it by checking that a valid token file appears at '/opt/vault/agent-token' after the Agent starts.
Step 3: Create the Consul Template file. The team writes a template called 'database.tpl' with the exact content they want in the final config file:
db_host = "postgres-primary.finflow.internal"
db_port = 5432
db_user = "finflow-app"
db_password = {{ with secret "database/creds/finflow-app-role" }}{{ .Data.password }}{{ end }}
Step 4: Configure Consul Template to watch for changes. They tell Consul Template to read the template file, use the Vault Agent token (via 'vault_agent_token_file = "/opt/vault/agent-token"'), and write the output to '/etc/finflow-app/db.conf'. They also add a 'command' directive: 'command = "systemctl restart finflow-app"' so the application picks up the new config.
Step 5: Start Consul Template as a separate systemd service. Now both daemons run on the server. When the database password rotates in Vault, the following happens automatically:
Vault Agent detects its token is about to expire, renews it, and writes the new token to the sink file.
Consul Template notices the token file changed, re-authenticates to Vault with the new token, re-fetches the database password, and re-renders 'db.conf'.
Consul Template runs the command 'systemctl restart finflow-app', which causes the application to read the new db.conf file with the new password.
Result: Priya no longer has to perform the monthly manual update. The system is self-healing. If an attacker compromises one server and steals the token, that token is short-lived and gets renewed constantly, making it much less valuable than a static password file. The company passes its security audit because no secrets are stored in configuration files.
The IT professional who implements this needs to know how to write the configuration files for both Agent and Template, how to set up the auth method in Vault, and how to restart services safely. They also need to troubleshoot issues like token permission errors (the Agent's token might not have access to the 'database/creds' path) or file permission conflicts (the config file output might be owned by root but the application runs as a limited user).
The VA-003 exam tests your understanding of Vault Agent and Consul Template as two distinct but complementary tools. You will not be asked to write a full configuration from memory, but you will need to identify the correct use case for each tool and understand the flow of authentication and secret delivery.
What concepts does the exam love to test?
- The exact difference between Vault Agent and Consul Template. This is the most common question. Vault Agent handles authentication and token lifecycle management. Consul Template handles template rendering and file rewriting. They are not interchangeable. - The 'sidecar' pattern. The exam expects you to know that Vault Agent runs as a sidecar process alongside the application, not inside it. - The purpose of the 'auto_auth' configuration block in Vault Agent. This block tells the Agent which authentication method to use (e.g., AWS, Azure, GCP, AppRole, Token). - The concept of the 'sink' in Vault Agent. A sink is a location where the Agent writes its current token so that other processes (like Consul Template) can read it. Common sinks are files or the 'agent/sink' endpoint. - How Consul Template uses the Vault Agent's token. The exam might ask: 'Consul Template needs a token to talk to Vault. How does it get one?' The answer is it reads the token from a file that Vault Agent writes, or it can be configured to use its own token, but the recommended pattern is to use the Agent's token. - The template syntax itself. You do not need to memorise every detail, but you should recognise '{{ with secret "PATH" }}' as the way to fetch a secret, and '{{ .Data.KEY }}' as the way to access a specific field.
Common question traps on the exam:
- Trick questions that suggest Consul Template can handle authentication directly. It cannot. Consul Template needs either its own Vault token or the Agent's token. It does not perform the auth handshake itself. - Questions that imply Vault Agent writes configuration files. Vault Agent can write secrets to files using a 'template' configuration block (a feature called 'Vault Agent Templates'), but the classic exam distinction is that Consul Template is the dedicated tool for that job. - Questions about token renewal. The exam expects you to know that Vault Agent handles automatic token renewal, not Consul Template.
Key definitions to memorise:
- Vault Agent: A daemon that authenticates to Vault, manages token lifecycle, and can cache and deliver secrets to local files or processes. - Consul Template: A daemon that watches for changes in Vault (or Consul) data, renders templates with the new values, and writes output files or executes commands. - Sidecar: A secondary process that runs alongside the main application process, providing supporting functionality like secret delivery. - Sink: A location (usually a file) where Vault Agent writes its current token for other tools to consume. - Template: A configuration file with placeholder variables that gets filled in with real data from Vault or another source.
What the exam does NOT test:
- The exam will not ask you to debug complex Consul Template errors. - It will not ask about the internal implementation details of the Go templates library. - It will not ask about advanced features like Vault Agent Caching (which is a separate, advanced exam objective, 3.3).
Focus on the conceptual difference, the authentication flow, and the use cases. Know that Vault Agent is the 'who' (authentication) and Consul Template is the 'what' (rendering). That is the core of what the exam tests.
Vault Agent manages authentication to Vault and the lifecycle of the token; Consul Template manages the rendering of configuration templates with secret values.
The 'sink' in Vault Agent is the file or endpoint where the current token is written so that other processes (like Consul Template) can consume it.
Consul Template can fetch secrets from Vault using a token provided either directly or from a Vault Agent sink file.
The sidecar pattern means Vault Agent runs as a separate process alongside the application, not embedded within it.
Using Vault Agent and Consul Template eliminates the need to store static secrets in configuration files and automates secret rotation.
On the VA-003 exam, you must be able to distinguish which tool handles authentication (Vault Agent) and which handles template rendering (Consul Template).
These come up on the exam all the time. Here's how to tell them apart.
Vault Agent
Manages authentication to Vault and token lifecycle
Can write secrets to files using its own template engine
Does not execute commands after writing files
Consul Template
Renders templates with secret values from Vault
Cannot authenticate to Vault on its own (needs a token)
Can execute a command (e.g., restart) after writing a file
Vault Agent Templates
Built into the Vault Agent binary (no extra install)
Simpler, less flexible template syntax
Does not support all Vault secret engines natively
Consul Template
Separate binary, must be installed independently
Rich, flexible template syntax with many functions
Supports multiple data sources (Vault, Consul, files)
Static Secret Delivery
Secret is generated once and does not change automatically
Typically requires manual rotation or custom scripting
Higher risk if the secret is stolen because it is long-lived
Dynamic Secret Delivery
Secret is generated on demand with a TTL (time to live)
Can be rotated automatically by Vault without human intervention
Lower risk because secrets expire and are constantly renewed
Mistake
Vault Agent and Consul Template are the same thing, just with different names.
Correct
They are separate tools with different jobs. Vault Agent handles authentication and token management. Consul Template handles template rendering and file rewriting. They can work together but are not interchangeable.
Both tools are often mentioned together in documentation and guides, so beginners assume they are the same product. The similar names (both start with 'Vault' and 'Consul') add to the confusion.
Mistake
Consul Template can only work with Consul, not Vault.
Correct
Consul Template was originally built for Consul, but it also natively supports Vault as a data source. It can query Vault secrets just as easily as Consul KV values.
The name 'Consul Template' strongly biases people to think it is exclusive to the Consul ecosystem. Many beginners are unaware that HashiCorp designed it to be multi-source.
Mistake
You must use Vault Agent and Consul Template together. You cannot use one without the other.
Correct
You can use Consul Template on its own if you provide it with a Vault token directly. You can use Vault Agent on its own to authenticate and write secrets to files using its own template functionality. They are independent tools.
Documentation examples often show them working hand-in-hand because it is the best-practice pattern, but this creates the misconception that they are a single coupled system.
Mistake
Vault Agent writes secrets directly into your application's configuration file.
Correct
Vault Agent can write secrets to files using its own template engine, but it is more commonly used to manage authentication and write the token to a sink. Consul Template is the tool that then rewrites the actual application config file using that token.
The term 'Agent' sounds like an active helper that does everything, including file writing. Beginners overlook that the agent's primary job is auth, not template rendering.
Mistake
If I use Vault Agent, my application no longer needs to restart when a secret rotates.
Correct
Vault Agent itself does not restart your application. Consul Template can execute a command (like a restart command) after writing a new config file, but the application must be designed to re-read its config file or be restarted. Vault Agent alone does not trigger application reloads.
Beginners want a magical 'no-restart' solution. They hear 'secret rotation' and assume the app will instantly pick up the change, not realising that a separate step (restart or reload) is usually required.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
Yes. They are separate binaries from HashiCorp. Vault Agent comes bundled with the Vault binary, but Consul Template is a separate download. You install each independently on the server.
Yes. Consul Template was originally built to work with Consul's key-value store, and it can also read from local files. However, for the VA-003 exam, you should focus on its use with Vault as a secret source.
No. Vault Agent can write a file but it does not execute commands. To restart an application, you need to use Consul Template with a 'command' directive, or use a separate tool like 'systemctl' triggered by a watch utility.
The token in the sink file will eventually expire (if not renewed). Consul Template will then fail to authenticate when it tries to fetch a new secret. Your application will continue using the last good config file until it is restarted or the token fails. Best practice is to have monitoring that alerts if the Agent stops.
No. Vault Agent itself has a 'vault_agent_template' feature that can render templates, and there are other alternatives like 'envconsul' (which injects secrets as environment variables). Consul Template is just the most popular and flexible solution.
It means the Vault Agent runs as a separate process next to your main application process, not inside it. They share a filesystem so the Agent can write a token file or config file that the application reads, but the application never directly communicates with Vault. This keeps the application code simple and secure.
You've finished Vault Agent and Consul Template for Secret Delivery. Continue through the VA-003 study guide to build a complete picture of the exam.
Done with this chapter?