Automate certificates with Vault Agent and TPM auth attestation
Enterprise
Appropriate Vault Enterprise license required
Vault Agent can do TPM-based attestation to ask Vault to generate an x509 certificate without manual operator intervention.
Requirements
- Vault Enterprise v2.2.0 or later
- A Vault TPM auth mount
- The local TPM must be enrolled in Vault's identity secret engine
- The TPM must either be included in the auth mount role's
tpm_idsfield or be part of a group included in the role'stpmgroup_idsfield.
Configuration
Add a tpm_cert stanza to your Agent configuration file.
Each block must have a unique label that you reference in an auto_auth tpm method.
Minimal example
vault {
address = "https://vault.example.com:8200"
}
auto_auth {
method "tpm" {
mount_path = "auth/tpm"
config = {
tpm_cert = "machine"
reload = true
reload_period = "30s"
}
}
sink "file" {
config = {
path = "/private/vault-token"
}
}
}
tpm_cert "machine" {
mount_path = "auth/tpm"
role_name = "myrole"
destination {
path = "/private/certs"
}
}
Full example
tpm_cert "machine" {
mount_path = "auth/tpm"
role_name = "myrole"
renew {
percent_renew_before_expiry = 20
}
tpm {
device_path = "/dev/tpmrm0"
}
destination {
path = "/private/certs"
umask = "077"
}
csr {
CN = "api.internal.example.com"
C = "US"
ST = "California"
L = "San Francisco"
O = "Example Corp"
OU = "Engineering"
}
}
tpm_cert stanza reference
| Parameter | Required | Default | Description |
|---|---|---|---|
<label> | yes | — | A unique name for this block, used as the argument to tpm_cert in auto_auth tpm stanzas. |
mount_path | yes | — | tpm auth mount path (for example, auth/tpm). |
role_name | yes | — | tpm auth role used to issue the certificate. |
namespace | no | Inherited from vault.namespace | Vault namespace override for this block. |
csr | no | — | Explicit CSR subject configuration block. |
destination | yes | — | Output path configuration for the issued certificate and key. |
renew | no | — | Configure certificate renewal. |
tpm | no | — | Configure TPM device. |
destination block
| Parameter | Required | Default | Description |
|---|---|---|---|
path | yes | — | An existing directory where Agent writes certificate files. Duplicate paths across tpm_cert blocks are not allowed. |
umask | no | "077" | Octal umask applied when writing certificate files. |
csr block
| Parameter | Required | Description |
|---|---|---|
CN | yes | Common name for the certificate subject. |
C | no | Country field for the certificate subject. |
ST | no | State field for the certificate subject. |
L | no | Locality field for the certificate subject. |
O | no | Organization field for the certificate subject. |
OU | no | Organizational unit field for the certificate subject. |
renew block
| Parameter | Required | Default | Description |
|---|---|---|---|
percent_renew_before_expiry | no | 20 | Percentage of TTL remaining at which renewal is triggered. Must be between 1 and 99. |
tpm block
| Parameter | Required | Description |
|---|---|---|
device_path | no | Path to TPM device. Usually unnecessary. |
Considerations
- Destination
pathvalues must be unique and must point to existing directories. Agent does not create them. - The default
umaskof077means only the agent process owner can read the written key files. percent_renew_before_expiryis evaluated against the remaining TTL of the certificate. A value of20triggers renewal when 20% of the certificate's lifetime remains.