blob: 2cdc2fa9d18d57f12e4a7a701cb9dd7e1ec03438 [file] [log] [blame]
Jesse Andrews73e27b82011-09-12 17:55:00 -07001#!/bin/bash
Dean Troyerb7d1fbb2012-03-02 08:43:09 -06002#
3# Initial data for Keystone using python-keystoneclient
4#
Dean Troyerb7d1fbb2012-03-02 08:43:09 -06005# Tenant User Roles
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +00006# ------------------------------------------------------------------
Dean Troyerb7d1fbb2012-03-02 08:43:09 -06007# admin admin admin
8# service glance admin
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +00009# service nova admin, [ResellerAdmin (swift only)]
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060010# service quantum admin # if enabled
11# service swift admin # if enabled
12# demo admin admin
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +000013# demo demo Member, anotherrole
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060014# invisible_to_admin demo Member
Jay Pipesb297d2d2012-05-10 11:21:22 -040015# Tempest Only:
16# alt_demo alt_demo Member
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060017#
18# Variables set before calling this script:
19# SERVICE_TOKEN - aka admin_token in keystone.conf
20# SERVICE_ENDPOINT - local Keystone admin endpoint
21# SERVICE_TENANT_NAME - name of tenant containing service accounts
22# ENABLED_SERVICES - stack.sh's list of services to start
23# DEVSTACK_DIR - Top-level DevStack directory
24
25ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete}
26SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000027export SERVICE_TOKEN=$SERVICE_TOKEN
28export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060029SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000030
31function get_id () {
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060032 echo `$@ | awk '/ id / { print $4 }'`
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000033}
34
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060035# Tenants
36ADMIN_TENANT=$(get_id keystone tenant-create --name=admin)
37SERVICE_TENANT=$(get_id keystone tenant-create --name=$SERVICE_TENANT_NAME)
38DEMO_TENANT=$(get_id keystone tenant-create --name=demo)
39INVIS_TENANT=$(get_id keystone tenant-create --name=invisible_to_admin)
termiea96a4182012-01-09 22:13:29 -080040
Jesse Andrews73e27b82011-09-12 17:55:00 -070041
42# Users
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060043ADMIN_USER=$(get_id keystone user-create --name=admin \
44 --pass="$ADMIN_PASSWORD" \
45 --email=admin@example.com)
46DEMO_USER=$(get_id keystone user-create --name=demo \
47 --pass="$ADMIN_PASSWORD" \
48 --email=demo@example.com)
Jesse Andrews73e27b82011-09-12 17:55:00 -070049
Dean Troyer0bd24102012-03-08 00:33:54 -060050
Jesse Andrews73e27b82011-09-12 17:55:00 -070051# Roles
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060052ADMIN_ROLE=$(get_id keystone role-create --name=admin)
53KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin)
54KEYSTONESERVICE_ROLE=$(get_id keystone role-create --name=KeystoneServiceAdmin)
Anthony Youngae604982012-03-12 17:12:00 -070055# ANOTHER_ROLE demonstrates that an arbitrary role may be created and used
56# TODO(sleepsonthefloor): show how this can be used for rbac in the future!
57ANOTHER_ROLE=$(get_id keystone role-create --name=anotherrole)
termiea96a4182012-01-09 22:13:29 -080058
59
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060060# Add Roles to Users in Tenants
Everett Toewsa143e732012-05-08 22:13:08 +000061keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $ADMIN_TENANT
62keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $DEMO_TENANT
63keystone user-role-add --user_id $DEMO_USER --role_id $ANOTHER_ROLE --tenant_id $DEMO_TENANT
termiea96a4182012-01-09 22:13:29 -080064
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060065# TODO(termie): these two might be dubious
Everett Toewsa143e732012-05-08 22:13:08 +000066keystone user-role-add --user_id $ADMIN_USER --role_id $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT
67keystone user-role-add --user_id $ADMIN_USER --role_id $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT
Dean Troyerf4565c42012-02-23 11:21:10 -060068
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060069
70# The Member role is used by Horizon and Swift so we need to keep it:
71MEMBER_ROLE=$(get_id keystone role-create --name=Member)
Everett Toewsa143e732012-05-08 22:13:08 +000072keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $DEMO_TENANT
73keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $INVIS_TENANT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060074
Jesse Andrews73e27b82011-09-12 17:55:00 -070075
Anthony Younge2d139b2012-03-09 15:47:28 -080076# Configure service users/roles
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060077NOVA_USER=$(get_id keystone user-create --name=nova \
78 --pass="$SERVICE_PASSWORD" \
79 --tenant_id $SERVICE_TENANT \
80 --email=nova@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -060081keystone user-role-add --tenant_id $SERVICE_TENANT \
Everett Toewsa143e732012-05-08 22:13:08 +000082 --user_id $NOVA_USER \
83 --role_id $ADMIN_ROLE
termiea96a4182012-01-09 22:13:29 -080084
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060085GLANCE_USER=$(get_id keystone user-create --name=glance \
86 --pass="$SERVICE_PASSWORD" \
87 --tenant_id $SERVICE_TENANT \
88 --email=glance@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -060089keystone user-role-add --tenant_id $SERVICE_TENANT \
Everett Toewsa143e732012-05-08 22:13:08 +000090 --user_id $GLANCE_USER \
91 --role_id $ADMIN_ROLE
Vishvananda Ishaya5f9473e2012-02-24 01:57:07 +000092
Jesse Andrews9c7c9082011-11-23 10:10:53 -080093if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060094 SWIFT_USER=$(get_id keystone user-create --name=swift \
95 --pass="$SERVICE_PASSWORD" \
96 --tenant_id $SERVICE_TENANT \
97 --email=swift@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -060098 keystone user-role-add --tenant_id $SERVICE_TENANT \
Everett Toewsa143e732012-05-08 22:13:08 +000099 --user_id $SWIFT_USER \
100 --role_id $ADMIN_ROLE
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +0000101 # Nova needs ResellerAdmin role to download images when accessing
102 # swift through the s3 api. The admin role in swift allows a user
103 # to act as an admin for their tenant, but ResellerAdmin is needed
104 # for a user to act as any tenant. The name of this role is also
105 # configurable in swift-proxy.conf
106 RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin)
107 keystone user-role-add --tenant_id $SERVICE_TENANT \
Everett Toewsa143e732012-05-08 22:13:08 +0000108 --user_id $NOVA_USER \
109 --role_id $RESELLER_ROLE
Jesse Andrews9c7c9082011-11-23 10:10:53 -0800110fi
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600111
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800112if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600113 QUANTUM_USER=$(get_id keystone user-create --name=quantum \
114 --pass="$SERVICE_PASSWORD" \
115 --tenant_id $SERVICE_TENANT \
116 --email=quantum@example.com)
Dean Troyerb3288382012-02-28 16:41:10 -0600117 keystone user-role-add --tenant_id $SERVICE_TENANT \
Everett Toewsa143e732012-05-08 22:13:08 +0000118 --user_id $QUANTUM_USER \
119 --role_id $ADMIN_ROLE
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800120fi
Jay Pipesb297d2d2012-05-10 11:21:22 -0400121
122if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
123 # Tempest has some tests that validate various authorization checks
124 # between two regular users in separate tenants
125 ALT_DEMO_TENANT=$(get_id keystone tenant-create --name=alt_demo)
126 ALT_DEMO_USER=$(get_id keystone user-create --name=alt_demo \
127 --pass="$ADMIN_PASSWORD" \
128 --email=alt_demo@example.com)
129 keystone user-role-add --user $ALT_DEMO_USER --role $MEMBER_ROLE --tenant_id $ALT_DEMO_TENANT
130fi