fix(dns): validate nameserver addresses are valid IP addresses#534
Open
cluster2600 wants to merge 1 commit intoapple:mainfrom
Open
fix(dns): validate nameserver addresses are valid IP addresses#534cluster2600 wants to merge 1 commit intoapple:mainfrom
cluster2600 wants to merge 1 commit intoapple:mainfrom
Conversation
Resolves apple#467. Previously, any arbitrary string could be passed as a nameserver in DNS configuration, which would silently result in an invalid /etc/resolv.conf inside the container. This change adds a DNS.validate() method that ensures every nameserver string is a valid IPv4 or IPv6 address (using the existing ContainerizationExtras parsers). The method is called from Vminitd.configureDNS() before applying the configuration. Tests added to DNSTests.swift covering valid IPv4, IPv6, mixed, empty nameserver lists, and invalid hostname/address rejection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add a
DNS.validate()method that verifies all nameserver entries are valid IPv4 or IPv6 addresses. The method is called fromVminitd.configureDNS()before applying the configuration.Why
Closes #467. Currently, any arbitrary string can be passed as a nameserver in
DNSConfiguration, which silently results in an invalid/etc/resolv.confinside the container. Hostname strings likedns.example.comwould be written to resolv.conf but would not work as nameservers.How
DNS.validate() throwsmethod inDNSConfiguration.swiftthat iterates over all nameservers and attempts to parse each as either anIPv4AddressorIPv6Address(using the existing parsers inContainerizationExtras)import ContainerizationExtrastoDNSConfiguration.swift(theContainerizationtarget already depends onContainerizationExtras)config.validate()at the start ofVminitd.configureDNS()so validation happens before any GRPC callTesting
Added 6 new unit tests in
DNSTests.swift:Checklist