Step-by-Step Guide — Authentication, Authorization, and Identity with Hachicorp Vault Set Up On Google Cloud Platform
Introduction
In today’s digital age, securing sensitive data and managing user access is paramount. HashiCorp Vault is a powerful tool designed to manage secrets and protect sensitive data. In this blog, we’ll explore the concepts of Authentication, Authorization, and Identity within the context of Vault.
What is Vault?
HashiCorp Vault is an open-source tool that provides a secure way to store and manage sensitive information such as passwords, API keys, and certificates. It helps organizations control access to secrets and encrypt data in transit and at rest.
Authentication in Vault
Authentication is the process of verifying the identity of a user or service. In Vault, this involves providing credentials to prove who you are.
Authorization in Vault
Authorization is the process of determining what an authenticated user or service is allowed to do. Vault uses policies to manage authorization.
How do you set up Vault to manage authentication and authorization?
Task 1. Install Vault
- In Cloud Shell, add the HashiCorp GPG key:
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
Add the official HashiCorp Linux repository:
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
Update and install Vault:
sudo apt-get update
sudo apt-get install vault
Verify the installation
After installing Vault, verify the installation worked by checking that the Vault binary is available.
- Execute the
vault
command to verify the installation:
vault
You should see help output similar to the following:
Usage: vault <command> [args]
Common commands:
read Read data and retrieves secrets
write Write data, configuration, and secrets
delete Delete secrets and configuration
list List data or secrets
login Authenticate locally
agent Start a Vault agent
server Start a Vault server
status Print seal and HA status
unwrap Unwrap a wrapped secretOther commands:
audit Interact with audit devices
auth Interact with auth methods
debug Runs the debug command
kv Interact with Vault's Key-Value storage
lease Interact with leases
monitor Stream log messages from a Vault server
namespace Interact with namespaces
operator Perform operator-specific tasks
path-help Retrieve API help for paths
plugin Interact with Vault plugins and catalog
policy Interact with policies
print Prints runtime configurations
secrets Interact with secrets engines
ssh Initiate an SSH session
token Interact with tokens
Task 2. Start the Vault server
With Vault installed, the next step is to start a Vault server.
Vault operates as a client/server application. The Vault server is the only piece of the Vault architecture that interacts with the data storage and backends. All operations done via the Vault CLI interact with the server over a TLS connection.
In this lab, you will start and interact with the Vault server running in development mode.
This dev-mode server requires no further setup, and your local vault CLI will be authenticated to talk to it. This makes it easy to experiment with Vault or start a Vault instance for development. Every feature of Vault is available in “dev” mode. The -dev
flag just short-circuits a lot of setup to insecure defaults.
Note: Never run a “dev” mode server in production. It is insecure and will lose data on every restart (since it stores data in-memory). It is only made for development or experimentation.
Starting the dev server
First, start a Vault dev server. The dev server is a built-in, pre-configured server that is not very secure but useful for playing with Vault locally.
- To start the Vault dev server, run:
vault server -dev
You should see output relating to your Vault server configuration. Notice that Unseal Key and Root Token values are displayed.
==> Vault server configuration:
Api Address: http://127.0.0.1:8200
Cgo: disabled
Cluster Address: https://127.0.0.1:8201
Listener 1: tcp (addr: "127.0.0.1:8200", cluster address: "127.0.0.1:8201", max_request_duration: "1m30s", max_request_size: "33554432", tls: "disabled")
Log Level: info
Mlock: supported: false, enabled: false
Recovery Mode: false
Storage: inmem
Version: Vault v1.4.1WARNING! dev mode is enabled! In this mode, Vault runs entirely in-memory
and starts unsealed with a single unseal key. The root token is already
authenticated to the CLI, so you can immediately begin using Vault.You may need to set the following environment variable: $ export VAULT_ADDR='http://127.0.0.1:8200'The unseal key and root token are displayed below in case you want to
seal/unseal the Vault or re-authenticate.Unseal Key: 1+yv+v5mz+aSCK67X6slL3ECxb4UDL8ujWZU/ONBpn0=
Root Token: s.XmpNPoi9sRhYtdKHaQhkHP6xDevelopment mode should NOT be used in production installations!==> Vault server started! Log data will stream in below:
Note: The dev server stores all its data in-memory (but still encrypted), listens on localhost
without TLS, and automatically unseals and shows you the unseal key and root access key.Note: Insecure operation
Do not run a Vault dev server in production! This approach is only used here to simplify the unsealing process for this demonstration.
Now that you have the Vault development server running, you can continue setting up access to it.
- Open a new Cloud Shell tab.
- Copy and run the export
VAULT_ADDR ..
. command from the terminal output. This will configure the Vault client to talk to the dev server:
export VAULT_ADDR='http://127.0.0.1:8200'
The Vault CLI determines which Vault servers to send requests using the VAULT_ADDR
environment variable.
- Save the unseal key somewhere. Don’t worry about how to save this securely. For now, just save it anywhere.
- Set the
VAULT_TOKEN
environment variable value to the generated Root Token value displayed in the terminal output:
export VAULT_TOKEN="<REPLACE WITH YOUR ROOT TOKEN>"
Verify the server is running
- Verify the server is running by running the
vault status
command:
vault status
If it ran successfully, the output should look like the following:
$ vault status
Key Value
--- -----
Seal Type shamir
Initialized true
Sealed false
Total Shares 1
Threshold 1
Version 1.9.2
Storage Type inmem
Cluster Name vault-cluster-e2392b81
Cluster ID 48d7aba0-5416-a36b-2c27-0b256b222f57
HA Enabled false
Great! You’ve started the Vault development server. You can now continue on to the next section.
Log in to the Vault web UI
- First, click on the web preview icon on the toolbar of Cloud Shell.
- Click Change port.
- Change the Port Number to
8200
and click Change and Preview.
- You should be redirected to the Vault sign in page.
- Enter your Root Token that you saved earlier in the lab and click Sign In.
Your Vault development server should resemble the following.
Now that you’re logged in to the development server web UI, you can continue on to the next section. Keep this page open as you will need to use the UI later in the lab.
Task 3. Authentication in Vault
Before a client can interact with Vault, it must authenticate against an auth method. Upon authentication, a token is generated. This token is conceptually similar to a session ID on a website. The token may have attached policy, which is mapped at authentication time. This process is described in detail in the policies concepts documentation.
Auth methods
Vault supports a number of auth methods. Some backends are targeted toward users while others are targeted toward machines. Most authentication backends must be enabled before use. Often you will see authentications at the same path as their name, but this is not a requirement.
To learn more about authentication, you could use the built-in path-help
command:
vault path-help auth/my-auth
Vault supports multiple auth methods simultaneously, and you can even mount the same type of auth method at different paths. Only one authentication is required to gain access to Vault, and it is not currently possible to force a user through multiple auth methods to gain access, although some backends do support MFA.
Tokens
It is important to understand that authentication works by verifying your identity and then generating a token to associate with that identity.
For example, even though you may authenticate using something like GitHub, Vault generates a unique access token for you to use for future requests. The CLI automatically attaches this token to requests, but if you’re using the API you’ll have to do this manually.
This token given for authentication with any backend can also be used with the full set of token commands, such as creating new sub-tokens, revoking tokens, and renewing tokens. This is all covered on the token concepts page.
API
API authentication is generally used for machine authentication. Each auth method implements its own login endpoint. Use the vault path-help mechanism to find the proper endpoint. For example, the GitHub login endpoint is located at auth/github/login
. And to determine the arguments needed, vault path-help auth/github/login
can be used.
Task 4. AppRole auth method overview
The approle
auth method allows machines or apps to authenticate with Vault-defined roles. The open design of AppRole
enables a varied set of workflows and configurations to handle large numbers of apps. This auth method is oriented to automated workflows (machines and services), and is less useful for human operators.
An “AppRole” represents a set of Vault policies and login constraints that must be met to receive a token with those policies. The scope can be as narrow or broad as desired. An AppRole can be created for a particular machine, or even a particular user on that machine, or a service spread across machines. The credentials required for successful login depend upon the constraints set on the AppRole associated with the credentials.
What makes AppRole better?
The most essential feature of AppRole that makes it better than direct token assignment is that the credential is split into a Role ID and a Secret ID, delivered through different channels. Furthermore, the Secret ID is delivered to the application only at the expected time of use (usually at application startup).
This pattern of authorization by using knowledge delivered just in time, in parts, through independent delivery paths should be familiar from standard multi-factor authentication methods: to log in to a service, you have an already-known identity, but you need a one-time-use token generated and delivered at the time you log in as well.
The Role ID is not sensitive and can be used for any number of instances of a given application; you can hardcode it into things like VM or container images (though as a best practice, you should not provide it to processes that don’t need it, e.g. processes that manage roles rather than using them to authenticate). Role ID can be seen as the “username” for a particular application. This means that multiple instances of the same application can share the same Role ID.
The Secret ID, by contrast, is:
- Always intended to be a secret and can be seen as the “password” that is required to login to Vault.
- Intended to be access-limited so it can be used only by authorized applications; it may be usable by only a single application or even a single app instance.
- Intended to be short-lived to reduce the window for compromise; it may be valid for only seconds.
For more information on AppRole, and the Secret and Role IDs, check out the Authenticating Applications with HashiCorp Vault AppRole documentation.
Task 5. Using the AppRole auth method
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.
Since tokens are the core method for authentication within Vault, there is a token auth method (often referred to as token store). This is a special auth method responsible for creating and storing tokens. In this section, you will generate tokens for machines or apps by enabling the AppRole auth method.
Challenge
Think of a scenario where a DevOps team wants to configure Jenkins to read secrets from Vault so that it can inject the secrets to an app’s environment variables (e.g. MYSQL_DB_HOST
) at deployment time. Instead of hardcoding secrets in each build script as plain text, Jenkins retrieves secrets from Vault.
As a user, you can authenticate with Vault using your LDAP credentials, and Vault generates a token. This token has policies granting you permission to perform the appropriate operations. How can a Jenkins server programmatically request a token so that it can read secrets from Vault?
Solution:
Enable the AppRole auth method so that the Jenkins server can obtain a Vault token with appropriate policies attached. Since each AppRole has attached policies, you can write fine-grained policies limiting which app can access which path.
Create a policy and test data
As discussed earlier, AppRole is an authentication mechanism within Vault to allow machines or apps to acquire a token to interact with Vault. It uses RoleID and SecretID for login. The basic workflow is:
Note: For the purpose of introducing the basics of AppRole, this lab walks you through a very simple scenario involving only two personas (admin
and app
).
- In Cloud Shell, run the following to create some test data:
vault kv put secret/mysql/webapp db_name="users" username="admin" password="passw0rd"
You should receive the following output:
Key Value
--- -----
created_time 2021-06-08T02:34:23.182299Z
deletion_time n/a
destroyed false
version 1
- Next, enable
approle
auth method by executing the following command:
vault auth enable approle
Success! Enabled approle auth method at: approle/
When you enabled the AppRole auth method, it gets mounted at the /auth/approle
path. In this example, you are going to create a role for the app
persona (jenkins
in our scenario).
- Before creating a role, use the following command to create a
jenkins
policy file:
vault policy write jenkins -<<EOF
# Read-only permission on secrets stored at 'secret/data/mysql/webapp'
path "secret/data/mysql/webapp" {
capabilities = [ "read" ]
}
EOF
You should receive the following output:
Success! Uploaded policy: jenkins
- Next, create a role named
jenkins
withjenkins
policy attached:
vault write auth/approle/role/jenkins token_policies="jenkins" \
token_ttl=1h token_max_ttl=4h
Output:
Success! Data written to: auth/approle/role/jenkins
The generated token’s time-to-live (TTL) is set to 1 hour and can be renewed for up to 4 hours of its first creation. (Note: This example creates a role which operates in pull mode.)
Note: To attach multiple policies, pass the policy names as a comma separated string: token_policies="jenkins,anotherpolicy"
.
There are a number of parameters that you can set on a role. If you want to limit the use of the generated secret ID, set secret_id_num_uses
or secret_id_ttl
parameter values. Similarly, you can specify token_num_uses
and token_ttl
. You may never want the app token to expire. In such a case, specify the period so that the token generated by this AppRole is a periodic token. To learn more about periodic tokens, refer to the Tokens tutorial.
- Read the
jenkins
role you created to verify:
vault read auth/approle/role/jenkins
Your output should resemble the following:
Key Value
--- -----
bind_secret_id true
local_secret_ids false
secret_id_bound_cidrs <nil>
secret_id_num_uses 0
secret_id_ttl 0s
token_bound_cidrs []
token_explicit_max_ttl 0s
token_max_ttl 4h
token_no_default_policy false
token_num_uses 0
token_period 0s
token_policies [jenkins]
token_ttl 1h
token_type default
Get RoleID and SecretID
The RoleID and SecretID are like a username and password that a machine or app uses to authenticate. Since the example created a jenkins
role which operates in pull mode, Vault will generate the SecretID. You can set properties such as usage-limit, TTLs, and expirations on the SecretIDs to control its lifecycle.
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.
Now, you’ll need to fetch the RoleID and SecretID of a role.
- Execute the following command to retrieve the RoleID for the
jenkins
role:
vault read auth/approle/role/jenkins/role-id
Your output should resemble the following:
Key Value
--- -----
role_id 675a50e7-cfe0-be76-e35f-49ec009731ea
- Execute the following command to generate a SecretID for the
jenkins
role:
vault write -force auth/approle/role/jenkins/secret-id
You should receive output resembling the following:
Key Value
--- -----
secret_id ed0a642f-2acf-c2da-232f-1b21300d5f29
secret_id_accessor a240a31f-270a-4765-64bd-94ba1f65703c
The -force
(or -f
) flag forces the write operation to continue without any data values specified. Or you can set parameters such as cidr_list
.
Note: The RoleID is similar to a username; therefore, you will get the same value for a given role. In this case, the jenkins
role has a fixed RoleID. While SecretID is similar to a password that Vault will generate a new value every time you request it.
Login with RoleID & SecretID
The client (in this case, Jenkins) uses the RoleID and SecretID passed by the admin to authenticate with Vault. If Jenkins did not receive the RoleID and/or SecretID, the admin needs to investigate.
- To login, use the
auth/approle/login
endpoint by passing the RoleID and SecretID. Make sure to replace the values with your RoleID and SecretID:
vault write auth/approle/login role_id="your-role-ID" secret_id="your-secret-ID"
Your output should resemble:
Key Value
--- -----
token s.ncEw5bAZJqvGJgl8pBDM0C5h
token_accessor gIQFfVhUd8fDsZjC7gLBMnQu
token_duration 1h
token_renewable true
token_policies ["default" "jenkins"]
identity_policies []
policies ["default" "jenkins"]
token_meta_role_name jenkins
Vault returns a client token with default
and jenkins
policies attached.
- Store the generated token value in an environment variable named,
APP_TOKEN
:
export APP_TOKEN="your-token"
Read secrets using the AppRole token
Once receiving a token from Vault, the client can make future requests using this token.
- Verify that you can access the secrets at secret/mysql/webapp:
VAULT_TOKEN=$APP_TOKEN vault kv get secret/mysql/webapp
Your output should resemble the following:
====== Metadata ======
Key Value
--- -----
created_time 2021-06-08T02:34:23.182299Z
deletion_time n/a
destroyed false
version 1
====== Data ======
Key Value
--- -----
db_name users
password passw0rd
username admin
- The app has a read-only access; therefore, the following
delete
command will fail:
VAULT_TOKEN=$APP_TOKEN vault kv delete secret/mysql/webapp
The error message indicates permission error.
Error deleting secret/mysql/webapp: Error making API request.
URL: DELETE http://127.0.0.1:8200/v1/secret/data/mysql/webapp
Code: 403. Errors:* 1 error occurred:
* permission denied
- Run the following command to copy the values of the
mysql/webapp
secret to text files:
VAULT_TOKEN=$APP_TOKEN vault kv get -format=json secret/mysql/webapp | jq -r .data.data.db_name > db_name.txt
VAULT_TOKEN=$APP_TOKEN vault kv get -format=json secret/mysql/webapp | jq -r .data.data.password > password.txt
VAULT_TOKEN=$APP_TOKEN vault kv get -format=json secret/mysql/webapp | jq -r .data.data.username > username.txt
- Run the following command to copy these file to a pre-created Cloud Storage bucket to track your progress:
export PROJECT_ID=$(gcloud config get-value project)
gsutil cp *.txt gs://$PROJECT_ID
Click Check my progress to verify the objective.
Using the AppRole Auth Method
Check my progress
Response wrap the SecretID
The RoleID is equivalent to a username, and SecretID is the corresponding password. The app needs both to log in with Vault. Naturally, the next question becomes how to deliver those values to the client securely.
A common solution involves three personas instead of two: admin
, app
, and trusted entity
. The trusted entity delivers the RoleID and SecretID to the client by separate means.
For example, Terraform as a trusted entity can deliver the RoleID onto the virtual machine. When the app runs on the virtual machine, the RoleID already exists on the virtual machine.
SecretID is like a password. To keep the SecretID confidential, use response wrapping so that only the expecting client can unwrap the SecretID.
Earlier, you executed the following command to retrieve the Secret ID.
vault write -force auth/approle/role/jenkins/secret-id
- Instead, you can use response wrapping by passing the
-wrap-ttl
parameter:
vault write -wrap-ttl=60s -force auth/approle/role/jenkins/secret-id
Key Value
--- -----
wrapping_token: s.yzbznr9NlZNzsgEtz3SI56pX
wrapping_accessor: Smi4CO0Sdhn8FJvL8XvOT30y
wrapping_token_ttl: 1m
wrapping_token_creation_time: 2021-06-07 20:02:01.019838 -0700 PDT
wrapping_token_creation_path: auth/approle/role/jenkins/secret-id
- Now you can send this
wrapping_token
to the client so that the response can be unwrapped and obtain the SecretID:
VAULT_TOKEN="<your-wrapping-token>" vault unwrap
You should now see the SecretID unwrapped:
Key Value
--- -----
secret_id d3eb75bc-2fb4-9d4e-9d81-17179130609c
secret_id_accessor 54b2683c-9c14-cb49-2510-b87c82c7d279
secret_id_ttl 0s
Note: To learn more about the wrapping token, read the Cubbyhole Response Wrapping tutorial.
Limit the SecretID usages
Another best practice is to treat the SecretID like a password and force it to be regenerated after a number of use.
- To do so, update the role definition with
secret_id_num_uses
set:
vault write auth/approle/role/jenkins token_policies="jenkins" \
token_ttl=1h token_max_ttl=4h \
secret_id_num_uses=10
In this example, a SecretID of the jenkins
role can be used for up to 10 times to authenticate and fetch a client token. After the number of uses is reached, the SecretID expires and you would need to generate a new one. This is similar to forcing a password rotation.
Task 6. Entities, aliases, and groups
A common scenario is that users may have multiple accounts with various identity providers, and Vault supports many of those providers to authenticate with Vault. Vault Identity can tie authentications from various auth methods to a single representation. This representation of a consolidated identity is called an Entity and their corresponding accounts with authentication providers can be mapped as Aliases. In essence, each entity is made up of zero or more aliases. An entity cannot have more than one alias for a particular authentication backend.
The idea of Identity is to maintain the clients who are recognized by Vault. As such, Vault provides an identity management solution through the Identity secrets engine. For more information about the Identify secrets engine and how it is used, refer to the Identify Secrets Engine documentation.
Challenge
Bob has accounts in both Github and LDAP. Both Github and LDAP auth methods are enabled on the Vault server that he can authenticate using either one of his accounts. Although both accounts belong to Bob, there is no association between the two accounts to set some common properties.
Solution:
Create an entity representing Bob, and associate aliases representing each of his accounts as the entity member. You can set additional policies and metadata on the entity level so that both accounts can inherit.
When Bob authenticates using either one of his accounts, the entity identifier will be tied to the authenticated token. When such tokens are put to use, their entity identifiers are audit logged, marking a trail of actions performed by specific users.
Create an entity with Alias
You are first going to create a new entity with base policy assigned. The entity defines two entity aliases with each having a different policy assigned.
For this lab, let’s assume a user, Bob Smith at ACME Inc. happened to have two sets of credentials: bob
and bsmith
. Bob can authenticate with Vault using either one of his accounts. To manage the user's accounts and link them to identity Bob Smith in QA team, you are going to create an entity for Bob.
For the simplicity of this lab, you are going to work with the userpass auth method. In reality, the user bob
might be a username that exists in Active Directory, and bsmith
might be Bob's username in GitHub. To mock the behavior, you are going to enable the userpass auth method at two separate paths: userpass-test
and userpass-qa
. Pretend that they are two different types of auth methods.
You’ll first start by creating the appropriate policies.
- Navigate to the Vault UI. Click the Policies tab from the home page. You should see the default and root ACL policies, along with the
jenkins
policy you created earlier.
- Click Create ACL policy.
- Name this policy:
base
. - In the Policy box, add the following policy:
path "secret/data/training_*" {
capabilities = ["create", "read"]
}
Click Create policy.
- Click ACL Policies to navigate back to the Policies page.
- Click Create ACL policy .
- Name this policy:
test
. - In the Policy box, add the following policy:
path "secret/data/test" {
capabilities = [ "create", "read", "update", "delete" ]
}Click Create policy.
- Click ACL Policies to navigate back to the Policies page.
- Click Create ACL policy .
- Name this policy:
team-qa
. - In the Policy box, add the following policy:
path "secret/data/team-qa" {
capabilities = [ "create", "read", "update", "delete" ]
}
Click Create policy.
- Click ACL Policies to navigate back to the Policies page.
Your policies should resemble the following:
Create the users and attach policies
Now, you are going to create bob
and bsmith
users with appropriate policies attached.
- On the Navigation menu click the Access tab and then click Enable new method.
- Select Username & Password and click Next.
- For the Path, use:
userpass-test
. - Click Enable Method.
- Navigate back to the
userpass-test
auth method.
- Click Create user.
- For the Username, use
bob
. For the Password, usetraining
.
- Click Tokens to open the sub-menu.
- Under Generated Token’s Policies, add the
test
policy. - Click Save.
Great! You’ve created the bob
user on the userpass-test
path and attached the test
policy to it.
- Click methods to navigate back to the Authentication Methods page.
- Click Enable new method.
- Select Username & Password and click Next.
- For the Path, use:
userpass-qa
. - Click Enable Method.
- Navigate back to the
userpass-qa
auth method.
- Click Create user.
- For the Username, use
bsmith
. For the Password, usetraining
.
- Click Tokens to open the sub-menu.
- Under Generated Token’s Policies, add the
team-qa
policy. - Click Save.
Associate aliases as entity members
You can set policies on the entity level that both accounts can inherit. In this section you will associate two aliases (bob
and bsmith
) as entity members.
- Click the Access tab, then under the Access menu on the left, click Entities.
- Click Create entity.
- For the name, use
bob-smith
. - For the Policies, choose
base
.
- Click Create.
Now it’s time to create aliases.
- Click Add alias.
- For the Name, use
bob
. - For Auth Backend, select
userpass-test/
.
- Click Create. Your alias should resemble the following.
- Navigate back to the bob-smith entity.
- Click Add alias.
- For the Name, use
bsmith
. - For Auth Backend, select
userpass-qa/
.
- Click Create. Your alias should resemble the following.
- Click Entities on the left menu to navigate back to the entities page. You should see the
bob-smith
entity with 2 aliases.
Note: You can ignore the other entity that was created earlier in setting up the approle auth method.
Test the entity
- First, navigate back to Cloud Shell and run the following command to log in as the
bob
user:
vault login -method=userpass -path=userpass-test \
username=bob password=training
You should see the following output:
Key Value
--- -----
token s.upfmMlX7tvFE0caUUVuCj7Fjtoken_accessor j8KxZUPJ4R4yEQYYV2T4Slow
token_duration 768h
token_renewable true
token_policies ["default" "test"]
identity_policies ["base"]
policies ["base" "default" "test"]
token_meta_username bob
- Notice the two lines:
identity_policies
andpolicies
.
identity_policies ["base"]
policies ["base" "default" "test"]
Here you see that within the policies, there are three policies attached: base
, default
, and test
. The test
policy is the one directly associated with the user, and the base
policy is the one inherited by the entity.
The identity_policies
shows which policies are coming directly from the entity. Although the username bob
does not have base
policy attached, the token inherits the capabilities granted in the base policy because bob
is a member of the bob-smith
entity, and the entity has base policy attached. Check to see that the bob's token inherited the capabilities.
- Copy the token for
bob
and run the following command to check the token capabilities:
vault token capabilities <bob token> secret/data/training_test
You should see:
create, read
The base
policy grants create and read capabilities on secret/training_*
path; therefore bob is permitted to run create and read operations against any path starting with secret/training_*
.
- What about the
secret/team-qa
path?
vault token capabilities <bob token> secret/data/team-qa
You should see:
deny
The user bob
only inherits capability from its associating entity's policy. The user can access the secret/team-qa
path only if he logs in with bsmith
credentials. Let's try that now.
- Next, run the following command to log in as the
bsmith
user:
vault login -method=userpass -path=userpass-qa \
username=bsmith password=training
You should see the following output:
Key Value
--- -----
token s.zsPGSIolQ1SdInhHv4IhV12v
token_accessor y2ephSbQCGZ7LV6oLCOmUBno
token_duration 768h
token_renewable true
token_policies ["default" "team-qa"]
identity_policies ["base"]
policies ["base" "default" "team-qa"]
token_meta_username bsmith
- Notice the two lines:
identity_policies
andpolicies
.
identity_policies ["base"]
policies ["base" "default" "team-qa"]
Again, you see that within the policies, there are three policies attached: base
, default
, and team-qa
. The team-qa
policy is the one directly associated with the user, and the base
policy is inheritied. You can now optionally test out the token capabilities.
Create an internal group
Vault identity has support for groups. A group can contain multiple entities as its members. A group can also have subgroups. Policies set on the group are granted to all members of the group. During request time, when the token’s entity ID is being evaluated for the policies that it has access to, policies that are inherited due to group memberships are granted along with the policies on the entity itself.
Now you are going to create an internal group named engineers
. Its member is bob-smith
entity that you created earlier.
- Navigate back to the Vault UI and click on the Policies tab.
- Click Create ACL Policy.
- For the name, use
team-eng
. - In the Policy box, add the following policy:
path "secret/data/team/eng" {
capabilities = [ "create", "read", "update", "delete"]
}
- Click Create policy.
- Click the Access tab, then select Groups from the left hand side.
- Click Create group.
- For the name, use:
engineers
. - For Policies, choose
team-eng
. - For Member Entity IDs, select
bob-smith
. - Click Create.
Now verify that the user has inherited the policy.
- Navigate back to Cloud Shell and run the following command to log in as
bob
:
vault login -method=userpass -path=userpass-test username=bob password=training
You should see similar output:
Key Value
--- -----
token s.6Z13hPfLY6FxHxIypRprwHxS
token_accessor 25onRmi8TrSVbjYix6zdvpae
token_duration 768h
token_renewable true
token_policies ["default" "test"]
identity_policies ["base" "team-eng"]
policies ["base" "default" "team-eng" "test"]
token_meta_username bob
- Notice the following lines:
identity_policies ["base" "team-eng"]
policies ["base" "default" "team-eng" "test"]
Here you see that within the policies, there are now four policies attached: base
, default
, test
, and team-eng
. Within the identity_policies
, you can also see that team-eng
is now associated with the user. You can optionally log in with the bsmith
user and verify this is the case as well.
References
- HashiCorp Vault Documentation
- Vault Authentication Methods
- Vault Policies
- Vault Identity
Hands-on labs practice