blob: 90bc108448034fd3f5245f9cebb2284411998bca [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
Alan Pevece0bb4472013-03-12 11:10:52 +010034KEYSTONE_PASTE_INI=${KEYSTONE_PASTE_INI:-$KEYSTONE_CONF_DIR/keystone-paste.ini}
Dean Troyerbc071bc2012-10-01 14:06:44 -050035KEYSTONE_AUTH_CACHE_DIR=${KEYSTONE_AUTH_CACHE_DIR:-/var/cache/keystone}
Dean Troyerd81a0272012-08-31 18:04:55 -050036
37KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
38
Dean Troyerbc071bc2012-10-01 14:06:44 -050039# Select the backend for Keystone's service catalog
Dean Troyerb80379c2012-09-10 18:30:37 -050040KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
Dean Troyerd81a0272012-08-31 18:04:55 -050041KEYSTONE_CATALOG=$KEYSTONE_CONF_DIR/default_catalog.templates
42
Davanum Srinivas5bd96f92013-01-29 15:12:20 -050043# Select the backend for Tokens
44KEYSTONE_TOKEN_BACKEND=${KEYSTONE_TOKEN_BACKEND:-sql}
45
Dean Troyerbc071bc2012-10-01 14:06:44 -050046# Select Keystone's token format
47# Choose from 'UUID' and 'PKI'
48KEYSTONE_TOKEN_FORMAT=${KEYSTONE_TOKEN_FORMAT:-PKI}
49
Dean Troyerd81a0272012-08-31 18:04:55 -050050# Set Keystone interface configuration
Dean Troyerd81a0272012-08-31 18:04:55 -050051KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
52KEYSTONE_AUTH_PORT=${KEYSTONE_AUTH_PORT:-35357}
Dean Troyerc83a7e12012-11-29 11:47:58 -060053KEYSTONE_AUTH_PORT_INT=${KEYSTONE_AUTH_PORT_INT:-35358}
54KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-$SERVICE_PROTOCOL}
55
56# Public facing bits
Dean Troyerd81a0272012-08-31 18:04:55 -050057KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
58KEYSTONE_SERVICE_PORT=${KEYSTONE_SERVICE_PORT:-5000}
Dean Troyerc83a7e12012-11-29 11:47:58 -060059KEYSTONE_SERVICE_PORT_INT=${KEYSTONE_SERVICE_PORT_INT:-5001}
60KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Dean Troyerd81a0272012-08-31 18:04:55 -050061
62
63# Entry Points
64# ------------
65
66# cleanup_keystone() - Remove residual data files, anything left over from previous
67# runs that a clean run would need to clean up
68function cleanup_keystone() {
69 # kill instances (nova)
70 # delete image files (glance)
71 # This function intentionally left blank
72 :
73}
74
75# configure_keystoneclient() - Set config files, create data dirs, etc
76function configure_keystoneclient() {
77 setup_develop $KEYSTONECLIENT_DIR
78}
79
80# configure_keystone() - Set config files, create data dirs, etc
81function configure_keystone() {
82 setup_develop $KEYSTONE_DIR
83
84 if [[ ! -d $KEYSTONE_CONF_DIR ]]; then
85 sudo mkdir -p $KEYSTONE_CONF_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -050086 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +010087 sudo chown $STACK_USER $KEYSTONE_CONF_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -050088
89 if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
90 cp -p $KEYSTONE_DIR/etc/keystone.conf.sample $KEYSTONE_CONF
91 cp -p $KEYSTONE_DIR/etc/policy.json $KEYSTONE_CONF_DIR
Alan Pevece0bb4472013-03-12 11:10:52 +010092 if [[ -f "$KEYSTONE_DIR/etc/keystone-paste.ini" ]]; then
93 cp -p "$KEYSTONE_DIR/etc/keystone-paste.ini" "$KEYSTONE_PASTE_INI"
94 fi
95 fi
96 if [[ -f "$KEYSTONE_PASTE_INI" ]]; then
97 iniset "$KEYSTONE_CONF" paste_deploy config_file "$KEYSTONE_PASTE_INI"
98 else
99 # compatibility with mixed cfg and paste.deploy configuration
100 KEYSTONE_PASTE_INI="$KEYSTONE_CONF"
Dean Troyerd81a0272012-08-31 18:04:55 -0500101 fi
102
103 # Rewrite stock ``keystone.conf``
Terry Wilson428af5a2012-11-01 16:12:39 -0400104 local dburl
105 database_connection_url dburl keystone
Dean Troyerc83a7e12012-11-29 11:47:58 -0600106
Brad Topolf127e2f2013-01-22 10:17:50 -0600107 if is_service_enabled ldap; then
108 #Set all needed ldap values
109 iniset $KEYSTONE_CONF ldap password $LDAP_PASSWORD
110 iniset $KEYSTONE_CONF ldap user "dc=Manager,dc=openstack,dc=org"
111 iniset $KEYSTONE_CONF ldap suffix "dc=openstack,dc=org"
Brad Topolf41024e2013-02-19 15:36:41 -0600112 iniset $KEYSTONE_CONF ldap use_dumb_member "True"
113 iniset $KEYSTONE_CONF ldap user_attribute_ignore "enabled,email,tenants,tenantId"
114 iniset $KEYSTONE_CONF ldap tenant_attribute_ignore "enabled"
115 iniset $KEYSTONE_CONF ldap tenant_domain_id_attribute "businessCategory"
116 iniset $KEYSTONE_CONF ldap tenant_desc_attribute "description"
117 iniset $KEYSTONE_CONF ldap tenant_tree_dn "ou=Projects,dc=openstack,dc=org"
118 iniset $KEYSTONE_CONF ldap user_domain_id_attribute "businessCategory"
119 iniset $KEYSTONE_CONF ldap user_tree_dn "ou=Users,dc=openstack,dc=org"
120 iniset $KEYSTONE_CONF DEFAULT member_role_id "9fe2ff9ee4384b1894a90878d3e92bab"
121 iniset $KEYSTONE_CONF DEFAULT member_role_name "_member_"
Brad Topolf127e2f2013-01-22 10:17:50 -0600122 fi
123
124 if [[ "$KEYSTONE_IDENTITY_BACKEND" == "ldap" ]]; then
125 iniset $KEYSTONE_CONF identity driver "keystone.identity.backends.ldap.Identity"
126 fi
127
Dean Troyerc83a7e12012-11-29 11:47:58 -0600128 if is_service_enabled tls-proxy; then
129 # Set the service ports for a proxy to take the originals
130 iniset $KEYSTONE_CONF DEFAULT public_port $KEYSTONE_SERVICE_PORT_INT
131 iniset $KEYSTONE_CONF DEFAULT admin_port $KEYSTONE_AUTH_PORT_INT
132 fi
133
Dean Troyerd81a0272012-08-31 18:04:55 -0500134 iniset $KEYSTONE_CONF DEFAULT admin_token "$SERVICE_TOKEN"
Doug Hellmann4de55e92012-10-26 12:24:28 -0400135 iniset $KEYSTONE_CONF signing token_format "$KEYSTONE_TOKEN_FORMAT"
Terry Wilson428af5a2012-11-01 16:12:39 -0400136 iniset $KEYSTONE_CONF sql connection $dburl
Dean Troyerd81a0272012-08-31 18:04:55 -0500137 iniset $KEYSTONE_CONF ec2 driver "keystone.contrib.ec2.backends.sql.Ec2"
Dean Troyerd81a0272012-08-31 18:04:55 -0500138
Davanum Srinivas5bd96f92013-01-29 15:12:20 -0500139 if [[ "$KEYSTONE_TOKEN_BACKEND" = "sql" ]]; then
140 iniset $KEYSTONE_CONF token driver keystone.token.backends.sql.Token
141 else
142 iniset $KEYSTONE_CONF token driver keystone.token.backends.kvs.Token
143 fi
144
Dean Troyerd81a0272012-08-31 18:04:55 -0500145 if [[ "$KEYSTONE_CATALOG_BACKEND" = "sql" ]]; then
146 # Configure ``keystone.conf`` to use sql
147 iniset $KEYSTONE_CONF catalog driver keystone.catalog.backends.sql.Catalog
148 inicomment $KEYSTONE_CONF catalog template_file
149 else
150 cp -p $FILES/default_catalog.templates $KEYSTONE_CATALOG
151
152 # Add swift endpoints to service catalog if swift is enabled
Sean Daguef3fd44c2013-03-04 17:33:35 -0500153 if is_service_enabled swift; then
Dean Troyerd81a0272012-08-31 18:04:55 -0500154 echo "catalog.RegionOne.object_store.publicURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
155 echo "catalog.RegionOne.object_store.adminURL = http://%SERVICE_HOST%:8080/" >> $KEYSTONE_CATALOG
156 echo "catalog.RegionOne.object_store.internalURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
157 echo "catalog.RegionOne.object_store.name = Swift Service" >> $KEYSTONE_CATALOG
158 fi
159
160 # Add quantum endpoints to service catalog if quantum is enabled
161 if is_service_enabled quantum; then
162 echo "catalog.RegionOne.network.publicURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
163 echo "catalog.RegionOne.network.adminURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
164 echo "catalog.RegionOne.network.internalURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
165 echo "catalog.RegionOne.network.name = Quantum Service" >> $KEYSTONE_CATALOG
166 fi
167
Vincent Untz7e86dbe2012-12-13 08:50:37 +0100168 sed -e "
Dean Troyerd81a0272012-08-31 18:04:55 -0500169 s,%SERVICE_HOST%,$SERVICE_HOST,g;
170 s,%S3_SERVICE_PORT%,$S3_SERVICE_PORT,g;
171 " -i $KEYSTONE_CATALOG
172
173 # Configure ``keystone.conf`` to use templates
174 iniset $KEYSTONE_CONF catalog driver "keystone.catalog.backends.templated.TemplatedCatalog"
175 iniset $KEYSTONE_CONF catalog template_file "$KEYSTONE_CATALOG"
176 fi
177
178 # Set up logging
179 LOGGING_ROOT="devel"
180 if [ "$SYSLOG" != "False" ]; then
181 LOGGING_ROOT="$LOGGING_ROOT,production"
182 fi
183 KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_CONF_DIR/logging.conf"
184 cp $KEYSTONE_DIR/etc/logging.conf.sample $KEYSTONE_CONF_DIR/logging.conf
185 iniset $KEYSTONE_CONF_DIR/logging.conf logger_root level "DEBUG"
186 iniset $KEYSTONE_CONF_DIR/logging.conf logger_root handlers "devel,production"
187
188}
189
Dean Troyerd835de82012-11-29 17:11:35 -0600190# create_keystone_accounts() - Sets up common required keystone accounts
191
192# Tenant User Roles
193# ------------------------------------------------------------------
194# service -- --
195# -- -- Member
196# admin admin admin
197# demo admin admin
198# demo demo Member, anotherrole
199# invisible_to_admin demo Member
200
201# Migrated from keystone_data.sh
202create_keystone_accounts() {
203
204 # admin
205 ADMIN_TENANT=$(keystone tenant-create \
206 --name admin \
207 | grep " id " | get_field 2)
208 ADMIN_USER=$(keystone user-create \
209 --name admin \
210 --pass "$ADMIN_PASSWORD" \
211 --email admin@example.com \
212 | grep " id " | get_field 2)
213 ADMIN_ROLE=$(keystone role-create \
214 --name admin \
215 | grep " id " | get_field 2)
216 keystone user-role-add \
217 --user_id $ADMIN_USER \
218 --role_id $ADMIN_ROLE \
219 --tenant_id $ADMIN_TENANT
220
221 # service
222 SERVICE_TENANT=$(keystone tenant-create \
223 --name $SERVICE_TENANT_NAME \
224 | grep " id " | get_field 2)
225
226 # The Member role is used by Horizon and Swift so we need to keep it:
227 MEMBER_ROLE=$(keystone role-create --name=Member | grep " id " | get_field 2)
228 # ANOTHER_ROLE demonstrates that an arbitrary role may be created and used
229 # TODO(sleepsonthefloor): show how this can be used for rbac in the future!
230 ANOTHER_ROLE=$(keystone role-create --name=anotherrole | grep " id " | get_field 2)
231
232 # invisible tenant - admin can't see this one
233 INVIS_TENANT=$(keystone tenant-create --name=invisible_to_admin | grep " id " | get_field 2)
234
235 # demo
236 DEMO_TENANT=$(keystone tenant-create \
237 --name=demo \
238 | grep " id " | get_field 2)
239 DEMO_USER=$(keystone user-create \
240 --name demo \
241 --pass "$ADMIN_PASSWORD" \
242 --email demo@example.com \
243 | grep " id " | get_field 2)
244 keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $DEMO_TENANT
245 keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $DEMO_TENANT
246 keystone user-role-add --user_id $DEMO_USER --role_id $ANOTHER_ROLE --tenant_id $DEMO_TENANT
247 keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $INVIS_TENANT
248
249 # Keystone
250 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
251 KEYSTONE_SERVICE=$(keystone service-create \
252 --name keystone \
253 --type identity \
254 --description "Keystone Identity Service" \
255 | grep " id " | get_field 2)
256 keystone endpoint-create \
257 --region RegionOne \
258 --service_id $KEYSTONE_SERVICE \
Dean Troyerc83a7e12012-11-29 11:47:58 -0600259 --publicurl "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0" \
260 --adminurl "$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0" \
261 --internalurl "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0"
Dean Troyerd835de82012-11-29 17:11:35 -0600262 fi
263
264 # TODO(dtroyer): This is part of a series of changes...remove these when
265 # complete if they are really unused
266# KEYSTONEADMIN_ROLE=$(keystone role-create \
267# --name KeystoneAdmin \
268# | grep " id " | get_field 2)
269# KEYSTONESERVICE_ROLE=$(keystone role-create \
270# --name KeystoneServiceAdmin \
271# | grep " id " | get_field 2)
272
273 # TODO(termie): these two might be dubious
274# keystone user-role-add \
275# --user_id $ADMIN_USER \
276# --role_id $KEYSTONEADMIN_ROLE \
277# --tenant_id $ADMIN_TENANT
278# keystone user-role-add \
279# --user_id $ADMIN_USER \
280# --role_id $KEYSTONESERVICE_ROLE \
281# --tenant_id $ADMIN_TENANT
282}
283
Dean Troyerd81a0272012-08-31 18:04:55 -0500284# init_keystone() - Initialize databases, etc.
285function init_keystone() {
286 # (Re)create keystone database
Terry Wilson428af5a2012-11-01 16:12:39 -0400287 recreate_database keystone utf8
Dean Troyerd81a0272012-08-31 18:04:55 -0500288
289 # Initialize keystone database
290 $KEYSTONE_DIR/bin/keystone-manage db_sync
291
Dean Troyerbc071bc2012-10-01 14:06:44 -0500292 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
293 # Set up certificates
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800294 rm -rf $KEYSTONE_CONF_DIR/ssl
Dean Troyerbc071bc2012-10-01 14:06:44 -0500295 $KEYSTONE_DIR/bin/keystone-manage pki_setup
296
297 # Create cache dir
298 sudo mkdir -p $KEYSTONE_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100299 sudo chown $STACK_USER $KEYSTONE_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800300 rm -f $KEYSTONE_AUTH_CACHE_DIR/*
Dean Troyerbc071bc2012-10-01 14:06:44 -0500301 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500302}
303
304# install_keystoneclient() - Collect source and prepare
305function install_keystoneclient() {
306 git_clone $KEYSTONECLIENT_REPO $KEYSTONECLIENT_DIR $KEYSTONECLIENT_BRANCH
307}
308
309# install_keystone() - Collect source and prepare
310function install_keystone() {
Brad Topolf127e2f2013-01-22 10:17:50 -0600311 # only install ldap if the service has been enabled
312 if is_service_enabled ldap; then
313 install_ldap
314 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500315 git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
316}
317
318# start_keystone() - Start running processes, including screen
319function start_keystone() {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600320 # Get right service port for testing
321 local service_port=$KEYSTONE_SERVICE_PORT
322 if is_service_enabled tls-proxy; then
323 service_port=$KEYSTONE_SERVICE_PORT_INT
324 fi
325
Dean Troyerd81a0272012-08-31 18:04:55 -0500326 # Start Keystone in a screen window
327 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 -0600328 echo "Waiting for keystone to start..."
Dean Troyerc83a7e12012-11-29 11:47:58 -0600329 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
Nachi Ueno07115eb2013-02-26 12:38:18 -0800330 die $LINENO "keystone did not start"
Dean Troyerd835de82012-11-29 17:11:35 -0600331 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600332
333 # Start proxies if enabled
334 if is_service_enabled tls-proxy; then
335 start_tls_proxy '*' $KEYSTONE_SERVICE_PORT $KEYSTONE_SERVICE_HOST $KEYSTONE_SERVICE_PORT_INT &
336 start_tls_proxy '*' $KEYSTONE_AUTH_PORT $KEYSTONE_AUTH_HOST $KEYSTONE_AUTH_PORT_INT &
337 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500338}
339
340# stop_keystone() - Stop running processes
341function stop_keystone() {
342 # Kill the Keystone screen window
343 screen -S $SCREEN_NAME -p key -X kill
344}
Dean Troyer7903b792012-09-13 17:16:12 -0500345
346# Restore xtrace
347$XTRACE