Skip to content

[libbeat] fix: aws & openstack metadata conflict in add_cloud_metadata processor#41636

Merged
Kavindu-Dodan merged 5 commits intoelastic:mainfrom
Kavindu-Dodan:fix/fix-aws-openstack-metadata-conflict
Nov 27, 2024
Merged

[libbeat] fix: aws & openstack metadata conflict in add_cloud_metadata processor#41636
Kavindu-Dodan merged 5 commits intoelastic:mainfrom
Kavindu-Dodan:fix/fix-aws-openstack-metadata-conflict

Conversation

@Kavindu-Dodan
Copy link
Copy Markdown
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 a team, kaiyan-sheng and zmoog 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
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@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 <kavindu.dodanduwa@elastic.co>
Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

# Conflicts:
#	libbeat/processors/add_cloud_metadata/providers.go
Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
@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
mergify bot pushed a commit that referenced this pull request Nov 27, 2024
…a processor (#41636)

* rename misleading variable

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

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

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* documentation

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review changes

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(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 <kavindu.dodanduwa@elastic.co>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

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

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* documentation

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review changes

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(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 <kavindu.dodanduwa@elastic.co>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

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

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* documentation

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review changes

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(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 <kavindu.dodanduwa@elastic.co>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

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

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* documentation

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review changes

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(cherry picked from commit 6d4e641)

Co-authored-by: Kavindu Dodanduwa <Kavindu-Dodan@users.noreply.github.com>
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 <kavindu.dodanduwa@elastic.co>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

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

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* documentation

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review changes

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(cherry picked from commit 6d4e641)

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

Co-authored-by: Kavindu Dodanduwa <Kavindu-Dodan@users.noreply.github.com>
@Kavindu-Dodan Kavindu-Dodan added the backport-8.17 Automated backport with mergify label Feb 5, 2025
mergify bot pushed a commit that referenced this pull request Feb 5, 2025
…a processor (#41636)

* rename misleading variable

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

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

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* documentation

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review changes

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(cherry picked from commit 6d4e641)
Kavindu-Dodan added a commit that referenced this pull request Feb 5, 2025
…a processor (#41636) (#42606)

* rename misleading variable

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* introduce provider priority

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

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

* isolate priority logic and add testing

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* documentation

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review changes

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(cherry picked from commit 6d4e641)

Co-authored-by: Kavindu Dodanduwa <Kavindu-Dodan@users.noreply.github.com>
@khushijain21 khushijain21 mentioned this pull request Jun 23, 2025
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 backport-8.17 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