설명
ServiceAccount에 바인딩한 Role이나 ClusterRole이 secrets에 get, list 또는 watch를 허용하면 해당 계정을 쓰는 파드가 허용 범위의 Secret 값을 읽을 수 있습니다.
잠재적 영향
노출된 비밀번호나 토큰으로 다른 시스템에 접근할 수 있습니다. Secret에 update를 허용하면 저장된 자격 증명까지 바꿀 수 있습니다.
해결 방법
앱이 Secret API를 직접 호출할 때만 전용 계정에 필요한 권한을 부여하세요. 볼륨이나 환경 변수로 받는 파드에는 이 읽기 권한이 필요 없습니다. 다른 역할과 바인딩의 와일드카드 권한까지 확인해 불필요한 Secret 접근을 제거하세요.
예시
assembly-prod 네임스페이스에 testsa를 먼저 생성하세요. 두 예시는 이름이 다른 Role과 RoleBinding을 만듭니다.
변경 전
yaml
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: assembly-prod
name: testRoleVulnerable
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "watch", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: assembly-prod
name: testRoleBinding
subjects:
- kind: ServiceAccount
name: testsa
namespace: assembly-prod
roleRef:
kind: Role
name: testRoleVulnerable
apiGroup: rbac.authorization.k8s.io
변경 후
yaml
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: assembly-prod
name: testRoleWithBindingSafe
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: assembly-prod
name: bindingtestRoleWithBindingSafe
subjects:
- kind: ServiceAccount
name: testsa
namespace: assembly-prod
roleRef:
kind: Role
name: testRoleWithBindingSafe
apiGroup: rbac.authorization.k8s.io
설명:
- 변경 전:
testRoleBinding은testsa에 이 네임스페이스의 Secret 조회·목록·변경 감시 권한을 부여합니다. - 변경 후: 새 바인딩은 파드 조회와 목록만 허용합니다. 기존
testRoleBinding도 제거하고testsa가 Secret 값을 읽을 수 없는지 확인하세요.