HashiCorp Vault is an identity-based secrets and encryption management system. A secret is anything that you want to tightly control access to, such as API encryption keys, passwords, and certificates. Vault provides encryption services that are gated by authentication and authorization methods. Using Vault’s UI, CLI, or HTTP API, access to secrets and other sensitive data can be securely stored and managed, tightly controlled (restricted), and auditable.
Sealing and unsealing are important concepts in Vault. When a Vault server is started, it starts in a sealed state. In this state, Vault is configured to know where and how to access the physical storage, but doesn’t know how to decrypt any of it. Unsealing is the process of obtaining the plaintext root key necessary to read the decryption key to decrypt the data, allowing access to the Vault1.
Once a Vault node is unsealed, it remains unsealed until one of these things happens: It is resealed via the API (see below). The server is restarted.
If you encounter an error, use the command below
sudo apt install gnupg
gpg --keyserver keyserver.ubuntu.com --recv-keys AA16FCBCA621E701
gpg --export --armor AA16FCBCA621E701 | sudo apt-key add -
sudo apt update
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
apt update
apt install vaultsystemctl status vault.serviceCGroup: /system.slice/vault.service
└─5547 /usr/bin/vault server -config=/etc/vault.d/vault.hcl
ui = true
storage "file" {
path = "/opt/vault/data"
}
# HTTP listener
listener "tcp" {
address = "127.0.0.1:8200"
tls_disable = 1
}server {
listen 80;
server_name Zakops.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name Zakops.com;
ssl_certificate /opt/vault/tls/tls.crt;
ssl_certificate_key /opt/vault/tls/tls.key;
access_log /var/log/nginx/domains/vault/access.log;
error_log /var/log/nginx/domains/vault/error.log;
location / {
proxy_pass http://127.0.0.1:8200;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Ho to use Web UI: https://YourDomain.com
- key shares : 7
- Key threshold : 5
- Encrypt Output with PGP: Use this option to encrypt the keys generated by Vault using your PGP key
- Encrypt Root Token with PGP: Use this option to encrypt only the root token generated by Vault using your PGP key
- Click "Initialize" and download the xxx.json file
- Access
- Authentication Methods
- Enable new method
- Fill in the username and password section
- Change Path
- Select the 'List Method' when unauthenticated
- Enable method
- Access
- Authentication Methods
- Select your method
- Create user
- Fill in the username and password
- Save
- Policies
- Create ACL policy
- Fill in the name and policy Example : User access to change their password and revoke their own token
path "auth/token/create" {
capabilities = ["create", "update"]
}
path "auth/userpass/users/{{identity.entity.aliases.auth_userpass_86b9cc68.name}}/password" {
capabilities = ["update"]
}whats this auth_userpass_86b9cc68 ??
vault auth listCheck the Accessor field
- Access
- Entities
- Select the entity, then check under the Aliases tab to ensure the correct user has been selected
- Edit the entity
- Change the name to the username
- Search for the policy in the Policies box, then select it
- Access
- Groups
- Create a Group
- Set Name to devops
- Set Type to internal
- Select Policies
- Select Member Entity IDs
- Create
- Secrets Engines
- Enable new engine
- Select KV
- Edit the Path (e.g., servers) and set the Maximum number of versions to 3
- Enable engine
- Secrets Engines
- Select your created engine
- Create Secret
- Edit the Path for this secret (e.g., zakops)
- Fill in the Secret data
- save
- Secrets Engines
- servers
- zakops
- Secret
- Create new Version
- Add or edit key-values
- save
- Secrets Engines
- Enable new engine
- SSH
- Change the Default Lease TTL and Max Lease TTL
- Enable engine
At this stage, by checking the 'Generate signing key' option, a public key will be generated for you, which you need to place on all the hosts you want to SSH into. Alternatively, if you uncheck the 'Generate signing key' option, you can manually enter your own public and private keys. In this case, make sure to place your public key on all the servers.
- Secrets Engines
- ssh
- configuration
- configure
- Add the private key and public key
- Unselect Generate signing key
- save
- Using the command below, copy your public key into the specified file. If the file does not exist, create it manually and paste public key
vim /etc/ssh/trusted-user-ca-keys.pub- Now, modify the sshd_config file as follows
PubkeyAuthentication yes
TrustedUserCAKeys /etc/ssh/trusted-user-ca-keys.pub
- Finally, restart the SSH service
systemctl restart sshd- Create role
- Set the Key type to ca
- Check Allow user certificates
- Check Allow host certificates
- Set Allowed users to zak
- Change TTL and Max TTL to 1 day
- Set Allowed extensions to permit-pty, permit-port-forwarding
- Configure Default Extensions as Follows
{
"permit-pty": ""
}- Change the "Not before duration" to 1 day
- Select 'Default' for the Signing Algorithm (supports RSA and ED)
- save
- Secrets Engines
- ssh
- zak
- Select the [...] option on the right side
- Sign Keys
- Add your Public Key
- Set Valid principals to zak (as specified in the previous step under Allowed users )
- Set Certificate Type to user
- Configure Extensions as Follows
{
"permit-pty": ""
}- Change the TTL to 1 day
- Copy the signed key and heed the warning
- Paste the signed key into a file. For example: vault.pub
- Use your private key. For example: id_ed25519
- Connect to the host using the following command
ssh -i id_ed25519 -o CertificateFile=vault.pub zak@yourhost -p port- Policies
- Create ACL Policy
- Add a name
- Add the following policy
path "identity/mfa/method/totp/*" {
capabilities = ["update"]
}- Create policy
- Assign this policy to users or groups