2

我在启用 rbac 的 GKE 中设置了一个 k8s 集群,并将 Istio 安装到集群中。

我按照此步骤(链接)为 Istio 入口控制器创建密钥/证书,并将密钥/证书存储为名称为 istio-ingress-certs 的秘密。

现在我想使用 RBAC 来限制对 istio-ingress-certs 的访问,以便允许 istio-system 中的每个组件读取秘密,但没有人可以修改或删除它。

我创建了一个 secrets-rbac.yaml 文件,然后运行 ​​kubectl apply -f secrets-rbac.yaml,它创建了一个角色来读取密钥,并将这个角色绑定到 istio-system 命名空间中的所有服务帐户。

验证服务帐户不允许修改 istio-ingress-certs。我用这个命令来测试。kubectl auth can-i edit secrets/istio-ingress-certs -n istio-system --as system:serviceaccount:istio-system:istio-pilot-service-account

我希望该命令会返回 false,但它会返回 true。我认为我没有在yaml文件中正确设置rbac,但我不清楚哪个部分不正确。

kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: istio-system
  name: istio-ingress-certs-reader
rules:
- apiGroups: ["*"]
  resources: ["secrets"]
  resourceNames: ["istio-ingress-certs"]
  verbs: ["get"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: istio-system
  name: read-istio-ingress-certs
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: istio-ingress-certs-reader
subjects:
- kind: Group
  name: system:serviceaccounts:istio-system
  apiGroup: rbac.authorization.k8s.io
- kind: Group
  name: system:authenticated
  apiGroup: rbac.authorization.k8s.io
- kind: Group
  name: system:unauthenticated
  apiGroup: rbac.authorization.k8s.io

4

0 回答 0