Advertisement
Guest User

Untitled

a guest
Mar 27th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Initial data for Keystone using python-keystoneclient
  4. #
  5. # Tenant User Roles
  6. # ------------------------------------------------------------------
  7. # admin admin admin
  8. # service glance admin
  9. # service nova admin, [ResellerAdmin (swift only)]
  10. # service quantum admin # if enabled
  11. # service swift admin # if enabled
  12. # demo admin admin
  13. # demo demo Member, anotherrole
  14. # invisible_to_admin demo Member
  15. #
  16. # Variables set before calling this script:
  17. # SERVICE_TOKEN - aka admin_token in keystone.conf
  18. # SERVICE_ENDPOINT - local Keystone admin endpoint
  19. # SERVICE_TENANT_NAME - name of tenant containing service accounts
  20. # ENABLED_SERVICES - stack.sh's list of services to start
  21. # DEVSTACK_DIR - Top-level DevStack directory
  22.  
  23. ADMIN_PASSWORD="secretword"
  24. SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD}
  25. export SERVICE_TOKEN="11223344"
  26. export SERVICE_ENDPOINT="http://localhost:35357/v2.0"
  27. SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
  28.  
  29. function get_id( ){
  30. echo `$@ | awk '/ id / { print $4 }'`
  31. }
  32.  
  33. # Tenants
  34. ADMIN_TENANT=$(get_id keystone tenant-create --name=admin)
  35. SERVICE_TENANT=$(get_id keystone tenant-create --name=$SERVICE_TENANT_NAME)
  36. DEMO_TENANT=$(get_id keystone tenant-create --name=demo)
  37. INVIS_TENANT=$(get_id keystone tenant-create --name=invisible_to_admin)
  38.  
  39.  
  40. # Users
  41. ADMIN_USER=$(get_id keystone user-create --name=admin \
  42. --pass="$ADMIN_PASSWORD" \
  43. DEMO_USER=$(get_id keystone user-create --name=demo \
  44. --pass="$ADMIN_PASSWORD" \
  45.  
  46.  
  47. # Roles
  48. ADMIN_ROLE=$(get_id keystone role-create --name=admin)
  49. KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin)
  50. KEYSTONESERVICE_ROLE=$(get_id keystone role-create --name=KeystoneServiceAdmin)
  51. # ANOTHER_ROLE demonstrates that an arbitrary role may be created and used
  52. # TODO(sleepsonthefloor): show how this can be used for rbac in the future!
  53. ANOTHER_ROLE=$(get_id keystone role-create --name=anotherrole)
  54.  
  55.  
  56. # Add Roles to Users in Tenants
  57. keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $ADMIN_TENANT
  58. keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $DEMO_TENANT
  59. keystone user-role-add --user $DEMO_USER --role $ANOTHER_ROLE --tenant_id $DEMO_TENANT
  60.  
  61. # TODO(termie): these two might be dubious
  62. keystone user-role-add --user $ADMIN_USER --role $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT
  63. keystone user-role-add --user $ADMIN_USER --role $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT
  64.  
  65.  
  66. # The Member role is used by Horizon and Swift so we need to keep it:
  67. MEMBER_ROLE=$(get_id keystone role-create --name=Member)
  68. keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $DEMO_TENANT
  69. keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $INVIS_TENANT
  70.  
  71.  
  72. # Configure service users/roles
  73. NOVA_USER=$(get_id keystone user-create --name=nova \
  74. --pass="$SERVICE_PASSWORD" \
  75. --tenant_id $SERVICE_TENANT \
  76. keystone user-role-add --tenant_id $SERVICE_TENANT \
  77. --user $NOVA_USER \
  78. --role $ADMIN_ROLE
  79.  
  80. GLANCE_USER=$(get_id keystone user-create --name=glance \
  81. --pass="$SERVICE_PASSWORD" \
  82. --tenant_id $SERVICE_TENANT \
  83. keystone user-role-add --tenant_id $SERVICE_TENANT \
  84. --user $GLANCE_USER \
  85. --role $ADMIN_ROLE
  86.  
  87. if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
  88. SWIFT_USER=$(get_id keystone user-create --name=swift \
  89. --pass="$SERVICE_PASSWORD" \
  90. --tenant_id $SERVICE_TENANT \
  91. keystone user-role-add --tenant_id $SERVICE_TENANT \
  92. --user $SWIFT_USER \
  93. --role $ADMIN_ROLE
  94. # Nova needs ResellerAdmin role to download images when accessing
  95. # swift through the s3 api. The admin role in swift allows a user
  96. # to act as an admin for their tenant, but ResellerAdmin is needed
  97. # for a user to act as any tenant. The name of this role is also
  98. # configurable in swift-proxy.conf
  99. RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin)
  100. keystone user-role-add --tenant_id $SERVICE_TENANT \
  101. --user $NOVA_USER \
  102. --role $RESELLER_ROLE
  103. fi
  104.  
  105. if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then
  106. QUANTUM_USER=$(get_id keystone user-create --name=quantum \
  107. --pass="$SERVICE_PASSWORD" \
  108. --tenant_id $SERVICE_TENANT \
  109. keystone user-role-add --tenant_id $SERVICE_TENANT \
  110. --user $QUANTUM_USER \
  111. --role $ADMIN_ROLE
  112. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement