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
|
||||
}
|
||||
|
@@ -44,6 +44,7 @@ function run_kube_apiserver() {
|
||||
--public-address-override="127.0.0.1" \
|
||||
--port="${API_PORT}" \
|
||||
--authorization-mode="${AUTHORIZATION_MODE}" \
|
||||
--secure-port="${SECURE_API_PORT}" \
|
||||
--admission-control="${ADMISSION_CONTROL}" \
|
||||
--etcd-servers="http://${ETCD_HOST}:${ETCD_PORT}" \
|
||||
--public-address-override="127.0.0.1" \
|
||||
@@ -51,7 +52,8 @@ function run_kube_apiserver() {
|
||||
--runtime-config=api/v1 \
|
||||
--storage-media-type="${KUBE_TEST_API_STORAGE_TYPE-}" \
|
||||
--cert-dir="${TMPDIR:-/tmp/}" \
|
||||
--service-cluster-ip-range="10.0.0.0/24" 1>&2 &
|
||||
--service-cluster-ip-range="10.0.0.0/24" \
|
||||
--insecure-allow-any-token 1>&2 &
|
||||
APISERVER_PID=$!
|
||||
|
||||
kube::util::wait_for_url "http://127.0.0.1:${API_PORT}/healthz" "apiserver"
|
||||
|
@@ -38,10 +38,12 @@ function run_federation_apiserver() {
|
||||
|
||||
"${KUBE_OUTPUT_HOSTBIN}/federation-apiserver" \
|
||||
--insecure-port="${API_PORT}" \
|
||||
--secure-port="${SECURE_API_PORT}" \
|
||||
--admission-control="${ADMISSION_CONTROL}" \
|
||||
--etcd-servers="http://${ETCD_HOST}:${ETCD_PORT}" \
|
||||
--storage-media-type="${KUBE_TEST_API_STORAGE_TYPE-}" \
|
||||
--cert-dir="${TMPDIR:-/tmp/}" 1>&2 &
|
||||
--cert-dir="${TMPDIR:-/tmp/}" \
|
||||
--insecure-allow-any-token 1>&2 &
|
||||
APISERVER_PID=$!
|
||||
|
||||
kube::util::wait_for_url "http://127.0.0.1:${API_PORT}/healthz" "apiserver"
|
||||
|
Reference in New Issue
Block a user