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

ec2 client credential init fix for AWS IRSA #29784

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Greyeye
Copy link

@Greyeye Greyeye commented Oct 4, 2024

What does this PR do?

This PR modifies the initialisation of the AWS EC2 client to use the AWS configuration package. This change enables support for built-in credentials such as AWS IAM Roles for Service Accounts (IRSA). The current use of ec2.New() does not work with IRSA, and although not tested, a similar issue likely occurs with EKS Pod Identity as well.

When a pod is assigned an IRSA with the correct permissions to perform DescribeTags, it encounters an error and logs the following message:

(pkg/util/ec2/ec2_tags.go:104 in fetchEc2TagsFromAPI) | unable to get tags using default credentials (falling back to instance role): operation error EC2: DescribeTags, https response error StatusCode: 400, RequestID: 1234-1234-1234, api error MissingParameter: The request must contain the parameter AWSAccessKeyId

fixes issue 29916

Motivation

We are currently running the Datadog Agent pod in AWS EKS and are aiming to clean up the instance role by eliminating unnecessary permissions attached to it. Datadog is one of many services that currently use the instance role for the ec2:DescribeTags permission, and we would like to switch to using the IRSA-assigned role.

After extensive debugging and tracing, we discovered that when the pod is assigned an IRSA token but the instance is running IMDSv2, it fails to use IRSA and always falls back to using the instance role.

Describe how to test/QA your changes

  1. create a new EKS node and instance role that does not allow ec2:describeTags.
  2. create a new AWS IAM Rolewith ec2:describeTags, and attach this to datadog-agent using IRSA
  3. deploy datadog-agent with config.yaml (or using configMap) like this
    collect_ec2_tags: true
    collect_ec2_tags_use_imds: true
    ec2_prefer_imdsv2: true
  4. start the datadog-agent and verify the role gets used, and tags are collected using the IRSA role.

Possible Drawbacks / Trade-offs

none

Additional Notes

none

@Greyeye Greyeye requested a review from a team as a code owner October 4, 2024 04:28
@bits-bot
Copy link
Collaborator

bits-bot commented Oct 4, 2024

CLA assistant check
All committers have signed the CLA.

current use of ec2.New() does not work with IRSA. (not tested but most like same problem with EKS Pod Identity as well)

```
(pkg/util/ec2/ec2_tags.go:104 in fetchEc2TagsFromAPI) | unable to get tags using default credentials (falling back to instance role): operation error EC2: DescribeTags, https response error StatusCode: 400, RequestID: 1234-1234-1234, api error MissingParameter: The request must contain the parameter AWSAccessKeyId
```

This change is to change to use aws config package to help initialise aws ec2 client with the built-in credentials such as AWS IRSA tokens.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] datadog-agent pod cannot assume AWS IRSA credentials
2 participants