|
...
|
...
|
@@ -16,45 +16,45 @@ cat <<EOF
|
|
16
|
16
|
|
|
17
|
17
|
usage: $0 <options..>
|
|
18
|
18
|
|
|
19
|
|
-This script creates certificates and sourcable rc files per tenant/user.
|
|
|
19
|
+This script creates certificates and sourcable rc files per project/user.
|
|
20
|
20
|
|
|
21
|
21
|
Target account directory hierarchy:
|
|
22
|
22
|
target_dir-|
|
|
23
|
23
|
|-cacert.pem
|
|
24
|
|
- |-tenant1-name|
|
|
25
|
|
- | |- user1
|
|
26
|
|
- | |- user1-cert.pem
|
|
27
|
|
- | |- user1-pk.pem
|
|
28
|
|
- | |- user2
|
|
29
|
|
- | ..
|
|
30
|
|
- |-tenant2-name..
|
|
|
24
|
+ |-project1-name|
|
|
|
25
|
+ | |- user1
|
|
|
26
|
+ | |- user1-cert.pem
|
|
|
27
|
+ | |- user1-pk.pem
|
|
|
28
|
+ | |- user2
|
|
|
29
|
+ | ..
|
|
|
30
|
+ |-project2-name..
|
|
31
|
31
|
..
|
|
32
|
32
|
|
|
33
|
33
|
Optional Arguments
|
|
34
|
34
|
-P include password to the rc files; with -A it assume all users password is the same
|
|
35
|
35
|
-A try with all user
|
|
36
|
36
|
-u <username> create files just for the specified user
|
|
37
|
|
--C <tenant_name> create user and tenant, the specifid tenant will be the user's tenant
|
|
38
|
|
--r <name> when combined with -C and the (-u) user exists it will be the user's tenant role in the (-C)tenant (default: Member)
|
|
|
37
|
+-C <project_name> create user and project, the specifid project will be the user's project
|
|
|
38
|
+-r <name> when combined with -C and the (-u) user exists it will be the user's project role in the (-C)project (default: Member)
|
|
39
|
39
|
-p <userpass> password for the user
|
|
40
|
40
|
--heat-url <heat_url>
|
|
41
|
41
|
--os-username <username>
|
|
42
|
42
|
--os-password <admin password>
|
|
|
43
|
+--os-project-name <project_name>
|
|
|
44
|
+--os-project-id <project_id>
|
|
43
|
45
|
--os-auth-url <auth_url>
|
|
44
|
46
|
--os-cacert <cert file>
|
|
45
|
47
|
--target-dir <target_directory>
|
|
|
48
|
+--skip-project <project-name>
|
|
46
|
49
|
--debug
|
|
47
|
50
|
|
|
48
|
51
|
Example:
|
|
49
|
52
|
$0 -AP
|
|
50
|
|
-$0 -P -C mytenant -u myuser -p mypass
|
|
|
53
|
+$0 -P -C myproject -u myuser -p mypass
|
|
51
|
54
|
EOF
|
|
52
|
55
|
}
|
|
53
|
56
|
|
|
54
|
|
-if ! options=$(getopt -o hPAp:u:r:C: -l os-username:,os-password:,os-tenant-name:,os-tenant-id:,os-auth-url:,target-dir:,heat-url:,skip-tenant:,os-cacert:,help,debug -- "$@"); then
|
|
|
57
|
+if ! options=$(getopt -o hPAp:u:r:C: -l os-username:,os-password:,os-tenant-id:,os-tenant-name:,os-project-name:,os-project-id:,os-auth-url:,target-dir:,heat-url:,skip-project:,os-cacert:,help,debug -- "$@"); then
|
|
55
|
58
|
display_help
|
|
56
|
59
|
exit 1
|
|
57
|
60
|
fi
|
|
...
|
...
|
@@ -62,10 +62,10 @@ eval set -- $options
|
|
62
|
62
|
ADDPASS=""
|
|
63
|
63
|
HEAT_URL=""
|
|
64
|
64
|
|
|
65
|
|
-# The services users usually in the service tenant.
|
|
|
65
|
+# The services users usually in the service project.
|
|
66
|
66
|
# rc files for service users, is out of scope.
|
|
67
|
|
-# Supporting different tenant for services is out of scope.
|
|
68
|
|
-SKIP_TENANT="service"
|
|
|
67
|
+# Supporting different project for services is out of scope.
|
|
|
68
|
+SKIP_PROJECT="service"
|
|
69
|
69
|
MODE=""
|
|
70
|
70
|
ROLE=Member
|
|
71
|
71
|
USER_NAME=""
|
|
...
|
...
|
@@ -75,9 +75,12 @@ while [ $# -gt 0 ]; do
|
|
75
|
75
|
-h|--help) display_help; exit 0 ;;
|
|
76
|
76
|
--os-username) export OS_USERNAME=$2; shift ;;
|
|
77
|
77
|
--os-password) export OS_PASSWORD=$2; shift ;;
|
|
78
|
|
- --os-tenant-name) export OS_TENANT_NAME=$2; shift ;;
|
|
79
|
|
- --os-tenant-id) export OS_TENANT_ID=$2; shift ;;
|
|
80
|
|
- --skip-tenant) SKIP_TENANT="$SKIP_TENANT$2,"; shift ;;
|
|
|
78
|
+ --os-tenant-name) export OS_PROJECT_NAME=$2; shift ;;
|
|
|
79
|
+ --os-tenant-id) export OS_PROJECT_ID=$2; shift ;;
|
|
|
80
|
+ --os-project-name) export OS_PROJECT_NAME=$2; shift ;;
|
|
|
81
|
+ --os-project-id) export OS_PROJECT_ID=$2; shift ;;
|
|
|
82
|
+ --skip-tenant) SKIP_PROJECT="$SKIP_PROJECT$2,"; shift ;;
|
|
|
83
|
+ --skip-project) SKIP_PROJECT="$SKIP_PROJECT$2,"; shift ;;
|
|
81
|
84
|
--os-auth-url) export OS_AUTH_URL=$2; shift ;;
|
|
82
|
85
|
--os-cacert) export OS_CACERT=$2; shift ;;
|
|
83
|
86
|
--target-dir) ACCOUNT_DIR=$2; shift ;;
|
|
...
|
...
|
@@ -87,7 +90,7 @@ while [ $# -gt 0 ]; do
|
|
87
|
87
|
-p) USER_PASS=$2; shift ;;
|
|
88
|
88
|
-A) MODE=all; ;;
|
|
89
|
89
|
-P) ADDPASS="yes" ;;
|
|
90
|
|
- -C) MODE=create; TENANT=$2; shift ;;
|
|
|
90
|
+ -C) MODE=create; PROJECT=$2; shift ;;
|
|
91
|
91
|
-r) ROLE=$2; shift ;;
|
|
92
|
92
|
(--) shift; break ;;
|
|
93
|
93
|
(-*) echo "$0: error - unrecognized option $1" >&2; display_help; exit 1 ;;
|
|
...
|
...
|
@@ -105,8 +108,16 @@ if [ -z "$OS_PASSWORD" ]; then
|
|
105
|
105
|
fi
|
|
106
|
106
|
fi
|
|
107
|
107
|
|
|
108
|
|
-if [ -z "$OS_TENANT_NAME" -a -z "$OS_TENANT_ID" ]; then
|
|
109
|
|
- export OS_TENANT_NAME=admin
|
|
|
108
|
+if [ -z "$OS_PROJECT_ID" -a "$OS_TENANT_ID" ]; then
|
|
|
109
|
+ export OS_PROJECT_ID=$OS_TENANT_ID
|
|
|
110
|
+fi
|
|
|
111
|
+
|
|
|
112
|
+if [ -z "$OS_PROJECT_NAME" -a "$OS_TENANT_NAME" ]; then
|
|
|
113
|
+ export OS_PROJECT_NAME=$OS_TENANT_NAME
|
|
|
114
|
+fi
|
|
|
115
|
+
|
|
|
116
|
+if [ -z "$OS_PROJECT_NAME" -a -z "$OS_PROJECT_ID" ]; then
|
|
|
117
|
+ export OS_PROJECT_NAME=admin
|
|
110
|
118
|
fi
|
|
111
|
119
|
|
|
112
|
120
|
if [ -z "$OS_USERNAME" ]; then
|
|
...
|
...
|
@@ -156,21 +167,21 @@ fi
|
|
156
|
156
|
function add_entry {
|
|
157
|
157
|
local user_id=$1
|
|
158
|
158
|
local user_name=$2
|
|
159
|
|
- local tenant_id=$3
|
|
160
|
|
- local tenant_name=$4
|
|
|
159
|
+ local project_id=$3
|
|
|
160
|
+ local project_name=$4
|
|
161
|
161
|
local user_passwd=$5
|
|
162
|
162
|
|
|
163
|
163
|
# The admin user can see all user's secret AWS keys, it does not looks good
|
|
164
|
|
- local line=`openstack ec2 credentials list --user $user_id | grep " $tenant_id "`
|
|
|
164
|
+ local line=`openstack ec2 credentials list --user $user_id | grep " $project_id "`
|
|
165
|
165
|
if [ -z "$line" ]; then
|
|
166
|
|
- openstack ec2 credentials create --user $user_id --project $tenant_id 1>&2
|
|
167
|
|
- line=`openstack ec2 credentials list --user $user_id | grep " $tenant_id "`
|
|
|
166
|
+ openstack ec2 credentials create --user $user_id --project $project_id 1>&2
|
|
|
167
|
+ line=`openstack ec2 credentials list --user $user_id | grep " $project_id "`
|
|
168
|
168
|
fi
|
|
169
|
169
|
local ec2_access_key ec2_secret_key
|
|
170
|
170
|
read ec2_access_key ec2_secret_key <<< `echo $line | awk '{print $2 " " $4 }'`
|
|
171
|
|
- mkdir -p "$ACCOUNT_DIR/$tenant_name"
|
|
172
|
|
- local rcfile="$ACCOUNT_DIR/$tenant_name/$user_name"
|
|
173
|
|
- # The certs subject part are the tenant ID "dash" user ID, but the CN should be the first part of the DN
|
|
|
171
|
+ mkdir -p "$ACCOUNT_DIR/$project_name"
|
|
|
172
|
+ local rcfile="$ACCOUNT_DIR/$project_name/$user_name"
|
|
|
173
|
+ # The certs subject part are the project ID "dash" user ID, but the CN should be the first part of the DN
|
|
174
|
174
|
# Generally the subject DN parts should be in reverse order like the Issuer
|
|
175
|
175
|
# The Serial does not seams correctly marked either
|
|
176
|
176
|
local ec2_cert="$rcfile-cert.pem"
|
|
...
|
...
|
@@ -183,7 +194,7 @@ function add_entry {
|
|
183
|
183
|
mv -f "$ec2_cert" "$ec2_cert.old"
|
|
184
|
184
|
fi
|
|
185
|
185
|
# It will not create certs when the password is incorrect
|
|
186
|
|
- if ! nova --os-password "$user_passwd" --os-username "$user_name" --os-tenant-name "$tenant_name" x509-create-cert "$ec2_private_key" "$ec2_cert"; then
|
|
|
186
|
+ if ! nova --os-password "$user_passwd" --os-username "$user_name" --os-project-name "$project_name" x509-create-cert "$ec2_private_key" "$ec2_cert"; then
|
|
187
|
187
|
if [ -e "$ec2_private_key.old" ]; then
|
|
188
|
188
|
mv -f "$ec2_private_key.old" "$ec2_private_key"
|
|
189
|
189
|
fi
|
|
...
|
...
|
@@ -199,8 +210,8 @@ export EC2_URL="$EC2_URL"
|
|
199
|
199
|
export S3_URL="$S3_URL"
|
|
200
|
200
|
# OpenStack USER ID = $user_id
|
|
201
|
201
|
export OS_USERNAME="$user_name"
|
|
202
|
|
-# OpenStack Tenant ID = $tenant_id
|
|
203
|
|
-export OS_TENANT_NAME="$tenant_name"
|
|
|
202
|
+# OpenStack project ID = $project_id
|
|
|
203
|
+export OS_PROJECT_NAME="$project_name"
|
|
204
|
204
|
export OS_AUTH_URL="$OS_AUTH_URL"
|
|
205
|
205
|
export OS_CACERT="$OS_CACERT"
|
|
206
|
206
|
export EC2_CERT="$ec2_cert"
|
|
...
|
...
|
@@ -213,7 +224,7 @@ EOF
|
|
213
|
213
|
echo "export OS_PASSWORD=\"$user_passwd\"" >>"$rcfile"
|
|
214
|
214
|
fi
|
|
215
|
215
|
if [ -n "$HEAT_URL" ]; then
|
|
216
|
|
- echo "export HEAT_URL=\"$HEAT_URL/$tenant_id\"" >>"$rcfile"
|
|
|
216
|
+ echo "export HEAT_URL=\"$HEAT_URL/$project_id\"" >>"$rcfile"
|
|
217
|
217
|
echo "export OS_NO_CLIENT_AUTH=True" >>"$rcfile"
|
|
218
|
218
|
fi
|
|
219
|
219
|
}
|
|
...
|
...
|
@@ -245,9 +256,9 @@ function get_user_id {
|
|
245
|
245
|
}
|
|
246
|
246
|
|
|
247
|
247
|
if [ $MODE != "create" ]; then
|
|
248
|
|
- # looks like I can't ask for all tenant related to a specified user
|
|
249
|
|
- openstack project list --long --quote none -f csv | grep ',True' | grep -v "${SKIP_TENANT}" | while IFS=, read tenant_id tenant_name desc enabled; do
|
|
250
|
|
- openstack user list --project $tenant_id --long --quote none -f csv | grep ',True' | while IFS=, read user_id user_name project email enabled; do
|
|
|
248
|
+ # looks like I can't ask for all project related to a specified user
|
|
|
249
|
+ openstack project list --long --quote none -f csv | grep ',True' | grep -v "${SKIP_PROJECT}" | while IFS=, read project_id project_name desc enabled; do
|
|
|
250
|
+ openstack user list --project $project_id --long --quote none -f csv | grep ',True' | while IFS=, read user_id user_name project email enabled; do
|
|
251
|
251
|
if [ $MODE = one -a "$user_name" != "$USER_NAME" ]; then
|
|
252
|
252
|
continue;
|
|
253
|
253
|
fi
|
|
...
|
...
|
@@ -259,21 +270,21 @@ if [ $MODE != "create" ]; then
|
|
259
|
259
|
if [ -n "$SPECIFIC_UPASSWORD" ]; then
|
|
260
|
260
|
USER_PASS=$SPECIFIC_UPASSWORD
|
|
261
|
261
|
fi
|
|
262
|
|
- add_entry "$user_id" "$user_name" "$tenant_id" "$tenant_name" "$USER_PASS"
|
|
|
262
|
+ add_entry "$user_id" "$user_name" "$project_id" "$project_name" "$USER_PASS"
|
|
263
|
263
|
done
|
|
264
|
264
|
done
|
|
265
|
265
|
else
|
|
266
|
|
- tenant_name=$TENANT
|
|
267
|
|
- tenant_id=$(create_or_get_project "$TENANT")
|
|
|
266
|
+ project_name=$PROJECT
|
|
|
267
|
+ project_id=$(create_or_get_project "$PROJECT")
|
|
268
|
268
|
user_name=$USER_NAME
|
|
269
|
269
|
user_id=`get_user_id $user_name`
|
|
270
|
270
|
if [ -z "$user_id" ]; then
|
|
271
|
|
- eval $(openstack user create "$user_name" --project "$tenant_id" --password "$USER_PASS" --email "$user_name@example.com" -f shell -c id)
|
|
|
271
|
+ eval $(openstack user create "$user_name" --project "$project_id" --password "$USER_PASS" --email "$user_name@example.com" -f shell -c id)
|
|
272
|
272
|
user_id=$id
|
|
273
|
|
- add_entry "$user_id" "$user_name" "$tenant_id" "$tenant_name" "$USER_PASS"
|
|
|
273
|
+ add_entry "$user_id" "$user_name" "$project_id" "$project_name" "$USER_PASS"
|
|
274
|
274
|
else
|
|
275
|
275
|
role_id=$(create_or_get_role "$ROLE")
|
|
276
|
|
- openstack role add "$role_id" --user "$user_id" --project "$tenant_id"
|
|
277
|
|
- add_entry "$user_id" "$user_name" "$tenant_id" "$tenant_name" "$USER_PASS"
|
|
|
276
|
+ openstack role add "$role_id" --user "$user_id" --project "$project_id"
|
|
|
277
|
+ add_entry "$user_id" "$user_name" "$project_id" "$project_name" "$USER_PASS"
|
|
278
|
278
|
fi
|
|
279
|
279
|
fi
|