説明
ServiceAccount にバインドした Role または ClusterRole が secrets の get、list、watch のいずれかを許可すると、そのアカウントを使う Pod は許可された範囲の Secret の値を読み取れます。
想定される影響
漏えいしたパスワードやトークンが他のシステムへのアクセスに使われるおそれがあります。update を許可すると、保存された認証情報を書き換えることもできます。
対処方法
アプリケーションが Secret API を直接呼ぶ場合だけ、専用アカウントに必要な操作を許可します。ボリュームや環境変数で受け取る Pod には、そのための読み取り権限は不要です。不要な 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 の取得、一覧取得、変更の監視を許可します。 - 変更後: 新しいバインディングで許可するのは Pod の取得と一覧取得だけです。元の
testRoleBindingも削除し、testsaが Secret の値を読めなくなったことを確認してください。