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

imdsclient: return a single hostname from fetch_hostname #3032

Merged
merged 1 commit into from
Apr 19, 2023

Conversation

zmrow
Copy link
Contributor

@zmrow zmrow commented Apr 18, 2023

Issue number:

Related to #3031

Description of changes:

The fetch_hostname method queries the metadata/local-hostname IMDS target, which has the potential to return multiple space-delimited hostnames. This changes the method to return only the first hostname in the list.

Testing done:
Build and booted an aws-k8s-1.24 node into a VPC setup with a DHCP option set with multiple domain names.

Confirmed IMDS returns multiple hostnames from the meta-data/local-hostname endpoint:

[ec2-user@admin]$ curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/local-hostname
ip-192-168-23-243.us-west-2.compute.internal fdjskl.com abcdefg.com

Confirmed my node has the proper hostname set in /proc/sys/kernel/hostname and in settings.network.hostname

bash-5.1# cat /proc/sys/kernel/hostname 
ip-192-168-23-243.us-west-2.compute.internal
bash-5.1# apiclient get settings.network.hostname
{
  "settings": {
    "network": {
      "hostname": "ip-192-168-23-243.us-west-2.compute.internal"
    }
  }
}

Confirm the node properly joins the cluster and has the expected name:

$ kubectl get nodes
NAME                                           STATUS   ROLES    AGE   VERSION
ip-192-168-23-243.us-west-2.compute.internal   Ready    <none>   18m   v1.24.12-eks-76dc719

Also turned on RBN in my subnet and launched another instance to validate we see the same correct behavior:

[ec2-user@admin]$ curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/local-hostname
i-009d9789c65c9a4a4.us-west-2.compute.internal fdjskl.com abcdefg.com

[ec2-user@admin]$ cat /proc/sys/kernel/hostname 
i-009d9789c65c9a4a4.us-west-2.compute.internal

[ec2-user@admin]$ apiclient get settings.network.hostname
{
  "settings": {
    "network": {
      "hostname": "i-009d9789c65c9a4a4.us-west-2.compute.internal"
    }
  }
}

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

Copy link
Contributor

@stmcginnis stmcginnis left a comment

Choose a reason for hiding this comment

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

Assuming testing goes well, this looks good to me.

I don't actually think it would be worth it, but I noticed there is a library out there that could be used to set up some unit testing for this. Just pointing out in case it is helpful in any way with manually testing things.

@zmrow zmrow marked this pull request as ready for review April 19, 2023 15:57
@zmrow
Copy link
Contributor Author

zmrow commented Apr 19, 2023

Updated the testing in the description and pulled out of draft

@zmrow
Copy link
Contributor Author

zmrow commented Apr 19, 2023

Added additional testing on a subnet with RBN enabled.

Copy link
Contributor

@arnaldo2792 arnaldo2792 left a comment

Choose a reason for hiding this comment

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

Typo in the commit, potentiall.

The `fetch_hostname` method queries the `metadata/local-hostname` IMDS
target, which has the potential to return multiple space-delimited
hostnames.  This changes the method to return only the first hostname in
the list.
@zmrow
Copy link
Contributor Author

zmrow commented Apr 19, 2023

^ Fixed the typo in the commit message. Thanks @arnaldo2792

@zmrow zmrow merged commit 142ed1b into bottlerocket-os:develop Apr 19, 2023
37 checks passed
@zmrow zmrow deleted the imds-hostname-multiple branch April 19, 2023 21:09
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

Successfully merging this pull request may close these issues.

None yet

6 participants