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

support non-standard DHCP Option 15 in EC2 #3416

Merged

Conversation

bcressey
Copy link
Contributor

@bcressey bcressey commented Sep 5, 2023

Issue number:

Fixes #3412

Description of changes:
EC2 VPCs have an associated DHCP option set which can include a field for domain name. This data is passed to instances via DHCP Option 15 in the lease.

For Linux distros not using systemd-networkd, such as older versions of Amazon Linux and older variants of Bottlerocket, the data from the option is written into /etc/resolv.conf as the "search" field, with essentially no validation or normalization. Separating domain names with a space character in the VPC's DHCP option set "just works" and causes host lookups to use all of the domains in the DNS search path.

However, systemd-networkd normalizes the Option 15 payload, replacing the space character with "032". While this results in a valid domain name, it doesn't match any of the ones that are present in the VPC's DHCP option set, and breaks this accidentally useful but non-standard functionality.

Ideally, any EC2 VPC DHCP option sets relying on this behavior would be modified to set only one domain name. Unfortunately, DHCP option sets are a VPC-wide setting, so the change can't be restricted to a subset of instances without creating a new VPC for those instances.

Alternatively, EC2 could detect when space-separated domain names are present in the DHCP option set, then use DHCP Option 15 for the first domain name and DHCP Option 119 for the full list.

In the meantime, carry a patch to cause systemd-networkd to do that instead: treat Option 15 as a potentially space-separated list of domain names; use the first such domain as the domain name; and use the full list for search domains unless Option 119 is provided.

Testing done:
No domain name in option set:

# /run/systemd/netif/leases/2
<no DOMAINNAME>
<no DOMAIN_SEARCH_LIST>

#/etc/resolv.conf
...
search .

One domain name in option set:

# /run/systemd/netif/leases/2
DOMAINNAME=us-west-2.compute.internal
<no DOMAIN_SEARCH_LIST>

# /etc/resolv.conf
search us-west-2.compute.internal

Two domain names in option set:

# /run/systemd/netif/leases/2
DOMAINNAME=us-west-2.compute.internal
DOMAIN_SEARCH_LIST=us-west-2.compute.internal cressey.org

# /etc/resolv.conf
search us-west-2.compute.internal cressey.org

253 characters' worth of domain names in option set:

# /run/systemd/netif/leases/2
DOMAINNAME=so-many.kubernetes-instances.dev.pets2.ec2.vpc.ben.cressey.org
DOMAIN_SEARCH_LIST=so-many.kubernetes-instances.dev.pets2.ec2.vpc.ben.cressey.org kubernetes-instances.dev.pets2.ec2.vpc.ben.cressey.org dev.pets2.ec2.vpc.ben.cressey.org pets2.ec2.vpc.ben.cressey.org ec2.vpc.ben.cressey.org vpc.ben.cressey.org ben.cressey.org cressey.org

# /etc/resolv.conf
...
search so-many.kubernetes-instances.dev.pets2.ec2.vpc.ben.cressey.org kubernetes-instances.dev.pets2.ec2.vpc.ben.cressey.org dev.pets2.ec2.vpc.ben.cressey.org pets2.ec2.vpc.ben.cressey.org ec2.vpc.ben.cressey.org vpc.ben.cressey.org ben.cressey.org cressey.org

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

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

At the very edge of my understanding of C but it makes sense. Nice work!

Copy link
Contributor

@yeazelm yeazelm left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Member

@markusboehme markusboehme left a comment

Choose a reason for hiding this comment

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

This looks like a clean way to deal with the ambiguity resulting from multiple domains being specified. ✔️

EC2 VPCs have an associated DHCP option set which can include a field
for domain name. This data is passed to instances via DHCP Option 15
in the lease.

For Linux distros not using systemd-networkd, such as older versions
of Amazon Linux and older variants of Bottlerocket, the data from the
option is written into `/etc/resolv.conf` as the "search" field, with
essentially no validation or normalization. Separating domain names
with a space character in the VPC's DHCP option set "just works" and
causes host lookups to use all of the domains in the DNS search path.

However, systemd-networkd normalizes the Option 15 payload, replacing
the space character with "032". While this results in a valid domain
name, it doesn't match any of the ones that are present in the VPC's
DHCP option set, and breaks this accidentally useful but non-standard
functionality.

Ideally, any EC2 VPC DHCP option sets relying on this behavior would
be modified to set only one domain name. Unfortunately, DHCP option
sets are a VPC-wide setting, so the change can't be restricted to a
subset of instances without creating a new VPC for those instances.

Alternatively, EC2 could detect when space-separated domain names are
present in the DHCP option set, then use DHCP Option 15 for the first
domain name and DHCP Option 119 for the full list.

In the meantime, carry a patch to cause systemd-networkd to do that
instead: treat Option 15 as a potentially space-separated list of
domain names; use the first such domain as the domain name; and use
the full list for search domains unless Option 119 is provided.

Signed-off-by: Ben Cressey <[email protected]>
@markusboehme
Copy link
Member

Still looking good!

@bcressey bcressey merged commit 8812c57 into bottlerocket-os:develop Sep 6, 2023
48 checks passed
@bcressey bcressey deleted the resolved-to-parse-domains branch September 6, 2023 23:46
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.

AWS DHCP Option set domain names separated by 032 when using systemd-networkd
4 participants