HashiCorp Cloud Platform
Retrieve a secret from HCP Vault Secrets
In the previous tutorial, you created a secret and learned how to authenticate with HCP Vault Secrets.
In this tutorial, you will learn how to retrieve secrets using the vlt
CLI and HCP Vault Secrets API.
Prerequisites
- An existing HCP account
- Completed the previous HCP Vault Secrets tutorials
- jq
- curl (API only)
- HCP service principal with
HCP_CLIENT_ID
andHCP_CLIENT_SECRET
environment variables set
Applications, services, and workflows need to retrieve secrets so teams do not have to store secret information such as usernames and passwords, or API keys in source code.
HCP Vault Secrets provides the flexibility to use either the vlt
CLI tool, or an API to interact
with secrets.
Tip
The HCP Vault Secrets CLI includes a --help
parameter. This parameter can be appended to the vlt
command, and any sub-commands.
Review the available secrets.
$ vlt secrets list Name Latest Version Created At username 2 2023-05-24T12:22:18.395Z
The
username
secret was created during the Create a secret in HCP Vault Secrets tutorial.The version was incremented to version
2
when you changed theusername
value fromdatabase-user
todb-user
.Retrieve details about the
username
secret.$ vlt secrets get username Name Value Latest Version Created At username ************ 2 2023-05-24T12:22:18.395Z
By default, the secret value is redacted.
You can control the CLI output using the
--format
parameter. Use--format json
to retrieve a secret in JSON format.$ vlt secrets get --format json username | jq { "created_at": "2023-06-09T13:14:28.140Z", "created_by": { "email": "username@example.com", "name": "example", "type": "TYPE_USER" }, "latest_version": "2", "name": "username" }
Retrieve the
username
secret and inject the value into a process.$ vlt run -- env | grep USERNAME USERNAME=db-user
The
run
command runs a process while injecting all available secrets from a HCP Vault Secrets application as environment variables.Refer to the HCP Vault Secrets documentation for a list of all available CLI commands.
Next steps
In this tutorial you learned how to retrieve a secret using the HCP Vault Secrets CLI, and API.
You can learn more about supported integrations in the HCP Vault Secrets documentation