Rotate Azure auth method root credentials with Vault CLI
Challenge
Operators with a need to rotate client secrets in the Azure Auth Engine mounts and Secrets Engine on a routine basis are currently limited to the Vault API. Until recently this was not available as a dedicated CLI command.
Solution
Vault 1.13 adds a rotate-root
command to the Vault CLI. Now the Vault CLI has a dedicated command to generate a new client secret for the root account defined in the configuration for Azure Auth Engine mounts and Secrets Engine. The generated value will be known only by Vault.
Prerequisites
- Azure Subscription.
- Vault version 1.13 binary.
- Terraform CLI to provision Vault server.
- Azure CLI.
- jq - used by Terraform.
- ssh or PUTTY installed.
- You should generate a new RSA key for this tutorial and delete as you clean up.
Set up environment
Open a new window and start up Vault as a local server.
Open a second window and add a
VAULT_ADDR
andVAULT_TOKEN
environment variable.To use the Terraform configuration in this lab you need to set up authentication to Azure.
CLI is easiest method, but feel free to use other methods as detailed for the Azure provider.
Follow the directions as given by the CLI.
Open a second window and clone the
learn-vault-azure-rotate-root-creds
repository.Go into the directory you just created.
Initialize the terraform in that directory.
Create a new RSA key-pair
You will need a environment variables for the path of these public and private keys.
Terraform configuration
Create the VM and supporting infrastructure.
Vault configuration
The Terraform configuration in the earlier section also created a file called
local_environment_setup.sh
. Source this file and set up the environment variables needed to configure the Azure plugin for Vault.Enable Azure plugin.
Write the azure auth configuration.
Write the role.
Login using the access token and VM name.
The output should resemble the following:
Azure UI
Now that you have created application and configured Vault, take a look at the secret in the Azure UI.
Open Microsoft Azure and sign in.
Go to the Search field and type in
Azure Active Directory
, then click on the same after it appears.On the left nav choose App Registrations.
In the section that opens to right, choose All Applications tab. There will be a vault_azure_tests displayed.
Click on the vault_azure_tests link and open the Overview. On the left navigation bar, click on Certificates and Secrets.
Look at the secret listed on that page, and for future reference note down the unmasked portion of the secret.
Compare it to the
CLIENT_SECRET
environment variable that was set earlier. The first three characters should be the same.Keeping the Credentials and Secrets Window open, go back to your terminal and rotate the credentials.
Return to the Credentials and Secrets Window and reload the screen.
It takes a while to sync, but after a reload or two you will to see two secrets. This is because it takes a few minutes for all the Azure regions to sync.
Wait a few minutes and reload the page again, notice the original secret has disappeared. Only the new secrets is listed.
Next steps
You have created simple Azure infrastructure with a client secret. Then you started Vault, configured the Azure secrets engine and finally learned how to use the Azure Vault plugin to rotate the client credentials of an Azure Active Directory Application.
Clean up
Remove the infrastructure you created.
Unset the environment variables.
Go to window with dev Vault server running and type in control-c (
^C
). You should notice the following:Find the RSA Key Pair generated for this lab and delete it.
References
- Azure Secrets Engine - Rotate Root API Call
- Azure Secret Engine
- Secure Access Azure SQL Database
- Key Management Secrets Engine with Azure Key Vault
- Azure Active Directory with OIDC Auth Method and External Groups
- Auto-unseal using Azure Key Vault
- Peering an Azure Virtual Network with HashiCorp Cloud Platform (HCP)