2012-08-31 18:04:55 -05:00
# lib/keystone
# Functions to control the configuration and operation of **Keystone**
# Dependencies:
# ``functions`` file
2013-01-24 14:14:28 -06:00
# ``DEST``, ``STACK_USER``
# ``IDENTITY_API_VERSION``
2012-08-31 18:04:55 -05:00
# ``BASE_SQL_CONN``
2012-11-29 11:47:58 -06:00
# ``SERVICE_HOST``, ``SERVICE_PROTOCOL``
2012-08-31 18:04:55 -05:00
# ``SERVICE_TOKEN``
# ``S3_SERVICE_PORT`` (template backend only)
# ``stack.sh`` calls the entry points in this order:
#
# install_keystone
# configure_keystone
# init_keystone
# start_keystone
2012-11-29 17:11:35 -06:00
# create_keystone_accounts
2012-08-31 18:04:55 -05:00
# stop_keystone
# cleanup_keystone
2012-09-13 17:16:12 -05:00
# Save trace setting
XTRACE=$(set +o | grep xtrace)
set +o xtrace
2012-08-31 18:04:55 -05:00
# Defaults
# --------
# Set up default directories
KEYSTONE_DIR=$DEST/keystone
KEYSTONE_CONF_DIR=${KEYSTONE_CONF_DIR:-/etc/keystone}
KEYSTONE_CONF=$KEYSTONE_CONF_DIR/keystone.conf
2013-03-12 11:10:52 +01:00
KEYSTONE_PASTE_INI=${KEYSTONE_PASTE_INI:-$KEYSTONE_CONF_DIR/keystone-paste.ini}
2012-10-01 14:06:44 -05:00
KEYSTONE_AUTH_CACHE_DIR=${KEYSTONE_AUTH_CACHE_DIR:-/var/cache/keystone}
2012-08-31 18:04:55 -05:00
KEYSTONECLIENT_DIR=$DEST/python-keystoneclient
2012-10-01 14:06:44 -05:00
# Select the backend for Keystone's service catalog
2012-09-10 18:30:37 -05:00
KEYSTONE_CATALOG_BACKEND=${KEYSTONE_CATALOG_BACKEND:-sql}
2012-08-31 18:04:55 -05:00
KEYSTONE_CATALOG=$KEYSTONE_CONF_DIR/default_catalog.templates
2013-01-29 15:12:20 -05:00
# Select the backend for Tokens
KEYSTONE_TOKEN_BACKEND=${KEYSTONE_TOKEN_BACKEND:-sql}
2013-09-01 16:26:03 +02:00
# Select the backend for Identity
KEYSTONE_IDENTITY_BACKEND=${KEYSTONE_IDENTITY_BACKEND:-sql}
# Select the backend for Assignment
KEYSTONE_ASSIGNMENT_BACKEND=${KEYSTONE_ASSIGNMENT_BACKEND:-sql}
2012-10-01 14:06:44 -05:00
# Select Keystone's token format
# Choose from 'UUID' and 'PKI'
KEYSTONE_TOKEN_FORMAT=${KEYSTONE_TOKEN_FORMAT:-PKI}
2012-08-31 18:04:55 -05:00
# Set Keystone interface configuration
KEYSTONE_AUTH_HOST=${KEYSTONE_AUTH_HOST:-$SERVICE_HOST}
KEYSTONE_AUTH_PORT=${KEYSTONE_AUTH_PORT:-35357}
2012-11-29 11:47:58 -06:00
KEYSTONE_AUTH_PORT_INT=${KEYSTONE_AUTH_PORT_INT:-35358}
KEYSTONE_AUTH_PROTOCOL=${KEYSTONE_AUTH_PROTOCOL:-$SERVICE_PROTOCOL}
# Public facing bits
2012-08-31 18:04:55 -05:00
KEYSTONE_SERVICE_HOST=${KEYSTONE_SERVICE_HOST:-$SERVICE_HOST}
KEYSTONE_SERVICE_PORT=${KEYSTONE_SERVICE_PORT:-5000}
2012-11-29 11:47:58 -06:00
KEYSTONE_SERVICE_PORT_INT=${KEYSTONE_SERVICE_PORT_INT:-5001}
KEYSTONE_SERVICE_PROTOCOL=${KEYSTONE_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
2012-08-31 18:04:55 -05:00
2013-03-18 16:07:56 -05:00
# Set the tenant for service accounts in Keystone
SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service}
2013-09-01 16:26:03 +02:00
# valid identity backends as per dir keystone/identity/backends
KEYSTONE_VALID_IDENTITY_BACKENDS=kvs,ldap,pam,sql
# valid assignment backends as per dir keystone/identity/backends
KEYSTONE_VALID_ASSIGNMENT_BACKENDS=kvs,ldap,sql
2012-08-31 18:04:55 -05:00
2013-04-08 15:38:03 -05:00
# Functions
# ---------
2012-08-31 18:04:55 -05:00
# cleanup_keystone() - Remove residual data files, anything left over from previous
# runs that a clean run would need to clean up
function cleanup_keystone() {
# kill instances (nova)
# delete image files (glance)
# This function intentionally left blank
:
}
# configure_keystone() - Set config files, create data dirs, etc
function configure_keystone() {
if [[ ! -d $KEYSTONE_CONF_DIR ]]; then
sudo mkdir -p $KEYSTONE_CONF_DIR
fi
2013-01-06 22:40:09 +01:00
sudo chown $STACK_USER $KEYSTONE_CONF_DIR
2012-08-31 18:04:55 -05:00
if [[ "$KEYSTONE_CONF_DIR" != "$KEYSTONE_DIR/etc" ]]; then
cp -p $KEYSTONE_DIR/etc/keystone.conf.sample $KEYSTONE_CONF
cp -p $KEYSTONE_DIR/etc/policy.json $KEYSTONE_CONF_DIR
2013-03-12 11:10:52 +01:00
if [[ -f "$KEYSTONE_DIR/etc/keystone-paste.ini" ]]; then
cp -p "$KEYSTONE_DIR/etc/keystone-paste.ini" "$KEYSTONE_PASTE_INI"
fi
fi
if [[ -f "$KEYSTONE_PASTE_INI" ]]; then
iniset "$KEYSTONE_CONF" paste_deploy config_file "$KEYSTONE_PASTE_INI"
else
# compatibility with mixed cfg and paste.deploy configuration
KEYSTONE_PASTE_INI="$KEYSTONE_CONF"
2012-08-31 18:04:55 -05:00
fi
# Rewrite stock ``keystone.conf``
2012-11-29 11:47:58 -06:00
2013-01-22 10:17:50 -06:00
if is_service_enabled ldap; then
#Set all needed ldap values
iniset $KEYSTONE_CONF ldap password $LDAP_PASSWORD
iniset $KEYSTONE_CONF ldap user "dc=Manager,dc=openstack,dc=org"
iniset $KEYSTONE_CONF ldap suffix "dc=openstack,dc=org"
2013-02-19 15:36:41 -06:00
iniset $KEYSTONE_CONF ldap use_dumb_member "True"
iniset $KEYSTONE_CONF ldap user_attribute_ignore "enabled,email,tenants,tenantId"
iniset $KEYSTONE_CONF ldap tenant_attribute_ignore "enabled"
iniset $KEYSTONE_CONF ldap tenant_domain_id_attribute "businessCategory"
iniset $KEYSTONE_CONF ldap tenant_desc_attribute "description"
iniset $KEYSTONE_CONF ldap tenant_tree_dn "ou=Projects,dc=openstack,dc=org"
iniset $KEYSTONE_CONF ldap user_domain_id_attribute "businessCategory"
iniset $KEYSTONE_CONF ldap user_tree_dn "ou=Users,dc=openstack,dc=org"
iniset $KEYSTONE_CONF DEFAULT member_role_id "9fe2ff9ee4384b1894a90878d3e92bab"
iniset $KEYSTONE_CONF DEFAULT member_role_name "_member_"
2013-01-22 10:17:50 -06:00
fi
2013-09-01 16:26:03 +02:00
# check if identity backend is valid
if [[ "$KEYSTONE_VALID_IDENTITY_BACKENDS" =~ "$KEYSTONE_IDENTITY_BACKEND" ]]; then
iniset $KEYSTONE_CONF identity driver "keystone.identity.backends.$KEYSTONE_IDENTITY_BACKEND.Identity"
fi
# check if assignment backend is valid
if [[ "$KEYSTONE_VALID_ASSIGNMENT_BACKENDS" =~ "$KEYSTONE_ASSIGNMENT_BACKEND" ]]; then
iniset $KEYSTONE_CONF assignment driver "keystone.assignment.backends.$KEYSTONE_ASSIGNMENT_BACKEND.Assignment"
2013-01-22 10:17:50 -06:00
fi
2013-06-28 09:16:08 -05:00
# Set the URL advertised in the ``versions`` structure returned by the '/' route
iniset $KEYSTONE_CONF DEFAULT public_endpoint "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:%(public_port)s/"
iniset $KEYSTONE_CONF DEFAULT admin_endpoint "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:%(admin_port)s/"
2012-11-29 11:47:58 -06:00
if is_service_enabled tls-proxy; then
# Set the service ports for a proxy to take the originals
iniset $KEYSTONE_CONF DEFAULT public_port $KEYSTONE_SERVICE_PORT_INT
iniset $KEYSTONE_CONF DEFAULT admin_port $KEYSTONE_AUTH_PORT_INT
fi
2012-08-31 18:04:55 -05:00
iniset $KEYSTONE_CONF DEFAULT admin_token "$SERVICE_TOKEN"
2012-10-26 12:24:28 -04:00
iniset $KEYSTONE_CONF signing token_format "$KEYSTONE_TOKEN_FORMAT"
2013-07-16 00:47:54 +00:00
if [[ "$KEYSTONE_TOKEN_FORMAT" = "UUID" ]]; then
iniset $KEYSTONE_CONF token provider keystone.token.providers.uuid.Provider
fi
2013-03-03 12:23:04 +01:00
iniset $KEYSTONE_CONF sql connection `database_connection_url keystone`
2012-08-31 18:04:55 -05:00
iniset $KEYSTONE_CONF ec2 driver "keystone.contrib.ec2.backends.sql.Ec2"
2013-01-29 15:12:20 -05:00
if [[ "$KEYSTONE_TOKEN_BACKEND" = "sql" ]]; then
iniset $KEYSTONE_CONF token driver keystone.token.backends.sql.Token
else
iniset $KEYSTONE_CONF token driver keystone.token.backends.kvs.Token
fi
2012-08-31 18:04:55 -05:00
if [[ "$KEYSTONE_CATALOG_BACKEND" = "sql" ]]; then
# Configure ``keystone.conf`` to use sql
iniset $KEYSTONE_CONF catalog driver keystone.catalog.backends.sql.Catalog
inicomment $KEYSTONE_CONF catalog template_file
else
cp -p $FILES/default_catalog.templates $KEYSTONE_CATALOG
# Add swift endpoints to service catalog if swift is enabled
2013-03-06 10:58:33 +01:00
if is_service_enabled s-proxy; then
2012-08-31 18:04:55 -05:00
echo "catalog.RegionOne.object_store.publicURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
echo "catalog.RegionOne.object_store.adminURL = http://%SERVICE_HOST%:8080/" >> $KEYSTONE_CATALOG
echo "catalog.RegionOne.object_store.internalURL = http://%SERVICE_HOST%:8080/v1/AUTH_\$(tenant_id)s" >> $KEYSTONE_CATALOG
echo "catalog.RegionOne.object_store.name = Swift Service" >> $KEYSTONE_CATALOG
fi
2013-07-06 23:29:39 -04:00
# Add neutron endpoints to service catalog if neutron is enabled
if is_service_enabled neutron; then
2012-08-31 18:04:55 -05:00
echo "catalog.RegionOne.network.publicURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
echo "catalog.RegionOne.network.adminURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
echo "catalog.RegionOne.network.internalURL = http://%SERVICE_HOST%:$Q_PORT/" >> $KEYSTONE_CATALOG
2013-07-06 23:29:39 -04:00
echo "catalog.RegionOne.network.name = Neutron Service" >> $KEYSTONE_CATALOG
2012-08-31 18:04:55 -05:00
fi
2012-12-13 08:50:37 +01:00
sed -e "
2012-08-31 18:04:55 -05:00
s,%SERVICE_HOST%,$SERVICE_HOST,g;
s,%S3_SERVICE_PORT%,$S3_SERVICE_PORT,g;
" -i $KEYSTONE_CATALOG
# Configure ``keystone.conf`` to use templates
iniset $KEYSTONE_CONF catalog driver "keystone.catalog.backends.templated.TemplatedCatalog"
iniset $KEYSTONE_CONF catalog template_file "$KEYSTONE_CATALOG"
fi
# Set up logging
LOGGING_ROOT="devel"
if [ "$SYSLOG" != "False" ]; then
LOGGING_ROOT="$LOGGING_ROOT,production"
fi
KEYSTONE_LOG_CONFIG="--log-config $KEYSTONE_CONF_DIR/logging.conf"
cp $KEYSTONE_DIR/etc/logging.conf.sample $KEYSTONE_CONF_DIR/logging.conf
iniset $KEYSTONE_CONF_DIR/logging.conf logger_root level "DEBUG"
iniset $KEYSTONE_CONF_DIR/logging.conf logger_root handlers "devel,production"
}
2012-11-29 17:11:35 -06:00
# create_keystone_accounts() - Sets up common required keystone accounts
# Tenant User Roles
# ------------------------------------------------------------------
# service -- --
# -- -- Member
# admin admin admin
# demo admin admin
# demo demo Member, anotherrole
# invisible_to_admin demo Member
# Migrated from keystone_data.sh
create_keystone_accounts() {
# admin
ADMIN_TENANT=$(keystone tenant-create \
--name admin \
| grep " id " | get_field 2)
ADMIN_USER=$(keystone user-create \
--name admin \
--pass "$ADMIN_PASSWORD" \
--email admin@example.com \
| grep " id " | get_field 2)
ADMIN_ROLE=$(keystone role-create \
--name admin \
| grep " id " | get_field 2)
keystone user-role-add \
2013-09-02 17:18:40 +02:00
--user-id $ADMIN_USER \
--role-id $ADMIN_ROLE \
--tenant-id $ADMIN_TENANT
2012-11-29 17:11:35 -06:00
# service
SERVICE_TENANT=$(keystone tenant-create \
--name $SERVICE_TENANT_NAME \
| grep " id " | get_field 2)
# The Member role is used by Horizon and Swift so we need to keep it:
MEMBER_ROLE=$(keystone role-create --name=Member | grep " id " | get_field 2)
# ANOTHER_ROLE demonstrates that an arbitrary role may be created and used
# TODO(sleepsonthefloor): show how this can be used for rbac in the future!
ANOTHER_ROLE=$(keystone role-create --name=anotherrole | grep " id " | get_field 2)
# invisible tenant - admin can't see this one
INVIS_TENANT=$(keystone tenant-create --name=invisible_to_admin | grep " id " | get_field 2)
# demo
DEMO_TENANT=$(keystone tenant-create \
--name=demo \
| grep " id " | get_field 2)
DEMO_USER=$(keystone user-create \
--name demo \
--pass "$ADMIN_PASSWORD" \
--email demo@example.com \
| grep " id " | get_field 2)
2013-09-02 17:18:40 +02:00
keystone user-role-add --user-id $DEMO_USER --role-id $MEMBER_ROLE --tenant-id $DEMO_TENANT
keystone user-role-add --user-id $ADMIN_USER --role-id $ADMIN_ROLE --tenant-id $DEMO_TENANT
keystone user-role-add --user-id $DEMO_USER --role-id $ANOTHER_ROLE --tenant-id $DEMO_TENANT
keystone user-role-add --user-id $DEMO_USER --role-id $MEMBER_ROLE --tenant-id $INVIS_TENANT
2012-11-29 17:11:35 -06:00
# Keystone
if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
KEYSTONE_SERVICE=$(keystone service-create \
--name keystone \
--type identity \
--description "Keystone Identity Service" \
| grep " id " | get_field 2)
keystone endpoint-create \
--region RegionOne \
--service_id $KEYSTONE_SERVICE \
2013-01-24 14:14:28 -06:00
--publicurl "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v$IDENTITY_API_VERSION" \
--adminurl "$KEYSTONE_AUTH_PROTOCOL://$KEYSTONE_AUTH_HOST:$KEYSTONE_AUTH_PORT/v$IDENTITY_API_VERSION" \
--internalurl "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/v$IDENTITY_API_VERSION"
2012-11-29 17:11:35 -06:00
fi
}
2012-08-31 18:04:55 -05:00
# init_keystone() - Initialize databases, etc.
function init_keystone() {
# (Re)create keystone database
2012-11-01 16:12:39 -04:00
recreate_database keystone utf8
2012-08-31 18:04:55 -05:00
# Initialize keystone database
$KEYSTONE_DIR/bin/keystone-manage db_sync
2012-10-01 14:06:44 -05:00
if [[ "$KEYSTONE_TOKEN_FORMAT" == "PKI" ]]; then
# Set up certificates
2012-12-12 15:57:33 -08:00
rm -rf $KEYSTONE_CONF_DIR/ssl
2012-10-01 14:06:44 -05:00
$KEYSTONE_DIR/bin/keystone-manage pki_setup
# Create cache dir
sudo mkdir -p $KEYSTONE_AUTH_CACHE_DIR
2013-01-06 22:40:09 +01:00
sudo chown $STACK_USER $KEYSTONE_AUTH_CACHE_DIR
2012-12-12 15:57:33 -08:00
rm -f $KEYSTONE_AUTH_CACHE_DIR/*
2012-10-01 14:06:44 -05:00
fi
2012-08-31 18:04:55 -05:00
}
# install_keystoneclient() - Collect source and prepare
function install_keystoneclient() {
git_clone $KEYSTONECLIENT_REPO $KEYSTONECLIENT_DIR $KEYSTONECLIENT_BRANCH
2013-04-01 16:44:31 -04:00
setup_develop $KEYSTONECLIENT_DIR
2013-08-14 16:04:01 +02:00
sudo install -D -m 0644 -o $STACK_USER {$KEYSTONECLIENT_DIR/tools/,/etc/bash_completion.d/}keystone.bash_completion
2012-08-31 18:04:55 -05:00
}
# install_keystone() - Collect source and prepare
function install_keystone() {
2013-01-22 10:17:50 -06:00
# only install ldap if the service has been enabled
if is_service_enabled ldap; then
install_ldap
fi
2012-08-31 18:04:55 -05:00
git_clone $KEYSTONE_REPO $KEYSTONE_DIR $KEYSTONE_BRANCH
2013-04-01 16:44:31 -04:00
setup_develop $KEYSTONE_DIR
2012-08-31 18:04:55 -05:00
}
# start_keystone() - Start running processes, including screen
function start_keystone() {
2012-11-29 11:47:58 -06:00
# Get right service port for testing
local service_port=$KEYSTONE_SERVICE_PORT
if is_service_enabled tls-proxy; then
service_port=$KEYSTONE_SERVICE_PORT_INT
fi
2012-08-31 18:04:55 -05:00
# Start Keystone in a screen window
screen_it key "cd $KEYSTONE_DIR && $KEYSTONE_DIR/bin/keystone-all --config-file $KEYSTONE_CONF $KEYSTONE_LOG_CONFIG -d --debug"
2012-11-29 17:11:35 -06:00
echo "Waiting for keystone to start..."
2013-01-24 14:14:28 -06:00
if ! timeout $SERVICE_TIMEOUT sh -c "while ! http_proxy= curl -s http://$SERVICE_HOST:$service_port/v$IDENTITY_API_VERSION/ >/dev/null; do sleep 1; done"; then
2013-02-26 12:38:18 -08:00
die $LINENO "keystone did not start"
2012-11-29 17:11:35 -06:00
fi
2012-11-29 11:47:58 -06:00
# Start proxies if enabled
if is_service_enabled tls-proxy; then
start_tls_proxy '*' $KEYSTONE_SERVICE_PORT $KEYSTONE_SERVICE_HOST $KEYSTONE_SERVICE_PORT_INT &
start_tls_proxy '*' $KEYSTONE_AUTH_PORT $KEYSTONE_AUTH_HOST $KEYSTONE_AUTH_PORT_INT &
fi
2012-08-31 18:04:55 -05:00
}
# stop_keystone() - Stop running processes
function stop_keystone() {
# Kill the Keystone screen window
screen -S $SCREEN_NAME -p key -X kill
}
2012-09-13 17:16:12 -05:00
2013-06-03 16:47:36 -05:00
2012-09-13 17:16:12 -05:00
# Restore xtrace
$XTRACE
2013-03-29 14:34:53 -04:00
# Local variables:
# mode: shell-script
# End: