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

Metadata tags with spaces cause ohai ec2 to return an empty response #1763

Open
krayzie32 opened this issue Aug 9, 2022 · 0 comments
Open

Comments

@krayzie32
Copy link

krayzie32 commented Aug 9, 2022

Describe the problem

EC2 tags, that have a space, cause ohai ec2 to return empty data during its run. We are currently using SSM to patch our EC2 instances and we are required (by AWS) to use the tag 'Patch Group' to utilize the SSM patching process. Due to this, ohai ec2 returns empty data on instances with this tag. The issue is that the metadata_get method is not creating the path (used in http_client.get) with %20 for tags with spaces.

Example: The tag 'Patch Group' will have a path of /2021-07-15/meta-data/tags/instance/Patch Group and that will create an invalid URL. A path of /2021-07-15/meta-data/tags/instance/Patch%20Group is valid and will return data.

Software Version

ohai 17.9.0 on Windows 2016/2019 hosts and soon centos hosts.

Replication Case

  1. Find/create an EC2 Windows instance to test with
  2. Disable 'Allow tags in instance metadata'
  3. Add 'Patch Group' as a tag and enter any value
  4. RDP to the host and open an elevated cmd prompt and execute ohai ec2
  5. The output of the command will be empty

Possible Solution

The way I found to fix this issue was to update the ec2_metadata.rb metadata_get method by adding id = id.gsub(" ", "%20") right after the line def metadata_get(id, api_version). I am sure there is a better way of performing this fix, but this was a quick fix for me. Let me know if you need any additional information. Thank you

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

No branches or pull requests

1 participant