Skip to content

Commit 3078d5e

Browse files
authored
Adds RBAC error during apply end-to-end test case (#1425)
1 parent 998d233 commit 3078d5e

File tree

7 files changed

+186
-0
lines changed

7 files changed

+186
-0
lines changed

e2e/live/end-to-end-test.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,39 @@ assertPodNotExists "pod-c" "test-namespace"
882882
assertPodNotExists "pod-d" "test-namespace"
883883
printResult
884884

885+
# Test 21: RBAC error applying a resource
886+
echo "Testing RBAC error during apply"
887+
echo "kpt live apply e2e/live/testdata/rbac-error-step-1"
888+
echo "kpt live apply e2e/live/testdata/rbac-error-step-2"
889+
# Setup: create a service account and bind a Role to it so it has administrative
890+
# privileges on the "test" namespace, but no permissions on the default
891+
# namespace.
892+
kubectl apply -f e2e/live/testdata/rbac-error-step-1 > $OUTPUT_DIR/status
893+
assertContains "namespace/rbac-error created"
894+
assertContains "rolebinding.rbac.authorization.k8s.io/admin created"
895+
assertContains "serviceaccount/user created"
896+
wait 2
897+
898+
# Setup: use the service account just created. It does not have permissions
899+
# on the default namespace, so it will give a permissions error on apply
900+
# for anything attempted to apply to the default namespace.
901+
kubectl config set-credentials user --token="$(kubectl get secrets -ojsonpath='{.data.token}' \
902+
"$(kubectl get sa user -ojsonpath='{.secrets[0].name}')" \
903+
| base64 -d)" > $OUTPUT_DIR/status
904+
kubectl config set-context kind-kind:user --cluster=kind-kind --user=user > $OUTPUT_DIR/status
905+
kubectl config use-context kind-kind:user > $OUTPUT_DIR/status
906+
wait 2
907+
908+
# Attempt to apply two ConfigMaps: one in the default namespace (fails), and one
909+
# in the test namespace (succeeds).
910+
${BIN_DIR}/kpt live apply e2e/live/testdata/rbac-error-step-2 > $OUTPUT_DIR/status
911+
assertCMInventory "rbac-error" "1"
912+
assertContains "configmap/error-config-map failed"
913+
assertContains "configmap/valid-config-map created"
914+
assertContains "2 resource(s) applied. 1 created, 0 unchanged, 0 configured, 1 failed"
915+
assertContains "0 resource(s) pruned, 0 skipped, 0 failed"
916+
printResult
917+
885918
# Clean-up the k8s cluster
886919
echo "Cleaning up cluster"
887920
kind delete cluster
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: Namespace
17+
metadata:
18+
name: rbac-error
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: rbac.authorization.k8s.io/v1
16+
kind: RoleBinding
17+
metadata:
18+
name: admin
19+
namespace: rbac-error
20+
roleRef:
21+
apiGroup: rbac.authorization.k8s.io
22+
kind: ClusterRole
23+
name: cluster-admin
24+
subjects:
25+
- kind: User
26+
name: system:serviceaccount:default:user
27+
apiGroup: rbac.authorization.k8s.io
28+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: ServiceAccount
17+
metadata:
18+
name: user
19+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: valid-config-map
19+
namespace: rbac-error
20+
data: {}
21+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: error-config-map
19+
data: {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# NOTE: auto-generated. Some fields should NOT be modified.
16+
# Date: 2020-11-17 02:17:32 PST
17+
#
18+
# Contains the "inventory object" template ConfigMap.
19+
# When this object is applied, it is handled specially,
20+
# storing the metadata of all the other objects applied.
21+
# This object and its stored inventory is subsequently
22+
# used to calculate the set of objects to automatically
23+
# delete (prune), when an object is omitted from further
24+
# applies. When applied, this "inventory object" is also
25+
# used to identify the entire set of objects to delete.
26+
#
27+
# NOTE: The name of this inventory template file
28+
# does NOT have any impact on group-related functionality
29+
# such as deletion or pruning.
30+
#
31+
apiVersion: v1
32+
kind: ConfigMap
33+
metadata:
34+
# DANGER: Do not change the inventory object namespace.
35+
# Changing the namespace will cause a loss of continuity
36+
# with previously applied grouped objects. Set deletion
37+
# and pruning functionality will be impaired.
38+
namespace: rbac-error
39+
# NOTE: The name of the inventory object does NOT have
40+
# any impact on group-related functionality such as
41+
# deletion or pruning.
42+
name: inventory-40897991
43+
labels:
44+
# DANGER: Do not change the value of this label.
45+
# Changing this value will cause a loss of continuity
46+
# with previously applied grouped objects. Set deletion
47+
# and pruning functionality will be impaired.
48+
cli-utils.sigs.k8s.io/inventory-id: 0d433e0b-d9dd-4313-a58c-53f939a38fe1

0 commit comments

Comments
 (0)