ServiceAccount
- 파드에서 실행 중인 프로세스를 위한 신원(identity)을 제공한다.
- 파드 내부에서, 자신에게 부여된 ServiceAccount의 식별자를 사용하여 클러스터의 API에 인증할 수 있다.
- 파드 내부의 프로세스가 클러스터에 엑세스할 때, API 서버에 의해서 특별한 서비스 어카운트(예를 들면, 기본(default))로 인증된다.
- 파드를 생성할 때, 서비스 어카운트를 명시하지 않으면, 동일한 네임스페이스의 기본 서비스 어카운트가 자동적으로 할당된다.
Example
- ServiceAccount, ClusterRole, ClusterRoleBinding 예시
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: test-network
subjects:
- kind: ServiceAccount
name: test-network
namespace: mdl
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: test-network
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: create-blockchain-network
namespace: mdl
rules:
- apiGroups: ["", "apps", "batch"]
resources:
- pods
- secrets
- configmaps
- services
- deployments
- jobs
- persistentvolumes
- persistentvolumeclaims
- pods/exec
- pods/log
- nodes
- namespaces
- events
verbs: ["get", "watch", "list", "update", "create", "delete", "patch"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: test-network
namespace: mdl
ServiceAccount를 할당할 pod나 deployment의 spec에, 다음을 명시해준다.
---
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 1
...
spec:
serviceAccountName: test-network
- 이러면, 이 deployment는 ClusterRoleBinding에 의해 할당되어, ClusterRole에 허락된 작업 or 리소스들만 수행할 수 있다.
- RBAC
- Role, RoleBinding, ClusterRole, ClusterRoleBinding을 통해 RBAC를 관리한다.
- 쿠버네티스 1.24 버전 이후부터, 보안 강화로 service account의 토큰을 직접 생성해 주어야 한다고 한다.
Share article