Boundary
Manage targets
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 Boundary on the CLI, the admin console, and using our Terraform provider.
Warning
All resource IDs in this tutorial are illustrations only. IDs are uniquely generated for every resource upon creation with the exception being generated resources in development mode. 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 that you successfully completed the Manage Scopes tutorial.
Setup a PostgreSQL target
Deploy a postgres database container, which will be configured as a target.
Launch the container by passing the postgres password, sample database name, and URL port mapping as options. In this example the sample database is named "sample".
Export the database URL as an environment variable.
$ export PG_URL="postgres://postgres:secret@localhost:16001/sampledb?sslmode=disable"
Next, start the Postgres container.
$ docker run -d \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB="sampledb" \
--name postgres \
-p 16001:5432 \
postgres
Check that the container is running.
$ docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Status}}"
CONTAINER ID NAMES IMAGE STATUS
af573c7093cd postgres postgres Up About a minute
Add hosts to project
Hosts and host sets are defined within a host catalog, so you need to create a 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, "postgres" with description, "Postgres host" under the newly created host catalog.
$ boundary hosts create static \ -name=postgres \ -description="Postgres host" \ -address="127.0.0.1" \ -host-catalog-id=$HOST_CATALOG_ID
Example output:
$ boundary hosts create static \ -name=postgres \ -description="Postgres host" \ -address="127.0.0.1" \ -host-catalog-id=$HOST_CATALOG_ID Host information: Created Time: Fri, 27 May 2022 10:48:29 MDT Description: Postgres host Host Catalog ID: hcst_xM3iCCkf1K ID: hst_U1qYKzKfXO Name: postgres 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: 127.0.0.1
Repeat the step to create another host named, "localhost".
$ boundary hosts create static \ -name=localhost \ -description="Localhost for testing" \ -address="localhost" \ -host-catalog-id=$HOST_CATALOG_ID
Example output:
$ boundary hosts create static \ -name=localhost \ -description="Localhost for testing" \ -address="localhost" \ -host-catalog-id=$HOST_CATALOG_ID Host information: Created Time: Fri, 27 May 2022 10:49:40 MDT Description: Localhost for testing Host Catalog ID: hcst_xM3iCCkf1K ID: hst_FrdNPd9Zm9 Name: localhost Type: static Updated Time: Fri, 27 May 2022 10:49:40 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: localhost
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, "test-machines".
$ boundary host-sets create static \ -name="test-machines" \ -description="Test machine host set" \ -host-catalog-id=$HOST_CATALOG_ID
Example output:
$ boundary host-sets create static \ -name="test-machines" \ -description="Test machine host set" \ -host-catalog-id=$HOST_CATALOG_ID Host Set information: Created Time: Fri, 27 May 2022 10:51:02 MDT Description: Test machine host set Host Catalog ID: hcst_xM3iCCkf1K ID: hsst_X8gmzYXbO4 Name: test-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
test-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=<test-machines_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: localhost Description: Localhost for testing Authorized Actions: no-op read update delete ID: hst_U1qYKzKfXO Version: 1 Type: static Name: postgres Description: Postgres host Authorized Actions: no-op read update delete
In the example output, the
postgres
host ID ishst_U1qYKzKfXO
and thelocalhost
host ID ishst_FrdNPd9Zm9
. You will pass these IDs in the next step.Add
postgres
andlocalhost
hosts to thetest-machines
host set. Be sure to replace<postgres_host_id>
and<localhost_host_id>
with the host IDs you just retrieved.$ boundary host-sets add-hosts \ -id=$HOST_SET_ID \ -host=<postgres_host_id> \ -host=<localhost_host_id>
Example:
$ boundary host-sets add-hosts \ -id=$HOST_SET_ID \ -host=hst_U1qYKzKfXO \ -host=hst_FrdNPd9Zm9 Host Set information: Created Time: Fri, 27 May 2022 10:51:02 MDT Description: Test machine host set Host Catalog ID: hcst_xM3iCCkf1K ID: hsst_X8gmzYXbO4 Name: test-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 hst_FrdNPd9Zm9
Define a target
Finally, create a target associated with the QA_Tests
project.
Create a target named, "postgres" with description, "Postgres target". Set the default port to be
16001
. To allow unlimited number of session connections, set the session connection limit to-1
.$ boundary targets create tcp \ -name="postgres" \ -description="Postgres target" \ -default-port=16001 \ -scope-id=$PROJECT_ID \ -session-connection-limit="-1"
Example output:
Target information: Created Time: Fri, 27 May 2022 11:02:22 MDT Description: Postgres target ID: ttcp_34yV5O9cwt Name: postgres 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: 16001
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=<postgres_TARGET_ID>
Example:
$ export TARGET_ID="ttcp_34yV5O9cwt"
Add the
test-machines
host set to thepostgres
target. Replace<target_id>
with your postgres target ID, and<host_set_id>
with your test-machines host set ID.$ 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: Postgres target ID: ttcp_34yV5O9cwt Name: postgres 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: 16001
Manage targets
First, verify you can connect to the target. Then update the target description.
Open a session to the postgres target using boundary connect
. When prompted,
enter the password secret
to connect.
$ boundary connect postgres -target-id $TARGET_ID -username postgres
Password for user postgres:
psql (13.2)
Type "help" for help.
postgres=#
Note
If you followed the Admin Console workflow and did not export the
TARGET_ID
environment variable, supply it directly instead. In this example
the target ID is ttcp_34yV5O9cwt
.
After successfully testing the connection, terminate the session by executing
\q
.
Targets can be managed using arguments to the boundary targets
command, such
as update
, delete
, add-host-sources
and delete-host-sources
.
Update the target description.
$ boundary targets update tcp -id $TARGET_ID -description "updated postgres target"
Target information:
Created Time: Mon, 23 Jan 2023 17:47:38 MST
Description: updated postgres target
ID: ttcp_UYMMW2Z13C
Name: postgres
Session Connection Limit: -1
Session Max Seconds: 28800
Type: tcp
Updated Time: Mon, 23 Jan 2023 17:48:42 MST
Version: 3
Scope:
ID: p_OVOOKRiV5J
Name: QA_Tests
Parent Scope ID: o_8EhpHB3qEN
Type: project
Authorized Actions:
no-op
read
update
delete
add-host-sources
set-host-sources
remove-host-sources
add-credential-sources
set-credential-sources
remove-credential-sources
authorize-session
Host Sources:
Host Catalog ID: hcst_k9Ezh5xv0k
ID: hsst_FWqrawz1hn
Attributes:
Default Port: 16001
Next steps
This tutorial demonstrated the steps to define and manage targets under a scope
(QA_Tests
). Targets represent network services a user can connect to, such as
the postgres
Docker container.
In the Manage Users and Groups
tutorial, you will add and manage users in the org
scope.