Guest User

Untitled

a guest
Aug 27th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #!/bin/bash
  2. set -aex
  3.  
  4. # 2 items in this script are redacted
  5.  
  6. # Enable Okta backend
  7. vault auth-enable okta
  8.  
  9. # Get the mount accessor of okta
  10. oktaMountAccessor=$(vault auth list -detailed -format json | jq -r '.["okta/"].accessor')
  11.  
  12. # Configure okta mount with policies and users
  13. vault write auth/okta/config org_name=dev-511503-admin api_token=<redacted> base_url=oktapreview.com
  14. vault write auth/okta/groups/testgroup policies=okta-group-policy
  15. vault write auth/okta/users/vishalnayakv@gmail.com groups=testgroup policies=okta-user-policy
  16.  
  17. # Create an external group in root namespace
  18. extGroupID=$(vault write -format json identity/group type=external policies=ext-okta-group-policy | jq -r '.data.id')
  19.  
  20. # Attach a group alias to the external group that points to 'testgroup' in okta
  21. vault write identity/group-alias mount_accessor=$oktaMountAccessor canonical_id=$extGroupID name=testgroup
  22.  
  23. # Create a namespace
  24. vault namespace create testns
  25.  
  26. # Create a resource in the namespace
  27. vault secrets enable -namespace testns -version=2 kv
  28.  
  29. # Write a secret in it
  30. vault kv put -ns testns kv/foo bar=baz
  31.  
  32. # Create a policy in testns that grants read access to this secret
  33. vault policy write -ns testns testns-policy - <<EOF
  34. path "kv/data/foo" {
  35. capabilities = ["read"]
  36. }
  37. EOF
  38.  
  39. # Create an internal group in testns; add the external group from root
  40. # namespace as its member; grant access to the namespace local resouce.
  41. nsIntGroupID=$(vault write -ns testns identity/group member_group_ids=$extGroupID policies=testns-policy)
  42.  
  43. # Login and create a token
  44. token=$(vault auth -format json -method=okta username=vishalnayakv@gmail.com password=<redacted> | jq -r '.auth.client_token')
  45.  
  46. VAULT_TOKEN=$token vault token lookup
  47.  
  48. # Access the namespace resource using the token from the root namespace
  49. VAULT_TOKEN=$token vault kv get -ns testns kv/foo
Add Comment
Please, Sign In to add comment