【问题标题】:RBAC - Limit access for one service accountRBAC - 限制一个服务帐户的访问权限
【发布时间】:2017-07-06 10:26:23
【问题描述】:

我想限制以下服务帐号的权限,创建如下:

kubectl create serviceaccount alice --namespace default

secret=$(kubectl get sa alice -o json | jq -r .secrets[].name)

kubectl get secret $secret -o json | jq -r '.data["ca.crt"]' | base64 -d > ca.crt

user_token=$(kubectl get secret $secret -o json | jq -r '.data["token"]' | base64 -d)

c=`kubectl config current-context`

name=`kubectl config get-contexts $c | awk '{print $3}' | tail -n 1`

endpoint=`kubectl config view -o jsonpath="{.clusters[?(@.name == \"$name\")].cluster.server}"`

kubectl config set-cluster cluster-staging \
  --embed-certs=true \
  --server=$endpoint \
  --certificate-authority=./ca.crt

kubectl config set-credentials alice-staging --token=$user_token

kubectl config set-context alice-staging \
  --cluster=cluster-staging \
  --user=alice-staging \
  --namespace=default

kubectl config get-contexts

#kubectl config use-context alice-staging

这有权查看所有内容: kubectl --context=alice-staging get pods --all-namespaces

我尝试通过以下方式对其进行限制,但仍然拥有所有权限:

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: no-access
rules:
- apiGroups: [""]
  resources: [""]
  verbs: [""]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: no-access-role
subjects:
- kind: ServiceAccount
  name: alice
  namespace: default
roleRef:
  kind: ClusterRole
  name: no-access
  apiGroup: rbac.authorization.k8s.io

这个想法是限制对命名空间的访问来为用户分发令牌,但我不明白......我认为这可能是为了继承权限,但我不能为单个 serviceacount 禁用。

使用:GKE、容器虚拟机

谢谢!

【问题讨论】:

    标签: kubernetes google-kubernetes-engine kubectl google-container-os


    【解决方案1】:

    请注意,服务帐户并非针对用户,而是针对在 pod 内运行的进程 (https://kubernetes.io/docs/admin/service-accounts-admin/)。

    Create user in Kubernetes for kubectl,您可以找到如何为您的 K8s 集群创建用户帐户。

    此外,我建议您检查集群中是否实际启用了 RBAC,这可以解释用户可以执行更多预期的操作。

    【讨论】:

    • 它正在使用 Webhook:ps -aux | grep -o "authorization-mode=[a-zA-Z]* " >>> authorization-mode=Webhook --- 我必须弄清楚如何为 GKE 进行此更改
    • 最终使用:gcloud container clusters update NAME-CLUSTER --no-enable-legacy-authorization --zone=YOUR-ZONE来源:cloud.google.com/container-engine/docs/…
    猜你喜欢
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    • 2020-04-27
    • 2021-04-19
    • 2020-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多