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] fix: aws & openstack metadata conflict in add_cloud_metadata processor #41636

Conversation

Kavindu-Dodan
Copy link
Contributor

@Kavindu-Dodan Kavindu-Dodan commented Nov 13, 2024

Proposed commit message

This PR fixes incorrect recognition of EC2/AWS cloud provider as Openstack. The root cause was the common metadata endpoints used by both AWS SDK & Openstack logic. And this happened when IMDSv2 is disabled in AWS.

I attempted to migrate Openstack logic to another metadata implementation. However, I did not manage to create a fully functioning setup to validate the implementation. Hence, this PR focuses on a priority-based solution where priority is given for SDK-backed metadata fetching over HTTP endpoints.

Current priory providers are - aws/ec2 & azure

Note - I have done a minor refactoring to rename Local struct property to DefaultEnabled to make intention clearer

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.

How to test this PR locally

You need a local copy and an EC2 instance to validate the fix.

  • Enable metadata service in EC2 instance and make IMDSv2 optional
  • Build a beats (ex:- metricbeat) module based on this libbeat change
  • Copy the beats module to EC2 instance and start the module with add_cloud_metadata processor enabled & logs set to debug for more in-depth logs & no provider enforced
  • Observe logs and see data (ex:- system monitoring) through Kibana to validate cloud provider detection

Related issues

Screenshots

-IMDSv2 disabled

Screenshot 2024-11-13 at 11 45 38 AM

  • Processor enabled but no provider enforced

Screenshot 2024-11-13 at 11 50 24 AM

  • Debug logs on multi-result and priority based selection

Screenshot 2024-11-13 at 11 44 47 AM

  • Cloud provider detected correctly,

Screenshot 2024-11-13 at 11 45 13 AM

@Kavindu-Dodan Kavindu-Dodan added bug backport-8.x Automated backport to the 8.x branch with mergify backport-8.16 Automated backport with mergify labels Nov 13, 2024
@Kavindu-Dodan Kavindu-Dodan requested review from zmoog, kaiyan-sheng and a team November 13, 2024 19:52
@Kavindu-Dodan Kavindu-Dodan requested a review from a team as a code owner November 13, 2024 19:52
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 13, 2024
@Kavindu-Dodan Kavindu-Dodan added the Team:obs-ds-hosted-services Label for the Observability Hosted Services team label Nov 13, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 13, 2024
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.

Thanks for working on this issue! Can we document this new logic around priorityProviders in the doc please?

@Kavindu-Dodan Kavindu-Dodan requested a review from a team as a code owner November 14, 2024 17:51
@Kavindu-Dodan Kavindu-Dodan force-pushed the fix/fix-aws-openstack-metadata-conflict branch from adcdc7d to cbb6a96 Compare November 14, 2024 17:52
@Kavindu-Dodan
Copy link
Contributor Author

Thanks for working on this issue! Can we document this new logic around priorityProviders in the doc please?

Thank you, I added documentation :)

@axw
Copy link
Member

axw commented Nov 18, 2024

@Kavindu-Dodan with this change could we end up having the opposite problem, where OpenStack is misidentified as AWS?

@Kavindu-Dodan
Copy link
Contributor Author

@Kavindu-Dodan with this change could we end up having the opposite problem, where OpenStack is misidentified as AWS?

This shouldn't happen as priority is given for cloud provider SDK based metadata fetchers (AWS & Azure 1), where they should fail if configurations are not set (ex:- AWS credential profile/env vars).

Footnotes

  1. https://github.com/elastic/beats/pull/41636/files#diff-54e31882d706ede511023836a842dd7c1e570ce1eab2c7208601afacee49a995R76-R79

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
@Kavindu-Dodan Kavindu-Dodan force-pushed the fix/fix-aws-openstack-metadata-conflict branch from 5b6ab95 to f416516 Compare November 19, 2024 15:22
@elastic elastic deleted a comment from mergify bot Nov 19, 2024
Signed-off-by: Kavindu Dodanduwa <[email protected]>
Signed-off-by: Kavindu Dodanduwa <[email protected]>

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go
Signed-off-by: Kavindu Dodanduwa <[email protected]>
Signed-off-by: Kavindu Dodanduwa <[email protected]>
@Kavindu-Dodan Kavindu-Dodan force-pushed the fix/fix-aws-openstack-metadata-conflict branch from f416516 to 69c70b2 Compare November 22, 2024 16:16
@Kavindu-Dodan Kavindu-Dodan merged commit 6d4e641 into elastic:main Nov 27, 2024
142 checks passed
mergify bot pushed a commit that referenced this pull request Nov 27, 2024
…a processor (#41636)

* rename misleading variable

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <[email protected]>

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* documentation

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* review changes

Signed-off-by: Kavindu Dodanduwa <[email protected]>

---------

Signed-off-by: Kavindu Dodanduwa <[email protected]>
(cherry picked from commit 6d4e641)

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go
mergify bot pushed a commit that referenced this pull request Nov 27, 2024
…a processor (#41636)

* rename misleading variable

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <[email protected]>

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* documentation

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* review changes

Signed-off-by: Kavindu Dodanduwa <[email protected]>

---------

Signed-off-by: Kavindu Dodanduwa <[email protected]>
(cherry picked from commit 6d4e641)
Kavindu-Dodan added a commit that referenced this pull request Nov 27, 2024
…a processor (#41636)

* rename misleading variable

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <[email protected]>

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* documentation

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* review changes

Signed-off-by: Kavindu Dodanduwa <[email protected]>

---------

Signed-off-by: Kavindu Dodanduwa <[email protected]>
(cherry picked from commit 6d4e641)

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go
Kavindu-Dodan added a commit that referenced this pull request Nov 27, 2024
…a processor (#41636) (#41815)

* rename misleading variable

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <[email protected]>

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* documentation

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* review changes

Signed-off-by: Kavindu Dodanduwa <[email protected]>

---------

Signed-off-by: Kavindu Dodanduwa <[email protected]>
(cherry picked from commit 6d4e641)

Co-authored-by: Kavindu Dodanduwa <[email protected]>
Kavindu-Dodan added a commit that referenced this pull request Nov 27, 2024
…a processor (#41636) (#41814)

* rename misleading variable

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <[email protected]>

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* documentation

Signed-off-by: Kavindu Dodanduwa <[email protected]>

* review changes

Signed-off-by: Kavindu Dodanduwa <[email protected]>

---------

Signed-off-by: Kavindu Dodanduwa <[email protected]>
(cherry picked from commit 6d4e641)

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go

Co-authored-by: Kavindu Dodanduwa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify backport-8.16 Automated backport with mergify bug Team:obs-ds-hosted-services Label for the Observability Hosted Services team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add_cloud_metadata detecting wrong cloud provider (aws as openstack)
5 participants