真题解析2

题目

Context

绑定到 Deployment 的 ServiceAccount 的 Role 授予过度宽松的权限,完成以下项目以减少权限集。

Task

一个名为 nginx 的现有 Deployment 已在 namespace monitoring 中运行。

编辑绑定到 Deployment 的 ServiceAccount test-sa-3 的现有 Role,仅允许只对 endpoints 类型的资源执行 get 操作。

在 namespace monitoring 中创建一个名为 role-2 ,并仅允许对 namespaces 类型的资源执行 delete 操作的新 Role。

创建一个名为 role-2-binding 的新 RoleBinding,将 role-2 绑定到 Deployment 的 ServiceAccount。

解析

查询 SA test-sa-3 绑定的是哪个 Role(若没有可以直接 kubectl get role -n monitoring)

kubectl get rolebinding -n monitoring -o yaml | grep -i test-sa-3 -C 6
roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: Role
    name: web-role
  subjects:
  - kind: ServiceAccount
    name: test-sa-3
    namespace: monitoring
kind: List
metadata:
  resourceVersion: ""

根据查询到的 Role ,编辑 Role 的权限

创建 role-2

创建 role-2-binding

Last updated