Skip to content

Instantly share code, notes, and snippets.

@russau
Last active August 2, 2024 01:34

Revisions

  1. russau revised this gist Aug 2, 2024. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion demo-podid.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,12 @@
    # My pod wants to access AWS resources - pod-identity assoc
    # My pod wants to access AWS resources - pod-identity assoc


    ## Pod identity association

    ```
    # install the addon into the cluster
    eksctl create addon --cluster quick-cluster --name eks-pod-identity-agent
    kubectl create serviceaccount sa-buckets-man
    # aws eks create-pod-identity-association \
    @@ -12,12 +15,18 @@ kubectl create serviceaccount sa-buckets-man
    # --service-account sa-buckets-man \
    # --role-arn arn:aws:iam::414514743156:role/pods-s3-reader
    # currently blocked by SCP
    eksctl create podidentityassociation \
    --cluster quick-cluster \
    --namespace default \
    --service-account-name sa-buckets-man \
    --permission-policy-arns="arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
    # while we wait go into the console and look at cloudformation and the role created
    kubectl run -ti --rm buckets-test \
    --image=amazon/aws-cli \
    --overrides='{ "spec": { "serviceAccount": "sa-buckets-man" } }' \
  2. russau revised this gist Aug 2, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions demo-irsa.md
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,8 @@ eksctl create iamserviceaccount --cluster=quick-cluster \
    # let's look at the service account
    kubectl get sa dynamo-sa -o yaml
    # we see the role that was created by eks - jump into the console and look at the trust policy on the role
    # launch a container with the new service account
    kubectl run -ti --rm super-pod-man \
    --image=amazon/aws-cli \
  3. russau revised this gist Aug 1, 2024. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions demo-podid.md
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,17 @@
    ```
    kubectl create serviceaccount sa-buckets-man
    aws eks create-pod-identity-association \
    --cluster-name quick-cluster \
    --namespace default \
    --service-account sa-buckets-man \
    --role-arn arn:aws:iam::414514743156:role/pods-s3-reader
    # aws eks create-pod-identity-association \
    # --cluster-name quick-cluster \
    # --namespace default \
    # --service-account sa-buckets-man \
    # --role-arn arn:aws:iam::414514743156:role/pods-s3-reader
    eksctl create podidentityassociation \
    --cluster quick-cluster \
    --namespace default \
    --service-account-name sa-buckets-man \
    --permission-policy-arns="arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
    kubectl run -ti --rm buckets-test \
    --image=amazon/aws-cli \
  4. russau revised this gist Aug 1, 2024. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions demo-irsa.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,18 @@
    # My pod wants to access AWS resources - irsa

    ```
    # set up trust between IAM and the EKS cluster OIDC provider
    eksctl utils associate-iam-oidc-provider --cluster=quick-cluster --approve
    # create a role and service account with dynamo db access
    eksctl create iamserviceaccount --cluster=quick-cluster \
    --name=dynamo-sa --namespace=default \
    --attach-policy-arn=arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess --approve
    # let's look at the service account
    kubectl get sa dynamo-sa -o yaml
    # launch a container with the new service account
    kubectl run -ti --rm super-pod-man \
    --image=amazon/aws-cli \
    --overrides='{ "spec": { "serviceAccount": "dynamo-sa" } }' \
  5. russau revised this gist Aug 1, 2024. 2 changed files with 20 additions and 1 deletion.
    19 changes: 19 additions & 0 deletions demo-irsa.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # My pod wants to access AWS resources - irsa

    ```
    kubectl run -ti --rm super-pod-man \
    --image=amazon/aws-cli \
    --overrides='{ "spec": { "serviceAccount": "dynamo-sa" } }' \
    --command bash
    # from inside the container
    aws dynamodb list-tables
    ```

    Where does IRSA get its credentials from

    ```
    aws sts assume-role-with-web-identity --role-arn $AWS_ROLE_ARN --web-identity-token $(cat $AWS_WEB_IDENTITY_TOKEN_FILE) --role-session-name session1
    ```
    2 changes: 1 addition & 1 deletion demo-podid.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # My pod wants to access AWS resources - pod-identity assoc, and IRSA
    # My pod wants to access AWS resources - pod-identity assoc


    ## Pod identity association
  6. russau renamed this gist Aug 1, 2024. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion demo-podid-irsa.md → demo-podid.md
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,13 @@ kubectl run -ti --rm buckets-test \
    --overrides='{ "spec": { "serviceAccount": "sa-buckets-man" } }' \
    --command bash
    ```
    # from inside the pod container
    aws s3api list-buckets
    ```

    Where does pod identities get its credentials from

    ```
    curl -H "Authorization: $(cat $AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE)" http://169.254.170.23/v1/credentials
    ```
  7. russau renamed this gist Aug 1, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. russau created this gist Aug 1, 2024.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # My pod wants to access AWS resources - pod-identity assoc, and IRSA


    ## Pod identity association

    ```
    kubectl create serviceaccount sa-buckets-man

    aws eks create-pod-identity-association \
    --cluster-name quick-cluster \
    --namespace default \
    --service-account sa-buckets-man \
    --role-arn arn:aws:iam::414514743156:role/pods-s3-reader

    kubectl run -ti --rm buckets-test \
    --image=amazon/aws-cli \
    --overrides='{ "spec": { "serviceAccount": "sa-buckets-man" } }' \
    --command bash

    ```