»Dynamic Secrets for Waypoint with Vault
When an app is deployed with Waypoint, its deployment can also be configured using Waypoint! This can be done with static application configuration, where static environment variables or files can be applied to your running deployment. Alternatively, configuration can be sourced dynamically from external sources, using a config sourcer plugin.
The HashiCorp Vault plugin for Waypoint is one of the config sourcer plugins that is built-in to the Waypoint binary. This plugin can be used to source static values from the Vault KV secrets engine, but also for dynamic secrets! A dynamic secret is one that is managed by Vault and has a lease associated with it, where the secret will expire after a set time to live (TTL). This is a huge benefit for the security of your application, as any possibly leaked secrets would automatically expire after a pre-configured amount of time, among other things including that developers and operators don’t need to know secrets for their deployed applications.
Prior to using Waypoint to deploy Nomad jobs, Nomad users have relied on Nomad’s integration with Vault to template secrets to their applications. Users may still make use of this integration, but in instances where Waypoint is used to deploy an app, it can be abstracted away by using Waypoint’s dynamic configuration integration with Vault, even when not deploying to a Nomad cluster. This use case goes over how this can be done in Waypoint.
An example application, located at this path
in the waypoint-examples GitHub repository, will eventually need read-only access
from a Postgres database, and should provide dynamic credentials to access it.
To make this happen, a role will be created in the Postgres database with read-only
access, using the psql
command line tool. The IP, port, and user below should be
filled in based on the configuration and environment in which your Postgres instance
is running.
There is already a Vault cluster up and running, and a database secrets engine will be configured and enabled, so that Vault can connect to a database and generate credentials dynamically.
In the database secrets engine, a connection and role have been configured. With this, authorized entities in Vault will be able to generate dynamic credentials using the secrets engine.
The final steps in Vault are to create a Vault policy, which will allow an entity to access the database secrets engine and generate a dynamic credential for the database, and to create a token with this policy attached to it:
Now that Vault is configured to produce dynamic database credentials, Waypoint needs to be configured to connect to Vault. A configuration source for the Vault plugin will be added like so:
To double-check that the token and address are what is expected, waypoint config source-get
can be run:
At this point, the config source isn't actually being used yet, but that can be made ready by adding it to the waypoint.hcl file, and committing it to the git repository for the project.
In the configuration above, Waypoint has been informed that it must get a secret
from Vault at the path database/creds/my-role
. To learn more about how Waypoint
does this, see the Waypoint Entrypoint docs.
The values for the keys username
and password
at the secret path will be configured
as environment variables, USERNAME
and PASSWORD
, in the deployment of the app. We
can confirm that the secret was successfully templated after running waypoint up
,
by checking the environment variables using waypoint exec
, and checking the application
logs using waypoint logs
:
With the application successfully deployed and configured with dynamic credentials, it can securely connect to the database, and no user ever needed to provide the app with an actual secret value. The Waypoint Entrypoint, built-in to the application image, can now dynamically source this Vault configuration wherever the app is deployed. If a user deployed to Docker on their laptop for some local development testing, or an EKS cluster in AWS, as long as the application container can access the Vault cluster, the secrets necessary to run the application will be provided by Waypoint.