Retrieve secrets from HashiCorp Vault
P4 Server can retrieve secrets from a HashiCorp Vault server, so that the secrets do not reside on the P4 Server host. P4 Server supports the Vault KV version 2 secrets engine only.
Before you begin
Ensure that you have the following:
-
A Vault server that is reachable over HTTPS from the P4 Server host.
-
A KV version 2 secrets engine mounted in Vault.
-
A Vault token that can read the secrets that P4 Server uses.
Store a secret in Vault
Store each secret as a Vault entry that has a single field named secret. For example, to store a client secret in the secret mount, run the following command. Replace the example names with your own.
vault kv put -mount=secret oidc-client-secret secret=-
Vault reads the value from standard input when you use secret=-. Type the value, and then end the input. On Linux and macOS, press Ctrl+D. On Windows, press Ctrl+Z, and then press Enter.
The following format applies to the value:
-
Vault returns the entry as JSON in the form
{"secret":"value"}. P4 Server uses thesecretfield and ignores other fields. -
The value follows the formats in Supply secrets to P4 Server.
Configure the connection to Vault
Set P4VAULTCONFIG, with p4 configure set or in the environment, to a JSON object that describes the Vault server. The following table lists the fields.
| Field | Description |
|---|---|
|
|
Required. The address of the Vault server. The address must be an HTTPS URL that includes a host name. Do not include user information ( |
|
|
The mount point of the KV version 2 secrets engine. The default is |
|
|
The Vault namespace. P4 Server sends the value in the |
|
|
The request timeout in milliseconds. The default is |
|
|
The number of times that P4 Server retries a failed request. The default is |
|
|
The path to a PEM file that contains the certificate authorities (CAs) to trust when P4 Server connects to Vault. See Retrieve secrets from HashiCorp Vault. |
The following example shows a typical value. Replace the example values with your own.
{"addr":"https://vault.example.com:8200","kv_mount":"secret","namespace":"p4","ca_bundle":"/etc/p4d/vault-ca.pem"}
P4 Server rejects unknown fields. In particular, it rejects verify_ssl, because P4 Server always verifies the Vault certificate.
Provide the Vault token
Supply the token in one of the following ways:
-
Set
P4VAULTTOKEN, in the environment, to the token. P4 Server refuses to store the token withp4 configure set, so that it is never in the database or the journal. -
Set
P4VAULTTOKENFILEto the path of a file that contains the token. A path is not a secret, so you can set this variable withp4 configure set.
If you set both variables, P4 Server uses P4VAULTTOKEN.
P4 Server does not read a file that names the configuration, so supply the configuration in P4VAULTCONFIG itself.
Use a custom CA bundle
If your Vault server uses a certificate that a private CA signed, set ca_bundle to a PEM file that contains the CA certificates.
When P4 Server connects to Vault, it trusts the CA certificates from the following sources, in this order:
-
The PEM file that
ca_bundlenames, if you set it. -
The PEM file that the
ssl.client.ca.pathconfigurable names, if you set it. -
The trust store of the operating system.
To learn how ssl.client.ca.path interacts with the trust store of the operating system, see Configure P4 Server for built-in SSO.
Point a secret at its Vault entry
To retrieve a secret from Vault, set the NAMENAME variable to the name of the Vault entry, and unset the NAME and NAMEFILE variables. For example, on Linux, add the following to a systemd service unit:
[Service]
Environment='P4VAULTCONFIG={"addr":"https://vault.example.com:8200"}'
Environment=P4VAULTTOKENFILE=/etc/p4d/secrets/vault-token
Environment=P4IDPCLIENTSECRETNAME=oidc-client-secret
Follow the security guidelines
Observe the following guidelines:
-
Use an HTTPS address without user information.
-
P4 Server follows HTTP redirects from Vault, and the token goes with each request. Ensure that your Vault server redirects only to trusted hosts.
-
Do not use the characters
%,?,#, or&in the names of secrets.
Next steps
To change a secret after you configure it, see Rotate secrets.