blob: 71994a816f1919271d7a25658c64ed4c23bd7af5 [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
Steve Bakerbfdad752012-08-18 09:00:42 +1200143# Heat
144if [[ "$ENABLED_SERVICES" =~ "heat" ]]; then
145 HEAT_USER=$(get_id keystone user-create --name=heat \
146 --pass="$SERVICE_PASSWORD" \
147 --tenant_id $SERVICE_TENANT \
148 --email=heat@example.com)
149 keystone user-role-add --tenant_id $SERVICE_TENANT \
150 --user_id $HEAT_USER \
151 --role_id $ADMIN_ROLE
152 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Baker36cf7ee2012-09-17 16:49:24 +1200153 HEAT_CFN_SERVICE=$(get_id keystone service-create \
Steve Bakerbb421be2012-10-10 13:19:10 +1300154 --name=heat-cfn \
155 --type=cloudformation \
156 --description="Heat CloudFormation Service")
Steve Bakerbfdad752012-08-18 09:00:42 +1200157 keystone endpoint-create \
158 --region RegionOne \
Angus Salkelde2790212012-09-11 11:24:09 +1000159 --service_id $HEAT_CFN_SERVICE \
160 --publicurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
161 --adminurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1" \
162 --internalurl "http://$SERVICE_HOST:$HEAT_API_CFN_PORT/v1"
Steve Bakerbb421be2012-10-10 13:19:10 +1300163 HEAT_SERVICE=$(get_id keystone service-create \
164 --name=heat \
165 --type=orchestration \
166 --description="Heat Service")
167 keystone endpoint-create \
168 --region RegionOne \
169 --service_id $HEAT_SERVICE \
170 --publicurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
171 --adminurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s" \
172 --internalurl "http://$SERVICE_HOST:$HEAT_API_PORT/v1/\$(tenant_id)s"
Steve Bakerbfdad752012-08-18 09:00:42 +1200173 fi
174fi
175
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500176# Glance
177if [[ "$ENABLED_SERVICES" =~ "g-api" ]]; then
178 GLANCE_USER=$(get_id keystone user-create \
179 --name=glance \
180 --pass="$SERVICE_PASSWORD" \
181 --tenant_id $SERVICE_TENANT \
182 --email=glance@example.com)
183 keystone user-role-add \
184 --tenant_id $SERVICE_TENANT \
185 --user_id $GLANCE_USER \
186 --role_id $ADMIN_ROLE
187 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
188 GLANCE_SERVICE=$(get_id keystone service-create \
189 --name=glance \
190 --type=image \
191 --description="Glance Image Service")
192 keystone endpoint-create \
193 --region RegionOne \
194 --service_id $GLANCE_SERVICE \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200195 --publicurl "http://$SERVICE_HOST:9292" \
196 --adminurl "http://$SERVICE_HOST:9292" \
197 --internalurl "http://$SERVICE_HOST:9292"
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500198 fi
199fi
200
201# Swift
202if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then
203 SWIFT_USER=$(get_id keystone user-create \
204 --name=swift \
205 --pass="$SERVICE_PASSWORD" \
206 --tenant_id $SERVICE_TENANT \
207 --email=swift@example.com)
208 keystone user-role-add \
209 --tenant_id $SERVICE_TENANT \
210 --user_id $SWIFT_USER \
211 --role_id $ADMIN_ROLE
212 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
213 SWIFT_SERVICE=$(get_id keystone service-create \
214 --name=swift \
215 --type="object-store" \
216 --description="Swift Service")
217 keystone endpoint-create \
218 --region RegionOne \
219 --service_id $SWIFT_SERVICE \
220 --publicurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s" \
Steve Baker8d6c9bc2012-09-11 10:05:14 +1200221 --adminurl "http://$SERVICE_HOST:8080" \
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500222 --internalurl "http://$SERVICE_HOST:8080/v1/AUTH_\$(tenant_id)s"
223 fi
224fi
225
226if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
227 QUANTUM_USER=$(get_id keystone user-create \
228 --name=quantum \
229 --pass="$SERVICE_PASSWORD" \
230 --tenant_id $SERVICE_TENANT \
231 --email=quantum@example.com)
232 keystone user-role-add \
233 --tenant_id $SERVICE_TENANT \
234 --user_id $QUANTUM_USER \
235 --role_id $ADMIN_ROLE
236 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
237 QUANTUM_SERVICE=$(get_id keystone service-create \
238 --name=quantum \
239 --type=network \
240 --description="Quantum Service")
241 keystone endpoint-create \
242 --region RegionOne \
243 --service_id $QUANTUM_SERVICE \
244 --publicurl "http://$SERVICE_HOST:9696/" \
245 --adminurl "http://$SERVICE_HOST:9696/" \
246 --internalurl "http://$SERVICE_HOST:9696/"
247 fi
248fi
249
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400250if [[ "$ENABLED_SERVICES" =~ "ceilometer" ]]; then
251 CEILOMETER_USER=$(get_id keystone user-create --name=ceilometer \
252 --pass="$SERVICE_PASSWORD" \
253 --tenant_id $SERVICE_TENANT \
254 --email=ceilometer@example.com)
255 keystone user-role-add --tenant_id $SERVICE_TENANT \
256 --user_id $CEILOMETER_USER \
257 --role_id $ADMIN_ROLE
Julien Danjouf36afe52012-10-04 18:00:10 +0200258 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
259 CEILOMETER_SERVICE=$(get_id keystone service-create \
260 --name=ceilometer \
261 --type=metering \
262 --description="Ceilometer Service")
263 keystone endpoint-create \
264 --region RegionOne \
265 --service_id $CEILOMETER_SERVICE \
266 --publicurl "http://$SERVICE_HOST:8777/" \
267 --adminurl "http://$SERVICE_HOST:8777/" \
268 --internalurl "http://$SERVICE_HOST:8777/"
269 fi
270fi
271
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500272# EC2
273if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
274 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
275 EC2_SERVICE=$(get_id keystone service-create \
276 --name=ec2 \
277 --type=ec2 \
278 --description="EC2 Compatibility Layer")
279 keystone endpoint-create \
280 --region RegionOne \
281 --service_id $EC2_SERVICE \
282 --publicurl "http://$SERVICE_HOST:8773/services/Cloud" \
283 --adminurl "http://$SERVICE_HOST:8773/services/Admin" \
284 --internalurl "http://$SERVICE_HOST:8773/services/Cloud"
285 fi
286fi
287
288# S3
289if [[ "$ENABLED_SERVICES" =~ "n-obj" || "$ENABLED_SERVICES" =~ "swift" ]]; then
290 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
291 S3_SERVICE=$(get_id keystone service-create \
292 --name=s3 \
293 --type=s3 \
294 --description="S3")
295 keystone endpoint-create \
296 --region RegionOne \
297 --service_id $S3_SERVICE \
298 --publicurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
299 --adminurl "http://$SERVICE_HOST:$S3_SERVICE_PORT" \
300 --internalurl "http://$SERVICE_HOST:$S3_SERVICE_PORT"
301 fi
Gabriel Hurleya3a496f2012-02-13 12:29:23 -0800302fi
Jay Pipesb297d2d2012-05-10 11:21:22 -0400303
304if [[ "$ENABLED_SERVICES" =~ "tempest" ]]; then
305 # Tempest has some tests that validate various authorization checks
306 # between two regular users in separate tenants
Dean Troyer3f7c06f2012-04-03 17:19:36 -0500307 ALT_DEMO_TENANT=$(get_id keystone tenant-create \
308 --name=alt_demo)
309 ALT_DEMO_USER=$(get_id keystone user-create \
310 --name=alt_demo \
311 --pass="$ADMIN_PASSWORD" \
312 --email=alt_demo@example.com)
313 keystone user-role-add \
314 --tenant_id $ALT_DEMO_TENANT \
315 --user_id $ALT_DEMO_USER \
316 --role_id $MEMBER_ROLE
Jay Pipesb297d2d2012-05-10 11:21:22 -0400317fi
Dean Troyer67787e62012-05-02 11:48:15 -0500318
Chmouel Boudjnahd55509d2012-07-20 15:00:02 +0000319if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
Dean Troyer67787e62012-05-02 11:48:15 -0500320 CINDER_USER=$(get_id keystone user-create --name=cinder \
321 --pass="$SERVICE_PASSWORD" \
322 --tenant_id $SERVICE_TENANT \
323 --email=cinder@example.com)
324 keystone user-role-add --tenant_id $SERVICE_TENANT \
325 --user_id $CINDER_USER \
326 --role_id $ADMIN_ROLE
Anthony Young1cdf5fa2012-07-03 13:57:39 -0700327 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
328 CINDER_SERVICE=$(get_id keystone service-create \
329 --name=cinder \
330 --type=volume \
331 --description="Cinder Service")
332 keystone endpoint-create \
333 --region RegionOne \
334 --service_id $CINDER_SERVICE \
335 --publicurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
336 --adminurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s" \
337 --internalurl "http://$SERVICE_HOST:8776/v1/\$(tenant_id)s"
338 fi
Dean Troyer67787e62012-05-02 11:48:15 -0500339fi