Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update amazon session.New to support web identity token from service account in K8s #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Lowess
Copy link

@Lowess Lowess commented Apr 19, 2023

Hi Everyone !

While trying to get the drone autoscaler running on Amazon EKS Kubernetes cluster I encountered an issue with the way the AWS SDK handles the session when using an IAM role.

The drone autoscaler deployment is assigned a ServiceAccount to grant the service access to an IAM role (IRSA / OIDC IAM role dedicated to the pod) as stated in this documentation https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html

While digging into AWS SDK issues I found this relevant issue that makes a mention of using session.NewSession instead of session.New which does not handle well web identity token files aws/aws-sdk-go#4436

I made a local build of the project and took it for a spin and it works like charm now. The Drone autoscaler service is able to assume the ServiceAccount IAM role instead of the IAM role assigned to the EC2 machine.

  • Here are the relevant Drone autoscaler env vars I am using:
AWS_IAM: true
DRONE_AMAZON_IAM_PROFILE_ARN: arn:aws:iam::123456789101:instance-profile/drone-autoscaler
  • The Service Account object looks like this
apiVersion: v1
kind: ServiceAccount
metadata:
  annotations:
    eks.amazonaws.com/role-arn: arn:aws:iam::123456789101:role/drone-autoscaler
    meta.helm.sh/release-name: drone-autoscaler--production
    meta.helm.sh/release-namespace: cicd
  creationTimestamp: "2023-04-18T09:55:18Z"
  labels:
    release: drone-autoscaler--production
  name: drone-autoscaler--production-monochart-default
  namespace: cicd
secrets:
- name: drone-autoscaler--production-monochart-default-token-fzgrm
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Federated": "arn:aws:iam::123456789101:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/<OIDC_ID>"
            },
            "Action": "sts:AssumeRoleWithWebIdentity",
            "Condition": {
                "StringLike": {
                    "oidc.eks.us-east-1.amazonaws.com/id/<OIDC_ID>": "system:serviceaccount:cicd:drone-autoscaler--production-monochart-default"
                }
            }
        }
    ]
}

@Lowess
Copy link
Author

Lowess commented May 11, 2023

@julienduchesne do you mind checking if this sounds legitimate ? That would be great if this could go through a future release.

Thanks !

@julienduchesne
Copy link
Contributor

@julienduchesne do you mind checking if this sounds legitimate ? That would be great if this could go through a future release.

Thanks !

I’m not a Drone maintainer, just a random guy launching agents in AWS from a k8s cluster in GCP. So about auth, I have no idea

@Lowess
Copy link
Author

Lowess commented Jul 9, 2024

@vistaarjuneja any changes you could review this PR and get it merged ? I saw you recently merged changes related to the Amazon provider.

Many thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants