Skip to content

Instantly share code, notes, and snippets.

@ejohn20
Created February 12, 2024 21:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejohn20/212ef7ea95d6dd92bda8b77e8b3b3881 to your computer and use it in GitHub Desktop.
Save ejohn20/212ef7ea95d6dd92bda8b77e8b3b3881 to your computer and use it in GitHub Desktop.
aws-eks-audit-pod-identity-pods.sh
#!/bin/bash
CLUSTER_NAME="$1"
while IFS= read -r pod_identity_assn; do
association_id=$(jq -r .associationId <<<"${pod_identity_assn}")
service_account=$(jq -r .serviceAccount <<<"${pod_identity_assn}")
namespace=$(jq -r .namespace <<<"${pod_identity_assn}")
association=$(aws eks describe-pod-identity-association --cluster "${CLUSTER_NAME}" --association-id "${association_id}")
role_arn=$(jq -r '.association.roleArn' <<<"${association}")
role_name=$(jq -r '.association.roleArn | split("/") | .[1]' <<<"${association}")
echo "Kubernetes Service Account: system:serviceaccount:${namespace}:${service_account}"
echo "Role ARN: ${role_arn}"
echo "Policy Attachments:"
aws iam list-attached-role-policies --role-name "${role_name}" | jq -r .'AttachedPolicies[].PolicyArn'
echo ""
done < <(aws eks list-pod-identity-associations --cluster-name "${CLUSTER_NAME}" | jq -c '.associations[]')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment