blob: 866c62e165b83d3e2a8ae8ecf236c6a67d1e36c0 [file] [log] [blame]
Dean Troyerd81a0272012-08-31 18:04:55 -05001# lib/keystone
2# Functions to control the configuration and operation of **Keystone**
3
4# Dependencies:
5# ``functions`` file
6# ``BASE_SQL_CONN``
Dean Troyerc83a7e12012-11-29 11:47:58 -06007# ``SERVICE_HOST``, ``SERVICE_PROTOCOL``
Dean Troyerd81a0272012-08-31 18:04:55 -05008# ``SERVICE_TOKEN``
9# ``S3_SERVICE_PORT`` (template backend only)
Attila Fazekas91b8d132013-01-06 22:40:09 +010010# ``STACK_USER``
Dean Troyerd81a0272012-08-31 18:04:55 -050011
Dean Troyerd81a0272012-08-31 18:04:55 -050012# ``stack.sh`` calls the entry points in this order:
13#
14# install_keystone
15# configure_keystone
16# init_keystone
17# start_keystone
Dean Troyerd835de82012-11-29 17:11:35 -060018# create_keystone_accounts
Dean Troyerd81a0272012-08-31 18:04:55 -050019# stop_keystone
20# cleanup_keystone
21
Dean Troyer7903b792012-09-13 17:16:12 -050022# Save trace setting
23XTRACE=$(set +o | grep xtrace)
24set +o xtrace
Dean Troyerd81a0272012-08-31 18:04:55 -050025
26
27# Defaults
28# --------
29
Dean Troyerd81a0272012-08-31 18:04:55 -050030# Set up default directories
31KEYSTONE_DIR=$DEST/keystone
32KEYSTONE_CONF_DIR=${KEYSTONE_CONF_DIR:-/etc/keystone}
33KEYSTONE_CONF=$KEYSTONE_CONF_DIR/keystone.conf
Dean Troyerbc071bc2012-10-01 14:06:44 -050034KEYSTONE_AUTH_CACHE_DIR=${KEYSTONE_AUTH_CACHE_DIR:-/var/cache/keystone}
Dean Troyerd81a0272012-08-31 18:04:55 -050035
36KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
37
Dean Troyerbc071bc2012-10-01 14:06:44 -050038# Select the backend for Keystone's service catalog
Dean Troyerb80379c2012-09-10 18:30:37 -050039KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
Dean Troyerd81a0272012-08-31 18:04:55 -050040KEYSTONE_CATALOG=$KEYSTONE_CONF_DIR/default_catalog.templates
41
Davanum Srinivas5bd96f92013-01-29 15:12:20 -050042# Select the backend for Tokens
43KEYSTONE_TOKEN_BACKEND=${KEYSTONE_TOKEN_BACKEND:-sql}
44
Dean Troyerbc071bc2012-10-01 14:06:44 -050045# Select Keystone's token format
46# Choose from 'UUID' and 'PKI'
47KEYSTONE_TOKEN_FORMAT=${KEYSTONE_TOKEN_FORMAT:-PKI}
48
Dean Troyerd81a0272012-08-31 18:04:55 -050049# Set Keystone interface configuration
Dean Troyerd81a0272012-08-31 18:04:55 -050050KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
51KEYSTONE_AUTH_PORT=${KEYSTONE_AUTH_PORT:-35357}
Dean Troyerc83a7e12012-11-29 11:47:58 -060052KEYSTONE_AUTH_PORT_INT=${KEYSTONE_AUTH_PORT_INT:-35358}
53KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-$SERVICE_PROTOCOL}
54
55# Public facing bits
Dean Troyerd81a0272012-08-31 18:04:55 -050056KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
57KEYSTONE_SERVICE_PORT=${KEYSTONE_SERVICE_PORT:-5000}
Dean Troyerc83a7e12012-11-29 11:47:58 -060058KEYSTONE_SERVICE_PORT_INT=${KEYSTONE_SERVICE_PORT_INT:-5001}
59KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Dean Troyerd81a0272012-08-31 18:04:55 -050060
61
62# Entry Points
63# ------------
64
65# cleanup_keystone() - Remove residual data files, anything left over from previous
66# runs that a clean run would need to clean up
67function cleanup_keystone() {
68 # kill instances (nova)
69 # delete image files (glance)
70 # This function intentionally left blank
71 :
72}
73
74# configure_keystoneclient() - Set config files, create data dirs, etc
75function configure_keystoneclient() {
76 setup_develop $KEYSTONECLIENT_DIR
77}
78
79# configure_keystone() - Set config files, create data dirs, etc
80function configure_keystone() {
81 setup_develop $KEYSTONE_DIR
82
83 if [[ ! -d $KEYSTONE_CONF_DIR ]]; then
84 sudo mkdir -p $KEYSTONE_CONF_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -050085 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +010086 sudo chown $STACK_USER $KEYSTONE_CONF_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -050087
88 if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
89 cp -p $KEYSTONE_DIR/etc/keystone.conf.sample $KEYSTONE_CONF
90 cp -p $KEYSTONE_DIR/etc/policy.json $KEYSTONE_CONF_DIR
91 fi
92
93 # Rewrite stock ``keystone.conf``
Terry Wilson428af5a2012-11-01 16:12:39 -040094 local dburl
95 database_connection_url dburl keystone
Dean Troyerc83a7e12012-11-29 11:47:58 -060096
Brad Topolf127e2f2013-01-22 10:17:50 -060097 if is_service_enabled ldap; then
98 #Set all needed ldap values
99 iniset $KEYSTONE_CONF ldap password $LDAP_PASSWORD
100 iniset $KEYSTONE_CONF ldap user "dc=Manager,dc=openstack,dc=org"
101 iniset $KEYSTONE_CONF ldap suffix "dc=openstack,dc=org"
102 fi
103
104 if [[ "$KEYSTONE_IDENTITY_BACKEND" == "ldap" ]]; then
105 iniset $KEYSTONE_CONF identity driver "keystone.identity.backends.ldap.Identity"
106 fi
107
Dean Troyerc83a7e12012-11-29 11:47:58 -0600108 if is_service_enabled tls-proxy; then
109 # Set the service ports for a proxy to take the originals
110 iniset $KEYSTONE_CONF DEFAULT public_port $KEYSTONE_SERVICE_PORT_INT
111 iniset $KEYSTONE_CONF DEFAULT admin_port $KEYSTONE_AUTH_PORT_INT
112 fi
113
Dean Troyerd81a0272012-08-31 18:04:55 -0500114 iniset $KEYSTONE_CONF DEFAULT admin_token "$SERVICE_TOKEN"
Doug Hellmann4de55e92012-10-26 12:24:28 -0400115 iniset $KEYSTONE_CONF signing token_format "$KEYSTONE_TOKEN_FORMAT"
Terry Wilson428af5a2012-11-01 16:12:39 -0400116 iniset $KEYSTONE_CONF sql connection $dburl
Dean Troyerd81a0272012-08-31 18:04:55 -0500117 iniset $KEYSTONE_CONF ec2 driver "keystone.contrib.ec2.backends.sql.Ec2"
118 sed -e "
119 /^pipeline.*ec2_extension crud_/s|ec2_extension crud_extension|ec2_extension s3_extension crud_extension|;
120 " -i $KEYSTONE_CONF
121
122 # Append the S3 bits
123 iniset $KEYSTONE_CONF filter:s3_extension paste.filter_factory "keystone.contrib.s3:S3Extension.factory"
124
Davanum Srinivas5bd96f92013-01-29 15:12:20 -0500125 if [[ "$KEYSTONE_TOKEN_BACKEND" = "sql" ]]; then
126 iniset $KEYSTONE_CONF token driver keystone.token.backends.sql.Token
127 else
128 iniset $KEYSTONE_CONF token driver keystone.token.backends.kvs.Token
129 fi
130
Dean Troyerd81a0272012-08-31 18:04:55 -0500131 if [[ "$KEYSTONE_CATALOG_BACKEND" = "sql" ]]; then
132 # Configure ``keystone.conf`` to use sql
133 iniset $KEYSTONE_CONF catalog driver keystone.catalog.backends.sql.Catalog
134 inicomment $KEYSTONE_CONF catalog template_file
135 else
136 cp -p $FILES/default_catalog.templates $KEYSTONE_CATALOG
137
138 # Add swift endpoints to service catalog if swift is enabled
139 if is_service_enabled swift; then
140 echo "catalog.RegionOne.object_store.publicURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
141 echo "catalog.RegionOne.object_store.adminURL = http://%SERVICE_HOST%:8080/" >> $KEYSTONE_CATALOG
142 echo "catalog.RegionOne.object_store.internalURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
143 echo "catalog.RegionOne.object_store.name = Swift Service" >> $KEYSTONE_CATALOG
144 fi
145
146 # Add quantum endpoints to service catalog if quantum is enabled
147 if is_service_enabled quantum; then
148 echo "catalog.RegionOne.network.publicURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
149 echo "catalog.RegionOne.network.adminURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
150 echo "catalog.RegionOne.network.internalURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
151 echo "catalog.RegionOne.network.name = Quantum Service" >> $KEYSTONE_CATALOG
152 fi
153
Vincent Untz7e86dbe2012-12-13 08:50:37 +0100154 sed -e "
Dean Troyerd81a0272012-08-31 18:04:55 -0500155 s,%SERVICE_HOST%,$SERVICE_HOST,g;
156 s,%S3_SERVICE_PORT%,$S3_SERVICE_PORT,g;
157 " -i $KEYSTONE_CATALOG
158
159 # Configure ``keystone.conf`` to use templates
160 iniset $KEYSTONE_CONF catalog driver "keystone.catalog.backends.templated.TemplatedCatalog"
161 iniset $KEYSTONE_CONF catalog template_file "$KEYSTONE_CATALOG"
162 fi
163
164 # Set up logging
165 LOGGING_ROOT="devel"
166 if [ "$SYSLOG" != "False" ]; then
167 LOGGING_ROOT="$LOGGING_ROOT,production"
168 fi
169 KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_CONF_DIR/logging.conf"
170 cp $KEYSTONE_DIR/etc/logging.conf.sample $KEYSTONE_CONF_DIR/logging.conf
171 iniset $KEYSTONE_CONF_DIR/logging.conf logger_root level "DEBUG"
172 iniset $KEYSTONE_CONF_DIR/logging.conf logger_root handlers "devel,production"
173
174}
175
Dean Troyerd835de82012-11-29 17:11:35 -0600176# create_keystone_accounts() - Sets up common required keystone accounts
177
178# Tenant User Roles
179# ------------------------------------------------------------------
180# service -- --
181# -- -- Member
182# admin admin admin
183# demo admin admin
184# demo demo Member, anotherrole
185# invisible_to_admin demo Member
186
187# Migrated from keystone_data.sh
188create_keystone_accounts() {
189
190 # admin
191 ADMIN_TENANT=$(keystone tenant-create \
192 --name admin \
193 | grep " id " | get_field 2)
194 ADMIN_USER=$(keystone user-create \
195 --name admin \
196 --pass "$ADMIN_PASSWORD" \
197 --email admin@example.com \
198 | grep " id " | get_field 2)
199 ADMIN_ROLE=$(keystone role-create \
200 --name admin \
201 | grep " id " | get_field 2)
202 keystone user-role-add \
203 --user_id $ADMIN_USER \
204 --role_id $ADMIN_ROLE \
205 --tenant_id $ADMIN_TENANT
206
207 # service
208 SERVICE_TENANT=$(keystone tenant-create \
209 --name $SERVICE_TENANT_NAME \
210 | grep " id " | get_field 2)
211
212 # The Member role is used by Horizon and Swift so we need to keep it:
213 MEMBER_ROLE=$(keystone role-create --name=Member | grep " id " | get_field 2)
214 # ANOTHER_ROLE demonstrates that an arbitrary role may be created and used
215 # TODO(sleepsonthefloor): show how this can be used for rbac in the future!
216 ANOTHER_ROLE=$(keystone role-create --name=anotherrole | grep " id " | get_field 2)
217
218 # invisible tenant - admin can't see this one
219 INVIS_TENANT=$(keystone tenant-create --name=invisible_to_admin | grep " id " | get_field 2)
220
221 # demo
222 DEMO_TENANT=$(keystone tenant-create \
223 --name=demo \
224 | grep " id " | get_field 2)
225 DEMO_USER=$(keystone user-create \
226 --name demo \
227 --pass "$ADMIN_PASSWORD" \
228 --email demo@example.com \
229 | grep " id " | get_field 2)
230 keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $DEMO_TENANT
231 keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $DEMO_TENANT
232 keystone user-role-add --user_id $DEMO_USER --role_id $ANOTHER_ROLE --tenant_id $DEMO_TENANT
233 keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $INVIS_TENANT
234
235 # Keystone
236 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
237 KEYSTONE_SERVICE=$(keystone service-create \
238 --name keystone \
239 --type identity \
240 --description "Keystone Identity Service" \
241 | grep " id " | get_field 2)
242 keystone endpoint-create \
243 --region RegionOne \
244 --service_id $KEYSTONE_SERVICE \
Dean Troyerc83a7e12012-11-29 11:47:58 -0600245 --publicurl "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0" \
246 --adminurl "$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0" \
247 --internalurl "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0"
Dean Troyerd835de82012-11-29 17:11:35 -0600248 fi
249
250 # TODO(dtroyer): This is part of a series of changes...remove these when
251 # complete if they are really unused
252# KEYSTONEADMIN_ROLE=$(keystone role-create \
253# --name KeystoneAdmin \
254# | grep " id " | get_field 2)
255# KEYSTONESERVICE_ROLE=$(keystone role-create \
256# --name KeystoneServiceAdmin \
257# | grep " id " | get_field 2)
258
259 # TODO(termie): these two might be dubious
260# keystone user-role-add \
261# --user_id $ADMIN_USER \
262# --role_id $KEYSTONEADMIN_ROLE \
263# --tenant_id $ADMIN_TENANT
264# keystone user-role-add \
265# --user_id $ADMIN_USER \
266# --role_id $KEYSTONESERVICE_ROLE \
267# --tenant_id $ADMIN_TENANT
268}
269
Dean Troyerd81a0272012-08-31 18:04:55 -0500270# init_keystone() - Initialize databases, etc.
271function init_keystone() {
272 # (Re)create keystone database
Terry Wilson428af5a2012-11-01 16:12:39 -0400273 recreate_database keystone utf8
Dean Troyerd81a0272012-08-31 18:04:55 -0500274
275 # Initialize keystone database
276 $KEYSTONE_DIR/bin/keystone-manage db_sync
277
Dean Troyerbc071bc2012-10-01 14:06:44 -0500278 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
279 # Set up certificates
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800280 rm -rf $KEYSTONE_CONF_DIR/ssl
Dean Troyerbc071bc2012-10-01 14:06:44 -0500281 $KEYSTONE_DIR/bin/keystone-manage pki_setup
282
283 # Create cache dir
284 sudo mkdir -p $KEYSTONE_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100285 sudo chown $STACK_USER $KEYSTONE_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800286 rm -f $KEYSTONE_AUTH_CACHE_DIR/*
Dean Troyerbc071bc2012-10-01 14:06:44 -0500287 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500288}
289
290# install_keystoneclient() - Collect source and prepare
291function install_keystoneclient() {
292 git_clone $KEYSTONECLIENT_REPO $KEYSTONECLIENT_DIR $KEYSTONECLIENT_BRANCH
293}
294
295# install_keystone() - Collect source and prepare
296function install_keystone() {
Brad Topolf127e2f2013-01-22 10:17:50 -0600297 # only install ldap if the service has been enabled
298 if is_service_enabled ldap; then
299 install_ldap
300 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500301 git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
302}
303
304# start_keystone() - Start running processes, including screen
305function start_keystone() {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600306 # Get right service port for testing
307 local service_port=$KEYSTONE_SERVICE_PORT
308 if is_service_enabled tls-proxy; then
309 service_port=$KEYSTONE_SERVICE_PORT_INT
310 fi
311
Dean Troyerd81a0272012-08-31 18:04:55 -0500312 # Start Keystone in a screen window
313 screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone-all --config-file $KEYSTONE_CONF $KEYSTONE_LOG_CONFIG -d --debug"
Dean Troyerd835de82012-11-29 17:11:35 -0600314 echo "Waiting for keystone to start..."
Dean Troyerc83a7e12012-11-29 11:47:58 -0600315 if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= curl -s http://$SERVICE_HOST:$service_port/v2.0/ >/dev/null; do sleep 1; done"; then
Dean Troyerd835de82012-11-29 17:11:35 -0600316 echo "keystone did not start"
317 exit 1
318 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600319
320 # Start proxies if enabled
321 if is_service_enabled tls-proxy; then
322 start_tls_proxy '*' $KEYSTONE_SERVICE_PORT $KEYSTONE_SERVICE_HOST $KEYSTONE_SERVICE_PORT_INT &
323 start_tls_proxy '*' $KEYSTONE_AUTH_PORT $KEYSTONE_AUTH_HOST $KEYSTONE_AUTH_PORT_INT &
324 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500325}
326
327# stop_keystone() - Stop running processes
328function stop_keystone() {
329 # Kill the Keystone screen window
330 screen -S $SCREEN_NAME -p key -X kill
331}
Dean Troyer7903b792012-09-13 17:16:12 -0500332
333# Restore xtrace
334$XTRACE