11
11
# cat msearch.json | curl https://localhost:9200/_msearch -XPOST --data-binary @-
12
12
source " $( dirname " ${BASH_SOURCE[0]} " ) /../hack/lib/init.sh"
13
13
source " ${OS_O_A_L_DIR} /hack/testing/util.sh"
14
+ current_dir=$( dirname " ${BASH_SOURCE[0]} " )
15
+ repo_dir=${repodir:- " $current_dir /../" }
16
+ test_name=$( basename $0 )
14
17
trap os::test::junit::reconcile_output EXIT
15
18
os::util::environment::use_sudo
16
19
17
20
os::test::junit::declare_suite_start " test/multi_tenancy"
18
21
19
22
LOGGING_PROJECT=${LOGGING_NS:- openshift-logging}
20
23
PROJECTS=" multi-tenancy-1 multi-tenancy-2 multi-tenancy-3 multi-tenancy-4"
21
- espod=$( get_es_pod es )
22
- esopspod=$( get_es_pod es-ops )
23
- esopspod=${esopspod:- $espod }
24
-
25
- # HACK HACK HACK
26
- # remove this once we have real multi-tenancy, multi-index support
27
- function hack_msearch_access() {
28
- LOGGING_PROJECT=${LOGGING_PROJECT} ${OS_O_A_L_DIR} /hack/enable-kibana-msearch-access.sh " $@ "
29
- }
30
24
31
25
delete_users=" "
32
26
cleanup_msearch_access=" "
33
27
34
28
function cleanup() {
29
+ local return_code=" $? "
30
+ cleanup_es
35
31
set +e
36
- os::log::info " Performing cleanup..."
37
- for user in $cleanup_msearch_access ; do
38
- hack_msearch_access $user 2>&1 | artifact_out
39
- done
32
+ if [ " ${DO_CLEANUP:- true} " == " true" ] ; then
33
+ mkdir -p $ARTIFACT_DIR /$test_name
34
+ oc -n $LOGGING_NS get configmap elasticsearch -o jsonpath={.data} --ignore-not-found > $ARTIFACT_DIR /$test_name /elasticsearch-configmap.log || :
35
+ get_all_logging_pod_logs $ARTIFACT_DIR /$test_name
36
+
37
+ os::log::info " Removing test namespaces...."
38
+ oc delete ns/openshift-logging ns/openshift-operators-redhat --force --grace-period=0
39
+ for item in " ns/openshift-logging" " ns/openshift-operators-redhat" ; do
40
+ os::cmd::try_until_failure " oc get ${item} " " $(( 1 * $minute )) "
41
+ done
42
+ fi
43
+ exit $return_code
44
+ }
45
+
46
+ # useful for local testing, just cleanup the ES instance.
47
+ function cleanup_es() {
48
+ set +e
49
+ os::log::info " Performing ES cleanup..."
40
50
for user in $delete_users ; do
41
51
oc delete user $user 2>&1 | artifact_out
42
52
done
43
53
if [ -n " ${espod:- } " ] ; then
44
- curl_es_pod $espod /project.multi-tenancy -* -XDELETE 2>&1 | artifact_out
54
+ curl_es_pod $espod /logs-app -* -XDELETE 2>&1 | artifact_out
45
55
fi
46
56
for proj in $PROJECTS ; do
47
57
oc delete project $proj 2>&1 | artifact_out
@@ -52,6 +62,16 @@ function cleanup() {
52
62
}
53
63
54
64
trap cleanup EXIT
65
+ # enable for local testing
66
+ # trap cleanup_es EXIT
67
+
68
+ if [ " ${DO_SETUP:- true} " == " true" ] ; then
69
+ os::log::info " Deploying cluster logging..."
70
+ ${repo_dir} /hack/deploy-logging.sh
71
+ fi
72
+ espod=$( get_es_pod es )
73
+ esopspod=$( get_es_pod es-ops )
74
+ esopspod=${esopspod:- $espod }
55
75
56
76
function create_user_and_assign_to_projects() {
57
77
local current_project; current_project=" $( oc project -q ) "
@@ -77,23 +97,23 @@ function create_user_and_assign_to_projects() {
77
97
function add_message_to_index() {
78
98
79
99
local namespace=$1
80
- local project_uuid= $( oc get project $1 -o jsonpath= ' { .metadata.uid } ' )
81
- local index= " project. $1 . $project_uuid . $( date -u + ' %Y.%m.%d ' ) "
82
- local pod =$3
100
+ local index= " logs-app-00001 "
101
+ local pod= $2
102
+ local aliasname =$3
83
103
84
104
local xff=" -H X-Forwarded-For:127.0.0.1"
85
105
local xocpns=' -H X-Ocp-Namespace:' " $namespace "
86
106
local contenttype=" -H Content-Type:application/json"
87
107
88
108
local payload=" {\" log\" :\" log message 1\" ,\" stream\" :\" stderr\" ,\" time\" :\" 2014-09-25T21:15:03.499185026Z\" ,\" kubernetes\" :{\" namespace_name\" :\" $namespace \" ,\" pod_name\" :\" synthetic-logger-0.25lps-pod\" },\" docker\" :{\" container_id\" :\" container123\" }}"
89
- local alias=" {\" actions\" :[{\" add\" :{\" index\" :\" $index \" ,\" alias\" :\" app \" }}]}"
109
+ local alias=" {\" actions\" :[{\" add\" :{\" index\" :\" $index \" ,\" alias\" :\" $aliasname \" }}]}"
90
110
91
111
# add index
92
- os::log::debug $( curl_es_pod " $pod " " /$index /multi-tenancy-test /" -XPOST $xff $xocpns $contenttype -d " $payload " | python -mjson.tool 2>&1 )
112
+ os::log::info $( curl_es_pod " $pod " " /$index /_doc /" -XPOST $xff $xocpns $contenttype -d " $payload " | python -mjson.tool 2>&1 )
93
113
# add alias
94
- os::log::debug $( curl_es_pod " $pod " " /_aliases" -XPOST $xff $xocpns $contenttype -d " $alias " | python -mjson.tool 2>&1 )
114
+ os::log::info $( curl_es_pod " $pod " " /_aliases" -XPOST $xff $xocpns $contenttype -d " $alias " | python -mjson.tool 2>&1 )
95
115
96
- os::log::debug $( curl_es_pod " $pod " " /app/multi-tenancy-test /_search" -XGET | python -mjson.tool)
116
+ os::log::info $( curl_es_pod " $pod " " /$aliasname /_doc /_search" -XGET | python -mjson.tool 2>&1 )
97
117
}
98
118
99
119
function test_user_has_proper_access() {
@@ -135,36 +155,36 @@ function test_user_has_proper_access() {
135
155
# verify normal user has no access to default indices
136
156
os::log::info See if user $user is denied /project.default.*
137
157
get_test_user_token $user $pw false
138
- nrecs=$( curl_es_pod_with_token $espod " /project.default.*/_count" $test_token | \
158
+ nrecs=$( curl_es_pod_with_token $espod " /project.default.*/_count" $test_token -XPOST $xfuser $xocpns $xfroles | \
139
159
get_count_from_json )
140
160
if ! os::cmd::expect_success " test $nrecs = 0" ; then
141
161
os::log::error $LOG_NORMAL_USER has improper access to project.default.* indices
142
- curl_es_pod_with_token $espod " /project.default.*/_count" $test_token | python -mjson.tool
162
+ curl_es_pod_with_token $espod " /project.default.*/_count" $test_token -XPOST $xfuser $xocpns $xfroles | python -mjson.tool
143
163
exit 1
144
164
fi
145
165
146
166
# verify normal user has no access to .operations
147
167
os::log::info See if user $user is denied /.operations.*
148
168
get_test_user_token $user $pw false
149
- nrecs=$( curl_es_pod_with_token $esopspod " /.operations.*/_count" $test_token | \
169
+ nrecs=$( curl_es_pod_with_token $esopspod " /.operations.*/_count" $test_token -XPOST $xfuser $xocpns $xfroles | \
150
170
get_count_from_json )
151
171
if ! os::cmd::expect_success " test $nrecs = 0" ; then
152
172
os::log::error $LOG_NORMAL_USER has improper access to .operations.* indices
153
- curl_es_pod_with_token $esopspod " /.operations.*/_count" $test_token | python -mjson.tool
173
+ curl_es_pod_with_token $esopspod " /.operations.*/_count" $test_token -XPOST $xfuser $xocpns $xfroles | python -mjson.tool
154
174
exit 1
155
175
fi
156
176
}
157
177
158
- curl_es_pod $espod /project.multi-tenancy- * -XDELETE > /dev/null
178
+ curl_es_pod $espod /logs-app * -XDELETE | artifact_out
159
179
160
180
for proj in multi-tenancy-1 multi-tenancy-2 multi-tenancy-3 ; do
161
181
os::log::info Creating project $proj
162
182
oc adm new-project $proj --node-selector=' ' 2>&1 | artifact_out
163
183
os::cmd::try_until_success " oc get project $proj " 2>&1 | artifact_out
164
184
os::log::info Creating test index and entry for $proj
165
- add_message_to_index $proj " " $espod
185
+ add_message_to_index $proj $espod logs-app
166
186
done
167
- os::log::info Creating project multi-tenancy-4
187
+ os::log::info Creating project multi-tenancy-4 2>&1 | artifact_out
168
188
oc adm new-project multi-tenancy-4 --node-selector=' ' 2>&1 | artifact_out
169
189
os::cmd::try_until_success " oc get project multi-tenancy-4" 2>&1 | artifact_out
170
190
@@ -189,6 +209,8 @@ create_users $LOG_NORMAL_USER1 $LOG_NORMAL_USER1_PW false \
189
209
$LOG_NORMAL_USER3 $LOG_NORMAL_USER3_PW false \
190
210
$LOG_NORMAL_USER4 $LOG_NORMAL_USER4_PW false 2>&1 | artifact_out
191
211
212
+ delete_users=" $LOG_NORMAL_USER1 $LOG_NORMAL_USER2 $LOG_NORMAL_USER3 $LOG_NORMAL_USER4 "
213
+
192
214
create_user_and_assign_to_projects $LOG_NORMAL_USER1 $LOG_NORMAL_USER1_PW multi-tenancy-1 multi-tenancy-2
193
215
create_user_and_assign_to_projects $LOG_NORMAL_USER2 $LOG_NORMAL_USER2_PW multi-tenancy-1
194
216
create_user_and_assign_to_projects $LOG_NORMAL_USER4 $LOG_NORMAL_USER4_PW multi-tenancy-4
@@ -197,10 +219,10 @@ oc login --username=system:admin > /dev/null
197
219
oc project $LOGGING_PROJECT > /dev/null
198
220
199
221
# loguser1 has access to two documents
200
- test_user_has_proper_access $LOG_NORMAL_USER1 $LOG_NORMAL_USER1_PW app
222
+ test_user_has_proper_access $LOG_NORMAL_USER1 $LOG_NORMAL_USER1_PW logs- app
201
223
# loguser2 has access to one document
202
- test_user_has_proper_access $LOG_NORMAL_USER2 $LOG_NORMAL_USER2_PW app
224
+ test_user_has_proper_access $LOG_NORMAL_USER2 $LOG_NORMAL_USER2_PW logs- app
203
225
# loguser3 has access to no ducuments as user has access to no projects
204
- test_user_has_proper_access $LOG_NORMAL_USER3 $LOG_NORMAL_USER3_PW app
226
+ test_user_has_proper_access $LOG_NORMAL_USER3 $LOG_NORMAL_USER3_PW logs- app
205
227
# loguser4 has access to no documents as there are no documents matching the project
206
- test_user_has_proper_access $LOG_NORMAL_USER4 $LOG_NORMAL_USER4_PW app 0
228
+ test_user_has_proper_access $LOG_NORMAL_USER4 $LOG_NORMAL_USER4_PW logs- app 0
0 commit comments