역할 기반 액세스 제어(RBAC) 설정

인증은 인증된 사용자 및 서비스 계정에 대해 클러스터에 보다 세분화된 액세스 제어를 제공하기 위해 Kubernetes 역할 기반 액세스 제어(RBAC)와 결합되는 경우가 많습니다. 사용자 식별자 대신 그룹 이름을 사용하는 RBAC 정책을 만드는 것이 좋습니다. RBAC 정책을 그룹에 명시적으로 연결하면 ID 공급업체를 통해 사용자 액세스 권한을 완전히 관리할 수 있으므로 사용자 권한이 변경될 때마다 클러스터를 업데이트할 필요가 없습니다. 보안 그룹의 멤버십에 따라 액세스 제어를 구성하려면 그룹 멤버십 정보를 가져오도록 GKE Identity Service가 설정되어 있는지 확인해야 합니다.

예시

인증된 특정 사용자가 클러스터의 포드에 액세스할 수 있도록 하려면 다음 예시와 같이 이러한 리소스에 대한 액세스 권한을 부여하는 ClusterRole을 만듭니다.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: pod-reader
rules:
- apiGroups: [""]
  # The resource type for which access is granted
  resources: ["pods"]
  # The permissions granted by the ClusterRole
  verbs: ["get", "watch", "list"]

그런 후 관련 사용자(여기에서는 us-east1-cluster-admins 보안 그룹의 구성원과 ID u98523-4509823가 있는 사용자)에게 ClusterRole의 권한을 부여하도록 해당 ClusterRoleBinding을 만듭니다.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: read-pods-admins
subjects:
  # Grants anyone in the "us-east1-cluster-admins" group
  # read access to Pods in any namespace within this cluster.
- kind: Group
  name: gid-us-east1-cluster-admins # Name is case-sensitive
  apiGroup: rbac.authorization.k8s.io
  # Grants this specific user read access to Pods in any
  # namespace within this cluster
- kind: User
  name: uid-u98523-4509823
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

다음 예시에서 ClusterRoleBinding은 ID가 12345678-BBBb-cCCCC-0000-123456789012인 관련 그룹에 ClusterRole 권한을 부여합니다. 이 설정은 Azure AD 제공업체에만 관련되며 베어메탈 클러스터용 Google Distributed Cloud Virtual에서 사용할 수 있습니다.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: pod-reader-binding
subjects:
  # Retrieves group information for the group ID mentioned
- kind: Group
  name: 12345678-BBBb-cCCCC-0000-123456789012
  apiGroup: rbac.authorization.k8s.io

RBAC 사용에 대한 자세한 내용은 역할 기반 액세스 제어 구성RBAC 승인 사용을 참조하세요.

Google Cloud 콘솔 액세스에 대한 RBAC 역할 만들기

OIDC 제공업체를 사용하여 인증된 사용자는 명령줄뿐만 아니라 Google Cloud 콘솔에서 클러스터에 로그인할 수 있습니다.

Google Cloud 콘솔에서 클러스터 리소스에 액세스하려는 인증된 사용자는 관련 Kubernetes 권한이 있어야 로그인할 수 있습니다. 이러한 사용자에게 클러스터 관리자와 같은 더 광범위한 권한을 부여하지 않으려면 클러스터의 노드, 영구 볼륨, 포드, 스토리지 클래스를 볼 수 있는 최소 권한이 포함된 커스텀 RBAC 역할을 만들 수 있습니다. 클러스터에 ClusterRole RBAC 리소스, cloud-console-reader를 만들어서 이 권한 집합을 정의할 수 있습니다.

cloud-console-reader는 사용자에게 클러스터의 노드, 영구 볼륨, 포드, 스토리지 클래스에 대한 get, list, watch 권한을 부여하여 관련 리소스에 대한 세부정보를 볼 수 있게 합니다.

kubectl

cloud-console-reader ClusterRole을 만들고 이를 클러스터에 적용하려면 다음 명령어를 실행합니다.

cat <<EOF > cloud-console-reader.yaml
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: cloud-console-reader
rules:
- apiGroups: [""]
  resources: ["nodes", "persistentvolumes", "pods"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["storage.k8s.io"]
  resources: ["storageclasses"]
  verbs: ["get", "list", "watch"]
EOF
kubectl apply -f cloud-console-reader.yaml

그런 다음 이전 섹션의 설명대로 권한 정책을 설정할 때 사용자에게 ClusterRole을 부여할 수 있습니다. Google Cloud 콘솔에서 클러스터를 보려면 IAM 권한도 필요합니다.