mirror of
https://github.com/apple/container.git
synced 2026-10-14 01:59:18 +00:00
## What Add a `DNS.validate()` method that verifies all nameserver entries are valid IPv4 or IPv6 addresses. The method is called from `Vminitd.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.conf` inside the container. Hostname strings like `dns.example.com` would be written to resolv.conf but would not work as nameservers. ## How - Added `DNS.validate() throws` method in `DNSConfiguration.swift` that iterates over all nameservers and attempts to parse each as either an `IPv4Address` or `IPv6Address` (using the existing parsers in `ContainerizationExtras`) - Added `import ContainerizationExtras` to `DNSConfiguration.swift` (the `Containerization` target already depends on `ContainerizationExtras`) - Called `config.validate()` at the start of `Vminitd.configureDNS()` so validation happens before any GRPC call ## Testing Added 6 new unit tests in `DNSTests.swift`: - ✅ Valid IPv4 nameservers accepted - ✅ Valid IPv6 nameservers accepted - ✅ Mixed IPv4/IPv6 nameservers accepted - ✅ Empty nameserver list accepted - ❌ Hostname rejected - ❌ Invalid address rejected ## Checklist - [x] Tests added - [x] No breaking changes to existing API (validate() is a new method, existing init is unchanged) - [x] Follows existing patterns (uses ContainerizationExtras IP address types, ContainerizationError for errors) Signed-off-by: Maxime Grenu <maxime.grenu@gmail.com>