blob: 7da07aaa9fe7f9cd59cba35d76f3e4882c8aab72 [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
Dean Troyer67787e62012-05-02 11:48:15 -050012# service cinder admin # if enabled
Steve Bakerbfdad752012-08-18 09:00:42 +120013# service heat admin # if enabled
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060014# demo admin admin
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +000015# demo demo Member, anotherrole
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060016# invisible_to_admin demo Member
Jay Pipesb297d2d2012-05-10 11:21:22 -040017# Tempest Only:
18# alt_demo alt_demo Member
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060019#
20# Variables set before calling this script:
21# SERVICE_TOKEN - aka admin_token in keystone.conf
22# SERVICE_ENDPOINT - local Keystone admin endpoint
23# SERVICE_TENANT_NAME - name of tenant containing service accounts
Dean Troyer3f7c06f2012-04-03 17:19:36 -050024# SERVICE_HOST - host used for endpoint creation
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060025# ENABLED_SERVICES - stack.sh's list of services to start
26# DEVSTACK_DIR - Top-level DevStack directory
Dean Troyer3f7c06f2012-04-03 17:19:36 -050027# KEYSTONE_CATALOG_BACKEND - used to determine service catalog creation
28
29# Defaults
30# --------
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060031
32ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete}
33SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000034export SERVICE_TOKEN=$SERVICE_TOKEN
35export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060036SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000037
38function get_id () {
Dean Troyer3f7c06f2012-04-03 17:19:36 -050039 echo `"$@" | awk '/ id / { print $4 }'`
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000040}
41
Dean Troyer3f7c06f2012-04-03 17:19:36 -050042
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060043# Tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -050044# -------
45
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060046ADMIN_TENANT=$(get_id keystone tenant-create --name=admin)
47SERVICE_TENANT=$(get_id keystone tenant-create --name=$SERVICE_TENANT_NAME)
48DEMO_TENANT=$(get_id keystone tenant-create --name=demo)
49INVIS_TENANT=$(get_id keystone tenant-create --name=invisible_to_admin)
termiea96a4182012-01-09 22:13:29 -080050
Jesse Andrews73e27b82011-09-12 17:55:00 -070051
52# Users
Dean Troyer3f7c06f2012-04-03 17:19:36 -050053# -----
54
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060055ADMIN_USER=$(get_id keystone user-create --name=admin \
56 --pass="$ADMIN_PASSWORD" \
57 --email=admin@example.com)
58DEMO_USER=$(get_id keystone user-create --name=demo \
59 --pass="$ADMIN_PASSWORD" \
60 --email=demo@example.com)
Jesse Andrews73e27b82011-09-12 17:55:00 -070061
Dean Troyer0bd24102012-03-08 00:33:54 -060062
Jesse Andrews73e27b82011-09-12 17:55:00 -070063# Roles
Dean Troyer3f7c06f2012-04-03 17:19:36 -050064# -----
65
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060066ADMIN_ROLE=$(get_id keystone role-create --name=admin)
67KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin)
68KEYSTONESERVICE_ROLE=$(get_id keystone role-create --name=KeystoneServiceAdmin)
Anthony Youngae604982012-03-12 17:12:00 -070069# ANOTHER_ROLE demonstrates that an arbitrary role may be created and used
70# TODO(sleepsonthefloor): show how this can be used for rbac in the future!
71ANOTHER_ROLE=$(get_id keystone role-create --name=anotherrole)
termiea96a4182012-01-09 22:13:29 -080072
73
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060074# Add Roles to Users in Tenants
Everett Toewsa143e732012-05-08 22:13:08 +000075keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $ADMIN_TENANT
76keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $DEMO_TENANT
77keystone user-role-add --user_id $DEMO_USER --role_id $ANOTHER_ROLE --tenant_id $DEMO_TENANT
termiea96a4182012-01-09 22:13:29 -080078
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060079# TODO(termie): these two might be dubious
Everett Toewsa143e732012-05-08 22:13:08 +000080keystone user-role-add --user_id $ADMIN_USER --role_id $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT
81keystone user-role-add --user_id $ADMIN_USER --role_id $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT
Dean Troyerf4565c42012-02-23 11:21:10 -060082
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060083
84# The Member role is used by Horizon and Swift so we need to keep it:
85MEMBER_ROLE=$(get_id keystone role-create --name=Member)
Everett Toewsa143e732012-05-08 22:13:08 +000086keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $DEMO_TENANT
87keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $INVIS_TENANT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060088
Jesse Andrews73e27b82011-09-12 17:55:00 -070089
Dean Troyer3f7c06f2012-04-03 17:19:36 -050090# Services
91# --------
termiea96a4182012-01-09 22:13:29 -080092
Dean Troyer3f7c06f2012-04-03 17:19:36 -050093# Keystone
94if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
95 KEYSTONE_SERVICE=$(get_id keystone service-create \
96 --name=keystone \
97 --type=identity \
98 --description="Keystone Identity Service")
99 keystone endpoint-create \
100 --region RegionOne \
101 --service_id $KEYSTONE_SERVICE \
102 --publicurl "http://$SERVICE_HOST:\$(public_port)s/v2.0" \
103 --adminurl "http://$SERVICE_HOST:\$(admin_port)s/v2.0" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200104 --internalurl "http://$SERVICE_HOST:\$(public_port)s/v2.0"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500105fi
Vishvananda Ishaya5f9473e2012-02-24 01:57:07 +0000106
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500107# Nova
108if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
109 NOVA_USER=$(get_id keystone user-create \
110 --name=nova \
111 --pass="$SERVICE_PASSWORD" \
112 --tenant_id $SERVICE_TENANT \
113 --email=nova@example.com)
114 keystone user-role-add \
115 --tenant_id $SERVICE_TENANT \
116 --user_id $NOVA_USER \
117 --role_id $ADMIN_ROLE
118 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
119 NOVA_SERVICE=$(get_id keystone service-create \
120 --name=nova \
121 --type=compute \
122 --description="Nova Compute Service")
123 keystone endpoint-create \
124 --region RegionOne \
125 --service_id $NOVA_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200126 --publicurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
127 --adminurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
128 --internalurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500129 fi
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +0000130 # Nova needs ResellerAdmin role to download images when accessing
131 # swift through the s3 api. The admin role in swift allows a user
132 # to act as an admin for their tenant, but ResellerAdmin is needed
133 # for a user to act as any tenant. The name of this role is also
134 # configurable in swift-proxy.conf
135 RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin)
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500136 keystone user-role-add \
137 --tenant_id $SERVICE_TENANT \
138 --user_id $NOVA_USER \
139 --role_id $RESELLER_ROLE
Jesse Andrews9c7c9082011-11-23 10:10:53 -0800140fi
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600141
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500142# Volume
143if [[ "$ENABLED_SERVICES" =~ "n-vol" ]]; then
144 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
145 VOLUME_SERVICE=$(get_id keystone service-create \
146 --name=volume \
147 --type=volume \
148 --description="Volume Service")
149 keystone endpoint-create \
150 --region RegionOne \
151 --service_id $VOLUME_SERVICE \
152 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
153 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
154 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
155 fi
156fi
157
Steve Bakerbfdad752012-08-18 09:00:42 +1200158# Heat
159if [[ "$ENABLED_SERVICES" =~ "heat" ]]; then
160 HEAT_USER=$(get_id keystone user-create --name=heat \
161 --pass="$SERVICE_PASSWORD" \
162 --tenant_id $SERVICE_TENANT \
163 --email=heat@example.com)
164 keystone user-role-add --tenant_id $SERVICE_TENANT \
165 --user_id $HEAT_USER \
166 --role_id $ADMIN_ROLE
167 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Baker36cf7ee2012-09-17 16:49:24 +1200168 HEAT_CFN_SERVICE=$(get_id keystone service-create \
Steve Bakerbb421be2012-10-10 13:19:10 +1300169 --name=heat-cfn \
170 --type=cloudformation \
171 --description="Heat CloudFormation Service")
Steve Bakerbfdad752012-08-18 09:00:42 +1200172 keystone endpoint-create \
173 --region RegionOne \
Angus Salkelde2790212012-09-11 11:24:09 +1000174 --service_id $HEAT_CFN_SERVICE \
175 --publicurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
176 --adminurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
177 --internalurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1"
Steve Bakerbb421be2012-10-10 13:19:10 +1300178 HEAT_SERVICE=$(get_id keystone service-create \
179 --name=heat \
180 --type=orchestration \
181 --description="Heat Service")
182 keystone endpoint-create \
183 --region RegionOne \
184 --service_id $HEAT_SERVICE \
185 --publicurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
186 --adminurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
187 --internalurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
Steve Bakerbfdad752012-08-18 09:00:42 +1200188 fi
189fi
190
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500191# Glance
192if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
193 GLANCE_USER=$(get_id keystone user-create \
194 --name=glance \
195 --pass="$SERVICE_PASSWORD" \
196 --tenant_id $SERVICE_TENANT \
197 --email=glance@example.com)
198 keystone user-role-add \
199 --tenant_id $SERVICE_TENANT \
200 --user_id $GLANCE_USER \
201 --role_id $ADMIN_ROLE
202 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
203 GLANCE_SERVICE=$(get_id keystone service-create \
204 --name=glance \
205 --type=image \
206 --description="Glance Image Service")
207 keystone endpoint-create \
208 --region RegionOne \
209 --service_id $GLANCE_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200210 --publicurl "http://$SERVICE_HOST:9292" \
211 --adminurl "http://$SERVICE_HOST:9292" \
212 --internalurl "http://$SERVICE_HOST:9292"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500213 fi
214fi
215
216# Swift
217if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
218 SWIFT_USER=$(get_id keystone user-create \
219 --name=swift \
220 --pass="$SERVICE_PASSWORD" \
221 --tenant_id $SERVICE_TENANT \
222 --email=swift@example.com)
223 keystone user-role-add \
224 --tenant_id $SERVICE_TENANT \
225 --user_id $SWIFT_USER \
226 --role_id $ADMIN_ROLE
227 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
228 SWIFT_SERVICE=$(get_id keystone service-create \
229 --name=swift \
230 --type="object-store" \
231 --description="Swift Service")
232 keystone endpoint-create \
233 --region RegionOne \
234 --service_id $SWIFT_SERVICE \
235 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200236 --adminurl "http://$SERVICE_HOST:8080" \
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500237 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
238 fi
239fi
240
241if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
242 QUANTUM_USER=$(get_id keystone user-create \
243 --name=quantum \
244 --pass="$SERVICE_PASSWORD" \
245 --tenant_id $SERVICE_TENANT \
246 --email=quantum@example.com)
247 keystone user-role-add \
248 --tenant_id $SERVICE_TENANT \
249 --user_id $QUANTUM_USER \
250 --role_id $ADMIN_ROLE
251 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
252 QUANTUM_SERVICE=$(get_id keystone service-create \
253 --name=quantum \
254 --type=network \
255 --description="Quantum Service")
256 keystone endpoint-create \
257 --region RegionOne \
258 --service_id $QUANTUM_SERVICE \
259 --publicurl "http://$SERVICE_HOST:9696/" \
260 --adminurl "http://$SERVICE_HOST:9696/" \
261 --internalurl "http://$SERVICE_HOST:9696/"
262 fi
263fi
264
265# EC2
266if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
267 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
268 EC2_SERVICE=$(get_id keystone service-create \
269 --name=ec2 \
270 --type=ec2 \
271 --description="EC2 Compatibility Layer")
272 keystone endpoint-create \
273 --region RegionOne \
274 --service_id $EC2_SERVICE \
275 --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \
276 --adminurl "http://$SERVICE_HOST:8773/services/Admin" \
277 --internalurl "http://$SERVICE_HOST:8773/services/Cloud"
278 fi
279fi
280
281# S3
282if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift" ]]; then
283 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
284 S3_SERVICE=$(get_id keystone service-create \
285 --name=s3 \
286 --type=s3 \
287 --description="S3")
288 keystone endpoint-create \
289 --region RegionOne \
290 --service_id $S3_SERVICE \
291 --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
292 --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
293 --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT"
294 fi
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800295fi
Jay Pipesb297d2d2012-05-10 11:21:22 -0400296
297if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
298 # Tempest has some tests that validate various authorization checks
299 # between two regular users in separate tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500300 ALT_DEMO_TENANT=$(get_id keystone tenant-create \
301 --name=alt_demo)
302 ALT_DEMO_USER=$(get_id keystone user-create \
303 --name=alt_demo \
304 --pass="$ADMIN_PASSWORD" \
305 --email=alt_demo@example.com)
306 keystone user-role-add \
307 --tenant_id $ALT_DEMO_TENANT \
308 --user_id $ALT_DEMO_USER \
309 --role_id $MEMBER_ROLE
Jay Pipesb297d2d2012-05-10 11:21:22 -0400310fi
Dean Troyer67787e62012-05-02 11:48:15 -0500311
Chmouel Boudjnahd55509d2012-07-20 15:00:02 +0000312if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Dean Troyer67787e62012-05-02 11:48:15 -0500313 CINDER_USER=$(get_id keystone user-create --name=cinder \
314 --pass="$SERVICE_PASSWORD" \
315 --tenant_id $SERVICE_TENANT \
316 --email=cinder@example.com)
317 keystone user-role-add --tenant_id $SERVICE_TENANT \
318 --user_id $CINDER_USER \
319 --role_id $ADMIN_ROLE
Anthony Young1cdf5fa2012-07-03 13:57:39 -0700320 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
321 CINDER_SERVICE=$(get_id keystone service-create \
322 --name=cinder \
323 --type=volume \
324 --description="Cinder Service")
325 keystone endpoint-create \
326 --region RegionOne \
327 --service_id $CINDER_SERVICE \
328 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
329 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
330 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
331 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500332fi
Steve Bakerbfdad752012-08-18 09:00:42 +1200333