[CKA] RBAC API

hope·2023년 11월 9일

CKA

목록 보기
6/8
post-thumbnail

참고 문서: kubernetes.io/rbac

Role, ClusterRole

  • 말 그대로 역할
  • 권한을 정의한 것임
  • aws로 치면 IAM 역할과 같다고 생각하면 될 것 같다
  • role과 clusterrole의 차이는 쉽게 말하면 지역변수, 전역변수 같은 느낌이다

Role

  • 네임스페이스 범위에서 적용됨
  • 파드에 대한 읽기 액세스 권한이 있는 default 네임스페이스의 역할
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      namespace: default
      name: pod-reader
    rules:
    - apiGroups: [""] # "" indicates the core API group
      resources: ["pods"]
      verbs: ["get", "watch", "list"]

ClusterRole

  • 클러스터 전체 범위에서 리소스에 대한 권한을 정의함
  • 시크릿에 대한 읽기 액세스 권한이 있는 역할
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      # "namespace" omitted since ClusterRoles are not namespaced
      name: secret-reader
    rules:
    - apiGroups: [""]
      #
      # at the HTTP level, the name of the resource for accessing Secret
      # objects is "secrets"
      resources: ["secrets"]
      verbs: ["get", "watch", "list"]

RoleBinding, ClusterRoleBinding

  • binding 의미 그대로 role을 사용자나 그룹에 바인딩하는 것이다
  • role을 부여하는 행위라고 생각하면 될 것 같다
  • aws에서 IAM role을 생성하고 사용자나 그룹에 추가하는 것처럼

RoleBinding

  • 특정 네임스페이스 내에서 Role에 정의된 권한을 사용자 또는 사용자 집합에 부여함

Role - RoleBinding

  • janedefault 네임스페이스의 Pod를 읽을 수 있음
    apiVersion: rbac.authorization.k8s.io/v1
    # This role binding allows "jane" to read pods in the "default" namespace.
    # You need to already have a Role named "pod-reader" in that namespace.
    kind: RoleBinding
    metadata:
      name: read-pods
      namespace: default
    subjects:
    # You can specify more than one "subject"
    - kind: User
      name: jane # "name" is case sensitive
      apiGroup: rbac.authorization.k8s.io
    roleRef:
      # "roleRef" specifies the binding to a Role / ClusterRole
      kind: Role #this must be Role or ClusterRole
      name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to
      apiGroup: rbac.authorization.k8s.io

ClusterRole - RoleBinding

  • ClusterRole을 특정 네임스페이스에 부여하고 싶을 경우에 사용
  • davedevelopment 네임스페이스에서만 secret을 읽을 수 있음
    apiVersion: rbac.authorization.k8s.io/v1
    # This role binding allows "dave" to read secrets in the "development" namespace.
    # You need to already have a ClusterRole named "secret-reader".
    kind: RoleBinding
    metadata:
      name: read-secrets
      #
      # The namespace of the RoleBinding determines where the permissions are granted.
      # This only grants permissions within the "development" namespace.
      namespace: development
    subjects:
    - kind: User
      name: dave # Name is case sensitive
      apiGroup: rbac.authorization.k8s.io
    roleRef:
      kind: ClusterRole
      name: secret-reader
      apiGroup: rbac.authorization.k8s.io

ClusterRoleBinding

  • 클러스터 전체에 권한을 부여할 때 사용
  • manager 그룹의 모든 사용자가 모든 네임스페이스시크릿을 읽도록 권한 부여
    apiVersion: rbac.authorization.k8s.io/v1
    # This cluster role binding allows anyone in the "manager" group to read secrets in any namespace.
    kind: ClusterRoleBinding
    metadata:
      name: read-secrets-global
    subjects:
    - kind: Group
      name: manager # Name is case sensitive
      apiGroup: rbac.authorization.k8s.io
    roleRef:
      kind: ClusterRole
      name: secret-reader
      apiGroup: rbac.authorization.k8s.io

주의 사항

  • 바인딩 생성 후에는 Role 또는 ClusterRole 변경이 불가함
  • roleRef 유효성 검사 오류가 발생함
  • 그래서 바인딩을 변경하기 위해서는 삭제 후 재생성이 필요함
profile
devops 엔지니어

0개의 댓글