Move secrets engines and auth methods across namespaces
Vault Namespaces
This tutorial demonstrates Vault CLI commands and API endpoint to move mounts across Vault namespaces. The namespaces feature requires a Vault Enterprise Standard license.
Vault Enterprise first introduced namespaces in version 0.11 to allow each organization or team (tenant) to manage their own secrets and policies by creating a Vault as a Service (VaaS) environment. Vault Namespace and Mount Structuring Guide provided guidance around the namespace structure.
Challenge
Vault namespace is an ideal solution to isolate secrets for each tenant (organizations, teams, sub-teams, etc.) and let the tenant-level administrator manage the secrets, policies, and tokens; however, it has a challenge.
Think of the following situations.
Migrating from Vault Community Edition to Vault Enterprise: Currently, once you move data from a Community Edition cluster into an Enterprise cluster, you need to manually move the mounts from the
root
namespace into the desired target namespaces.Structural reorganizations: Organizations change team structures and areas of responsibility or naming conventions, and as part of that would like to redistribute mounts from the current set of namespaces, into a new set of namespaces
Solution
Vault 1.10 extended the sys/remount
API
endpoint to support moving
secrets engines and auth methods mounts from one location to another, within a
namespace or across namespaces.
This tutorial focuses on the vault secrets move
and vault auth move
command
demonstration. If you are new to the namespace feature, read the following
tutorials first:
Note
The sys/remount
API endpoint as well as vault secrets move
and
vault auth move
CLI commands are available in both Vault Community Edition and
Enterprise. While this tutorial demonstrates moving mounts from one namespace
to another, you can remount secrets engines and auth methods from their current
mount path to another without the context of namespaces.
Targeted audience
Vault Enterprise cluster administrator with privileged policies to manage namespaces, secrets engines, and auth methods.
Prerequisites
To perform the tasks described in this tutorial, you need to have a Vault Enterprise environment.
Note
The creation of namespaces should be performed by a user with a
highly privileged token such as root
to set up isolated environments for
each organization, team, or application.
Scenario introduction
To demonstrate the migration of mount paths from one location to another, this tutorial sets up the following namespace hierarchy.
Initially, your organization had two namespaces: education/
and
education/training/
. As the organization grew, the Vault admin created
additional child namespaces to reflect the team structure so that each team can
manage their own secrets.
The following diagram shows the new namespace hierarchy.
Now that child namespaces were added, the Vault admin wishes to move the secrets engines and auth methods to the appropriate child namespace along with existing data.
Scenario tasks
In this tutorial, you are going to perform the Vault admin tasks to move secrets engines and auth method mounts.
Move the kv-v2 mount team-vault
from education/training
to
education/training/security-edu/vault-edu
namespace. Also, move the kv-v2
mount team-consul
from education/training
to
education/training/consul-edu/
namespace.
Warning
Each namespace provides an isolated Vault environment; therefore, the policies are tied to the namespace. When you move a mount from one path to another, you need to update the policies as well to ensure that Vault clients can access secrets from the new location. Read the Post-migration considerations section at the end.
Lab setup
Set the
VAULT_ADDR
environment variable to your Vault address (e.g., http://127.0.0.1:8200).Where
<vault_ent_address>
is your Vault address.Set the
VAULT_TOKEN
environment variable to store your Vault client token.Where
<client_token>
is a valid client token.Clone the
hashicorp/learn-vault-mount-move
GitHub repository.Be sure to set your working directory to where the
learn-vault-mount-move
folder is located.Make the
ns-setup.sh
script executable.Run the script. This creates the namespaces, and enables secrets engines and auth methods as described in the scenario introduction.
Migrate a secrets engine
Currently, key/value v2 secrets engine is enabled at team-vault
under
/education/training
namespace. Since vault-edu/
child namespace is created,
you want to migrate the secrets engine there.
List the enabled mounts in the
education/training
namespace.Output:
Read the pre-populated secrets.
Migrate the data at
education/training/team-vault
under theeducation/training/security-edu/vault-edu/
namespace.Current path is
education/training/team-vault
and the destination iseducation/training/security-edu/vault-edu/team-vault
.Example output:
Validation
Confirm that the data was successfully migrated.
The team-vault
mount path no longer exists under the education/training/
namespace.
Namespace hierarchy in the command
What does the following command do?
In this case, the VAULT_NAMESPACE
environment variable specifies the current
working namespace. Therefore, the target destination namespace must be
relative to the current namespace (education/training
), so you can omit
education/training
from the target namespace. Since the command specifies the
destination to consul-edu/team-data
, the mount gets moved to
education/training/consul-edu
namespace, and the path now become team-data
instead of team-consul
.
Example output:
Read the data at team-data/cert
under the education/training/consul-edu/
namespace to verify.
Example output:
Migrate an auth method
Similar to the secrets engine migration, you want to migrate the
education/userpass-cert
auth mount to the new education/certification/
namespace. Since the auth method will be in the dedicated namespace, you want to
change the path name to userpass
instead of userpass-cert
.
Warning
Migrating an auth method to another namespace will not move your existing entities and groups configurations. Read the Post-migration considerations section at the end.
Before migrating the auth method, login with Vault using the userpass auth method to test.
Example output:
Note
Tokens are tied to the namespace they were created in. Therefore, the generated token will be revoked after the auth mount migration.
Move the
education/approle-cert
auth mount toeducation/certification/approle
.Example output:
Validation
Login with Vault using the userpass auth method in the education/certification
namespace.
Notice that the path is set to userpass
instead of userpass-cert
.
Example output:
Post-migration Considerations
Each namespace has its own policies, auth methods, secrets engines, tokens, identity entities and groups. Therefore, after the mount migration, you must consider the following:
- Necessary policies exist in the target namespace
- Entities and groups may need to be updated after an auth mount migration
Secrets engines
The following policy allows Vault clients to access key/value v2 secrets at
team-vault
as well as its metadata.
After you successfully migrated the secrets engine from education/training/
namespace to education/training/security-edu/vault-edu
, you need to make sure
that the policy is deployed on the destination namespace.
As for the team-consul
, not only do you have to deploy a policy on the
education/training/consul-edu
namespace, but you need to ensure the policy path matches
the new mount point (team-data/
).
Auth methods
Similarly, you have to ensure that policies exist in the namespace so that auth configuration continues to work for Vault clients.
For example, if you created a user, bob-smith
as follow:
The certification-edu
policy must exist in the education/certification
namespace after the migration.
Entities and groups
Vault identities (entities and groups) are also tied to a namespace. The auth remount operation will not move the existing entities and groups as a part of the migration. Therefore, you need to recreate entities in the destination namespace to maintain the entity-alias configuration; otherwise, Vault will treat the post-migration login as a new entity.
Example: Before the migration
Example: Post-migration
This indicates that the entity-level policies and metadata were lost.
Note
If you are not familiar with Vault Identities, read the Identity: Entities and Groups tutorial.
Clean up
Make the
ns-cleanup.sh
script executable.Run the
ns-cleanup.sh
script.Unset the
VAULT_TOKEN
environment variable.Unset the
VAULT_ADDR
environment variable.