Boundary
Manage targets with HCP Boundary
Targets are
Boundary resources that contain one or more host
sets. A
target allows Boundary users to define an endpoint with a default port and a
protocol to establish a session. Unless specified with a -host-id
flag,
Boundary will choose one
Host in the
host set to connect to at random.
This tutorial demonstrates the basics of how to define a host, host set, and a target in HCP Boundary on the CLI, the admin console, and using our Terraform provider.
Note
All resource IDs in this tutorial are illustrations only. IDs are uniquely generated for every resource upon creation. Be sure to use the resource IDs that are generated for your environment.
You will create a host catalog, a host set containing hosts, and a target.
Prerequisites
This tutorial assumes you have:
- Access to an HCP Boundary instance.
- Successfully completed the Manage Scopes tutorial.
- A publicly accessible Ubuntu instance.
- An ssh key-pair that can be used to authenticate with the 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.
Add hosts to project
Hosts and host sets are defined within a host catalog. To get started, you will need to create the host catalog first.
To start this tutorial, be sure to Login to the Boundary Console first.
Create a host catalog named, "DevOps" with description, "For DevOps usage" in the
QA_Tests
project.$ boundary host-catalogs create static \ -scope-id=$PROJECT_ID \ -name=DevOps \ -description="For DevOps usage"
Example output:
$ boundary host-catalogs create static \ -scope-id=$PROJECT_ID \ -name=DevOps \ -description="For DevOps usage" Host Catalog information: Created Time: Fri, 27 May 2022 10:46:07 MDT Description: For DevOps usage ID: hcst_xM3iCCkf1K Name: DevOps Type: static Updated Time: Fri, 27 May 2022 10:46:07 MDT Version: 1 Scope: ID: p_oMgeFL2hP6 Name: QA_Tests Parent Scope ID: o_u54jrD6ydN Type: project Authorized Actions: no-op read update delete Authorized Actions on Host Catalog's Collections: host-sets: create list hosts: create list
Copy the generated host catalog ID and save it as an environment variabe,
HOST_CATALOG_ID
.$ export HOST_CATALOG_ID=<host_catalog_id>
Example:
$ export HOST_CATALOG_ID="hcst_xM3iCCkf1K"
Now, create a new host named, "ubuntu" with description, "Ubuntu host" under the newly created host catalog. Enter in your Ubuntu instance's public IP address (such as
50.16.114.201
) in theaddress
field.$ boundary hosts create static \ -name=ubuntu \ -description="Ubuntu host" \ -address="ubuntu-public-ip-address" \ -host-catalog-id=$HOST_CATALOG_ID
Example output:
$ boundary hosts create static \ -name=ubuntu \ -description="Ubuntu host" \ -address="50.16.114.201" \ -host-catalog-id=$HOST_CATALOG_ID Host information: Created Time: Fri, 27 May 2022 10:48:29 MDT Description: Ubuntu host Host Catalog ID: hcst_xM3iCCkf1K ID: hst_U1qYKzKfXO Name: ubuntu Type: static Updated Time: Fri, 27 May 2022 10:48:29 MDT Version: 1 Scope: ID: p_oMgeFL2hP6 Name: QA_Tests Parent Scope ID: o_u54jrD6ydN Type: project Authorized Actions: no-op read update delete Attributes: address: 50.16.114.201
Create a host set
A host set groups together hosts. These hosts provide logically equivalent services.
Note
A target works off of host sets. Therefore, even if there is only one host, you still create a host set containing one host.
Create a host set named, "ubuntu-machines".
$ boundary host-sets create static \ -name="ubuntu-machines" \ -description="Ubuntu host set" \ -host-catalog-id=$HOST_CATALOG_ID
Example output:
$ boundary host-sets create static \ -name="ubuntu-machines" \ -description="Ubuntu host set" \ -host-catalog-id=$HOST_CATALOG_ID Host Set information: Created Time: Fri, 27 May 2022 10:51:02 MDT Description: Ubuntu host set Host Catalog ID: hcst_xM3iCCkf1K ID: hsst_X8gmzYXbO4 Name: ubuntu-machines Type: static Updated Time: Fri, 27 May 2022 10:51:02 MDT Version: 1 Scope: ID: p_oMgeFL2hP6 Name: QA_Tests Parent Scope ID: o_u54jrD6ydN Type: project Authorized Actions: no-op read update delete add-hosts set-hosts remove-hosts
Copy the
ubuntu-machines
host set ID and save it as an environment variable,HOST_SET_ID
.. In the example, the ID ishsst_X8gmzYXbO4
.$ export HOST_SET_ID=<ubuntu_HOST_SET_ID>
Example:
$ export HOST_SET_ID="hsst_X8gmzYXbO4"
Retrieve the host IDs.
$ boundary hosts list -host-catalog-id=$HOST_CATALOG_ID Host information: ID: hst_FrdNPd9Zm9 Version: 1 Type: static Name: ubuntu Description: Ubuntu host for testing Authorized Actions: no-op read update delete
In the example output, the
ubuntu
host ID ishst_U1qYKzKfXO
.Copy the generated host ID and create an environment variable called HOST_ID using copied value.
$ export HOST_ID=<ubuntu_host_id>
Add the
ubuntu
host to theubuntu-machines
host set.$ boundary host-sets add-hosts \ -id=$HOST_SET_ID \ -host=$HOST_ID
Example:
$ boundary host-sets add-hosts \ -id=$HOST_SET_ID \ -host=hst_U1qYKzKfXO Host Set information: Created Time: Fri, 27 May 2022 10:51:02 MDT Description: Ubuntu host set Host Catalog ID: hcst_xM3iCCkf1K ID: hsst_X8gmzYXbO4 Name: ubuntu-machines Type: static Updated Time: Fri, 27 May 2022 10:59:00 MDT Version: 2 Scope: ID: p_oMgeFL2hP6 Name: QA_Tests Parent Scope ID: o_u54jrD6ydN Type: project Authorized Actions: no-op read update delete add-hosts set-hosts remove-hosts Host IDs: hst_U1qYKzKfXO
Define a target
Finally, create a target associated with the QA_Tests
project.
Create a target named, "tests" with description, "Test target". Set the default port to be
22
. To allow unlimited number of session connections, set the session connection limit to-1
.$ boundary targets create tcp \ -name="tests" \ -description="Test target" \ -default-port=22 \ -scope-id=$PROJECT_ID \ -session-connection-limit="-1"
Example output:
$ boundary targets create tcp \ -name="tests" \ -description="Test target" \ -default-port=22 \ -scope-id=$PROJECT_ID \ -session-connection-limit="-1" Target information: Created Time: Fri, 27 May 2022 11:02:22 MDT Description: Test target ID: ttcp_34yV5O9cwt Name: tests Session Connection Limit: -1 Session Max Seconds: 28800 Type: tcp Updated Time: Fri, 27 May 2022 11:02:22 MDT Version: 1 Scope: ID: p_oMgeFL2hP6 Name: QA_Tests Parent Scope ID: o_u54jrD6ydN Type: project Authorized Actions: no-op read update delete add-host-sources set-host-sources remove-host-sources add-credential-libraries set-credential-libraries remove-credential-libraries add-credential-sources set-credential-sources remove-credential-sources authorize-session Attributes: Default Port: 22
In this example, the generated target ID is
ttcp_34yV5O9cwt
. Notice that target IDs starts withttcp_
.Copy the ID of the
tests
target and save it as an environment variable,TARGET_ID
.$ export TARGET_ID=<tests_TARGET_ID>
Example:
$ export TARGET_ID="ttcp_34yV5O9cwt"
Add the
ubuntu-machines
host set to thetests
target.$ boundary targets add-host-sources -id=$TARGET_ID -host-source=$HOST_SET_ID Target information: Created Time: Fri, 27 May 2022 11:02:22 MDT Description: Test target ID: ttcp_34yV5O9cwt Name: tests Session Connection Limit: -1 Session Max Seconds: 28800 Type: tcp Updated Time: Fri, 27 May 2022 11:07:59 MDT Version: 2 Scope: ID: p_oMgeFL2hP6 Name: QA_Tests Parent Scope ID: o_u54jrD6ydN Type: project Authorized Actions: no-op read update delete add-host-sources set-host-sources remove-host-sources add-credential-libraries set-credential-libraries remove-credential-libraries add-credential-sources set-credential-sources remove-credential-sources authorize-session Host Sources: Host Catalog ID: hcst_xM3iCCkf1K ID: hsst_X8gmzYXbO4 Attributes: Default Port: 22
Next steps
This tutorial demonstrated the steps to define targets under a scope
(QA_Tests
). Targets represent network services a user can connect to.
In the Manage Users and Groups
tutorial, you will add and manage users in the org
scope.