Inject SSH credentials with HCP Boundary
Boundary includes support for credential management of SSH keys though its credential brokering feature. HCP Boundary and Boundary Enterprise introduce credential injection: the ability to inject SSH credentials into sessions, particularly using Vault.
This tutorial will demonstrate SSH credential injection for an SSH target previously configured in this tutorial series.
Warning
This tutorial requires you to have completed all previous tutorials in this series. For a complete example of SSH credential injection, refer to the HCP credential injection with private Vault tutorial.
A self-managed HCP worker is required for integrating private Vault clusters with HCP Boundary. To learn more about setting up self-managed workers, refer back to the Self-Managed Worker Registration with HCP Boundary tutorial.
Tutorial overview
- Prerequisites
- Background
- Set up Vault
- Set up Boundary
- Configure an SSH target
- Inject credentials into sessions
Prerequisites
This tutorial assumes the learner has completed all previous tutorials in the HCP Boundary Getting Administration collection. The learner should have a working HCP Boundary cluster, a preconfigured Ubuntu target, and a self-managed worker deployed in the same network as the target.
A Boundary binary greater than 0.12.0 in your
PATH
A Vault binary greater than 1.7.0 in your
PATH
Installing the Boundary Desktop App provides an optional workflow at the end of this tutorial. The 1.2.0 version or above is required for Vault support.
This tutorial assumes basic knowledge of using Vault, including running a development server and managing policies, roles, and tokens. If you are new to using Vault, complete the Getting Started with Vault quick start tutorials before integrating Vault with Boundary.
Credential injection background
Boundary is a distributed system for managing identity-based access to computing resources. Core to Boundary are controllers and workers which, from a resource point of view, are referred to as servers. Controllers are responsible for authenticating and authorizing users, as well as serving user API requests for processes like session initiation. They also assign jobs to workers, such as session handling, session recording, and parsing. Workers are responsible for session proxying, as well as other jobs that involve storage.
SSH, also known as Secure Shell, is arguably the de facto tool for remote administration, enabling end users and administrators with a simple, powerful and secure access method. SSH offers a variety of benefits and configurations, such as:
- Encryption
- Support for multiple keys types and sizes
- Built in key exchange
- Ability to create a tunnel and spawn multiple channels
Boundary seamlessly provides authenticated users access to remote machines via their SSH client, regardless of the authentication mechanisms implemented by their administrators.
Previously Boundary supported credential brokering, where Boundary controllers check out credentials from Vault and return them back to users and clients. In this workflow, Boundary acts as a broker of the credential.
Brokering lacks the ability to hide credentials from clients. For credential injection, controllers instead return credentials to Boundary workers and create a session to a target where the user/client never has access to the credential. This workflow is called credential injection because the credential is injected into a worker’s session, instead of being passed back to the client.
Set up Vault
Note
This tutorial uses a Vault dev server to test credential injection. To access Vault, HCP Boundary requires a self-managed worker deployed in the same network.
Open a new terminal session and run Vault in development mode.
Leave Vault running in dev mode and open a new terminal window.
Next, export the required Vault environment variables for the address and token.
Deploy a self-managed worker
An HCP worker deployed on the same network as Vault is required for integrating private Vault clusters with HCP Boundary. To learn more about setting up self-managed workers, refer to the Self-Managed Worker Registration with HCP Boundary tutorial.
Download the Boundary Enterprise binary
Download the Boundary Enterprise binary to the ~/boundary/
directory. If you
already have the Boundary Enterprise binary locally available from a previous
tutorial, skip to the Write the worker config
section.
Note
If you already deployed a self-managed worker locally in the Self-managed worker registration tutorial, verify it is still running, then skip to the Define the controller policy section.
You can manually download the latest binary for your operating system by navigating to the Boundary releases page. The example below demonstrates downloading the binary using the command line.
Note
The binary version should match the version of the HCP control plane. Check the version of the control plane in the HCP Boundary portal, and download the appropriate version using wget. The example below downloads the 0.13.2 version of the Boundary Enterprise binary.
Below is an example of downloading and unzipping the Boundary Enterprise binary on Ubuntu, MacOS, and Windows.
The following command downloads the Boundary Enterprise binary and unzips it to the current directory.
Once downloaded, verify the version of the boundary binary.
Ensure the Version Number matches the version of the HCP Boundary control plane. They should match in order to get the latest HCP Boundary features.
Write the worker config
Next, create a new file named vault-worker.hcl
in the ~/boundary/
directory.
Open the file with a text editor, such as Vi.
Paste the following configuration into the worker config file:
1 2 3 4 5 6 7 8 9 101112131415
Update the cluster id in the vault-worker.hcl
file:
The <cluster-id>
on line 3 can be determined from the UUID in the HCP
Boundary Cluster URL. For example, if your Cluster URL is:
https://c3a7a20a-f663-40f3-a8e3-1b2f69b36254.boundary.hashicorp.cloud
,
then the cluster id is c3a7a20a-f663-40f3-a8e3-1b2f69b36254
The auth_storage_path
should match the full path to the ~/boundary/vault-worker
directory, such as /home/myusername/boundary/vault-worker
.
Save this file.
Start the worker
With the worker config defined, start the worker server. Provide the full path
to the worker config file (such as /home/myusername/boundary/vault-worker.hcl
).
1 2 3 4 5 6 7 8 9 101112131415161718
The worker will start and begin attempting to connect to the upstream Controller.
The worker also outputs its authorization request as the Worker Auth
Registration Request token. This will also be saved to a file,
auth_request_token
, defined by the auth_storage_path
in the worker config.
Note the Worker Auth Registration Request:
value. This value can also be
located in the ~/boundary/vault-worker/auth_request_token
directory. Copy this
value.
Register the worker with HCP
HCP workers can be registered using the Boundary CLI or Admin Console Web UI.
Authenticate to HCP Boundary as the admin user.
Log in to the HCP portal.
From the HCP Portal's Boundary page, click Open Admin UI - a new page will open.
Enter the admin username and password you created when you deployed the new instance and click Authenticate.
Once logged in, navigate to the Workers page.
Notice that only HCP workers are listed.
Click New.
Scroll down to the bottom of the New Worker page and paste the Worker Auth Registration Request key you copied earlier.
Click Register Worker.
Click Done and notice the new worker on the Workers page.
Define the controller policy
The following Vault policy must be defined for the Boundary controller to support credential brokering. To learn more about these policies, refer to the HCP Boundary Vault credential brokering quickstart tutorial.
Export the required Vault environment variables to store the Vault address and token.
Now write the controller policy to Vault.
Define the KV policy
A policy must also be defined for the key-value secrets that will be brokered via Vault.
Create a new kv-read
policy in Vault.
Lastly, create a new Vault KV credential at the secret/my-secret
path and
provide the username and private key for the ubuntu target machine you are
connecting to. If using a cloud provider like AWS, the private
key
was provided or created when the instance was set up at the beginning of the
HCP administration
tutorials.
Ensure the path to the private key is entered after the @
symbol (for example,
private_key=@/Users/myuser/.ssh/ubuntu-private-key.pem
)
Create a Vault token
Now create a Vault token.
Example:
Copy the token value and export it as the $CRED_STORE_TOKEN
variable.
Note
If you plan on using the Admin Console UI to connect, save this value for creating a credential store later on.
Set up Boundary
Start by logging in to HCP Boundary within the terminal.
Export the BOUNDARY_ADDR
and BOUNDARY_AUTH_METHOD_ID
environment variables. These
values are gathered from the HCP Boundary Admin Console, as demonstrated in the
Get Started with HCP
Boundary
tutorials.
Log in to the CLI as an admin user, or a user with privileges to manage
resources in the global scope. Enter your admin username for login-name
.
Enter password
at the Please enter the password (it will be hidden):
prompt.
You will also need an ORG_ID
to create the SSH test project within. You may
create a new global scope for this, or utilize an existing scope used for
testing.
If creating a new org for testing, execute the following:
Whether you create a new org or not, be sure to export the org ID.
Set up a new project
Create a new project scope within Boundary. You will need an org ID to create
the new project within. To view your existing orgs, execute boundary scopes
list -recursive
.
Note
You may use an existing org scope, or create a new org scope for the ssh-project. Refer to the Manage Scopes tutorial to learn more about creating and managing scopes.
Copy the ID from the output and export it as the $PROJECT_ID
variable.
Create a credential store
Next, create a new credential store within Boundary using the new token. The
vault
credential store type is used to integrate with Vault, but static
credential stores can also be used with credential injection.
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 vault-worker.hcl
file earlier:
The Tags
or Name
of the worker (vault-worker
) 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
vault
tag. Boundary will consider any worker with this tag assigned to it an
acceptable proxy for the new credential store.
Create a new vault
credential store with a worker-filter
.
Example output:
Store the returned ID value in the $CRED_STORE_ID
variable.
Create credential library
Create a new credential library of type ssh_private_key
within Boundary
using the credential store ID and passing the vault-path of ubuntu-secret
.
Example output:
Copy the ID from the output and export it as the $CRED_LIB_SSH_ID
variable.
Create an SSH target
Earlier in this series, you created a target of type tcp
. To inject SSH
credentials, a target of type ssh
is required instead.
In the previous tutorials on worker management, you set up a multi-hop session to the target by configuring egress and ingress workers.
Ensure that you have the correct worker filter defined when setting up your
target. If you have modified how Boundary accesses the target, select from the
following examples to define the target worker config. For example, if you are
testing injection using a public ip address, you can omit the
-egress-worker-filter
entirely.
Select the appropriate tab for your worker setup.
Create a new ssh target, and set the address directly. Replace
"ubuntu-public-ip-address"
with the actual address of your Ubuntu host.
Example output:
Copy the ID from the output and export it as the $SSH_TARGET_ID
variable.
Associate the SSH target with the SSH credential library for credential injection.
Inject credentials into sessions
Now you are ready to inject credentials directly into the shell session. You can
accomplish this using the boundary connect
command, which has a helper called
ssh
.
Enter yes
when prompted to establish the connection.
Notice that you do not have to pass the target credentials to the boundary
connect
command. The credentials are injected by Boundary directly from Vault,
and never returned to the client.
Troubleshooting
If the boundary connect ssh
command fails with the following error message, then the Vault credential store token may have expired.
Expand the accordion below to continue troubleshooting.
The error information states that No egress workers can handle this session, as they have all been filtered
.
This implies that Boundary does not understand which worker should handle the session, and cannot route traffic through the worker it selected.
In this example the error could be due to either of the following errors:
- Boundary is unable to log into Vault using the provided credential store token.
- The ubuntu target's worker filters are unset, or incorrect.
First, troubleshoot the Vault credential store by generating a new Vault token.
Copy this token (such as hvs.CAESIAbmG5WIi0qILYm87ucbJSGa0rv879aJAchvFR6wG0pbGh4KHGh2cy5xY1BzTGpHUW91ZEx4ZGFTcFVDTkdPMTY
), and then update Boundary's Vault cred store with the new token value.
Log in to the Boundary Admin UI and select the
testing-org
scope. Select thessh-project
, then click Credential Stores.Select the Vault credential store (such as
csvlt_EsUGNcboLT
). Scroll down to the bottom of the credential store's Details page, and click Edit Form.Paste the newly generated vault token into the Token field, then click Save at the bottom of the page.
With the updated token in place, attempt to connect to the SSH target again.
If you are still unable to establish a connection, check that the filter has been defined correctly on the SSH target.
Navigate to Targets using the sidebar and select the ubuntu ssh target.
Scroll down to the bottom of the target Details page. Ensure that the Egress worker filter toggle is off, because any worker can be used to connect to the public instance.
If this is enabled, click Edit Form and disable the Egress worker filter. When finished, click Save.
After verifying the correct filter value, attempt to establish a session.
When finished, the user can close the connection to the server using exit
, or
the session can be canceled directly from Boundary in a new authenticated
terminal window.
Inject credentials with the Desktop App
To log into Boundary using the Desktop App, the BOUNDARY_ADDR
(Boundary
cluster address) and BOUNDARY_AUTH_METHOD_ID
(user Auth Method ID) values must be
gathered from the HCP Boundary Admin Console, as demonstrated in the HCP
Boundary Getting Started
tutorial.
Open the Boundary desktop app.
Enter the Boundary cluster URL (for example,
https://ffee961b-5fd8-4e68-ba1d-2bbb487b576e.boundary.hashicorp.cloud
) and
click Submit.
Authenticate using your HCP Boundary user credentials.
Under the Targets page, notice the target details for the ubuntu ssh target
.
Click Connect to initiate a session.
The Successfully Connected page will display the target ID (Target Connection details) and Proxy URL. Copy the Proxy URL and port.
To start a session, open your terminal or SSH client. A session can be started using SSH and the Proxy URL from the Boundary Desktop app.
Start an SSH connection on 127.0.0.1
and provide the proxy port using the
-p
option. Enter yes
when prompted to establish a connection.
When finished, the user can close the connection to the server by entering
exit
, or the session can be canceled directly from the Boundary desktop app
under the Sessions view.
Cleanup and teardown
Locate the terminal session used to execute the
vault dev
server command, and executectrl+c
to stop Vault.Locate the terminal session used to deploy the HCP worker server command, and execute
ctrl+c
to stop the Boundary worker.Unset the environment variables used in any active terminal windows for this tutorial.
Clean up the Ubuntu target in Amazon EC2. Refer to the instructions for terminating your Ubuntu instance.
Next steps
This tutorial demonstrated the steps to set up credential injection using HCP Boundary and an SSH target previously configured in this tutorial collection. You set up Vault, configured a self-managed worker to access Vault, and configured an SSH target within Boundary. Then you associated a vault credential store with the SSH target, and tested credential injection.
To learn more about credential injection, check out the SSH credential injection with private Vault tutorial.