In this lab, we will need to set up a web application and configure it to use HashiCorp vault for authentication, without storing user credentials to a local database.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Unseal the Vault and Login with the Root Token
- In the Vault Server, retrieve the vault keys.
- Unseal the vault.
- Log in with the
Initial Root Token
.
- Enable Kv Secrets Engine and Create a Token with a Policy That Allows Access to It
- Enable
kv
secrets engine. - Start
python3.6
. - In the Python Interactive Console, create a hash.
- Copy the hash.
- Write a key-value secret using the email and hash.
- Create a
policy
file namedweb-policy.hcl
, and give itread
permissions. - Write the
policy
. - Create a
token
with the newpolicy
. - Copy the
client_token
- Test out the token.
- Enable
- Install `pip for python3`, the `Django` framework, and Allow the Web Server to Access the App
- Clone the Git repository.
- Install
python3-pip
. - Using
pip3
, install theDjango
framework. - Open the
settings.py
file. - Add the
Web Server
public IP address to theALLOWED_HOSTS
. - Save the file.
- Open the
views.py
file. - In the
get_hashed_vault_creds()
function, change theurl
andhdr
. - Save the file.
- Change to the
HashiCorp-Vault/
directory. - Run the django app.
- Open a web browser, go to 0.0.0.0:8080, and test the login.