Enable login multi factor authentication (MFA)
Multi-Factor Authentication (MFA) is a mechanism for outsourcing the secondary authentication for your website (or other product) to a third party one-time key provider. With MFA a user is granted access to a website or application only after successfully presenting two or more pieces of evidence (or factors) to an authentication. MFA has been supported in Vault Enterprise with the Governance and Policy Module since Release Version 0.8.
Challenge
MFA is expected in any modern security product as a baseline feature. All Vault users (Community Edition practitioners, developers, admins, and operators) seek to secure highly sensitive information using strong security practices such as MFA. It is a key to zero-trust security framework. However, Vault Community Edition users are unable to get the benefit of security authentication best practices via MFA without switching to an Enterprise license.
Solution
Vault version 1.10.0 introduces a new Login MFA integration to allow for an additional authentication factor when authenticating to Vault.
The following MFA methods are currently supported:
- Time-Based One-Time Password (TOTP)
- Okta
- Duo
- PingIdentity
In the diagram, the workflow described in this tutorial for Two-Phase MFA is shown.
The admin persona configures the Vault and PingID environments.
The user persona uses the Vault API, CLI, or UI and the PingID application on an enrolled device.
The user persona attempts authentication with Vault.
Vault returns a message advising that the authentication requires MFA.
The PingID application returns a code which can be used as an extra authentication factor.
The user persona validates their authentication with the code returned from the PingID application.
Vault verifies the code through its MFA method integration, and if successful, the authentication attempt succeeds and the user persona receives a 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.
Target audience
This tutorial is for demonstrating workflows both to Vault admins who enable and configure authentication methods and MFA methods, and to users who are authenticating with Vault.
It uses the PingIdentity MFA method, and shares some detail on configuring the PingOne Identity Repository, but you can use any of the supported MFA methods and their associated resources to configure the production solution that you require.
Prerequisites
This lab was tested on macOS using an x86_64 based processor. If you are running macOS on an Apple silicon-based processor, use a x86_64 based Linux virtual machine in your preferred cloud provider.
To perform the steps in this tutorial, you need the following:
- Docker
- Working internet connection from Docker host
- PingIdentity PingOne account you can use a trial account to follow the steps in this tutorial.
- PingID application installed; this tutorial uses PingID for mobile on iOS.
- openssl CLI tool
- jq for parsing JSON responses
Scenario introduction
You will assume two personas in this tutorial to experience an end-to-end example usage of MFA when authenticating to Vault:
As the admin persona, you will first configure PingID for Enterprise using for example, the PingOne identity repository. You will then generate a properties file for integration with PingFederate and other clients that you will use when enabling the MFA method for Vault.
You will also enable an instance of the username and password auth method for authentication.
As the user persona, you will authenticate to Vault with the Username and Password auth method to validate that it is functional.
You will also enroll your application and device in the PingID application for the user persona using the PingID website.
Note
It is important that the username in PingID matches the username for the Vault auth method. You must also use the same domain name you used to sign up for your PingID account in places where this tutorial uses example.com
.
As the admin persona, you will enable a MFA method that uses the PingOne service using the Two-Phase Login approach. You will then create a login enforcement for the username and password auth method so that all users who authenticate with Vault using the auth method must also provide an additional authentication factor from a PingID application.
As the user persona, you will authenticate to Vault with the Username and Password auth method again. This will prompt you to provide an additional factor from the PingID application in the application associated to your username.
Lab setup
Before you can begin the scenario, you need to prepare your local environment and the PingOne environment.
Vault server container
Start a Vault dev mode server Docker container.
The container will run detached, publish the Vault API port to localhost, and remove itself when stopped.
Insecure operation
Do not run a Vault dev server in production. This approach starts a Vault server with an in-memory database and runs in an insecure way.
Create an alias to use the vault
binary in the container from your Docker host.
Export the VAULT_ADDR
environment variable locally to address the Vault server container. This is required for both future vault
CLI and HTTP API examples.
Validate that you can use the initial root token for authentication with Vault.
For consistency and convenience, set the initial root token value in the environment variable ROOT_TOKEN
:
Since the token lookup returns root policies, you can consider your access to the Vault server successful.
Note
For the purpose of this tutorial, you can use the root
token to work with Vault. However, it is recommended that root tokens are only used for just enough initial setup or in emergencies. As a best practice, use tokens with an appropriate set of policies based on your role in the organization.
If you experience any issues with this step, check the Docker logs with docker logs learn-vault
.
The Vault server is now ready for use.
PingOne setup
(As the admin persona)
You need to access your PingIdentity account and perform some initial setup tasks to prepare for the scenario steps. Sign into PingIdentity and during initial setup, choose the PingOne Identity Repository when prompted:
Next, under Setup, navigate to to PingID → Client Integration.
Under Integrate with PingFederate and Other Clients click Download to download the pingid.properties
file. If there is not already a properties file available, you can click Generate to generate one prior to downloading.
Note
Keep the downloaded properties file at hand as it will be used later when enabling the Vault MFA method.
This tutorial uses the PingID mobile application for a second authentication factor.
You can now add the user persona alice as a user, and enroll the PingID device you will use as the user persona with the PingID application.
From the PingOne dashboard, click USERS, then click the Add Users button and Create New User.
Complete the required user details.
Click Save to add the user.
Click Dashboard and under Notifications, click the application portal URL found within the Configure Single Sign-on notification.
This will route you to the PingID user application, where you need to sign out from the admin persona account, and then sign in as the user persona.
Click your user avatar for the drop-down menu and click Sign Off.
Once signed in, you will be prompted to reset your password. Enter the current password and the new one and click Submit.
Click your user avatar for the drop-down menu. Click Devices to add your device on which you will use the PingID application.
Click the Add button and a dialog containing a QR code and pairing code will appear. Use the PingID application on your user persona device with the QR code or pairing code to enroll it.
Once your Vault server container is up and you are able to validate that your initial root token works, and your PingOne account is set up with an enrolled device, you can proceed to the scenario tasks.
Scenario tasks
Perform the scenario tasks as each persona to work through the scenario.
Enable username and password auth method
(As the admin persona)
Enable an instance of the username and password auth method using default path, and add the user persona as a user.
Enable the username and password auth method.
Set the username and password auth method accessor value in the USERPASS_ACCESSOR
environment variable for use in configuring the MFA method later.
Add the user persona alice
to the user name and password auth method.
Successful output:
Create an entity and alias
(As the admin persona)
You need to create an Identity secrets engine entity and alias to correspond to the user persona. You will later make use of this entity alias when configuring the MFA method.
For convenience the value of the entity ID will be set in the ENTITY_ID
environment variable.
Check that ENTITY_ID
contains the value.
Create the entity alias; remember that the name
value must match the name of both the entity you just created, and the user you created in PingID.
Successful output:
Tip
If you are unfamiliar with Identity, entities, and aliases, review the Identity: Entities and Groups tutorial.
Authenticate to Vault
(As the user persona)
Use the username and password auth method to authenticate to Vault.
Successful output:
You are successfully authenticated to Vault as the user persona, alice.
Notice that you are not yet prompted for any additional authentication methods.
Enable MFA method
(As the admin persona)
Now that the user persona can authenticate with the username and password auth method, let's enable the MFA method and create a login enforcement on the auth method.
First, you need to convert the PingOne pingid.properties
file that you downloaded earlier into a suitable base64 representation for use when configuring the MFA method. You can use the openssl
tool for this purpose.
Next, enable the MFA method.
Write the MFA configuration to enable it. For convenience and later reference, the method_id
value will be set in the environment variable METHOD_ID
.
IMPORTANT
in this example, the user is alice@example.com
, but your user persona's actual domain value should match the domain you used when signing up and creating your own account in PingID. If these values do not match, you will likely encounter a 'username may be incorrect' error.
The method_id
value is now set in the environment variable:
Note
If you encounter a permission denied error here, be sure to login again with the root token as previously directed.
Create login enforcement
Create a login enforcement by specifying the mfa_method_id
value and tie it to the username and password auth method by specifying the accessor as the value of auth_method_accessors
.
Successful output:
Note
The mfa_method_ids
parameter is an array. You can specify more than one MFA method, and they will be ORed together, meaning that a successful authentication from any of those methods will qualify as an acceptable additional factor.
There are other possible fields that can be used for specifying what to enforce the MFA method on as well: auth_method_types
, identity_group_ids
, or identity_entity_ids
. Review the MFA Login documentation for full details on how to use them.
Authenticate to Vault
Now that the MFA method is enabled, and the login enforcement for authentications against the username and password auth method is defined, try another authentication attempt with the auth method.
(As the user persona)
Use the username and password auth method to authenticate to Vault.
Sucessful output:
The CLI automatically passes the MFA method details during authentication. You should receive a push notification from PingID and as soon as you slide up to approve it, you will be authenticated and receive a token.
You should receive a push notification from the PingID application.
Use the PingID application to acknowledge the request.
The first authentication attempt demonstrates the response from Vault.
Authenticate again, but this time store the result in the environment variable MFA_REQID
:
Check the value of MFA_REQID
:
Use the PingID application to get a code for validating your Vault authentication attempt.
Note the passcode from your PingID application and set it as the value to the PCODE environment variable. For example, the value from the screenshot of the PingID application is used.
Validate the authentication.
You should receive a push notification from the PingID application.
Confirm the notification by sliding up in the application.
Successful output:
The authentication is successful and a Vault token is received.
Vault validates your authentication and returns a token.
This demonstrates the Two-Phase approach to using Vault MFA methods.
You can also use the Single-Phase approach, and include an MFA code with your initial authentication attempt. Review the Login MFA documentation to learn more.
Clean Up
Stop the Docker container.
Unalias the
vault
alias.Unset the environment variables.
Remove created files.
Summary
As the admin persona, you learned how to enable and configure Login MFA with the PingID 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.