Vault first introduced Login MFA in version 1.10.0 to provide support for multiple authentication factors with Vault auth methods.
»Challenge
Your organization currently uses the Vault Active Directory Auth Method to allow users to authenticate with Vault using their Active Directory credentials, but you need to enforce additional authentication method, such as a Time-Based One Time Password (TOTP).
»Solution
The Vault Login MFA functionality provides a means to link an auth method to additional authentication factors such as those offered by third party services, also features a built in TOTP MFA method.
You can leverage the built-in TOTP MFA method with an authenticator application to enhance security with an additional authentication factor.
»Target audience
Vault cluster administrators with privileged policies to manage auth methods and secrets engines. The admin persona performs the steps of this role in the hands-on scenario that is part of this tutorial.
Vault users authenticating to Vault with the Active Directory secrets engine. The user persona will authenticate with the Active Directory secrets engine and the authenticator application to successfully authenticate to Vault.
»Scenario introduction
To demonstrate how Vault TOTP MFA works, this tutorial uses Vagrant to spin up a virtual machine with a Windows Server with Active Directory. In addition, you will run a Docker container running Vault in dev mode.
In the diagram, the workflow described in this tutorial for Two-Phase MFA is shown.
The admin persona configures the Vault environment.
The user persona uses the Vault API, CLI, or UI and their authentication application on an enrolled device.
The user persona attempts authentication with Vault.
Vault returns a message advising that the authentication requires MFA.
The user persona interacts with their authenticator app, which returns a code that can be used as the extra authentication factor.
The user persona validates their authentication with the code returned from authenticator app.
Vault verifies the code through the TOTP MFA method
If verification is successful, the authentication attempt also succeeds and the user persona receives a Vault token.
NOTE: The Login MFA integration introduced in version 1.10.0 is a new solution, and should not be confused with the legacy open source MFA or Enterprise Step Up MFA solutions. The solution covered in this tutorial is the preferred way to enable MFA for auth methods in all editions of Vault version 1.10.0 or greater.
»Prerequisites
A Windows environment with Active Directory. This scenario uses the community based Vagrant environment for a Windows Server based Active Directory project.
Docker. This scenario uses Docker Desktop for macOS.
Vagrant. Required if you choose to use the Vagrant environment for an Active Directory Server. This scenario was last tested with version 2.2.19.
- A supported Vagrant virtualization target; this scenario uses VirtualBox tested against version 6.1.34.
git required for cloning repositories used in the scenario.
An authenticator application; this scenario uses the Google Authenticator app for iOS, but you can use any compatible authenticator application.
The
xdg-open
utility is required if you are following along on a Linux based host. Sometimes this utility is part of anxdg-utils
meta-package that you can install with your OS package manager. Check your distribution specific documentation for details on how to installxdg-open
.
»Lab setup
You will use a terminal session and command line to start an Active Directory virtual machine and Vault server container.
Open a new terminal session to begin the lab setup.
For ease of cleanup and simplicity, create a temporary directory to contain all required configuration for the scenario, and assign the directory name value to the environment variable HC_LEARN_LAB
.
Change into this directory; you will execute all scenario commands on the local host from this directory or one of its descendants.
You can also echo this value so that you can find the files within the directory for using the generated QR code later.
»Windows Server with Active Directory
To set up your Windows Server environment with Active Directory environment, clone the project repository.
Change into the project directory.
NOTE: If you are using VirtualBox version 6.1.26 or later, you need to add some additional configuration to support the host only network adapter configured with this particular Vagrant box.
Create a directory for the extra VirtualBox network configuration.
Write the configuration file.
Start the virtual machine with Vagrant.
NOTE: The process of starting the Windows Server virtual machine and completely bringing up the Active Directory service is lengthy, and requires 20 minutes or more on a contemporary developer laptop to complete.
The last lines in the Vagrant log output indicate that the Active Directory server is ready because users and groups were successfully created:
Validate that the Active Directory services are available by connecting to the virtual machine with WinRM and using dcdiag to test services.
If the tests also indicate passing status, then the Active Directory server is ready.
»Docker network
Create a Docker network named learn-vault-network
.
»Vault server
Start a dev mode Vault server container.
NOTE: As all data are stored only in memory for a dev mode server, understand that when you stop the server all Vault data will be lost.
Access the learn-vault
container by executing a shell within it.
Notice that the prompt changes to:
Update the package cache.
Install jq
to parse JSON output.
Get Vault server status.
The Vault server is ready.
For the purposes of this scenario, you will use the initial root token value with the VAULT_TOKEN
environment variable for the scenario steps.
NOTE: For these tasks with a dev mode server, you can use the root token. In production Vault use, you should only use root tokens for initial setup or in emergencies.
»Scenario tasks
»Enable and configure LDAP auth method
Enable the LDAP auth method.
Configure the LDAP auth method.
TIP: Since your Vault server is running within a container, you must reference the host network, not the local network. You can do so by specifying host.docker.internal
in the url
parameter value.
Successful output example:
Since the Active Directory server for this scenario uses a self-signed TLS certificate, we instruct Vault to use insecure TLS with insecure_tls=true
. You should not use this setting in a production configuration however, and should instead prefer using certificates that can be validated.
»Login with LDAP auth method
Test the Vault login with LDAP auth method.
Successful output example:
You need to capture the identity entity ID of the w.kluge
user for configuration of the Login MFA method.
Export its value to the ENTITY_ID
environment variable for later use.
Check the value.
»Enable Login MFA method
Enable a Login MFA method to enforce TOTP on the LDAP auth method.
NOTE: Authenticator applications are not consistent in their support of encryption algorithms. You are encouraged to research the algorithms supported by your preferred authenticator app. The algorithms supported by Vault's Login MFA TOTP method are detailed in the Configure TOTP MFA Method documentation. Google Authenticator supports SHA256, so it is used in this scenario.
Configure the Login MFA TOTP method and assign its method ID to the TOTP_METHOD_ID
environment variable.
Check the value.
»Generate authenticator app QR code
Generate QR code as a PNG image.
You can open the QR code image from the host system in different ways depending on your operating system.
Examples are provided for Linux, macOS, and Windows.
If you are using a graphical environment on Linux, open the QR code image this way:
You can scan this image with your authenticator app to add Vault TOTP. Again, this scenario presumes that you will use the Google Authenticator app for this.
»Create Login MFA enforcement
Capture the LDAP auth method for use in creating a Login MFA enforcement.
Check the value.
Create the enforcement.
Successful output example:
»Login with LDAP auth method
Use the CLI to login with the LDAP auth method a second time.
Enter the TOTP from your authenticator app when prompted.
Successful output example:
You have successfully authenticated to Vault with the Active Directory. Enter exit
to quit out of the container.
»Cleanup
Stop the Vault server Docker container.
TIP: The container was started with the --rm
flag, so it will be automatically removed.
Remove the Docker network
Change into the vagrant-active-directory
project directory.
Destroy the virtual machine
Change to to your home directory.
To remove all configuration and other data you created during this scenario, you can recursively remove the $HC_LEARN_LAB
directory.
Remove the additional VirtualBox network configuration.
»Summary
As the admin persona, you learned how to enable and configure Login MFA with the LDAP auth method and TOTP MFA method.
As the user persona, you learned how to use a Login MFA method when authenticating to Vault.
You can learn more about Vault authentication and auth methods in the Manage Authentication Methods tutorial, and the Auth Methods documentation.