blob: 29407a0e69456b8405b2ccbcd2eea51bd96cfae8 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Dean Troyerd81a0272012-08-31 18:04:55 -05003# lib/keystone
4# Functions to control the configuration and operation of **Keystone**
5
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# - ``functions`` file
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +10009# - ``tls`` file
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010010# - ``DEST``, ``STACK_USER``
Adam Gandelmanc4b06712014-09-03 11:44:31 -070011# - ``FILES``
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010012# - ``IDENTITY_API_VERSION``
13# - ``BASE_SQL_CONN``
14# - ``SERVICE_HOST``, ``SERVICE_PROTOCOL``
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010015# - ``S3_SERVICE_PORT`` (template backend only)
Dean Troyerd81a0272012-08-31 18:04:55 -050016
Dean Troyerd81a0272012-08-31 18:04:55 -050017# ``stack.sh`` calls the entry points in this order:
18#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010019# - install_keystone
20# - configure_keystone
21# - _config_keystone_apache_wsgi
22# - init_keystone
23# - start_keystone
Steve Martinelli923be5f2015-12-20 00:24:19 -050024# - bootstrap_keystone
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010025# - create_keystone_accounts
26# - stop_keystone
27# - cleanup_keystone
Dean Troyerd81a0272012-08-31 18:04:55 -050028
Dean Troyer7903b792012-09-13 17:16:12 -050029# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +110030_XTRACE_KEYSTONE=$(set +o | grep xtrace)
Dean Troyer7903b792012-09-13 17:16:12 -050031set +o xtrace
Dean Troyerd81a0272012-08-31 18:04:55 -050032
Dean Troyerd81a0272012-08-31 18:04:55 -050033# Defaults
34# --------
35
Dean Troyerd81a0272012-08-31 18:04:55 -050036# Set up default directories
Jamie Lennox21a90772015-07-03 11:54:38 +100037GITDIR["keystoneauth"]=$DEST/keystoneauth
Sean Daguee08ab102014-11-13 17:09:28 -050038GITDIR["python-keystoneclient"]=$DEST/python-keystoneclient
Sean Dague658312c2014-11-14 11:35:56 -050039GITDIR["keystonemiddleware"]=$DEST/keystonemiddleware
Dean Troyerd81a0272012-08-31 18:04:55 -050040KEYSTONE_DIR=$DEST/keystone
Dean Troyerf8ae6472015-02-17 11:05:06 -060041
42# Keystone virtual environment
43if [[ ${USE_VENV} = True ]]; then
44 PROJECT_VENV["keystone"]=${KEYSTONE_DIR}.venv
45 KEYSTONE_BIN_DIR=${PROJECT_VENV["keystone"]}/bin
46else
47 KEYSTONE_BIN_DIR=$(get_python_exec_prefix)
48fi
49
Dean Troyerd81a0272012-08-31 18:04:55 -050050KEYSTONE_CONF_DIR=${KEYSTONE_CONF_DIR:-/etc/keystone}
51KEYSTONE_CONF=$KEYSTONE_CONF_DIR/keystone.conf
Sean Dague2f8c88e2017-04-13 09:08:39 -040052KEYSTONE_PUBLIC_UWSGI_CONF=$KEYSTONE_CONF_DIR/keystone-uwsgi-public.ini
53KEYSTONE_ADMIN_UWSGI_CONF=$KEYSTONE_CONF_DIR/keystone-uwsgi-admin.ini
54KEYSTONE_PUBLIC_UWSGI=$KEYSTONE_BIN_DIR/keystone-wsgi-public
55KEYSTONE_ADMIN_UWSGI=$KEYSTONE_BIN_DIR/keystone-wsgi-admin
Dean Troyerd81a0272012-08-31 18:04:55 -050056
Brant Knudsona0305362016-01-25 13:38:27 -060057# KEYSTONE_DEPLOY defines how keystone is deployed, allowed values:
58# - mod_wsgi : Run keystone under Apache HTTPd mod_wsgi
Brant Knudsonedc11c22015-12-14 15:32:05 -060059# - uwsgi : Run keystone under uwsgi
Sean Dague6ed53152017-04-13 13:33:16 -040060if [[ "$WSGI_MODE" == "uwsgi" ]]; then
61 KEYSTONE_DEPLOY=uwsgi
62else
63 KEYSTONE_DEPLOY=mod_wsgi
Brant Knudsona0305362016-01-25 13:38:27 -060064fi
65
Brant Knudson331a64f2015-05-11 10:02:24 -050066# Select the Identity backend driver
Alex Rudenkocd770582013-09-01 16:26:03 +020067KEYSTONE_IDENTITY_BACKEND=${KEYSTONE_IDENTITY_BACKEND:-sql}
68
Brant Knudson331a64f2015-05-11 10:02:24 -050069# Select the Assignment backend driver
Alex Rudenkocd770582013-09-01 16:26:03 +020070KEYSTONE_ASSIGNMENT_BACKEND=${KEYSTONE_ASSIGNMENT_BACKEND:-sql}
71
Steve Martinelli35262762016-01-05 23:56:40 -050072# Select the Role backend driver
73KEYSTONE_ROLE_BACKEND=${KEYSTONE_ROLE_BACKEND:-sql}
74
75# Select the Resource backend driver
76KEYSTONE_RESOURCE_BACKEND=${KEYSTONE_RESOURCE_BACKEND:-sql}
77
Brant Knudson331a64f2015-05-11 10:02:24 -050078# Select Keystone's token provider (and format)
ghanshyam27428752018-07-10 09:21:46 +000079# Refer keystone doc for supported token provider:
80# https://docs.openstack.org/keystone/latest/admin/token-provider.html
Steve Martinellidc486bc2016-09-08 02:29:25 +000081KEYSTONE_TOKEN_FORMAT=${KEYSTONE_TOKEN_FORMAT:-fernet}
Brant Knudson1e1fce82014-06-19 16:55:45 -050082KEYSTONE_TOKEN_FORMAT=$(echo ${KEYSTONE_TOKEN_FORMAT} | tr '[:upper:]' '[:lower:]')
Dean Troyerbc071bc2012-10-01 14:06:44 -050083
Dean Troyerd81a0272012-08-31 18:04:55 -050084# Set Keystone interface configuration
Dean Troyerd81a0272012-08-31 18:04:55 -050085KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
Dean Troyerc83a7e12012-11-29 11:47:58 -060086KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-$SERVICE_PROTOCOL}
87
88# Public facing bits
Dean Troyerd81a0272012-08-31 18:04:55 -050089KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
Dean Troyerc83a7e12012-11-29 11:47:58 -060090KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
Dean Troyerd81a0272012-08-31 18:04:55 -050091
David Kranz041fa712014-02-24 13:30:59 -050092# Bind hosts
93KEYSTONE_ADMIN_BIND_HOST=${KEYSTONE_ADMIN_BIND_HOST:-$KEYSTONE_SERVICE_HOST}
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -060094
Sean Dague0b1465b2016-04-04 10:15:47 -040095# Set the project for service accounts in Keystone
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -060096SERVICE_DOMAIN_NAME=${SERVICE_DOMAIN_NAME:-Default}
Sean Dague0b1465b2016-04-04 10:15:47 -040097SERVICE_PROJECT_NAME=${SERVICE_PROJECT_NAME:-service}
Ian Wienand982b9912016-04-14 07:48:24 +100098
99# Note 2016-03 : SERVICE_TENANT_NAME is kept for backwards
100# compatibility; we should be using SERVICE_PROJECT_NAME now
Sean Dague0b1465b2016-04-04 10:15:47 -0400101SERVICE_TENANT_NAME=${SERVICE_PROJECT_NAME:-service}
Dean Troyerb7490da2013-03-18 16:07:56 -0500102
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000103# if we are running with SSL use https protocols
Sean Daguef3b2f4c2017-04-13 10:11:48 -0400104if is_service_enabled tls-proxy; then
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000105 KEYSTONE_AUTH_PROTOCOL="https"
106 KEYSTONE_SERVICE_PROTOCOL="https"
107fi
108
Sean Dague6ed53152017-04-13 13:33:16 -0400109KEYSTONE_SERVICE_URI=${KEYSTONE_SERVICE_PROTOCOL}://${KEYSTONE_SERVICE_HOST}/identity
Sean Daguebb443112017-04-19 16:22:42 -0400110# for compat
111KEYSTONE_AUTH_URI=$KEYSTONE_SERVICE_URI
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000112
Steve Martinellib74e01c2014-12-18 01:35:35 -0500113# V3 URIs
Jens Harbott32c00892019-04-10 10:33:39 +0000114KEYSTONE_AUTH_URI_V3=$KEYSTONE_SERVICE_URI/v3
Steve Martinellib74e01c2014-12-18 01:35:35 -0500115KEYSTONE_SERVICE_URI_V3=$KEYSTONE_SERVICE_URI/v3
116
Rodrigo Duarteb51a8862016-09-26 15:22:35 -0300117# Security compliance
118KEYSTONE_SECURITY_COMPLIANCE_ENABLED=${KEYSTONE_SECURITY_COMPLIANCE_ENABLED:-True}
119KEYSTONE_LOCKOUT_FAILURE_ATTEMPTS=${KEYSTONE_LOCKOUT_FAILURE_ATTEMPTS:-2}
Lance Bragstaddcd4b642017-06-12 14:41:42 +0000120KEYSTONE_LOCKOUT_DURATION=${KEYSTONE_LOCKOUT_DURATION:-10}
Rodrigo Duarteb51a8862016-09-26 15:22:35 -0300121KEYSTONE_UNIQUE_LAST_PASSWORD_COUNT=${KEYSTONE_UNIQUE_LAST_PASSWORD_COUNT:-2}
122
Boris Pavlovic2b6e9ac2017-06-12 17:08:33 -0700123# Number of bcrypt hashing rounds, increasing number exponentially increases required
124# resources to generate password hash. This is very effective way to protect from
125# bruteforce attacks. 4 is minimal value that can be specified for bcrypt and
126# it works way faster than default 12. Minimal value is great for CI and development
127# however may not be suitable for real production.
128KEYSTONE_PASSWORD_HASH_ROUNDS=${KEYSTONE_PASSWORD_HASH_ROUNDS:-4}
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600129
Slawek Kaplonskid33cdd02019-08-01 14:58:37 +0200130# Cache settings
131KEYSTONE_ENABLE_CACHE=${KEYSTONE_ENABLE_CACHE:-True}
132
Dean Troyercc6b4432013-04-08 15:38:03 -0500133# Functions
134# ---------
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600135
136# Test if Keystone is enabled
137# is_keystone_enabled
138function is_keystone_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700139 [[ ,${DISABLED_SERVICES} =~ ,"keystone" ]] && return 1
Dean Troyer5ce44cd2015-02-12 22:18:33 -0600140 [[ ,${ENABLED_SERVICES}, =~ ,"key", ]] && return 0
141 return 1
142}
143
Dean Troyerd81a0272012-08-31 18:04:55 -0500144# cleanup_keystone() - Remove residual data files, anything left over from previous
145# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100146function cleanup_keystone {
Davanum Srinivasaa33c872017-08-16 22:51:07 -0400147 if [ "$KEYSTONE_DEPLOY" == "mod_wsgi" ]; then
148 # These files will be created if we are running WSGI_MODE="mod_wsgi"
149 disable_apache_site keystone
150 sudo rm -f $(apache_site_config_for keystone)
151 else
152 stop_process "keystone"
153 # TODO: remove admin at pike-2
154 remove_uwsgi_config "$KEYSTONE_PUBLIC_UWSGI_CONF" "$KEYSTONE_PUBLIC_UWSGI"
155 remove_uwsgi_config "$KEYSTONE_ADMIN_UWSGI_CONF" "$KEYSTONE_ADMIN_UWSGI"
156 sudo rm -f $(apache_site_config_for keystone-wsgi-public)
157 sudo rm -f $(apache_site_config_for keystone-wsgi-admin)
158 fi
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000159}
160
161# _config_keystone_apache_wsgi() - Set WSGI config files of Keystone
Ian Wienandaee18c72014-02-21 15:35:08 +1100162function _config_keystone_apache_wsgi {
Ian Wienandada886d2015-10-07 14:06:26 +1100163 local keystone_apache_conf
164 keystone_apache_conf=$(apache_site_config_for keystone)
Rob Crittendena1e1f512016-07-20 18:12:09 -0400165 keystone_ssl_listen="#"
Rob Crittenden18d47782014-03-19 17:47:42 -0400166 local keystone_ssl=""
167 local keystone_certfile=""
168 local keystone_keyfile=""
Dean Troyerf8ae6472015-02-17 11:05:06 -0600169 local venv_path=""
Rob Crittenden18d47782014-03-19 17:47:42 -0400170
Dean Troyerf8ae6472015-02-17 11:05:06 -0600171 if [[ ${USE_VENV} = True ]]; then
Chris Dent3a2c86a2015-05-12 13:41:25 +0000172 venv_path="python-path=${PROJECT_VENV["keystone"]}/lib/$(python_version)/site-packages"
Dean Troyerf8ae6472015-02-17 11:05:06 -0600173 fi
Morgan Fainbergd074dc72014-06-24 21:33:39 -0700174
Morgan Fainberg970ee902014-06-09 12:07:29 -0700175 sudo cp $FILES/apache-keystone.template $keystone_apache_conf
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000176 sudo sed -e "
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000177 s|%APACHE_NAME%|$APACHE_NAME|g;
Rob Crittendena1e1f512016-07-20 18:12:09 -0400178 s|%SSLLISTEN%|$keystone_ssl_listen|g;
Rob Crittenden18d47782014-03-19 17:47:42 -0400179 s|%SSLENGINE%|$keystone_ssl|g;
180 s|%SSLCERTFILE%|$keystone_certfile|g;
181 s|%SSLKEYFILE%|$keystone_keyfile|g;
Dean Troyerf8ae6472015-02-17 11:05:06 -0600182 s|%USER%|$STACK_USER|g;
183 s|%VIRTUALENV%|$venv_path|g
Brant Knudson2ad1a422015-06-23 10:53:50 -0500184 s|%KEYSTONE_BIN%|$KEYSTONE_BIN_DIR|g
Morgan Fainberg970ee902014-06-09 12:07:29 -0700185 " -i $keystone_apache_conf
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000186}
187
Dean Troyerd81a0272012-08-31 18:04:55 -0500188# configure_keystone() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100189function configure_keystone {
Dean Troyer8421c2b2015-03-16 13:52:19 -0500190 sudo install -d -o $STACK_USER $KEYSTONE_CONF_DIR
Dean Troyerd81a0272012-08-31 18:04:55 -0500191
192 if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
Lance Bragstadfe628b92018-04-17 17:01:46 +0000193 install -m 600 /dev/null $KEYSTONE_CONF
Alan Pevece0bb4472013-03-12 11:10:52 +0100194 fi
Lance Bragstadfe628b92018-04-17 17:01:46 +0000195 # Populate ``keystone.conf``
Brad Topolf127e2f2013-01-22 10:17:50 -0600196 if is_service_enabled ldap; then
Leticia Wanderleycc363972017-06-26 23:52:52 -0300197 iniset $KEYSTONE_CONF identity domain_config_dir "$KEYSTONE_CONF_DIR/domains"
198 iniset $KEYSTONE_CONF identity domain_specific_drivers_enabled "True"
Brad Topolf127e2f2013-01-22 10:17:50 -0600199 fi
Brant Knudson331a64f2015-05-11 10:02:24 -0500200 iniset $KEYSTONE_CONF identity driver "$KEYSTONE_IDENTITY_BACKEND"
Boris Pavlovic2b6e9ac2017-06-12 17:08:33 -0700201 iniset $KEYSTONE_CONF identity password_hash_rounds $KEYSTONE_PASSWORD_HASH_ROUNDS
Brant Knudson331a64f2015-05-11 10:02:24 -0500202 iniset $KEYSTONE_CONF assignment driver "$KEYSTONE_ASSIGNMENT_BACKEND"
Steve Martinelli35262762016-01-05 23:56:40 -0500203 iniset $KEYSTONE_CONF role driver "$KEYSTONE_ROLE_BACKEND"
204 iniset $KEYSTONE_CONF resource driver "$KEYSTONE_RESOURCE_BACKEND"
Brad Topolf127e2f2013-01-22 10:17:50 -0600205
Morgan Fainberga8ffe8a2016-01-24 20:36:35 -0800206 # Enable caching
Slawek Kaplonskid33cdd02019-08-01 14:58:37 +0200207 iniset $KEYSTONE_CONF cache enabled $KEYSTONE_ENABLE_CACHE
208 iniset $KEYSTONE_CONF cache backend $CACHE_BACKEND
209 iniset $KEYSTONE_CONF cache memcache_servers $MEMCACHE_SERVERS
Morgan Fainberga8ffe8a2016-01-24 20:36:35 -0800210
Lance Bragstaded6e1d02018-08-01 18:03:44 +0000211 iniset_rpc_backend keystone $KEYSTONE_CONF oslo_messaging_notifications
Sergey Skripnick8464a4c2014-07-08 21:05:23 +0300212
Brant Knudson841fdaf2015-06-21 10:08:22 -0500213 # Override the endpoints advertised by keystone (the public_endpoint and
Jens Harbottf6286cb2020-06-13 11:40:09 +0200214 # admin_endpoint) so that clients use the correct endpoint.
Sean Dague6ed53152017-04-13 13:33:16 -0400215 iniset $KEYSTONE_CONF DEFAULT public_endpoint $KEYSTONE_SERVICE_URI
216 iniset $KEYSTONE_CONF DEFAULT admin_endpoint $KEYSTONE_AUTH_URI
Dean Troyerc83a7e12012-11-29 11:47:58 -0600217
Brant Knudson1e1fce82014-06-19 16:55:45 -0500218 if [[ "$KEYSTONE_TOKEN_FORMAT" != "" ]]; then
Brant Knudson331a64f2015-05-11 10:02:24 -0500219 iniset $KEYSTONE_CONF token provider $KEYSTONE_TOKEN_FORMAT
Sudarshan Acharya37631412013-07-16 00:47:54 +0000220 fi
221
Brant Knudson16d3ad02014-02-13 18:59:50 -0600222 iniset $KEYSTONE_CONF database connection `database_connection_url keystone`
Dean Troyerd81a0272012-08-31 18:04:55 -0500223
Dean Troyerd81a0272012-08-31 18:04:55 -0500224 # Set up logging
Dean Troyerd81a0272012-08-31 18:04:55 -0500225 if [ "$SYSLOG" != "False" ]; then
Brant Knudson4968d1a2014-01-22 19:06:44 -0600226 iniset $KEYSTONE_CONF DEFAULT use_syslog "True"
Dean Troyerd81a0272012-08-31 18:04:55 -0500227 fi
Brant Knudson4968d1a2014-01-22 19:06:44 -0600228
229 # Format logging
Sean Dague27f66e92017-05-02 09:08:17 -0400230 setup_logging $KEYSTONE_CONF
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000231
Brant Knudson0fc336d2015-02-08 11:03:02 -0600232 iniset $KEYSTONE_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
233
Brant Knudsona0305362016-01-25 13:38:27 -0600234 if [ "$KEYSTONE_DEPLOY" == "mod_wsgi" ]; then
Morgan Fainbergda1cc572016-02-02 09:09:28 -0800235 iniset $KEYSTONE_CONF DEFAULT logging_exception_prefix "%(asctime)s.%(msecs)03d %(process)d TRACE %(name)s %(instance)s"
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000236 _config_keystone_apache_wsgi
Brant Knudson556eeb02016-03-24 14:01:57 -0500237 else # uwsgi
Sean Dague6ed53152017-04-13 13:33:16 -0400238 write_uwsgi_config "$KEYSTONE_PUBLIC_UWSGI_CONF" "$KEYSTONE_PUBLIC_UWSGI" "/identity"
239 write_uwsgi_config "$KEYSTONE_ADMIN_UWSGI_CONF" "$KEYSTONE_ADMIN_UWSGI" "/identity_admin"
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000240 fi
Bartosz Górski0abde392014-02-28 14:15:19 +0100241
242 iniset $KEYSTONE_CONF DEFAULT max_token_size 16384
Brant Knudson85a17ea2014-09-13 14:49:24 -0500243
Brant Knudsoncef5e402015-06-25 17:57:53 -0500244 iniset $KEYSTONE_CONF fernet_tokens key_repository "$KEYSTONE_CONF_DIR/fernet-keys/"
Attila Fazekas9ea49752016-03-22 15:22:03 +0100245
Lance Bragstad69d4a712016-08-27 01:01:37 +0000246 iniset $KEYSTONE_CONF credential key_repository "$KEYSTONE_CONF_DIR/credential-keys/"
247
Rodrigo Duarteb51a8862016-09-26 15:22:35 -0300248 if [[ "$KEYSTONE_SECURITY_COMPLIANCE_ENABLED" = True ]]; then
249 iniset $KEYSTONE_CONF security_compliance lockout_failure_attempts $KEYSTONE_LOCKOUT_FAILURE_ATTEMPTS
250 iniset $KEYSTONE_CONF security_compliance lockout_duration $KEYSTONE_LOCKOUT_DURATION
251 iniset $KEYSTONE_CONF security_compliance unique_last_password_count $KEYSTONE_UNIQUE_LAST_PASSWORD_COUNT
252 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500253}
254
Dean Troyerd835de82012-11-29 17:11:35 -0600255# create_keystone_accounts() - Sets up common required keystone accounts
256
Sean Dague0b1465b2016-04-04 10:15:47 -0400257# Project User Roles
Dean Troyerd835de82012-11-29 17:11:35 -0600258# ------------------------------------------------------------------
Dean Troyerd835de82012-11-29 17:11:35 -0600259# admin admin admin
Dean Troyer42a59c22014-03-03 14:31:29 -0600260# service -- --
261# -- -- service
262# -- -- ResellerAdmin
Lance Bragstada7d0c6f2018-06-18 15:06:48 +0000263# -- -- member
Dean Troyerd835de82012-11-29 17:11:35 -0600264# demo admin admin
Lance Bragstada7d0c6f2018-06-18 15:06:48 +0000265# demo demo member, anotherrole
Sean Daguec67d22e2016-02-02 05:51:14 -0500266# alt_demo admin admin
Lance Bragstada7d0c6f2018-06-18 15:06:48 +0000267# alt_demo alt_demo member, anotherrole
268# invisible_to_admin demo member
Dean Troyerd835de82012-11-29 17:11:35 -0600269
Sean Dague0b1465b2016-04-04 10:15:47 -0400270# Group Users Roles Project
Steve Martinelli4599fd12015-03-12 21:30:58 -0400271# ------------------------------------------------------------------
Dean Troyer50f75a92016-02-03 17:40:17 -0600272# admins admin admin admin
Lance Bragstada7d0c6f2018-06-18 15:06:48 +0000273# nonadmins demo, alt_demo member, anotherrole demo, alt_demo
Steve Martinelli4599fd12015-03-12 21:30:58 -0400274
275
Dean Troyerd835de82012-11-29 17:11:35 -0600276# Migrated from keystone_data.sh
Ian Wienandaee18c72014-02-21 15:35:08 +1100277function create_keystone_accounts {
Dean Troyerd835de82012-11-29 17:11:35 -0600278
Lance Bragstada7d0c6f2018-06-18 15:06:48 +0000279 # The keystone bootstrapping process (performed via keystone-manage
280 # bootstrap) creates an admin user, admin role, member role, and admin
281 # project. As a sanity check we exercise the CLI to retrieve the IDs for
282 # these values.
Sean Dague0b1465b2016-04-04 10:15:47 -0400283 local admin_project
284 admin_project=$(openstack project show "admin" -f value -c id)
Ian Wienandada886d2015-10-07 14:06:26 +1100285 local admin_user
Steve Martinelli923be5f2015-12-20 00:24:19 -0500286 admin_user=$(openstack user show "admin" -f value -c id)
Sean Dagueee37d202017-02-08 11:24:31 -0500287 local admin_role="admin"
Lance Bragstada7d0c6f2018-06-18 15:06:48 +0000288 local member_role="member"
Steve Martinelli923be5f2015-12-20 00:24:19 -0500289
Roxana Gherle59c63772015-09-09 18:22:31 -0700290 get_or_add_user_domain_role $admin_role $admin_user default
Dean Troyerd835de82012-11-29 17:11:35 -0600291
Dean Troyer42a59c22014-03-03 14:31:29 -0600292 # Create service project/role
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600293 get_or_create_domain "$SERVICE_DOMAIN_NAME"
Jens Rosenboom0afe2072016-05-12 14:09:03 +0200294 get_or_create_project "$SERVICE_PROJECT_NAME" "$SERVICE_DOMAIN_NAME"
Dean Troyer42a59c22014-03-03 14:31:29 -0600295
296 # Service role, so service users do not have to be admins
Bartosz Górski0abde392014-02-28 14:15:19 +0100297 get_or_create_role service
Dean Troyer42a59c22014-03-03 14:31:29 -0600298
299 # The ResellerAdmin role is used by Nova and Ceilometer so we need to keep it.
Sean Dague0b1465b2016-04-04 10:15:47 -0400300 # The admin role in swift allows a user to act as an admin for their project,
301 # but ResellerAdmin is needed for a user to act as any project. The name of this
Dean Troyer42a59c22014-03-03 14:31:29 -0600302 # role is also configurable in swift-proxy.conf
Bartosz Górski0abde392014-02-28 14:15:19 +0100303 get_or_create_role ResellerAdmin
Dean Troyerd835de82012-11-29 17:11:35 -0600304
Masayuki Igawad3654052014-09-01 17:30:05 +0900305 # another_role demonstrates that an arbitrary role may be created and used
Dean Troyerd835de82012-11-29 17:11:35 -0600306 # TODO(sleepsonthefloor): show how this can be used for rbac in the future!
Sean Dagueee37d202017-02-08 11:24:31 -0500307 local another_role="anotherrole"
308 get_or_create_role $another_role
Dean Troyerd835de82012-11-29 17:11:35 -0600309
Sean Dague0b1465b2016-04-04 10:15:47 -0400310 # invisible project - admin can't see this one
311 local invis_project
312 invis_project=$(get_or_create_project "invisible_to_admin" default)
Dean Troyerd835de82012-11-29 17:11:35 -0600313
314 # demo
Sean Dague0b1465b2016-04-04 10:15:47 -0400315 local demo_project
316 demo_project=$(get_or_create_project "demo" default)
Ian Wienandada886d2015-10-07 14:06:26 +1100317 local demo_user
318 demo_user=$(get_or_create_user "demo" \
Jamie Lennox9d7e7762015-05-29 01:08:53 +0000319 "$ADMIN_PASSWORD" "default" "demo@example.com")
Steve Martinelli19685422014-01-24 13:02:26 -0600320
Sean Dague0b1465b2016-04-04 10:15:47 -0400321 get_or_add_user_project_role $member_role $demo_user $demo_project
322 get_or_add_user_project_role $admin_role $admin_user $demo_project
323 get_or_add_user_project_role $another_role $demo_user $demo_project
324 get_or_add_user_project_role $member_role $demo_user $invis_project
Dean Troyerd835de82012-11-29 17:11:35 -0600325
Sean Daguec67d22e2016-02-02 05:51:14 -0500326 # alt_demo
Sean Dague0b1465b2016-04-04 10:15:47 -0400327 local alt_demo_project
328 alt_demo_project=$(get_or_create_project "alt_demo" default)
Sean Daguec67d22e2016-02-02 05:51:14 -0500329 local alt_demo_user
330 alt_demo_user=$(get_or_create_user "alt_demo" \
331 "$ADMIN_PASSWORD" "default" "alt_demo@example.com")
332
Sean Dague0b1465b2016-04-04 10:15:47 -0400333 get_or_add_user_project_role $member_role $alt_demo_user $alt_demo_project
334 get_or_add_user_project_role $admin_role $admin_user $alt_demo_project
335 get_or_add_user_project_role $another_role $alt_demo_user $alt_demo_project
Sean Daguec67d22e2016-02-02 05:51:14 -0500336
337 # groups
Ian Wienandada886d2015-10-07 14:06:26 +1100338 local admin_group
339 admin_group=$(get_or_create_group "admins" \
Steve Martinelli4599fd12015-03-12 21:30:58 -0400340 "default" "openstack admin group")
Ian Wienandada886d2015-10-07 14:06:26 +1100341 local non_admin_group
342 non_admin_group=$(get_or_create_group "nonadmins" \
Steve Martinelli4599fd12015-03-12 21:30:58 -0400343 "default" "non-admin group")
344
Sean Dague0b1465b2016-04-04 10:15:47 -0400345 get_or_add_group_project_role $member_role $non_admin_group $demo_project
346 get_or_add_group_project_role $another_role $non_admin_group $demo_project
347 get_or_add_group_project_role $member_role $non_admin_group $alt_demo_project
348 get_or_add_group_project_role $another_role $non_admin_group $alt_demo_project
349 get_or_add_group_project_role $admin_role $admin_group $admin_project
Leticia Wanderleycc363972017-06-26 23:52:52 -0300350
351 if is_service_enabled ldap; then
352 create_ldap_domain
353 fi
Dean Troyerd835de82012-11-29 17:11:35 -0600354}
355
Jamie Lennox85ff5322015-01-28 14:28:01 +1000356# Create a user that is capable of verifying keystone tokens for use with auth_token middleware.
357#
358# create_service_user <name> [role]
359#
Jamie Lennox7f685482016-12-13 15:47:11 +1100360# We always add the service role, other roles are also allowed to be added as historically
Jamie Lennox85ff5322015-01-28 14:28:01 +1000361# a lot of projects have configured themselves with the admin or other role here if they are
362# using this user for other purposes beyond simply auth_token middleware.
363function create_service_user {
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600364 get_or_create_user "$1" "$SERVICE_PASSWORD" "$SERVICE_DOMAIN_NAME"
Jamie Lennox7f685482016-12-13 15:47:11 +1100365 get_or_add_user_project_role service "$1" "$SERVICE_PROJECT_NAME" "$SERVICE_DOMAIN_NAME" "$SERVICE_DOMAIN_NAME"
366
367 if [[ -n "$2" ]]; then
368 get_or_add_user_project_role "$2" "$1" "$SERVICE_PROJECT_NAME" "$SERVICE_DOMAIN_NAME" "$SERVICE_DOMAIN_NAME"
369 fi
Jamie Lennox85ff5322015-01-28 14:28:01 +1000370}
371
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100372# Configure a service to use the auth token middleware.
Brant Knudson05952372014-09-19 17:22:22 -0500373#
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100374# configure_keystone_authtoken_middleware conf_file admin_user IGNORED [section]
Brant Knudson05952372014-09-19 17:22:22 -0500375#
376# section defaults to keystone_authtoken, which is where auth_token looks in
377# the .conf file. If the paste config file is used (api-paste.ini) then
378# provide the section name for the auth_token filter.
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100379function configure_keystone_authtoken_middleware {
Brant Knudson05952372014-09-19 17:22:22 -0500380 local conf_file=$1
381 local admin_user=$2
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100382 local section=${3:-keystone_authtoken}
Brant Knudson05952372014-09-19 17:22:22 -0500383
Hua Wangf7dc06c2015-12-23 12:15:59 +0800384 iniset $conf_file $section auth_type password
Jens Harbott32c00892019-04-10 10:33:39 +0000385 iniset $conf_file $section interface public
Sean Dague38d47822017-04-19 16:12:00 -0400386 iniset $conf_file $section auth_url $KEYSTONE_SERVICE_URI
Jamie Lennox78b77262014-12-19 12:56:01 +1000387 iniset $conf_file $section username $admin_user
388 iniset $conf_file $section password $SERVICE_PASSWORD
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600389 iniset $conf_file $section user_domain_name "$SERVICE_DOMAIN_NAME"
Sean Dague7580a0c2016-02-17 06:23:36 -0500390 iniset $conf_file $section project_name $SERVICE_PROJECT_NAME
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600391 iniset $conf_file $section project_domain_name "$SERVICE_DOMAIN_NAME"
Jamie Lennox78b77262014-12-19 12:56:01 +1000392
Rob Crittenden18d47782014-03-19 17:47:42 -0400393 iniset $conf_file $section cafile $SSL_BUNDLE_FILE
Mohammed Naser7db34f62020-03-18 15:35:27 -0400394 iniset $conf_file $section memcached_servers $MEMCACHE_SERVERS
Vincent Hou21fe4e72013-11-21 03:10:27 -0500395}
396
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100397# configure_auth_token_middleware conf_file admin_user IGNORED [section]
398# TODO(frickler): old function for backwards compatibility, remove in U cycle
399function configure_auth_token_middleware {
400 echo "WARNING: configure_auth_token_middleware is deprecated, use configure_keystone_authtoken_middleware instead"
401 configure_keystone_authtoken_middleware $1 $2 $4
402}
403
Dean Troyerd81a0272012-08-31 18:04:55 -0500404# init_keystone() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100405function init_keystone {
Dean Troyerb9e25132013-10-01 14:45:04 -0500406 if is_service_enabled ldap; then
407 init_ldap
408 fi
409
Julia Varlamovaea3e87d2016-12-16 14:39:31 +0400410 if [[ "$RECREATE_KEYSTONE_DB" == True ]]; then
411 # (Re)create keystone database
412 recreate_database keystone
413 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500414
Clark Boylan633dbc32017-06-14 12:09:21 -0700415 time_start "dbsync"
Dean Troyerd81a0272012-08-31 18:04:55 -0500416 # Initialize keystone database
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000417 $KEYSTONE_BIN_DIR/keystone-manage --config-file $KEYSTONE_CONF db_sync
Clark Boylan633dbc32017-06-14 12:09:21 -0700418 time_stop "dbsync"
Dean Troyerd81a0272012-08-31 18:04:55 -0500419
Brant Knudsoncef5e402015-06-25 17:57:53 -0500420 if [[ "$KEYSTONE_TOKEN_FORMAT" == "fernet" ]]; then
421 rm -rf "$KEYSTONE_CONF_DIR/fernet-keys/"
Einst Crazy4f55c2d2016-05-04 08:14:01 +0000422 $KEYSTONE_BIN_DIR/keystone-manage --config-file $KEYSTONE_CONF fernet_setup
Brant Knudsoncef5e402015-06-25 17:57:53 -0500423 fi
Lance Bragstad69d4a712016-08-27 01:01:37 +0000424 rm -rf "$KEYSTONE_CONF_DIR/credential-keys/"
425 $KEYSTONE_BIN_DIR/keystone-manage --config-file $KEYSTONE_CONF credential_setup
426
Dean Troyerd81a0272012-08-31 18:04:55 -0500427}
428
Jamie Lennox21a90772015-07-03 11:54:38 +1000429# install_keystoneauth() - Collect source and prepare
430function install_keystoneauth {
431 if use_library_from_git "keystoneauth"; then
432 git_clone_by_name "keystoneauth"
433 setup_dev_lib "keystoneauth"
434 fi
435}
436
Dean Troyerd81a0272012-08-31 18:04:55 -0500437# install_keystoneclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100438function install_keystoneclient {
Sean Daguee08ab102014-11-13 17:09:28 -0500439 if use_library_from_git "python-keystoneclient"; then
440 git_clone_by_name "python-keystoneclient"
441 setup_dev_lib "python-keystoneclient"
Sean Dague5cb19062014-11-01 01:37:45 +0100442 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500443}
444
Morgan Fainberg58936fd2014-06-24 12:26:07 -0700445# install_keystonemiddleware() - Collect source and prepare
446function install_keystonemiddleware {
Dean Troyerf8ae6472015-02-17 11:05:06 -0600447 # install_keystonemiddleware() is called when keystonemiddleware is needed
448 # to provide an opportunity to install it from the source repo
Sean Dague658312c2014-11-14 11:35:56 -0500449 if use_library_from_git "keystonemiddleware"; then
450 git_clone_by_name "keystonemiddleware"
451 setup_dev_lib "keystonemiddleware"
Dean Troyerf8ae6472015-02-17 11:05:06 -0600452 else
453 # When not installing from repo, keystonemiddleware is still needed...
Sean Dague60996b12015-04-08 09:06:49 -0400454 pip_install_gr keystonemiddleware
Sean Dague658312c2014-11-14 11:35:56 -0500455 fi
Morgan Fainberg5997ce32016-01-20 12:43:22 -0800456 # Install the memcache library so keystonemiddleware can cache tokens in a
457 # shared location.
458 pip_install_gr python-memcached
Morgan Fainberg58936fd2014-06-24 12:26:07 -0700459}
460
Dean Troyerd81a0272012-08-31 18:04:55 -0500461# install_keystone() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100462function install_keystone {
Brad Topolf127e2f2013-01-22 10:17:50 -0600463 # only install ldap if the service has been enabled
464 if is_service_enabled ldap; then
465 install_ldap
466 fi
Morgan Fainberg5997ce32016-01-20 12:43:22 -0800467
Dean Troyerd81a0272012-08-31 18:04:55 -0500468 git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
Sean Dague1b4b4be2013-04-01 16:44:31 -0400469 setup_develop $KEYSTONE_DIR
Brant Knudson6a4d3eb2015-08-01 09:19:18 -0500470
471 if is_service_enabled ldap; then
472 setup_develop $KEYSTONE_DIR ldap
473 fi
474
Brant Knudsona0305362016-01-25 13:38:27 -0600475 if [ "$KEYSTONE_DEPLOY" == "mod_wsgi" ]; then
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000476 install_apache_wsgi
477 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500478}
479
Sean Dague0eebeb42017-08-30 14:16:58 -0400480# start_keystone() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100481function start_keystone {
Brant Knudsona0305362016-01-25 13:38:27 -0600482 if [ "$KEYSTONE_DEPLOY" == "mod_wsgi" ]; then
Adam Gandelmanc4b06712014-09-03 11:44:31 -0700483 enable_apache_site keystone
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000484 restart_apache_server
Brant Knudson556eeb02016-03-24 14:01:57 -0500485 else # uwsgi
Ian Wienand312517d2018-06-22 22:23:29 +1000486 run_process keystone "$(which uwsgi) --procname-prefix keystone --ini $KEYSTONE_PUBLIC_UWSGI_CONF" ""
Jamie Lennoxa00e5f82013-09-17 12:47:03 +1000487 fi
488
Dean Troyerd835de82012-11-29 17:11:35 -0600489 echo "Waiting for keystone to start..."
Jens Harbottf6286cb2020-06-13 11:40:09 +0200490 # Check that the keystone service is running.
Sean Dague6ed53152017-04-13 13:33:16 -0400491 local service_uri=$auth_protocol://$KEYSTONE_SERVICE_HOST/identity/v$IDENTITY_API_VERSION/
Brant Knudson841fdaf2015-06-21 10:08:22 -0500492
493 if ! wait_for_service $SERVICE_TIMEOUT $service_uri; then
Sean Dague101b4242013-10-22 08:47:11 -0400494 die $LINENO "keystone did not start"
Dean Troyerd835de82012-11-29 17:11:35 -0600495 fi
Dean Troyerc83a7e12012-11-29 11:47:58 -0600496
Morgan Fainberg5997ce32016-01-20 12:43:22 -0800497 # (re)start memcached to make sure we have a clean memcache.
498 restart_service memcached
Dean Troyerd81a0272012-08-31 18:04:55 -0500499}
500
501# stop_keystone() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100502function stop_keystone {
Brant Knudsona0305362016-01-25 13:38:27 -0600503 if [ "$KEYSTONE_DEPLOY" == "mod_wsgi" ]; then
Adam Gandelmanc4b06712014-09-03 11:44:31 -0700504 disable_apache_site keystone
505 restart_apache_server
Matthew Treinish9c5ffd82017-03-29 16:47:57 -0400506 else
Sean Daguebb443112017-04-19 16:22:42 -0400507 stop_process keystone
Adam Gandelmanc4b06712014-09-03 11:44:31 -0700508 fi
Dean Troyerd81a0272012-08-31 18:04:55 -0500509}
Dean Troyer7903b792012-09-13 17:16:12 -0500510
Steve Martinelli923be5f2015-12-20 00:24:19 -0500511# bootstrap_keystone() - Initialize user, role and project
512# This function uses the following GLOBAL variables:
513# - ``KEYSTONE_BIN_DIR``
514# - ``ADMIN_PASSWORD``
Jens Harbottf6286cb2020-06-13 11:40:09 +0200515# - ``KEYSTONE_AUTH_URI``
Steve Martinelli923be5f2015-12-20 00:24:19 -0500516# - ``REGION_NAME``
Jens Harbottf6286cb2020-06-13 11:40:09 +0200517# - ``KEYSTONE_SERVICE_URI``
Steve Martinelli923be5f2015-12-20 00:24:19 -0500518function bootstrap_keystone {
Jamie Lennox32bf2c42016-03-08 12:24:52 +1100519 $KEYSTONE_BIN_DIR/keystone-manage bootstrap \
520 --bootstrap-username admin \
521 --bootstrap-password "$ADMIN_PASSWORD" \
522 --bootstrap-project-name admin \
523 --bootstrap-role-name admin \
524 --bootstrap-service-name keystone \
525 --bootstrap-region-id "$REGION_NAME" \
Armando Migliaccio8dda0612016-04-07 00:12:51 +0000526 --bootstrap-admin-url "$KEYSTONE_AUTH_URI" \
Sean Daguebfff93e2017-02-13 16:18:08 -0500527 --bootstrap-public-url "$KEYSTONE_SERVICE_URI"
Steve Martinelli923be5f2015-12-20 00:24:19 -0500528}
Dean Troyer1a6d4492013-06-03 16:47:36 -0500529
Leticia Wanderleycc363972017-06-26 23:52:52 -0300530# create_ldap_domain() - Create domain file and initialize domain with a user
531function create_ldap_domain {
532 # Creates domain Users
533 openstack --os-identity-api-version=3 domain create --description "LDAP domain" Users
534
535 # Create domain file inside etc/keystone/domains
536 KEYSTONE_LDAP_DOMAIN_FILE=$KEYSTONE_CONF_DIR/domains/keystone.Users.conf
537 mkdir -p "$KEYSTONE_CONF_DIR/domains"
538 touch "$KEYSTONE_LDAP_DOMAIN_FILE"
539
540 # Set identity driver 'ldap'
541 iniset $KEYSTONE_LDAP_DOMAIN_FILE identity driver "ldap"
542
543 # LDAP settings for Users domain
Leticia Wanderleycc363972017-06-26 23:52:52 -0300544 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap user_tree_dn "ou=Users,$LDAP_BASE_DN"
545 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap user_objectclass "inetOrgPerson"
546 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap user_name_attribute "cn"
547 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap user_mail_attribute "mail"
548 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap user_id_attribute "uid"
549 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap user "cn=Manager,dc=openstack,dc=org"
550 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap url "ldap://localhost"
551 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap suffix $LDAP_BASE_DN
552 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap password $LDAP_PASSWORD
553 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap group_tree_dn "ou=Groups,$LDAP_BASE_DN"
554 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap group_objectclass "groupOfNames"
555 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap group_name_attribute "cn"
556 iniset $KEYSTONE_LDAP_DOMAIN_FILE ldap group_id_attribute "cn"
557
558 # Restart apache and identity services to associate domain and conf file
559 sudo service apache2 reload
560 sudo systemctl restart devstack@keystone
561
562 # Create LDAP user.ldif and add user to LDAP backend
563 local tmp_ldap_dir
564 tmp_ldap_dir=$(mktemp -d -t ldap.$$.XXXXXXXXXX)
565
566 _ldap_varsubst $FILES/ldap/user.ldif.in $slappass >$tmp_ldap_dir/user.ldif
567 sudo ldapadd -x -w $LDAP_PASSWORD -D "$LDAP_MANAGER_DN" -H $LDAP_URL -c -f $tmp_ldap_dir/user.ldif
568 rm -rf $tmp_ldap_dir
569
570 local admin_project
571 admin_project=$(get_or_create_project "admin" default)
572 local ldap_user
573 ldap_user=$(openstack user show --domain=Users demo -f value -c id)
574 local admin_role="admin"
575 get_or_create_role $admin_role
576
577 # Grant demo LDAP user access to project and role
578 get_or_add_user_project_role $admin_role $ldap_user $admin_project
579}
580
Dean Troyer7903b792012-09-13 17:16:12 -0500581# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100582$_XTRACE_KEYSTONE
Sean Dague584d90e2013-03-29 14:34:53 -0400583
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100584# Tell emacs to use shell-script-mode
585## Local variables:
586## mode: shell-script
587## End: