Skip to content

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

Open

Description

@krayzie32

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions