Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 2 | # |
| 3 | # Initial data for Keystone using python-keystoneclient |
| 4 | # |
| 5 | # A set of EC2-compatible credentials is created for both admin and demo |
| 6 | # users and placed in $DEVSTACK_DIR/ec2rc. |
| 7 | # |
| 8 | # Tenant User Roles |
| 9 | # ------------------------------------------------------- |
| 10 | # admin admin admin |
| 11 | # service glance admin |
| 12 | # service nova admin |
| 13 | # service quantum admin # if enabled |
| 14 | # service swift admin # if enabled |
| 15 | # demo admin admin |
| 16 | # demo demo Member,sysadmin,netadmin |
| 17 | # invisible_to_admin demo Member |
| 18 | # |
| 19 | # Variables set before calling this script: |
| 20 | # SERVICE_TOKEN - aka admin_token in keystone.conf |
| 21 | # SERVICE_ENDPOINT - local Keystone admin endpoint |
| 22 | # SERVICE_TENANT_NAME - name of tenant containing service accounts |
| 23 | # ENABLED_SERVICES - stack.sh's list of services to start |
| 24 | # DEVSTACK_DIR - Top-level DevStack directory |
| 25 | |
| 26 | ADMIN_PASSWORD=${ADMIN_PASSWORD:-secrete} |
| 27 | SERVICE_PASSWORD=${SERVICE_PASSWORD:-$ADMIN_PASSWORD} |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 28 | export SERVICE_TOKEN=$SERVICE_TOKEN |
| 29 | export SERVICE_ENDPOINT=$SERVICE_ENDPOINT |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 30 | SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service} |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 31 | |
| 32 | function get_id () { |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 33 | echo `$@ | awk '/ id / { print $4 }'` |
Vishvananda Ishaya | d1f5243 | 2012-02-09 03:50:57 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 36 | # Tenants |
| 37 | ADMIN_TENANT=$(get_id keystone tenant-create --name=admin) |
| 38 | SERVICE_TENANT=$(get_id keystone tenant-create --name=$SERVICE_TENANT_NAME) |
| 39 | DEMO_TENANT=$(get_id keystone tenant-create --name=demo) |
| 40 | INVIS_TENANT=$(get_id keystone tenant-create --name=invisible_to_admin) |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 41 | |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 42 | |
| 43 | # Users |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 44 | ADMIN_USER=$(get_id keystone user-create --name=admin \ |
| 45 | --pass="$ADMIN_PASSWORD" \ |
| 46 | --email=admin@example.com) |
| 47 | DEMO_USER=$(get_id keystone user-create --name=demo \ |
| 48 | --pass="$ADMIN_PASSWORD" \ |
| 49 | --email=demo@example.com) |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 50 | |
| 51 | # Roles |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 52 | ADMIN_ROLE=$(get_id keystone role-create --name=admin) |
| 53 | KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin) |
| 54 | KEYSTONESERVICE_ROLE=$(get_id keystone role-create --name=KeystoneServiceAdmin) |
| 55 | SYSADMIN_ROLE=$(get_id keystone role-create --name=sysadmin) |
| 56 | NETADMIN_ROLE=$(get_id keystone role-create --name=netadmin) |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 57 | |
| 58 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 59 | # Add Roles to Users in Tenants |
| 60 | keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $ADMIN_TENANT |
| 61 | keystone user-role-add --user $ADMIN_USER --role $ADMIN_ROLE --tenant_id $DEMO_TENANT |
| 62 | keystone user-role-add --user $DEMO_USER --role $SYSADMIN_ROLE --tenant_id $DEMO_TENANT |
| 63 | keystone user-role-add --user $DEMO_USER --role $NETADMIN_ROLE --tenant_id $DEMO_TENANT |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 64 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 65 | # TODO(termie): these two might be dubious |
| 66 | keystone user-role-add --user $ADMIN_USER --role $KEYSTONEADMIN_ROLE --tenant_id $ADMIN_TENANT |
| 67 | keystone user-role-add --user $ADMIN_USER --role $KEYSTONESERVICE_ROLE --tenant_id $ADMIN_TENANT |
Dean Troyer | f4565c4 | 2012-02-23 11:21:10 -0600 | [diff] [blame] | 68 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 69 | |
| 70 | # The Member role is used by Horizon and Swift so we need to keep it: |
| 71 | MEMBER_ROLE=$(get_id keystone role-create --name=Member) |
| 72 | keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $DEMO_TENANT |
| 73 | keystone user-role-add --user $DEMO_USER --role $MEMBER_ROLE --tenant_id $INVIS_TENANT |
| 74 | |
Jesse Andrews | 73e27b8 | 2011-09-12 17:55:00 -0700 | [diff] [blame] | 75 | |
Anthony Young | e2d139b | 2012-03-09 15:47:28 -0800 | [diff] [blame^] | 76 | # Configure service users/roles |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 77 | NOVA_USER=$(get_id keystone user-create --name=nova \ |
| 78 | --pass="$SERVICE_PASSWORD" \ |
| 79 | --tenant_id $SERVICE_TENANT \ |
| 80 | --email=nova@example.com) |
Dean Troyer | b328838 | 2012-02-28 16:41:10 -0600 | [diff] [blame] | 81 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 82 | --user $NOVA_USER \ |
| 83 | --role $ADMIN_ROLE |
termie | a96a418 | 2012-01-09 22:13:29 -0800 | [diff] [blame] | 84 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 85 | GLANCE_USER=$(get_id keystone user-create --name=glance \ |
| 86 | --pass="$SERVICE_PASSWORD" \ |
| 87 | --tenant_id $SERVICE_TENANT \ |
| 88 | --email=glance@example.com) |
Dean Troyer | b328838 | 2012-02-28 16:41:10 -0600 | [diff] [blame] | 89 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 90 | --user $GLANCE_USER \ |
| 91 | --role $ADMIN_ROLE |
Vishvananda Ishaya | 5f9473e | 2012-02-24 01:57:07 +0000 | [diff] [blame] | 92 | |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 93 | if [[ "$ENABLED_SERVICES" =~ "swift" ]]; then |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 94 | SWIFT_USER=$(get_id keystone user-create --name=swift \ |
| 95 | --pass="$SERVICE_PASSWORD" \ |
| 96 | --tenant_id $SERVICE_TENANT \ |
| 97 | --email=swift@example.com) |
Dean Troyer | b328838 | 2012-02-28 16:41:10 -0600 | [diff] [blame] | 98 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 99 | --user $SWIFT_USER \ |
| 100 | --role $ADMIN_ROLE |
Jesse Andrews | 9c7c908 | 2011-11-23 10:10:53 -0800 | [diff] [blame] | 101 | fi |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 102 | |
Gabriel Hurley | a3a496f | 2012-02-13 12:29:23 -0800 | [diff] [blame] | 103 | if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 104 | QUANTUM_USER=$(get_id keystone user-create --name=quantum \ |
| 105 | --pass="$SERVICE_PASSWORD" \ |
| 106 | --tenant_id $SERVICE_TENANT \ |
| 107 | --email=quantum@example.com) |
Dean Troyer | b328838 | 2012-02-28 16:41:10 -0600 | [diff] [blame] | 108 | keystone user-role-add --tenant_id $SERVICE_TENANT \ |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 109 | --user $QUANTUM_USER \ |
| 110 | --role $ADMIN_ROLE |
Gabriel Hurley | a3a496f | 2012-02-13 12:29:23 -0800 | [diff] [blame] | 111 | fi |
Anthony Young | 8bdc263 | 2011-09-22 08:00:44 +0000 | [diff] [blame] | 112 | |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 113 | # create ec2 creds and parse the secret and access key returned |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 114 | RESULT=$(keystone ec2-credentials-create --tenant_id=$ADMIN_TENANT --user=$ADMIN_USER) |
| 115 | ADMIN_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }') |
| 116 | ADMIN_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }') |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 117 | |
Dean Troyer | b7d1fbb | 2012-03-02 08:43:09 -0600 | [diff] [blame] | 118 | RESULT=$(keystone ec2-credentials-create --tenant_id=$DEMO_TENANT --user=$DEMO_USER) |
| 119 | DEMO_ACCESS=$(echo "$RESULT" | awk '/ access / { print $4 }') |
| 120 | DEMO_SECRET=$(echo "$RESULT" | awk '/ secret / { print $4 }') |
Vishvananda Ishaya | 658ac7a | 2012-02-06 22:56:37 +0000 | [diff] [blame] | 121 | |
| 122 | # write the secret and access to ec2rc |
| 123 | cat > $DEVSTACK_DIR/ec2rc <<EOF |
| 124 | ADMIN_ACCESS=$ADMIN_ACCESS |
| 125 | ADMIN_SECRET=$ADMIN_SECRET |
| 126 | DEMO_ACCESS=$DEMO_ACCESS |
| 127 | DEMO_SECRET=$DEMO_SECRET |
| 128 | EOF |