mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-03 11:48:15 +00:00
add --as-group option to cli
The usecase of this change: When a super user grant some RBAC permissions to a group, he can use --as-group to test whether the group get the permissions. Note that now we support as-groups, as-user-extra in kubeconfig file after this change.
This commit is contained in:
@@ -28,6 +28,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
||||
ETCD_HOST=${ETCD_HOST:-127.0.0.1}
|
||||
ETCD_PORT=${ETCD_PORT:-2379}
|
||||
API_PORT=${API_PORT:-8080}
|
||||
SECURE_API_PORT=${SECURE_API_PORT:-6443}
|
||||
API_HOST=${API_HOST:-127.0.0.1}
|
||||
KUBELET_PORT=${KUBELET_PORT:-10250}
|
||||
KUBELET_HEALTHZ_PORT=${KUBELET_HEALTHZ_PORT:-10248}
|
||||
@@ -2855,8 +2856,14 @@ runTests() {
|
||||
kube_flags=(
|
||||
-s "http://127.0.0.1:${API_PORT}"
|
||||
)
|
||||
|
||||
kube_flags_with_token=(
|
||||
-s "https://127.0.0.1:${SECURE_API_PORT}" --token=admin/system:masters --insecure-skip-tls-verify=true
|
||||
)
|
||||
|
||||
if [[ -z "${ALLOW_SKEW:-}" ]]; then
|
||||
kube_flags+=("--match-server-version")
|
||||
kube_flags_with_token+=("--match-server-version")
|
||||
fi
|
||||
if kube::test::if_supports_resource "${nodes}" ; then
|
||||
[ "$(kubectl get nodes -o go-template='{{ .apiVersion }}' "${kube_flags[@]}")" == "v1" ]
|
||||
@@ -3762,5 +3769,25 @@ __EOF__
|
||||
output_message=$(! KUBECTL_PLUGINS_PATH=test/fixtures/pkg/kubectl/plugins/ kubectl plugin error 2>&1)
|
||||
kube::test::if_has_string "${output_message}" 'error: exit status 1'
|
||||
|
||||
#################
|
||||
# Impersonation #
|
||||
#################
|
||||
output_message=$(! kubectl get pods "${kube_flags_with_token[@]}" --as-group=foo 2>&1)
|
||||
kube::test::if_has_string "${output_message}" 'without impersonating a user'
|
||||
|
||||
if kube::test::if_supports_resource "${csr}" ; then
|
||||
# --as
|
||||
kubectl create -f hack/testdata/csr.yml "${kube_flags_with_token[@]}" --as=user1
|
||||
kube::test::get_object_assert 'csr/foo' '{{.spec.username}}' 'user1'
|
||||
kube::test::get_object_assert 'csr/foo' '{{range .spec.groups}}{{.}}{{end}}' 'system:authenticated'
|
||||
kubectl delete -f hack/testdata/csr.yml "${kube_flags_with_token[@]}"
|
||||
|
||||
# --as-group
|
||||
kubectl create -f hack/testdata/csr.yml "${kube_flags_with_token[@]}" --as=user1 --as-group=group2 --as-group=group1 --as-group=,,,chameleon
|
||||
kube::test::get_object_assert 'csr/foo' '{{len .spec.groups}}' '3'
|
||||
kube::test::get_object_assert 'csr/foo' '{{range .spec.groups}}{{.}} {{end}}' 'group2 group1 ,,,chameleon '
|
||||
kubectl delete -f hack/testdata/csr.yml "${kube_flags_with_token[@]}"
|
||||
fi
|
||||
|
||||
kube::test::clear_all
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user