blob: d07b34f797b5bda5daf69585cd5d9e28508a044f [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
Dean Troyerb7490da2013-03-18 16:07:56 -050062# Set the tenant for service accounts in Keystone
63SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
64
Dean Troyerd81a0272012-08-31 18:04:55 -050065
Dean Troyercc6b4432013-04-08 15:38:03 -050066# Functions
67# ---------
Dean Troyerd81a0272012-08-31 18:04:55 -050068
69# cleanup_keystone() - Remove residual data files, anything left over from previous
70# runs that a clean run would need to clean up
71function cleanup_keystone() {
72 # kill instances (nova)
73 # delete image files (glance)
74 # This function intentionally left blank
75 :
76}
77
Dean Troyerd81a0272012-08-31 18:04:55 -050078# configure_keystone() - Set config files, create data dirs, etc
79function configure_keystone() {
Dean Troyerd81a0272012-08-31 18:04:55 -050080 if [[ ! -d $KEYSTONE_CONF_DIR ]]; then
81 sudo mkdir -p $KEYSTONE_CONF_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -050082 fi
Attila Fazekas91b8d132013-01-06 22:40:09 +010083 sudo chown $STACK_USER $KEYSTONE_CONF_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -050084
85 if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
86 cp -p $KEYSTONE_DIR/etc/keystone.conf.sample $KEYSTONE_CONF
87 cp -p $KEYSTONE_DIR/etc/policy.json $KEYSTONE_CONF_DIR
Alan Pevece0bb4472013-03-12 11:10:52 +010088 if [[ -f "$KEYSTONE_DIR/etc/keystone-paste.ini" ]]; then
89 cp -p "$KEYSTONE_DIR/etc/keystone-paste.ini" "$KEYSTONE_PASTE_INI"
90 fi
91 fi
92 if [[ -f "$KEYSTONE_PASTE_INI" ]]; then
93 iniset "$KEYSTONE_CONF" paste_deploy config_file "$KEYSTONE_PASTE_INI"
94 else
95 # compatibility with mixed cfg and paste.deploy configuration
96 KEYSTONE_PASTE_INI="$KEYSTONE_CONF"
Dean Troyerd81a0272012-08-31 18:04:55 -050097 fi
98
99 # Rewrite stock ``keystone.conf``
Dean Troyerc83a7e12012-11-29 11:47:58 -0600100
Brad Topolf127e2f2013-01-22 10:17:50 -0600101 if is_service_enabled ldap; then
102 #Set all needed ldap values
103 iniset $KEYSTONE_CONF ldap password $LDAP_PASSWORD
104 iniset $KEYSTONE_CONF ldap user "dc=Manager,dc=openstack,dc=org"
105 iniset $KEYSTONE_CONF ldap suffix "dc=openstack,dc=org"
Brad Topolf41024e2013-02-19 15:36:41 -0600106 iniset $KEYSTONE_CONF ldap use_dumb_member "True"
107 iniset $KEYSTONE_CONF ldap user_attribute_ignore "enabled,email,tenants,tenantId"
108 iniset $KEYSTONE_CONF ldap tenant_attribute_ignore "enabled"
109 iniset $KEYSTONE_CONF ldap tenant_domain_id_attribute "businessCategory"
110 iniset $KEYSTONE_CONF ldap tenant_desc_attribute "description"
111 iniset $KEYSTONE_CONF ldap tenant_tree_dn "ou=Projects,dc=openstack,dc=org"
112 iniset $KEYSTONE_CONF ldap user_domain_id_attribute "businessCategory"
113 iniset $KEYSTONE_CONF ldap user_tree_dn "ou=Users,dc=openstack,dc=org"
114 iniset $KEYSTONE_CONF DEFAULT member_role_id "9fe2ff9ee4384b1894a90878d3e92bab"
115 iniset $KEYSTONE_CONF DEFAULT member_role_name "_member_"
Brad Topolf127e2f2013-01-22 10:17:50 -0600116 fi
117
118 if [[ "$KEYSTONE_IDENTITY_BACKEND" == "ldap" ]]; then
119 iniset $KEYSTONE_CONF identity driver "keystone.identity.backends.ldap.Identity"
120 fi
121
Dean Troyer245a4312013-06-28 09:16:08 -0500122 # Set the URL advertised in the ``versions`` structure returned by the '/' route
123 iniset $KEYSTONE_CONF DEFAULT public_endpoint "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:%(public_port)s/"
124 iniset $KEYSTONE_CONF DEFAULT admin_endpoint "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:%(admin_port)s/"
125
Dean Troyerc83a7e12012-11-29 11:47:58 -0600126 if is_service_enabled tls-proxy; then
127 # Set the service ports for a proxy to take the originals
128 iniset $KEYSTONE_CONF DEFAULT public_port $KEYSTONE_SERVICE_PORT_INT
129 iniset $KEYSTONE_CONF DEFAULT admin_port $KEYSTONE_AUTH_PORT_INT
130 fi
131
Dean Troyerd81a0272012-08-31 18:04:55 -0500132 iniset $KEYSTONE_CONF DEFAULT admin_token "$SERVICE_TOKEN"
Doug Hellmann4de55e92012-10-26 12:24:28 -0400133 iniset $KEYSTONE_CONF signing token_format "$KEYSTONE_TOKEN_FORMAT"
Attila Fazekas7e79d912013-03-03 12:23:04 +0100134 iniset $KEYSTONE_CONF sql connection `database_connection_url keystone`
Dean Troyerd81a0272012-08-31 18:04:55 -0500135 iniset $KEYSTONE_CONF ec2 driver "keystone.contrib.ec2.backends.sql.Ec2"
Dean Troyerd81a0272012-08-31 18:04:55 -0500136
Davanum Srinivas5bd96f92013-01-29 15:12:20 -0500137 if [[ "$KEYSTONE_TOKEN_BACKEND" = "sql" ]]; then
138 iniset $KEYSTONE_CONF token driver keystone.token.backends.sql.Token
139 else
140 iniset $KEYSTONE_CONF token driver keystone.token.backends.kvs.Token
141 fi
142
Dean Troyerd81a0272012-08-31 18:04:55 -0500143 if [[ "$KEYSTONE_CATALOG_BACKEND" = "sql" ]]; then
144 # Configure ``keystone.conf`` to use sql
145 iniset $KEYSTONE_CONF catalog driver keystone.catalog.backends.sql.Catalog
146 inicomment $KEYSTONE_CONF catalog template_file
147 else
148 cp -p $FILES/default_catalog.templates $KEYSTONE_CATALOG
149
150 # Add swift endpoints to service catalog if swift is enabled
Chmouel Boudjnah0c3a5582013-03-06 10:58:33 +0100151 if is_service_enabled s-proxy; then
Dean Troyerd81a0272012-08-31 18:04:55 -0500152 echo "catalog.RegionOne.object_store.publicURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
153 echo "catalog.RegionOne.object_store.adminURL = http://%SERVICE_HOST%:8080/" >> $KEYSTONE_CATALOG
154 echo "catalog.RegionOne.object_store.internalURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
155 echo "catalog.RegionOne.object_store.name = Swift Service" >> $KEYSTONE_CATALOG
156 fi
157
158 # Add quantum endpoints to service catalog if quantum is enabled
159 if is_service_enabled quantum; then
160 echo "catalog.RegionOne.network.publicURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
161 echo "catalog.RegionOne.network.adminURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
162 echo "catalog.RegionOne.network.internalURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
163 echo "catalog.RegionOne.network.name = Quantum Service" >> $KEYSTONE_CATALOG
164 fi
165
Vincent Untz7e86dbe2012-12-13 08:50:37 +0100166 sed -e "
Dean Troyerd81a0272012-08-31 18:04:55 -0500167 s,%SERVICE_HOST%,$SERVICE_HOST,g;
168 s,%S3_SERVICE_PORT%,$S3_SERVICE_PORT,g;
169 " -i $KEYSTONE_CATALOG
170
171 # Configure ``keystone.conf`` to use templates
172 iniset $KEYSTONE_CONF catalog driver "keystone.catalog.backends.templated.TemplatedCatalog"
173 iniset $KEYSTONE_CONF catalog template_file "$KEYSTONE_CATALOG"
174 fi
175
176 # Set up logging
177 LOGGING_ROOT="devel"
178 if [ "$SYSLOG" != "False" ]; then
179 LOGGING_ROOT="$LOGGING_ROOT,production"
180 fi
181 KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_CONF_DIR/logging.conf"
182 cp $KEYSTONE_DIR/etc/logging.conf.sample $KEYSTONE_CONF_DIR/logging.conf
183 iniset $KEYSTONE_CONF_DIR/logging.conf logger_root level "DEBUG"
184 iniset $KEYSTONE_CONF_DIR/logging.conf logger_root handlers "devel,production"
Dean Troyerd81a0272012-08-31 18:04:55 -0500185}
186
Dean Troyerd835de82012-11-29 17:11:35 -0600187# create_keystone_accounts() - Sets up common required keystone accounts
188
189# Tenant User Roles
190# ------------------------------------------------------------------
191# service -- --
192# -- -- Member
193# admin admin admin
194# demo admin admin
195# demo demo Member, anotherrole
196# invisible_to_admin demo Member
197
198# Migrated from keystone_data.sh
199create_keystone_accounts() {
200
201 # admin
202 ADMIN_TENANT=$(keystone tenant-create \
203 --name admin \
204 | grep " id " | get_field 2)
205 ADMIN_USER=$(keystone user-create \
206 --name admin \
207 --pass "$ADMIN_PASSWORD" \
208 --email admin@example.com \
209 | grep " id " | get_field 2)
210 ADMIN_ROLE=$(keystone role-create \
211 --name admin \
212 | grep " id " | get_field 2)
213 keystone user-role-add \
214 --user_id $ADMIN_USER \
215 --role_id $ADMIN_ROLE \
216 --tenant_id $ADMIN_TENANT
217
218 # service
219 SERVICE_TENANT=$(keystone tenant-create \
220 --name $SERVICE_TENANT_NAME \
221 | grep " id " | get_field 2)
222
223 # The Member role is used by Horizon and Swift so we need to keep it:
224 MEMBER_ROLE=$(keystone role-create --name=Member | grep " id " | get_field 2)
225 # ANOTHER_ROLE demonstrates that an arbitrary role may be created and used
226 # TODO(sleepsonthefloor): show how this can be used for rbac in the future!
227 ANOTHER_ROLE=$(keystone role-create --name=anotherrole | grep " id " | get_field 2)
228
229 # invisible tenant - admin can't see this one
230 INVIS_TENANT=$(keystone tenant-create --name=invisible_to_admin | grep " id " | get_field 2)
231
232 # demo
233 DEMO_TENANT=$(keystone tenant-create \
234 --name=demo \
235 | grep " id " | get_field 2)
236 DEMO_USER=$(keystone user-create \
237 --name demo \
238 --pass "$ADMIN_PASSWORD" \
239 --email demo@example.com \
240 | grep " id " | get_field 2)
241 keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $DEMO_TENANT
242 keystone user-role-add --user_id $ADMIN_USER --role_id $ADMIN_ROLE --tenant_id $DEMO_TENANT
243 keystone user-role-add --user_id $DEMO_USER --role_id $ANOTHER_ROLE --tenant_id $DEMO_TENANT
244 keystone user-role-add --user_id $DEMO_USER --role_id $MEMBER_ROLE --tenant_id $INVIS_TENANT
245
246 # Keystone
247 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
248 KEYSTONE_SERVICE=$(keystone service-create \
249 --name keystone \
250 --type identity \
251 --description "Keystone Identity Service" \
252 | grep " id " | get_field 2)
253 keystone endpoint-create \
254 --region RegionOne \
255 --service_id $KEYSTONE_SERVICE \
Dean Troyerc83a7e12012-11-29 11:47:58 -0600256 --publicurl "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0" \
257 --adminurl "$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v2.0" \
258 --internalurl "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v2.0"
Dean Troyerd835de82012-11-29 17:11:35 -0600259 fi
Dean Troyerd835de82012-11-29 17:11:35 -0600260}
261
Dean Troyerd81a0272012-08-31 18:04:55 -0500262# init_keystone() - Initialize databases, etc.
263function init_keystone() {
264 # (Re)create keystone database
Terry Wilson428af5a2012-11-01 16:12:39 -0400265 recreate_database keystone utf8
Dean Troyerd81a0272012-08-31 18:04:55 -0500266
267 # Initialize keystone database
268 $KEYSTONE_DIR/bin/keystone-manage db_sync
269
Dean Troyerbc071bc2012-10-01 14:06:44 -0500270 if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
271 # Set up certificates
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800272 rm -rf $KEYSTONE_CONF_DIR/ssl
Dean Troyerbc071bc2012-10-01 14:06:44 -0500273 $KEYSTONE_DIR/bin/keystone-manage pki_setup
274
275 # Create cache dir
276 sudo mkdir -p $KEYSTONE_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100277 sudo chown $STACK_USER $KEYSTONE_AUTH_CACHE_DIR
Vishvananda Ishaya23431f32012-12-12 15:57:33 -0800278 rm -f $KEYSTONE_AUTH_CACHE_DIR/*
Dean Troyerbc071bc2012-10-01 14:06:44 -0500279 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500280}
281
282# install_keystoneclient() - Collect source and prepare
283function install_keystoneclient() {
284 git_clone $KEYSTONECLIENT_REPO $KEYSTONECLIENT_DIR $KEYSTONECLIENT_BRANCH
Sean Dague1b4b4be2013-04-01 16:44:31 -0400285 setup_develop $KEYSTONECLIENT_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -0500286}
287
288# install_keystone() - Collect source and prepare
289function install_keystone() {
Brad Topolf127e2f2013-01-22 10:17:50 -0600290 # only install ldap if the service has been enabled
291 if is_service_enabled ldap; then
292 install_ldap
293 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500294 git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
Sean Dague1b4b4be2013-04-01 16:44:31 -0400295 setup_develop $KEYSTONE_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -0500296}
297
298# start_keystone() - Start running processes, including screen
299function start_keystone() {
Dean Troyerc83a7e12012-11-29 11:47:58 -0600300 # Get right service port for testing
301 local service_port=$KEYSTONE_SERVICE_PORT
302 if is_service_enabled tls-proxy; then
303 service_port=$KEYSTONE_SERVICE_PORT_INT
304 fi
305
Dean Troyerd81a0272012-08-31 18:04:55 -0500306 # Start Keystone in a screen window
307 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 -0600308 echo "Waiting for keystone to start..."
Dean Troyerc83a7e12012-11-29 11:47:58 -0600309 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 -0800310 die $LINENO "keystone did not start"
Dean Troyerd835de82012-11-29 17:11:35 -0600311 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600312
313 # Start proxies if enabled
314 if is_service_enabled tls-proxy; then
315 start_tls_proxy '*' $KEYSTONE_SERVICE_PORT $KEYSTONE_SERVICE_HOST $KEYSTONE_SERVICE_PORT_INT &
316 start_tls_proxy '*' $KEYSTONE_AUTH_PORT $KEYSTONE_AUTH_HOST $KEYSTONE_AUTH_PORT_INT &
317 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500318}
319
320# stop_keystone() - Stop running processes
321function stop_keystone() {
322 # Kill the Keystone screen window
323 screen -S $SCREEN_NAME -p key -X kill
324}
Dean Troyer7903b792012-09-13 17:16:12 -0500325
Dean Troyer1a6d4492013-06-03 16:47:36 -0500326
Dean Troyer7903b792012-09-13 17:16:12 -0500327# Restore xtrace
328$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400329
330# Local variables:
331# mode: shell-script
332# End: