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

[libbeat][aws] Fix AWS config initialization issue when using a role #31014

Merged
merged 4 commits into from
Apr 6, 2022

Conversation

zmoog
Copy link
Contributor

@zmoog zmoog commented Mar 28, 2022

What does this PR do?

Set up the AssumeRoleProvider after the AWS region value from Filebeat settings is applied to the AWS SDK configuration.

Why is it important?

When Filebeat uses a role ARN, it sets up AssumeRoleProvider before evaluating the region value from its settings.

If the AWS SDK configuration loaded from ~/.aws/config does not contain a region, the error described in #30999 happens.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • [ ]

How to test this PR locally

Requirements:

  • A SQS queue (in this example, https://sqs.eu-west-1.amazonaws.com/000123456789/elastic-cloudtrail-logs),
  • an IAM role ARN (in this example, arn:aws:iam::000123456789:role/elastic-agent-role)

Configure the IAM Role as EC2 instance role with the following trust relationship:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

Also add some permission to the role to access SQS and S3 ("Amazon SQS Full Access" and "SQS Read only Access" are probably fine for a quick test).

Here's an example command line arguments for Filebeat:

-e
-v
-d
*
--strict.perms=false
--path.home
/Users/zmoog/code/projects/zmoog/beats/x-pack/filebeat
-E
cloud.id=<CLOUD_ID>
-E
cloud.api_key=<CLOUD_API_KEY>
-E
gc_percent=100
-E
setup.ilm.enabled=false
-E
setup.template.enabled=false
--modules
aws
-M
aws.s3access.enabled=true
-M
aws.s3access.input.default_region=eu-west-1
-M
aws.s3access.input.queue_url=https://sqs.eu-west-1.amazonaws.com/000123456789/elastic-cloudtrail-logs
-M
aws.s3access.input.role_arn=arn:aws:iam::000123456789:role/elastic-agent-role

Related issues

Use cases

Screenshots

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 28, 2022
@mergify
Copy link
Contributor

mergify bot commented Mar 28, 2022

This pull request does not have a backport label. Could you fix it @zmoog? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 7./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@mergify mergify bot assigned zmoog Mar 28, 2022
@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Mar 28, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 28, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-04-05T21:40:25.357+0000

  • Duration: 109 min 29 sec

Test stats 🧪

Test Results
Failed 0
Passed 8270
Skipped 532
Total 8802

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@zmoog zmoog changed the title Move assume role to AWS config initialisation [Filebeat] Fix AWS config initialization issue when using a role Mar 28, 2022
@zmoog zmoog added the bug label Mar 28, 2022
@zmoog zmoog changed the title [Filebeat] Fix AWS config initialization issue when using a role [libbeat][aws] Fix AWS config initialization issue when using a role Mar 28, 2022
@zmoog zmoog force-pushed the zmoog/fix-aws-region-on-assume-role branch from a722785 to 4151a26 Compare March 28, 2022 14:13
@kaiyan-sheng kaiyan-sheng added the Team:Cloud-Monitoring Label for the Cloud Monitoring team label Mar 28, 2022
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 28, 2022
@kaiyan-sheng kaiyan-sheng added backport-v8.1.0 Automated backport with mergify backport-7.17 Automated backport to the 7.17 branch with mergify and removed backport-skip Skip notification from the automated backport with mergify labels Mar 28, 2022
@zmoog zmoog requested a review from kaiyan-sheng March 28, 2022 15:29
@zmoog zmoog marked this pull request as ready for review March 28, 2022 15:29
@zmoog zmoog requested review from aspacca and endorama March 28, 2022 15:29
@kaiyan-sheng kaiyan-sheng added the backport-v8.2.0 Automated backport with mergify label Mar 30, 2022
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Could you add a changelog to it please? Thanks!

@zmoog zmoog force-pushed the zmoog/fix-aws-region-on-assume-role branch from 4151a26 to 706861b Compare March 31, 2022 10:46
@zmoog zmoog requested a review from a team as a code owner March 31, 2022 10:46
@zmoog
Copy link
Contributor Author

zmoog commented Mar 31, 2022

Looks good to me! Could you add a changelog to it please? Thanks!

Oh! 🤦

Thanks for the heads up! 🙇

@zmoog
Copy link
Contributor Author

zmoog commented Mar 31, 2022

@kaiyan-sheng could you please double check the CHANGELOG entry is in the right place for this issue?

Copy link
Contributor

@kaiyan-sheng kaiyan-sheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog entry looks good to me! Thanks!

@zmoog zmoog force-pushed the zmoog/fix-aws-region-on-assume-role branch 2 times, most recently from 95d457b to f0ea446 Compare April 5, 2022 14:23
@mergify
Copy link
Contributor

mergify bot commented Apr 5, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b zmoog/fix-aws-region-on-assume-role upstream/zmoog/fix-aws-region-on-assume-role
git merge upstream/main
git push upstream zmoog/fix-aws-region-on-assume-role

@zmoog zmoog force-pushed the zmoog/fix-aws-region-on-assume-role branch from f0ea446 to 2919fec Compare April 5, 2022 21:40
@zmoog zmoog merged commit cb5a951 into elastic:main Apr 6, 2022
@zmoog zmoog deleted the zmoog/fix-aws-region-on-assume-role branch April 6, 2022 10:09
mergify bot pushed a commit that referenced this pull request Apr 6, 2022
…31014)

* Move assume role to AWS config initialisation

* Wrap default aws config errors using std library

(cherry picked from commit cb5a951)

# Conflicts:
#	x-pack/libbeat/common/aws/credentials.go
mergify bot pushed a commit that referenced this pull request Apr 6, 2022
…31014)

* Move assume role to AWS config initialisation

* Wrap default aws config errors using std library

(cherry picked from commit cb5a951)
mergify bot pushed a commit that referenced this pull request Apr 6, 2022
…31014)

* Move assume role to AWS config initialisation

* Wrap default aws config errors using std library

(cherry picked from commit cb5a951)
rdner added a commit that referenced this pull request Apr 7, 2022
…issue when using a role (#31181)

[libbeat][aws] Fix AWS config initialization issue when using a role (#31014)

* Move assume role to AWS config initialisation

* Wrap default aws config errors using std library

(cherry picked from commit cb5a951)

Co-authored-by: Maurizio Branca <maurizio.branca@gmail.com>
Co-authored-by: Denis Rechkunov <denis.rechkunov@elastic.co>
rdner pushed a commit that referenced this pull request Apr 7, 2022
…31014) (#31183)

* Move assume role to AWS config initialisation

* Wrap default aws config errors using std library

(cherry picked from commit cb5a951)

Co-authored-by: Maurizio Branca <maurizio.branca@elastic.co>
zmoog added a commit that referenced this pull request Apr 7, 2022
…31014) (#31182)

* Move assume role to AWS config initialisation

* Wrap default aws config errors using std library

(cherry picked from commit cb5a951)

Co-authored-by: Maurizio Branca <maurizio.branca@elastic.co>
Co-authored-by: Denis Rechkunov <denis.rechkunov@elastic.co>
kush-elastic pushed a commit to kush-elastic/beats that referenced this pull request May 2, 2022
…lastic#31014)

* Move assume role to AWS config initialisation

* Wrap default aws config errors using std library
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
…31014)

* Move assume role to AWS config initialisation

* Wrap default aws config errors using std library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-7.17 Automated backport to the 7.17 branch with mergify backport-v8.1.0 Automated backport with mergify backport-v8.2.0 Automated backport with mergify bug Team:Cloud-Monitoring Label for the Cloud Monitoring team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Filebeat] sqs ReceiveMessage failed: unknown endpoint, could not resolve endpoint
4 participants