EKS Pod Identity

公式ブログの解説

環境作る
$ eksctl create cluster --name $CLUSTER_NAME \
--region ap-northeast-1 \
--version 1.31 \
--vpc-private-subnets $SUBNET_IDS \
--without-nodegroup
$ eksctl create nodegroup \
--cluster $CLUSTER_NAME \
--name test-group-2 \
--nodes 1 \
--managed \
--subnet-ids $SUBNET_IDS \
--node-private-networking \
--spot

eks-pod-identity-agent は daemonset として動作してる
❯ k get daemonsets | grep eks-pod-identity
eks-pod-identity-agent 1 1 1 1 1 <none> 23m

EKS Pod Identity では k8s serice account に annotation を設定する必要がない
その代わり EKS クラスタ/IAMロール/Namespace/k8s Service Account
を関連付ける必要がある
❯ a eks list-pod-identity-associations --cluster-name test-cluster
{
"associations": [
{
"clusterName": "test-cluster",
"namespace": "default",
"serviceAccount": "my-sa",
"associationArn": "arn:aws:eks:ap-northeast-1:787080764332:podidentityassociation/test-cluster/a-rpcft8f8fmf1uiqxf",
"associationId": "a-xxxxxxxxxxxx"
}
]
}

❯ k describe sa my-sa
Name: my-sa
Namespace: default
Labels: <none>
Annotations: <none>
Image pull secrets: <none>
Mountable secrets: <none>
Tokens: <none>
Events: <none>

Pod を作成すると pod-identity-webhook が以下のような設定を PodSpec に差し込む
IRSA と同じく、環境変数、volumeMount, volume を追加しているが内容は少しずつ違う。
env:
- name: AWS_STS_REGIONAL_ENDPOINTS
value: regional
- name: AWS_DEFAULT_REGION
value: ap-northeast-1
- name: AWS_REGION
value: ap-northeast-1
- name: AWS_CONTAINER_CREDENTIALS_FULL_URI
value: http://169.254.170.23/v1/credentials
- name: AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE
value: /var/run/secrets/pods.eks.amazonaws.com/serviceaccount/eks-pod-identity-token
volumeMounts:
- mountPath: /var/run/secrets/pods.eks.amazonaws.com/serviceaccount
name: eks-pod-identity-token
readOnly: true
volumes:
- name: eks-pod-identity-token
projected:
defaultMode: 420
sources:
- serviceAccountToken:
audience: pods.eks.amazonaws.com
expirationSeconds: 86400
path: eks-pod-identity-token

IRSA は pod-identity-webhook が annotation(eks.amazonaws.com/role-arn)が設定されている k8s service account を持つ Pod を mutate していたが、EKS Pod Identity では annotation を設定しなくても mutate が発生している
pod-identity-webhook は mutate すべき Pod をどのように判別しているのか?

Container Credentials Config を利用してるらしい
pod-identity-webhook の起動時に watch-container-credentials-config
にパスを渡すと Container Credentials Config を監視する

Container Credentials Config は Pod Identity の関連付けと連動してると思われる
関連付けされた k8s service account と namespace に一致する場合は EKS Pod Identity 用のmutate を実行する
ちなみに Audience: pods.eks.amazonaws.com が入る(後ほど TokenRequest API で発行される JWT トークンには aud: pods.eks.amazonaws.com が含まれるはず)

aws-sdk は認証情報プロパイダーと呼ばれる規定に沿って順番に認証情報を読み取っていく