Skip to content

Instantly share code, notes, and snippets.

@rigelreyes
Last active November 15, 2019 02:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rigelreyes/5d4c3c776823f0513aed13cf2f2120d5 to your computer and use it in GitHub Desktop.
Save rigelreyes/5d4c3c776823f0513aed13cf2f2120d5 to your computer and use it in GitHub Desktop.
Vault Enterpise Training
path "db_rsa_key/*" {
capabilities = ["read", "list"]
}
{
"policy": "path \"db_rsa_key/*\" { capabilities = [\"read\", \"list\"]}"
}
{
"value": [
"andrea_rsa",
"cipol"
]
}
#! /bin/bash auth_test_cli.sh
# Set env variable
export VAULT_ADDR=http://127.0.0.1:8200
export VAULT_TOKEN=AddYourVaultTokenHere
# Enable Transit db_rsa_key in root namespace
vault secrets enable -path=db_rsa_key transit
vault secrets list
vault create namespace ci
vault namespace list
# Enable LDAP and GitHub
vault auth enable ldap
vault auth enable github
vault auth list
# Create a new policy in db_rsa_key for Andrea
vault policy write andrea_rsa andrea_rsa_pol.hcl
vault policy list
# Create policy for CI namespace
export VAULT_NAMESPACE=ci
vault policy write cipol ci_pol.hcl
# Assign rsa and ci policy to Andrea on LDAP
vault write auth/ldap/users/andrea policies=andrea_rsa,cipol
vault read auth/ldap/users/andrea
# Assign rsa and ci policy to Andrea on GitHub
vault write auth/github/map/users/andrea value=andrea_rsa,cipol
vault read auth/github/map/users/andrea
#! /bin/bash auth_test_curl.sh
# Set env variable
export VAULT_ADDR=http://127.0.0.1:8200
export VAULT_TOKEN=AddYourVaultTokenHere
# Enable Transit db_rsa_key in root namespace
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--request POST \
--data @db_rsa_key.json \
$VAULT_ADDR/v1/sys/mounts/db_rsa_key
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
$VAULT_ADDR/v1/sys/mounts \
| jq
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--request POST \
$VAULT_ADDR/v1/sys/namespaces/ci
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
-X LIST \
$VAULT_ADDR/v1/sys/namespaces \
| jq
# Enable LDAP and GitHub
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--request POST \
--data @enable_ldap.json \
$VAULT_ADDR/v1/sys/auth/ldap
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--request POST \
--data @enable_github.json \
$VAULT_ADDR/v1/sys/auth/github
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
$VAULT_ADDR/v1/sys/auth \
| jq
# Create a new policy in db_rsa_key for Andrea
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--request PUT \
--data @andrea_rsa_pol.json \
$VAULT_ADDR/v1/sys/policies/acl/andrea_rsa
curl \
-X LIST \
--header "X-Vault-Token: $VAULT_TOKEN" \
$VAULT_ADDR/v1/sys/policies/acl \
| jq
# Create policy for CI namespace
export VAULT_NAMESPACE=ci
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--header "X-Vault-Namespace: $VAULT_NAMESPACE" \
--request PUT \
--data @ci_pol.json \
$VAULT_ADDR/v1/sys/policies/acl/cipol
# Assign rsa and ci policy to Andrea on LDAP
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--request POST \
--data @assign_pol.json \
$VAULT_ADDR/v1/auth/ldap/users/andrea
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
$VAULT_ADDR/v1/auth/ldap/users/andrea
# Assign rsa and ci policy to Andrea on GitHub
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
--request POST \
--data @assign_pol.json \
$VAULT_ADDR/v1/auth/ldap/map/users/andrea
curl \
--header "X-Vault-Token: $VAULT_TOKEN" \
$VAULT_ADDR/v1/auth/github/map/users/andrea
# Manage namespaces
path "sys/namespaces/*" {
capabilities = ["create", "read", "update", "delete", "list", "sudo"]
}
# Manage policies
path "sys/policies/acl/*" {
capabilities = ["create", "read", "update", "delete", "list", "sudo"]
}
# List policies
path "sys/policies/acl" {
capabilities = ["list"]
}
# Enable and manage secrets engines
path "sys/mounts/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}
# List available secrets engines
path "sys/mounts" {
capabilities = [ "read" ]
}
{
"policy": "path \"sys/namespaces/*\" { capabilities = [\"create\", \"read\", \"update\", \"delete\", \"list\", \"sudo\"]}path \"sys/policies/acl/*\" { capabilities = [\"read\", \"update\", \"list\", \"sudo\"]}path \"sys/policies/acl\" { capabilities = [\"list\"]}path \"sys/mounts/*\" { capabilities = [\"create\", \"read\", \"update\", \"delete\", \"list\"]}path \"sys/mounts\" { capabilities = [ \"read\" ]}"
}
{
"type": "transit"
}
{
"type": "github",
"description": "Login with GitHub"
}
{
"type": "github",
"description": "Login with GitHub"
}
@v6
Copy link

v6 commented Nov 14, 2019

@rigelreyes could you please include a README.md with this?

And include the .hcl versions of the Vault policies?

Might be worth using a regular gitlab repo for the sake of organization and accepting pull requests.

@v6
Copy link

v6 commented Nov 14, 2019

@bernardogza, could you review this, and perhaps set up a time to show Rigel and Rambabu how you handled this?

@rigelreyes
Copy link
Author

@v6 I included the hcl files here too, can you give me access to the vault-training repo in GitLab?

@v6
Copy link

v6 commented Nov 15, 2019

Sure @rigelreyes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment