Skip to content

Commit 47cb78e

Browse files
committed
Enable multi-tenancy test
Changed project_user role's index pattern from `logs.app` to `logs-app` Bumped ci build image to golang1.12
1 parent 1ce24f8 commit 47cb78e

File tree

5 files changed

+67
-47
lines changed

5 files changed

+67
-47
lines changed

elasticsearch/sgconfig/roles.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,17 @@ sg_project_operations:
163163
- indices:admin/get*
164164

165165
# To support multi-tenancy. User's access to indices is restricted to indices belonging to the user's projects, enforced by DLS.
166-
project_user:
167-
readonly: true
166+
project_user:
167+
readonly: true
168168
cluster:
169169
- CLUSTER_COMPOSITE_OPS_RO
170-
indices:
171-
app:
172-
'*':
173-
- READ
174-
- indices:data/read/search
170+
indices:
171+
app:
172+
'*':
173+
- READ
175174
_dls_: "{\"bool\":{\"filter\":{\"script\":{\"script\":{\"lang\":\"painless\",\"params\":{\"param1\":\"${attr.proxy.namespace}\"},\"source\":\"String namespace = doc['kubernetes.namespace_name.keyword'][0];StringTokenizer st = new StringTokenizer(params.param1,\\\",\\\");while (st.hasMoreTokens()){if (st.nextToken().equalsIgnoreCase(namespace)){return true;}}return false;\"}}}}}"
176-
logs.app:
177-
'*':
178-
- READ
179-
- indices:data/read/search
175+
logs-app:
176+
'*':
177+
- READ
180178
_dls_: "{\"bool\":{\"filter\":{\"script\":{\"script\":{\"lang\":\"painless\",\"params\":{\"param1\":\"${attr.proxy.namespace}\"},\"source\":\"String namespace = doc['kubernetes.namespace_name.keyword'][0];StringTokenizer st = new StringTokenizer(params.param1,\\\",\\\");while (st.hasMoreTokens()){if (st.nextToken().equalsIgnoreCase(namespace)){return true;}}return false;\"}}}}}"
181179

hack/deploy-logging.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ wait_for_logging_is_running() {
243243
result=0
244244
local actuales=$( oc -n ${LOGGING_NS} get pods -l component=elasticsearch 2> /dev/null | grep -c 'elasticsearch.* 2/2 .*Running' )
245245
if [ $expectedes -ne ${actuales:-0} ] ; then
246-
echo WARN: ${actuales:-0} of $expectedes Running
246+
echo WARN: ${actuales:-0} of $expectedes elasticsearch Running
247247
result=1
248248
else
249249
if [ "$es_ready" != "true" ] ; then
@@ -265,7 +265,7 @@ wait_for_logging_is_running() {
265265
fi
266266
local actualcollectors=$( oc -n ${LOGGING_NS} get pods -l component=fluentd 2> /dev/null | grep -c "fluentd.*Running" )
267267
if [ $expectedcollectors -ne ${actualcollectors:-0} ] ; then
268-
echo WARN: ${actualcollectors:-0} of $expectedcollectors Running
268+
echo WARN: ${actualcollectors:-0} of $expectedcollectors fluentd Running
269269
result=1
270270
else
271271
if [ "$fluent_ready" != "true" ] ; then

hack/test-e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ OPERATOR_LOGGING_IMAGE_STREAM=${OPERATOR_LOGGING_IMAGE_STREAM:-"stable"}
1010
# we do not want that
1111
set -f
1212
# EXCLUDE_SUITE="${EXCLUDE_SUITE:-"$^"}"
13-
INCLUDE_SUITE="test-010-*"
13+
INCLUDE_SUITE="test-010-*|multi-tenancy"
1414
set +f
1515
# log::info "Excluding tests: '${EXCLUDE_SUITE}'"
1616
# for test in $( find "${current_dir}/testing" -type f -name 'test-*.sh' | grep -Ev "${EXCLUDE_SUITE}" | sort); do
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dockerfile to bootstrap build and test in openshift-ci
22

3-
FROM openshift/origin-release:golang-1.10
3+
FROM openshift/origin-release:golang-1.12
44

55
RUN yum -y install epel-release && \
66
yum -y install jq bc sudo httpd-tools procps-ng

test/multi_tenancy.sh

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,47 @@
1111
# cat msearch.json | curl https://localhost:9200/_msearch -XPOST --data-binary @-
1212
source "$(dirname "${BASH_SOURCE[0]}" )/../hack/lib/init.sh"
1313
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)
1417
trap os::test::junit::reconcile_output EXIT
1518
os::util::environment::use_sudo
1619

1720
os::test::junit::declare_suite_start "test/multi_tenancy"
1821

1922
LOGGING_PROJECT=${LOGGING_NS:-openshift-logging}
2023
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-
}
3024

3125
delete_users=""
3226
cleanup_msearch_access=""
3327

3428
function cleanup() {
29+
local return_code="$?"
30+
cleanup_es
3531
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..."
4050
for user in $delete_users ; do
4151
oc delete user $user 2>&1 | artifact_out
4252
done
4353
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
4555
fi
4656
for proj in $PROJECTS ; do
4757
oc delete project $proj 2>&1 | artifact_out
@@ -52,6 +62,16 @@ function cleanup() {
5262
}
5363

5464
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}
5575

5676
function create_user_and_assign_to_projects() {
5777
local current_project; current_project="$( oc project -q )"
@@ -77,23 +97,23 @@ function create_user_and_assign_to_projects() {
7797
function add_message_to_index() {
7898

7999
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
83103

84104
local xff="-H X-Forwarded-For:127.0.0.1"
85105
local xocpns='-H X-Ocp-Namespace:'"$namespace"
86106
local contenttype="-H Content-Type:application/json"
87107

88108
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\"}}]}"
90110

91111
# 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 )
93113
# 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 )
95115

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 )
97117
}
98118

99119
function test_user_has_proper_access() {
@@ -135,36 +155,36 @@ function test_user_has_proper_access() {
135155
# verify normal user has no access to default indices
136156
os::log::info See if user $user is denied /project.default.*
137157
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 | \
139159
get_count_from_json )
140160
if ! os::cmd::expect_success "test $nrecs = 0" ; then
141161
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
143163
exit 1
144164
fi
145165

146166
# verify normal user has no access to .operations
147167
os::log::info See if user $user is denied /.operations.*
148168
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 | \
150170
get_count_from_json )
151171
if ! os::cmd::expect_success "test $nrecs = 0" ; then
152172
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
154174
exit 1
155175
fi
156176
}
157177

158-
curl_es_pod $espod /project.multi-tenancy-* -XDELETE > /dev/null
178+
curl_es_pod $espod /logs-app* -XDELETE | artifact_out
159179

160180
for proj in multi-tenancy-1 multi-tenancy-2 multi-tenancy-3 ; do
161181
os::log::info Creating project $proj
162182
oc adm new-project $proj --node-selector='' 2>&1 | artifact_out
163183
os::cmd::try_until_success "oc get project $proj" 2>&1 | artifact_out
164184
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
166186
done
167-
os::log::info Creating project multi-tenancy-4
187+
os::log::info Creating project multi-tenancy-4 2>&1 | artifact_out
168188
oc adm new-project multi-tenancy-4 --node-selector='' 2>&1 | artifact_out
169189
os::cmd::try_until_success "oc get project multi-tenancy-4" 2>&1 | artifact_out
170190

@@ -189,6 +209,8 @@ create_users $LOG_NORMAL_USER1 $LOG_NORMAL_USER1_PW false \
189209
$LOG_NORMAL_USER3 $LOG_NORMAL_USER3_PW false \
190210
$LOG_NORMAL_USER4 $LOG_NORMAL_USER4_PW false 2>&1 | artifact_out
191211

212+
delete_users="$LOG_NORMAL_USER1 $LOG_NORMAL_USER2 $LOG_NORMAL_USER3 $LOG_NORMAL_USER4"
213+
192214
create_user_and_assign_to_projects $LOG_NORMAL_USER1 $LOG_NORMAL_USER1_PW multi-tenancy-1 multi-tenancy-2
193215
create_user_and_assign_to_projects $LOG_NORMAL_USER2 $LOG_NORMAL_USER2_PW multi-tenancy-1
194216
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
197219
oc project $LOGGING_PROJECT > /dev/null
198220

199221
# 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
201223
# 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
203225
# 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
205227
# 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

Comments
 (0)