HCP Boundary Vault credential brokering quickstart
This tutorial demonstrated integrating HCP Boundary and Vault to broker secrets to Boundary clients.
Background
Boundary integrates with Vault to broker Vault secrets to Boundary clients. Secrets are brokered using the command line or desktop clients to use Boundary sessions.
Boundary 0.11 adds support for brokering secrets from private Vault clusters.
This feature enables Boundary as a credential broker for infrastructure targets by binding credentials with user sessions, and surfacing those credentials during session initialization.
This tutorial provides examples of integrating HCP Boundary and Vault, and then walks through the process of creating Boundary credentials stores and credential libraries for brokering of Vault secrets.
Tutorial Contents
- Setup Vault
- Deploy a demo database
- Setup Boundary
- Broker credentials for the database via Boundary
Prerequisites
A Boundary binary greater than 0.12.0 in your
PATH
A Vault binary greater than 1.7.0 in your
PATH
A psql binary greater than 13.0 in your
PATH
Docker is installed OR an AWS account for deploying Postgres
Installing the Boundary Desktop App provides an optional workflow at the end of this tutorial. The 1.2.0 version or greater is required for Vault support, and installing the latest version is recommended.
This tutorial assumes prior foundational knowledge of using Vault, including running a development server and managing policies, roles and tokens.
If you are new to using Vault, consider completing the Getting Started with Vault quick start tutorials before integrating Vault with Boundary.
Note
If using a public HCP Vault Dedicated cluster and Docker to deploy Postgres, a free ngrok account will also be required to create a publicly routable address. Instructions for installing and configuring ngrok are provided later on.
Tutorial Scenario
Connecting to a networked service often requires credentials for authentication and authorization. For example, a financial analyst might require access to their company's sales database to create a monthly report. When the analyst wants to create the report, they will (hopefully) need database credentials which their reporting tool can use to connect to the sales database and run the report.
In this example, the analyst only needs credentials to the sales database once a month and only for a limited amount of time. If connection to the sales database was through Boundary, the credentials could be generated at the beginning of the session, returned to the analyst, and then revoked when the session is terminated.
This tutorial provides an example of enabling the analyst scenario by setting up a Vault integration with Boundary, and introduces the Boundary resources used for managing credentials.
Get setup
Three pieces must be setup for this tutorial:
- A demo postgres database target
- A Vault server with policies allowing connections from Boundary
- Boundary credential resources for managing credential lifecycle
Open a terminal and navigate to a working directory, such as the home directory. Clone down the sample repository containing starter configuration files.
Navigate into the learn-boundary-vault-quickstart directory and list its contents.
The repository contains the following files:
analyst.sql.hcl
: Vault role for generating credentials for the analyst databaseboundary-controller-policy.hcl
: Vault policy for the Boundary controller that enables token managementdba.sql.hcl
: Vault role for the database analyst credential generationnorthwind-database-policy.hcl
: Vault policy for the demo database adminnorthwind-database.sql
: Demo database tablesnorthwind-roles.sql
: Demo database roles and permissionsworker.hcl
: Self-managed HCP worker config
Setup Vault
Vault needs to be configured to generate secrets for the database target. To set up Vault you need to:
- Start Vault
- Set up a Boundary controller policy
- Enable the database secrets engine
- Configure the postgres database plugin
- Create a database admin role to generate credentials
- Create an analyst role to generate credentials
Public or private Vault access is supported by HCP Boundary. Select one of the options for configuring Vault to continue.
The simplest method of testing Vault integration with HCP Boundary is using a public Vault address. This can be accomplished using HCP Vault Dedicated or Vault Enterprise, but this tutorial demonstrates Vault Dedicated using a public address.
Open the Vault Dedicated cluster Overview page and click Public under Cluster URLs. This will copy the URL to your clipboard.
In a terminal, set the VAULT_ADDR
environment variable to the copied address.
Return to the Overview page and click Generate token under New admin token. Click Copy to copy the token into your clipboard.
Return to the terminal and set the VAULT_TOKEN
environment variable.
Vault Dedicated also requires an exported VAULT_NAMESPACE
variable. This tutorial
demonstrates using the admin
namespace.
Export the VAULT_NAMESPACE
variable.
Verify that you are able to connect to Vault:
Setup PostgreSQL Northwind demo database
The Postgres database target can either be deployed using AWS or Docker. Choose the workflow that best meets your needs.
While most deployments of Postgres will work with the following steps, this tutorial demonstrates configuring Postgres on an Ubuntu instance.
Note
Ubuntu is used in this tutorial for demonstration purposes only. You can follow this guide to create a publicly accessible EC2 instance to use for this tutorial.
Warning
For the purposes of this tutorial it is important that the security group policy for the AWS Ubuntu instance accepts inbound TCP connections on port 5432 to allow incoming connections to Postgres. Additionally, you will want to allow inbound SSH and outbound TCP. To learn more about creating this security group and attaching it to your instance, check the AWS EC2 security group documentation. The screenshot below shows an example of this security group policy.
Log in to the Ubuntu instance that will be configured to run Postgres.
For example, using SSH:
Note
The above example is for demonstrative purposes. You will need to supply your Ubuntu instance's username, public IP address, and public key to connect. If using AWS EC2, check this article to learn more about connecting to a Linux instance using SSH.
Next, update the package manager and install PostgreSQL.
After confirming the installation, execute the following command to modify the
postgresql.conf
file to allow Postgres to listen on all ports.
Next, execute the following command to modify the pg_hba.conf
file to allow
connections from any address.
Now start the Postgres service.
Ensure that Postgres is running:
Next, log in as the postgres
user. Your prompt will change to postgres@
.
Download the lab environment repository for this tutorial to the Ubuntu instance:
Navigate into the ~/learn-boundary-vault-quickstart
directory and list its
contents.
Create the northwind
database.
Seed the database tables using the provided sql configuration.
Apply the database roles and permissions.
And check that the database tables were written correctly:
This information will be queried at the end of the tutorial after the credentials are successfully brokered via Vault.
Before logging out of the account, set a password for the postgres
user to
make it easy to test the initial connection from Boundary. This tutorial uses
the password secret
. Enter the password when prompted.
When finished, log out of the postgres account using exit
, and then log out of
the Ubuntu instance using exit
.
Create the boundary-controller policy
Boundary needs to lookup, renew, and revoke tokens and leases in order to broker credentials properly.
Examine the boundary-controller-policy.hcl
policy file, which assigns the
following:
- read
auth/token/lookup-self
- update
auth/token/renew-self
- update
auth/token/revoke-self
- update
sys/leases/renew
- update
sys/leases/revoke
- update
sys/capabilities-self
Create the boundary-controller
policy.
Configure the database secrets engine
Next, the database secrets engine must be enabled and configured with the postgresql plugin. Then a database admin (DBA) role and analyst role are created to enable credential generation.
Enable the database secrets engine.
Configure Vault with the postgres-database-plugin, connection information and allowed roles of dba and analyst.
Replace the
107.20.88.136
IP address example in the following command with your Postgres instance's public IP address.Create the DBA role that creates credentials with
dba.sql.hcl
:Request the DBA credentials from Vault to confirm.
Create the analyst role that creates credentials with
analyst.sql.hcl
:Request the analyst credentials from Vault to confirm.
Create northwind-database policy
A policy needs to be created that grants read access for both the DBA and analyst roles.
Examine the northwind-database-policy.hcl
policy file, which assigns the
following:
- read
database/creds/analyst
- read
database/creds/dba
Create Vault token for Boundary
Lastly, a Vault token is needed to access the Boundary credential store that will be configured when setting up Boundary.
It's very important that the token is:
- periodic
- orphan
- renewable
Boundary may not be able to broker credentials unless the Vault token has these properties.
Create the token with the boundary-controller
and northwind-database
policies.
Example output:
Export the Vault Boundary token and a the CRED_STORE_TOKEN
environment
variable. This will be used to set up a Vault credential store later on.
Note
Copy and store the generated token for setting up Boundary later on in case the environment variable is lost. In this example the token value is:
hvs.CAESIAEzd9SuNo84gRvPR...snip...2cy5YWFp4WUQ4YUtVRDU0amJoOElzcHVkSDU
.
Set up Boundary
Next the Boundary targets, host sets, and credential libraries will be configured for the database targets and credentials.
First, ensure that you are logged in to HCP Boundary.
Enter the username and password for your Boundary admin user.
Configure database targets
Two targets need to be created in Boundary's default project scope, one for the DBA and another for the analyst. The default host set will then be assigned to both targets.
Create a new scope for the DB targets.
Open the Orgs page and click New.
Name the new org
db-org
and click Save.Create a new project within
db-org
.Open the Projects page and click New.
Name the new project
db-project
and click Save.Create a new host catalog named
db-catalog
.Open the Host Catalogs page and click New.
Fill out the following details:
- Name:
db-catalog
- Type:
static
Click Save.
- Name:
Create a new host set named
db-host-set
.Within the new host catalog page, click on the Host Sets tab.
Click New and name the host set
db-host-set
. Click Save.Create a new host named
postgres-host
.From the Host Set page, click on the Manage dropdown and click Create and Add Host.
Fill out the following details:
- Name:
postgres-host
- Address:
107.20.88.136
Replace the
107.20.88.136
IP address example in the following command with your Postgres instance's public IP address.Click Save.
- Name:
Create a target for the DBA.
Navigate to the Targets page and click New.
Fill out the form details for the new TCP DBA Database target:
- Name:
Northwind DBA Database
- Type:
tcp
- Maximum Duration (in seconds):
28800
- Maximum Connections:
-1
- Default Port:
5432
Click Save.
- Name:
Create a target for the analyst.
Navigate to the Targets tab and click New.
Fill out the form details for the new TCP Analyst Database target:
- Name:
Northwind Analyst Database
- Type:
tcp
- Maximum Duration (in seconds):
28800
- Maximum Connections:
-1
- Default Port:
5432
Click Save.
- Name:
Add the default host set to both targets.
Add host set to the DBA target:
Click on the Northwind DBA Database target to view its details. Click on the Host Sources tab and select Add Host Sources.
Check the box beside the db-host-set Host Set, then click Add Host Sources.
The
db-host-set
should now be displayed under the Host Sources tab.Add host set to the analyst target:
Repeat the steps above for adding the
db-host-set
to the Northwind Analysts Database target.When finished, the
db-host-set
should be listed under the Host Sources tab for the Northwind Analyst Database target.
Test connection to the sample database
Verify that Boundary can connect to the database target directly, without having a credential brokered from Vault. This is to ensure the target container is accessible to Boundary before attempting to broker credentials via Vault.
Authenticate to Boundary as the admin user. Ensure you have exported the
BOUNDARY_AUTH_METHOD_ID
and BOUNDARY_ADDR
environment variables.
Execute boundary connect postgres
to verify the connection to the analyst
target. When prompted, enter the password secret
to connect.
Note
If you followed the Admin Console workflow and did not export the
ANALYST_TARGET_ID
environment variable, supply it directly instead. In this
example the analyst target ID is ttcp_1r9XGCXdwE
.
After successfully testing the connection, terminate the session by executing
\q
.
If unable to connect to the target, revisit the section on deploying the demo database at the beginning of the tutorial, and ensure the instance was configured properly.
Credential stores
A credential store belongs to a scope and must support the principle of least privilege by providing mechanisms to limit the credentials it can access to the minimum necessary for the scope it is in.
A credential store:
- is a Boundary resource
- belongs to one and only one scope
- owns zero or more credentials
- owns zero or more credential libraries
- is deleted when the scope it belongs to is deleted
In this example the credential store is created to manage HashiCorp Vault secrets. Configuring a Vault credential store requires:
- A Vault token with appropriate permissions to allow Boundary to access Vault secrets
- One or more credential libraries and credentials that specify the paths where Boundary should access Vault credentials
Create vault credential store
When setting up an HCP worker, it's important to create a worker filter for the credential store. A worker filter will identify workers that should be used as proxies for the new credential store, and ensure these credentials are brokered from the private Vault.
Recall the filters defined in the worker.hcl
file earlier:
The Tags
or Name
of the worker (hcp-worker1
) can be used to create a
worker filter for the target.
The example below adds a worker tag filter that searches for workers with the
worker
tag. Boundary will consider any worker with this tag assigned to it an
acceptable proxy for the new credential store.
Create a credential store resource in the default project scope. Supply the token created when setting up Vault.
Navigate to the Credential Stores tab and click New.
Fill out the following required fields for the vault credential type.
- Address:
https://vault-cluster-boundary.vault.11eb3a47-8920-4714-ba99-0242ac11000e.aws.hashicorp.cloud:8200
Recplace with your own public Vault address - Token:
hvs.CAESIAEzd9SuNo84gRvPRnxmck05fJBC5hcbgbMHBlDvR_EqGh4KHGh2cy5YWFp4WUQ4YUtVRDU0amJoOElzcHVkSDU
Replace with the Vault token - Namespace:
admin
Replace with your Vault namespace
Ensure that the Token field matches the token generated by running vault
token create
in the Create Vault token for
Boundary section.
Click Save when finished.
After the credential store has been created, copy the cred store ID (such as
csvlt_ytzGHsfp3r
) from its Details page.
Note
If you experience any issues creating the credential store, try regenerating the vault credential store token you created earlier. If the token is not renewed by Boundary within a timely fashion, it may be rejected when you attempt to create the credential store. After creating a new token, retry setting up the credential store.
Credential libraries
A credential library provides credentials for sessions. All credentials returned by a library must be equivalent from an access control perspective. A credential library is responsible for managing the lifecycle of the credentials it returns. For dynamic secrets, this includes creation, renewal, and revocation. For rotating credentials, this includes check-out, check-in, and rotation of secrets. The system retrieves credentials from a library for a session and notifies the library when the session has been terminated. A credential library belongs to a single credential store.
Vault credential libraries are the Boundary resource that maps to Vault secrets engines. A single credential store may have multiple types of credential libraries. For example, Vault credential store might include separate credential libraries corresponding to each of the Vault secret engine backends.
A credential library:
- is a Boundary resource
- belongs to one and only one credential store
- can be associated with zero or more targets
- can contain zero or more credentials
- is deleted when the credential store it belongs to is deleted
Create credential libraries
While there is only a single database target, two separate credential libraries should be created for the DBA and analyst roles within the credential store.
The DBA credential library is responsible for brokering credentials at the
database/creds/dba
vault path, while the analyst credential library brokers
credentials at database/creds/analyst
. Using two credential libraries allows
for separation of privileges, and enables distinct lifecycle management for the
different database roles.
Create a credential library for DBA credentials. Supply the credential store ID copied above.
Navigate to the Credential Stores tab and select the ID of the new credential store (
csvlt_W6MP2X0OfP
in this example).Select the Credential Libraries tab. Click New.
Fill in the Name and Vault Path for the DBA credential as follows:
- Name:
northwind dba
- Vault Path:
database/creds/dba
Leave the HTTP Method set as Get. Click Save when finished.
Note the DBA credential library ID. In this example the DBA credential library ID is
clvlt_ahqypiUJnK
.- Name:
Create a credential library for analyst credentials. From the Credential Stores tab, select the Manage dropdown and click New Credential Library.
Fill in the Name and Vault Path for the analyst credential as follows:
- Name:
northwind analyst
- Vault Path:
database/creds/analyst
Leave the HTTP Method set as Get. Click Save when finished.
Note the analyst credential library ID. In this example the analyst credential library ID is
clvlt_ejPFjL3Djf
.- Name:
Credentials and targets
A credential is a data structure containing one or more secrets that binds an identity to a set of permissions or capabilities. Static credential and dynamic credential are two additional base types derived from the credential base type.
A credential:
- may be a Boundary resource
- belongs to one and only one credential store
- can be associated with zero or more targets directly if it is a resource
- can be associated with zero or more libraries directly if it is a resource
- is deleted when the credential store or credential library it belongs to is deleted
A target can have multiple credentials or credential libraries associated with it:
- one for the connection from a user to a worker (ingress)
- one for the connection from a worker to an endpoint (egress)
- multiple for application credentials (like username and password)
Application credentials are returned to the user from the controller. Ingress and egress credentials are only given to a worker from a controller, and users never have direct access to them.
Add credential libraries to targets
With the credential libraries created, assign them to the appropriate targets. You will need the target ID and credential library ID for the respective targets.
Navigate to the Targets tab.
Add a credential library to the DBA target.
Select the Northwind DBA Database target.
Under the Brokered Credentials tab, select Add Brokered Credentials.
Select the checkbox next to the ID of the credential library associated with the
northwind dba
target.Click Add Brokered Credentials when finished.
Add a credential library to the analyst target.
Navigate back to the Targets tab and select the Northwind Analyst Database target.
Under the Brokered Credentials tab, select Add Brokered Credentials.
Select the checkbox next to the ID of the credential library associated with the
northwind analyst
target.Click Add Brokered Credentials when finished.
Broker credentials via Vault
With their respective credential libraries assigned added to the targets, sessions can be authorized using credentials brokered by Vault.
Use Boundary to connect to the northwind demo database
A session can be authorized directly using the boundary targets
authorize-session
command.
Authenticate to Boundary as the admin user. Ensure you have exported the
BOUNDARY_AUTH_METHOD_ID
and BOUNDARY_ADDR
environment variables.
Authorize a session to the analyst target, supplying its target ID.
Note
If you followed the Admin Console workflow and did not export the
ANALYST_TARGET_ID
environment variable, copy it from the web UI and supply it
directly instead. In this example the analyst target ID is ttcp_1r9XGCXdwE
.
Notice the Credentials:
section of the output, which displays the base64 credentials.
If desired, jq
can be used to parse the output and display the decoded credentials.
The decoded_credentials
key displays the credentials without the base64
encryption.
Next, establish a connection to the analyst target using the boundary connect
postgres
command. This will automatically pass the brokered credentials for the
target and establish a psql session to the northwind database.
A psql connection to the northwind database should open. Query the available schema.
When finished, run \q
to close the connection.
Connections can also be monitored using the Admin Console or the Boundary Desktop app in the Sessions tab in the Generated project scope.
Connect using the Desktop App
Credentials can also be brokered using the Boundary Desktop App.
Launch the Desktop app and authenticate to your HCP Boundary cluster by entering the BOUNDARY_ADDR
(such as https://c3a7a20a-f663-40f3-a8e3-1b2f69b36254.boundary.hashicorp.cloud
) and your admin credentials.
Navigate to the Targets view, locate the Northwind Analyst Database target and click Connect.
The credentials can be copied directly from this view. Depending on the target type other credentials may be available, such as the certificate and private key. The Desktop App's connect interface can be used instead of generating the credentials on the command-line.
The password, username and raw API output can also be displayed within the UI.
Cleanup and teardown
Locate the terminal session used to start the
vault server
command, and executectrl+c
to stop Vault.Unset the environment variables used in any active terminal windows for this tutorial.
Destroy the northwind postgres container created for the tutorial.
Check your work with a quick
docker ps
and ensure there are no more postgres containers from the tutorial leftover. If unexpected containers still exist, executedocker rm -f <CONTAINER_ID>
against each to remove them.Cleanup the
db-org
org and associated test resources in your HCP Boundary cluster.Open the Orgs page and select the
db-org
.Navigate to the Org Settings page and click the Manage dropdown.
Click Delete Org and confirm the deletion.