Authenticate users in HCP Vault Dedicated
Before a client can interact with Vault, it must authenticate against an auth method to acquire a token. This token has policies attached so that the behavior of the client can be governed.
In this tutorial, you will enable and configure AppRole auth method.
Note
As with secrets engines and policies, auth methods are tied to
a namespace. The auth method enabled on the admin
namespace is only
available to the admin
namespace and generates a token available to use
against the admin
namespace.
Personas
The steps described in this tutorial involve two personas:
- admin - Vault admin with privileged permissions to configure an auth method
- app - Vault client that consumes secrets stored in Vault
Note
This step assumes that you created and connected to the HCP Vault Dedicated
cluster in the Create a Vault Cluster on HashiCorp Cloud Platform
(HCP) step, and completed the Create
Vault Policies tutorial so the tester
policy exists.
Enable AppRole auth method
(Persona: admin)
The AppRole auth method must be enabled before it can be used.
In the Vault UI, make sure that current namespace is
admin/
.Click Access > Authentication methods.
Click Enable new method.
Select AppRole and click Next.
Leave the path value unchanged and click Enable Method.
Without making any change, click < approle to view its current configuration.
Create a role with policy attached
(Persona: admin)
When you enabled the AppRole auth method, it was mounted at the default /auth/approle
path. In this example, you are going to create a role for the app persona with
tester
policy attached.
Create the webapp
role with the generated token's time-to-live (TTL)
set to 1 hour and the max TTL up to 4 hours from the time of its creation.
Click the Vault CLI shell icon to open a command shell in the browser.
Copy the command below.
Paste the command into the command shell in the browser and press the enter button.
Generate RoleID and SecretID
(Persona: admin)
The RoleID and SecretID are like a username and password that a machine or app uses to authenticate.
To retrieve the RoleID, invoke the auth/approle/role/<ROLE_NAME>/role-id
endpoint. To generate a new SecretID, invoke the
auth/approle/role/<ROLE_NAME>/secret-id
endpoint.
Click the Vault CLI shell icon to open a command shell.
Read the RoleID.
Example output:
Generate a new SecretID of the
webapp
role.The
-force
(or-f
) flag forces thewrite
operation to continue without any data values specified. Or you can set parameters such ascidr_list
.The acquired
role-id
andsecret-id
are the credentials that your trusted application uses to authenticate with Vault.
Tip
The RoleID is similar to a username; therefore, you will get the same value
for a given role. In this case, the webapp
role has a fixed RoleID. While
SecretID is similar to a password that Vault will generate a new value every
time you request it.
Test and validate
(Persona: app)
The client (in this case, webapp) uses the RoleID and SecretID passed by the admin to authenticate with Vault. If webapp did not receive the RoleID and/or SecretID, the admin needs to investigate.
Tip
Refer to the Advanced Features section for further discussion on distributing the RoleID and SecretID to the client app securely.
To login, use the
auth/approle/login
endpoint by passing the RoleID and SecretID.Note
Replace the role_id and secret_id values in the example with those generated in the Generate RoleID and SecretID section above.
Example:
Example output:
Vault returns a client token with
default
andtester
policies attached.Store the generated token value in an environment variable named,
APP_TOKEN
.Note
Replace the APP_TOKEN value in the example with the one generated above.
Example:
Access the secrets at
secret/test/webapp
authenticated with theAPP_TOKEN
.
Tip
To learn more about the Key/Value v2 secrets engine, read the Versioned Key/Value Secrets Engine tutorial.
Clean up
If you wish to delete the resources you created to clean up your Vault environment, go through the steps in this section.
Disable the AppRole auth method enabled at
approle
.Delete the
tester
policy.Disable the key/value v2 secrets engine at
secret/
.Delete the
education/training
namespace.Delete the
education
namespace.Delete the stored token.
Help and reference
To learn more about the AppRole auth method, refer to the AppRole Pull Authentication tutorial.
If you followed the tutorials all the way through, you completed the common Vault operations workflow.
The differences between the HCP Vault Dedicated and self-managed Vault are:
- Vault Dedicated runs Vault Enterprise
- The root namespace of Vault Dedicated is
admin
You can follow any of the Vault tutorials. Your VAULT_ADDR
andVAULT_TOKEN
values are different from what the tutorials may say, but you know how to set
them for your Vault Dedicated cluster. In addition, be sure to set VAULT_NAMESPACE
.