hashicorp identity code example
Example: Identities entities in vault hashicorp
$ vault policy write base - << EOF
path "secret/data/training_*" {
capabilities = ["create", "read"]
}
EOF
$ vault policy write test - << EOF
path "secret/data/test" {
capabilities = [ "create", "read", "update", "delete" ]
}
EOF
$ vault policy write team-qa - << EOF
path "secret/data/team-qa" {
capabilities = [ "create", "read", "update", "delete" ]
}
EOF
$ vault write auth/userpass/users/bob password="training" policies="test"
$ vault write auth/userpass/users/bsmith password="training" policies="team-qa"
$ vault auth list -detailed
$ vault auth list -format=json | jq -r '.["userpass/"].accessor' > accessor.txt
$ vault write identity/entity name="bob-smith" policies="base" \
metadata=organization="ACME Inc." \
metadata=team="QA"
$ vault write identity/entity-alias name="bob" canonical_id=<ENTITY_ID from above> \
mount_accessor=$(cat accessor.txt)
$ vault write identity/entity-alias name="bsmith" canonical_id=<ENTITY_ID from above> \
mount_accessor=$(cat accessor.txt)
$ vault read identity/entity/id/<ENTITY_ID>
$ vault read identity/entity/name/bob-smith
$ vault secrets enable -path=secret kv-v2
$ vault login -method=userpass username=bob password=training
$ vault kv put secret/test owner="bob"
$ vault token capabilities secret/data/training_test
1. Create internal group
2. Add Entity to group along with users added as alias in entity
$ vault policy write team-eng - << EOF
path "secret/data/team/eng" {
capabilities = [ "create", "read", "update", "delete"]
}
EOF
$ vault write identity/group name="engineers" \
policies="team-eng" \
member_entity_ids=<entity_id> \
metadata=team="Engineering" \
metadata=region="India"