blob: 3da11bf0ed39657b32622c6e27523a2e0aa32cb4 [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#
Doug Hellmann4a2b1c62012-11-01 16:23:52 -04005# Tenant User Roles
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +00006# ------------------------------------------------------------------
Doug Hellmann4a2b1c62012-11-01 16:23:52 -04007# 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# service cinder admin # if enabled
13# service heat admin # if enabled
14# service ceilometer admin # if enabled
15# demo admin admin
16# demo demo Member, anotherrole
17# invisible_to_admin demo Member
Jay Pipesb297d2d2012-05-10 11:21:22 -040018# Tempest Only:
19# alt_demo alt_demo Member
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060020#
21# Variables set before calling this script:
22# SERVICE_TOKEN - aka admin_token in keystone.conf
23# SERVICE_ENDPOINT - local Keystone admin endpoint
24# SERVICE_TENANT_NAME - name of tenant containing service accounts
Dean Troyer3f7c06f2012-04-03 17:19:36 -050025# SERVICE_HOST - host used for endpoint creation
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060026# ENABLED_SERVICES - stack.sh's list of services to start
27# DEVSTACK_DIR - Top-level DevStack directory
Dean Troyer3f7c06f2012-04-03 17:19:36 -050028# KEYSTONE_CATALOG_BACKEND - used to determine service catalog creation
29
30# Defaults
31# --------
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060032
33ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete}
34SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000035export SERVICE_TOKEN=$SERVICE_TOKEN
36export SERVICE_ENDPOINT=$SERVICE_ENDPOINT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060037SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000038
39function get_id () {
Dean Troyer3f7c06f2012-04-03 17:19:36 -050040 echo `"$@" | awk '/ id / { print $4 }'`
Vishvananda Ishayad1f52432012-02-09 03:50:57 +000041}
42
Dean Troyer3f7c06f2012-04-03 17:19:36 -050043
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060044# Tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -050045# -------
46
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060047ADMIN_TENANT=$(get_id keystone tenant-create --name=admin)
48SERVICE_TENANT=$(get_id keystone tenant-create --name=$SERVICE_TENANT_NAME)
49DEMO_TENANT=$(get_id keystone tenant-create --name=demo)
50INVIS_TENANT=$(get_id keystone tenant-create --name=invisible_to_admin)
termiea96a4182012-01-09 22:13:29 -080051
Jesse Andrews73e27b82011-09-12 17:55:00 -070052
53# Users
Dean Troyer3f7c06f2012-04-03 17:19:36 -050054# -----
55
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060056ADMIN_USER=$(get_id keystone user-create --name=admin \
57 --pass="$ADMIN_PASSWORD" \
58 --email=admin@example.com)
59DEMO_USER=$(get_id keystone user-create --name=demo \
60 --pass="$ADMIN_PASSWORD" \
61 --email=demo@example.com)
Jesse Andrews73e27b82011-09-12 17:55:00 -070062
Dean Troyer0bd24102012-03-08 00:33:54 -060063
Jesse Andrews73e27b82011-09-12 17:55:00 -070064# Roles
Dean Troyer3f7c06f2012-04-03 17:19:36 -050065# -----
66
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060067ADMIN_ROLE=$(get_id keystone role-create --name=admin)
68KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin)
69KEYSTONESERVICE_ROLE=$(get_id keystone role-create --name=KeystoneServiceAdmin)
Anthony Youngae604982012-03-12 17:12:00 -070070# ANOTHER_ROLE demonstrates that an arbitrary role may be created and used
71# TODO(sleepsonthefloor): show how this can be used for rbac in the future!
72ANOTHER_ROLE=$(get_id keystone role-create --name=anotherrole)
termiea96a4182012-01-09 22:13:29 -080073
74
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060075# Add Roles to Users in Tenants
Everett Toewsa143e732012-05-08 22:13:08 +000076keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $ADMIN_TENANT
77keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $DEMO_TENANT
78keystone user-role-add --user_id $DEMO_USER --role_id $ANOTHER_ROLE --tenant_id $DEMO_TENANT
termiea96a4182012-01-09 22:13:29 -080079
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060080# TODO(termie): these two might be dubious
Everett Toewsa143e732012-05-08 22:13:08 +000081keystone user-role-add --user_id $ADMIN_USER --role_id $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT
82keystone user-role-add --user_id $ADMIN_USER --role_id $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT
Dean Troyerf4565c42012-02-23 11:21:10 -060083
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060084
85# The Member role is used by Horizon and Swift so we need to keep it:
86MEMBER_ROLE=$(get_id keystone role-create --name=Member)
Everett Toewsa143e732012-05-08 22:13:08 +000087keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $DEMO_TENANT
88keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $INVIS_TENANT
Dean Troyerb7d1fbb2012-03-02 08:43:09 -060089
Jesse Andrews73e27b82011-09-12 17:55:00 -070090
Dean Troyer3f7c06f2012-04-03 17:19:36 -050091# Services
92# --------
termiea96a4182012-01-09 22:13:29 -080093
Dean Troyer3f7c06f2012-04-03 17:19:36 -050094# Keystone
95if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
96 KEYSTONE_SERVICE=$(get_id keystone service-create \
97 --name=keystone \
98 --type=identity \
99 --description="Keystone Identity Service")
100 keystone endpoint-create \
101 --region RegionOne \
102 --service_id $KEYSTONE_SERVICE \
103 --publicurl "http://$SERVICE_HOST:\$(public_port)s/v2.0" \
104 --adminurl "http://$SERVICE_HOST:\$(admin_port)s/v2.0" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200105 --internalurl "http://$SERVICE_HOST:\$(public_port)s/v2.0"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500106fi
Vishvananda Ishaya5f9473e2012-02-24 01:57:07 +0000107
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500108# Nova
109if [[ "$ENABLED_SERVICES" =~ "n-cpu" ]]; then
110 NOVA_USER=$(get_id keystone user-create \
111 --name=nova \
112 --pass="$SERVICE_PASSWORD" \
113 --tenant_id $SERVICE_TENANT \
114 --email=nova@example.com)
115 keystone user-role-add \
116 --tenant_id $SERVICE_TENANT \
117 --user_id $NOVA_USER \
118 --role_id $ADMIN_ROLE
119 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
120 NOVA_SERVICE=$(get_id keystone service-create \
121 --name=nova \
122 --type=compute \
123 --description="Nova Compute Service")
124 keystone endpoint-create \
125 --region RegionOne \
126 --service_id $NOVA_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200127 --publicurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
128 --adminurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s" \
129 --internalurl "http://$SERVICE_HOST:\$(compute_port)s/v2/\$(tenant_id)s"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500130 fi
Chmouel Boudjnah77b0e1d2012-02-29 16:55:43 +0000131 # Nova needs ResellerAdmin role to download images when accessing
132 # swift through the s3 api. The admin role in swift allows a user
133 # to act as an admin for their tenant, but ResellerAdmin is needed
134 # for a user to act as any tenant. The name of this role is also
135 # configurable in swift-proxy.conf
136 RESELLER_ROLE=$(get_id keystone role-create --name=ResellerAdmin)
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500137 keystone user-role-add \
138 --tenant_id $SERVICE_TENANT \
139 --user_id $NOVA_USER \
140 --role_id $RESELLER_ROLE
Jesse Andrews9c7c9082011-11-23 10:10:53 -0800141fi
Dean Troyerb7d1fbb2012-03-02 08:43:09 -0600142
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500143# Volume
144if [[ "$ENABLED_SERVICES" =~ "n-vol" ]]; then
145 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
146 VOLUME_SERVICE=$(get_id keystone service-create \
147 --name=volume \
148 --type=volume \
149 --description="Volume Service")
150 keystone endpoint-create \
151 --region RegionOne \
152 --service_id $VOLUME_SERVICE \
153 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
154 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
155 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
156 fi
157fi
158
Steve Bakerbfdad752012-08-18 09:00:42 +1200159# Heat
160if [[ "$ENABLED_SERVICES" =~ "heat" ]]; then
161 HEAT_USER=$(get_id keystone user-create --name=heat \
162 --pass="$SERVICE_PASSWORD" \
163 --tenant_id $SERVICE_TENANT \
164 --email=heat@example.com)
165 keystone user-role-add --tenant_id $SERVICE_TENANT \
166 --user_id $HEAT_USER \
167 --role_id $ADMIN_ROLE
168 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Baker36cf7ee2012-09-17 16:49:24 +1200169 HEAT_CFN_SERVICE=$(get_id keystone service-create \
Steve Bakerbb421be2012-10-10 13:19:10 +1300170 --name=heat-cfn \
171 --type=cloudformation \
172 --description="Heat CloudFormation Service")
Steve Bakerbfdad752012-08-18 09:00:42 +1200173 keystone endpoint-create \
174 --region RegionOne \
Angus Salkelde2790212012-09-11 11:24:09 +1000175 --service_id $HEAT_CFN_SERVICE \
176 --publicurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
177 --adminurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
178 --internalurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1"
Steve Bakerbb421be2012-10-10 13:19:10 +1300179 HEAT_SERVICE=$(get_id keystone service-create \
180 --name=heat \
181 --type=orchestration \
182 --description="Heat Service")
183 keystone endpoint-create \
184 --region RegionOne \
185 --service_id $HEAT_SERVICE \
186 --publicurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
187 --adminurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
188 --internalurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
Steve Bakerbfdad752012-08-18 09:00:42 +1200189 fi
190fi
191
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500192# Glance
193if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
194 GLANCE_USER=$(get_id keystone user-create \
195 --name=glance \
196 --pass="$SERVICE_PASSWORD" \
197 --tenant_id $SERVICE_TENANT \
198 --email=glance@example.com)
199 keystone user-role-add \
200 --tenant_id $SERVICE_TENANT \
201 --user_id $GLANCE_USER \
202 --role_id $ADMIN_ROLE
203 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
204 GLANCE_SERVICE=$(get_id keystone service-create \
205 --name=glance \
206 --type=image \
207 --description="Glance Image Service")
208 keystone endpoint-create \
209 --region RegionOne \
210 --service_id $GLANCE_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200211 --publicurl "http://$SERVICE_HOST:9292" \
212 --adminurl "http://$SERVICE_HOST:9292" \
213 --internalurl "http://$SERVICE_HOST:9292"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500214 fi
215fi
216
217# Swift
218if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
219 SWIFT_USER=$(get_id keystone user-create \
220 --name=swift \
221 --pass="$SERVICE_PASSWORD" \
222 --tenant_id $SERVICE_TENANT \
223 --email=swift@example.com)
224 keystone user-role-add \
225 --tenant_id $SERVICE_TENANT \
226 --user_id $SWIFT_USER \
227 --role_id $ADMIN_ROLE
228 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
229 SWIFT_SERVICE=$(get_id keystone service-create \
230 --name=swift \
231 --type="object-store" \
232 --description="Swift Service")
233 keystone endpoint-create \
234 --region RegionOne \
235 --service_id $SWIFT_SERVICE \
236 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200237 --adminurl "http://$SERVICE_HOST:8080" \
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500238 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
239 fi
240fi
241
242if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
243 QUANTUM_USER=$(get_id keystone user-create \
244 --name=quantum \
245 --pass="$SERVICE_PASSWORD" \
246 --tenant_id $SERVICE_TENANT \
247 --email=quantum@example.com)
248 keystone user-role-add \
249 --tenant_id $SERVICE_TENANT \
250 --user_id $QUANTUM_USER \
251 --role_id $ADMIN_ROLE
252 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
253 QUANTUM_SERVICE=$(get_id keystone service-create \
254 --name=quantum \
255 --type=network \
256 --description="Quantum Service")
257 keystone endpoint-create \
258 --region RegionOne \
259 --service_id $QUANTUM_SERVICE \
260 --publicurl "http://$SERVICE_HOST:9696/" \
261 --adminurl "http://$SERVICE_HOST:9696/" \
262 --internalurl "http://$SERVICE_HOST:9696/"
263 fi
264fi
265
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400266if [[ "$ENABLED_SERVICES" =~ "ceilometer" ]]; then
267 CEILOMETER_USER=$(get_id keystone user-create --name=ceilometer \
268 --pass="$SERVICE_PASSWORD" \
269 --tenant_id $SERVICE_TENANT \
270 --email=ceilometer@example.com)
271 keystone user-role-add --tenant_id $SERVICE_TENANT \
272 --user_id $CEILOMETER_USER \
273 --role_id $ADMIN_ROLE
Julien Danjouf36afe52012-10-04 18:00:10 +0200274 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
275 CEILOMETER_SERVICE=$(get_id keystone service-create \
276 --name=ceilometer \
277 --type=metering \
278 --description="Ceilometer Service")
279 keystone endpoint-create \
280 --region RegionOne \
281 --service_id $CEILOMETER_SERVICE \
282 --publicurl "http://$SERVICE_HOST:8777/" \
283 --adminurl "http://$SERVICE_HOST:8777/" \
284 --internalurl "http://$SERVICE_HOST:8777/"
285 fi
286fi
287
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500288# EC2
289if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
290 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
291 EC2_SERVICE=$(get_id keystone service-create \
292 --name=ec2 \
293 --type=ec2 \
294 --description="EC2 Compatibility Layer")
295 keystone endpoint-create \
296 --region RegionOne \
297 --service_id $EC2_SERVICE \
298 --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \
299 --adminurl "http://$SERVICE_HOST:8773/services/Admin" \
300 --internalurl "http://$SERVICE_HOST:8773/services/Cloud"
301 fi
302fi
303
304# S3
305if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift" ]]; then
306 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
307 S3_SERVICE=$(get_id keystone service-create \
308 --name=s3 \
309 --type=s3 \
310 --description="S3")
311 keystone endpoint-create \
312 --region RegionOne \
313 --service_id $S3_SERVICE \
314 --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
315 --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
316 --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT"
317 fi
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800318fi
Jay Pipesb297d2d2012-05-10 11:21:22 -0400319
320if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
321 # Tempest has some tests that validate various authorization checks
322 # between two regular users in separate tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500323 ALT_DEMO_TENANT=$(get_id keystone tenant-create \
324 --name=alt_demo)
325 ALT_DEMO_USER=$(get_id keystone user-create \
326 --name=alt_demo \
327 --pass="$ADMIN_PASSWORD" \
328 --email=alt_demo@example.com)
329 keystone user-role-add \
330 --tenant_id $ALT_DEMO_TENANT \
331 --user_id $ALT_DEMO_USER \
332 --role_id $MEMBER_ROLE
Jay Pipesb297d2d2012-05-10 11:21:22 -0400333fi
Dean Troyer67787e62012-05-02 11:48:15 -0500334
Chmouel Boudjnahd55509d2012-07-20 15:00:02 +0000335if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Dean Troyer67787e62012-05-02 11:48:15 -0500336 CINDER_USER=$(get_id keystone user-create --name=cinder \
337 --pass="$SERVICE_PASSWORD" \
338 --tenant_id $SERVICE_TENANT \
339 --email=cinder@example.com)
340 keystone user-role-add --tenant_id $SERVICE_TENANT \
341 --user_id $CINDER_USER \
342 --role_id $ADMIN_ROLE
Anthony Young1cdf5fa2012-07-03 13:57:39 -0700343 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
344 CINDER_SERVICE=$(get_id keystone service-create \
345 --name=cinder \
346 --type=volume \
347 --description="Cinder Service")
348 keystone endpoint-create \
349 --region RegionOne \
350 --service_id $CINDER_SERVICE \
351 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
352 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
353 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
354 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500355fi