Set of scripts to deploy locally, vault and configure TLS server and user certificates for testing TLS AUTH.
credit to @reard3n (https://github.com/reard3n) and @v6 (https://github.com/v6) for the gist this grew from
This was tested using Vagrant and Ubuntu
- On the OS of your choice copy VaultCASetup.sh script locally and update any variables that would be specific to your environment and/or version of Vault you want to test against.
- Copy vaultCAuser.sh scripts locally, also updating any variables that you want to change and run. This creates a separate user cert, signed by the initial "server" certificate created in step 1.
nohup vault server -dev -config=vault.hcl > vault_verbose.log &
export VAULT_ADDR="https://vault.testdomain.local:8500"
TOKEN=$(grep "Root Token" vault_verbose.log | cut -c 12-)
now you can run vault login $TOKEN
to login as root
Enable the TLS Certificates Auth Method
vault auth enable cert
Create the "web" user certificate - simulates giving specific access to only a web app
vault write auth/cert/certs/web display_name=webcert policies=default,web [email protected] ttl=3600
Create the "app" user certificate - simulates giving specific access to only an application
vault write auth/cert/certs/app display_name=appcert policies=default,app [email protected] ttl=3600
You can either download and run create_policies.sh or copy below to create the unique policies.
Web Policy:
vault policy write web -<<EOF
path "secret/web" {
capabilities = ["read", "create", "update"]
}
path "secret/data/web" {
capabilities = ["read", "create", "update"]
}
EOF
App Policy:
vault policy write app -<<EOF
path "secret/app" {
capabilities = ["read", "create", "update"]
}
path "secret/data/app" {
capabilities = ["read", "create", "update"]
}
EOF
Confirm the policy is stored:
vault policy read web
vault policy read app
output would be similar to :
vault policy read web
path "secret/web" {
capabilities = ["read", "create", "update"]
}
path "secret/data/web" {
capabilities = ["read", "create", "update"]
}
Create some secrets:
vault kv put secret/web password=webPassword
vault kv put secret/app password=appPassword
attempt a login using the user certificate we created above (Web)
vault login -ca-cert=certAuth.pem -method=cert -client-cert=user.crt -client-key=user.key name=web
Investigate your token properties:
vault token lookup
Try to read the web secret:
vault kv get secret/web
Try to update the web secret:
vault kv put secret/web password=updateWebPassword
Try to read the app secret:
vault kv get secret/app
(note - this should error)
Try to update the app secret:
vault kv put secret/app testing=thisShouldFail
attempt a login using the user certificate we created above (App)
vault login -ca-cert=certAuth.pem -method=cert -client-cert=user_app.crt -client-key=user_app.key name=app
Investigate your token properties:
vault token lookup
Try to read the web secret:
vault kv get secret/web
(note - this should error)
Try to update the web secret:
vault kv put secret/web password=thisShouldFail
Try to read the app secret:
vault kv get secret/app
Try to update the app secret:
vault kv put secret/app password=
vault login -ca-cert=certAuth.pem -method=cert -client-cert=user_app.crt -client-key=user_app.key name=app