Repository navigation
Add DNS aliases and subtree aliases for container network attachments - #2390
Merged
Merged
Conversation
Container IDs may contain uppercase letters, so a container named `Foo` is attached with the hostname `Foo.test.`. The DNS decoder lowercases query names, so the helper's exact-match lookup never found such a container, and the create-time conflict check treated `Foo` and `foo` as different containers. Add AttachmentOptions.canonicalHostname (lowercase, no trailing dot) and use it in AttachmentAllocator and the ContainersService hostname conflict check.
A rule is either an exact name (`api.example.test`) or a subtree (`.example.test`) that matches every name below its base, at one or more labels, but not the base itself. Matching is by label, so `evilexample.test` is not below `example.test`. The string form is the normalized, persisted form of an alias. A value containing `*` is rejected with a message that points to the leading-dot form.
Aliases are additional DNS names that resolve to a network attachment. Each value is the normalized string form of a DNSMatchRule. The field is optional and defaults to nil, so existing persisted configurations and XPC messages decode unchanged, and configurations without aliases encode without the key.
Move the hostname conflict check in ContainersService.create into AttachmentNameValidator, which also checks the aliases that a container declares on its network attachments. Exact names must be unique across all containers, so a hostname cannot match an existing alias and an alias cannot match an existing hostname or alias. A subtree alias must have a base of at least two labels, and the base must be the hostname or an exact alias of the same attachment, so a container cannot claim the namespace below another container's name. An attachment may declare at most 32 aliases.
allocate now takes the aliases of an attachment and registers them next to the hostname, and deallocate removes them with it. A new match(name:) resolves a name to the attachment it belongs to and reports how it matched: a hostname wins over an exact alias, and an exact alias wins over a subtree alias, where the longest base wins. An alias that is already in use on the network, as a hostname or as an alias of another host, is rejected before any state changes. The ContainerNetworkServer target now depends on DNSServer.
The allocate request carries the aliases of an attachment, and a helper acknowledges them by echoing them in its reply. NetworkClient.allocate fails with an unsupported error that names the plugin when aliases were requested and the reply does not acknowledge them, which is what a helper that predates aliases produces. The lookup reply reports whether the name matched a hostname, an exact alias, or a subtree alias with a base of a given number of labels. A reply without a kind is a hostname match, so existing helpers keep working. NetworkService gains an allocate overload that takes aliases and a match method, both with default implementations, so helpers that implement only the existing methods still compile. DefaultNetworkService registers the aliases with its AttachmentAllocator and answers match from it.
NetworksService.lookup used to return the first network that knew the name, which is only correct while names are unique. With aliases, a network can report a subtree alias while another has a hostname, an exact alias, or a subtree with a longer base. A hostname or an exact alias ends the search, because both are unique across all networks. Otherwise every network is asked and the subtree with the most labels in its base wins.
The runtime service allocates each network attachment of a container when it bootstraps. Include the aliases of the attachment in the request, so the helper resolves them for as long as the container's session is open. A failure on any network closes all sessions opened so far, which releases their allocations.
`--network default,alias=api.example.test,alias=.example.test` declares additional DNS names for the container's attachment to a network. A name with a leading dot matches every name below it. The property can be repeated, and each value is validated and normalized as a DNSMatchRule. The aliases are stored on the attachment they are declared for.
The tests start containers with exact and subtree aliases and query the container DNS server directly with dig, so they do not depend on any resolver file. They check that aliases resolve and stop resolving when the container stops, that matching is by label and ignores case, that conflicting and invalid aliases are rejected, and that a name with no IPv6 address answers NODATA.
A name with a single label is not under any domain, so the system resolver never sends queries for it to the container DNS server, and an alias like that would be accepted and never resolve. The API server now rejects an exact alias, and the base of a subtree alias, that has fewer than two labels. Mirroring how `--name foo` becomes `foo.test.` when the default domain is `test`, the CLI adds the default domain to an alias that has no dot, so `alias=api` is stored as `api.test` and `alias=.gateway` as `.gateway.test`. A name with a dot is used as written, and without a default domain the names are left alone and the server's check applies.
Add a section to the networking guide on giving a container additional DNS names with the alias property of --network, including the rules for aliases and the default domain, and show the property in the command reference. Add a document describing the DNS architecture: the components, the names of a container, how a query is answered, the invariants that the implementation relies on, the security considerations and the known limitations.
NetworksService.lookup held the networks state lock while it called the network helpers. Network create and delete hold the same lock for as long as a helper takes to start or stop, so a DNS answer could be delayed by more than two seconds while another network was being deleted. Read the helper clients without the lock and call them outside of it. A network whose helper is starting up, shutting down or has failed cannot answer, so it is skipped and the failure is logged, and it no longer fails the answers of the other networks.
The alias tests run alongside suites that create and delete networks, so a DNS answer can be late. Ask again when a query gets no answer, and wait up to five seconds for each query, before comparing the result.
Simplify the network helper API. The helper and its client always ship together, so lookup now returns the match directly instead of adding a second method next to it. NetworkService.lookup(name:) and NetworkClient.lookup(name:) return a NetworkMatch, which holds the attachment and how the name matched, and the lookup request uses a `name` key. NetworkService has a single allocate that takes the aliases. Remove the compatibility behavior for helpers that predate aliases: a helper no longer acknowledges the aliases it registers, the client no longer checks for the acknowledgement, and a lookup reply must carry the match kind. Make AttachmentOptions.aliases a plain list instead of an optional one. A configuration stored without the key still decodes as no aliases, and a configuration without aliases is stored without the key.
Move the per-attachment alias rules into AliasPolicy and apply them in the API server at create and at bootstrap of a stored container, and in the network helper's allocate, so none of them takes the aliases on faith.
jglogan
marked this pull request as ready for review
October 13, 2026 23:55
Code Coverage
|
katiewasnothere
approved these changes
Oct 14, 2026
3 of 7 tasks
This was referenced Oct 20, 2026
6 tasks done
benoitf
pushed a commit
to socktainer/socktainer
that referenced
this pull request
Oct 20, 2026
) * deps: bump apple/container to 1.6.0 and containerization to 0.52.1 apple/container 1.6.0 pins containerization 0.52.1. The one source change it needs is in ExtraHostsFile: NetworkClient.lookup(hostname:) is now lookup(name:), and it returns a NetworkMatch wrapping the Attachment, since a name can now also match an attachment's DNS alias (apple/container#2390). That lookup's XPC message changed with it: a 1.6.0 network plugin reads only the new `name` key and a 1.5.0 one reads only `hostname`. A socktainer built against one version cannot look up attachments on the other, so socktainer and Apple Container have to move together. The release also brings, with no change here: - A fix to BuildFSSync.read()/info(), which checked a context path and then opened it again, so a symlink swapped in between could escape the build context (apple/container#2415). Symlinks with absolute targets are now rejected on that fallback path. - container-builder-shim 0.13.2 as the default builder image. - Sparse OCI images load on import (apple/containerization#961). Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Wes Morgan <[email protected]> * refactor(builder): start BuildKit with apple/container's Builder.start apple/container 1.6.0 moved the builder bootstrap that `container build` uses out of the CLI and into the ContainerBuild library as Builder.start (apple/container#2370). ClientBuilderService had its own copy, which has drifted from upstream before: #260 was the copy missing upstream's capAdd = ["ALL"]. Hand the non-running cases to Builder.start instead. It creates the "buildkit" container, restarts a stopped one, and recreates one whose image, CPUs, memory or DNS no longer match the system configuration. That last part is new for socktainer, which never replaced an existing builder before. A builder created before an upgrade now moves to the new default image the next time it has to be started. A builder that is already running is still used as it is, so a build in progress is never interrupted. Behavior differences from the old copy: - CPUs and memory come from the [build] section of the system configuration (default 2 CPUs and 2048MB, the values that were hard-coded here), so socktainer and `container build` agree on the shared builder instead of each recreating it to its own settings. - The nameserver is no longer set explicitly. The runtime fills in the network's gateway when none is given, the same address socktainer computed. - A builder in an unknown state is bootstrapped again instead of being deleted first. If that fails, Builder.start deletes it and the next request creates a new one. Builder.start fetches the image over HTTPS only, so socktainer still fetches it first with the scheme it picks for the reference. A builder image on a local insecure registry keeps working, and Builder.start finds it already in the store. The builderContainerConfiguration tests go with the code they covered. Those settings are now upstream's. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Wes Morgan <[email protected]> * fix(builder): don't fail a builder restart on the image pre-fetch startBuilder fetched the builder image, with the scheme its reference calls for, before handing over to Builder.start, and failed if that fetch did. Builder.start restarts a stopped builder that still matches without touching its image, which may since have been deleted (Apple Container only protects images of running containers), so an unreachable registry would fail a restart that needs no image. Make the pre-fetch best effort and log its failure: Builder.start still fails, with its own fetch, when it does need the image. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Wes Morgan <[email protected]> * ci: retrigger integration test The previous two runs' integration jobs failed on infrastructure: a dropped kernel download, then no macOS runner acquired. Co-authored-by: Claude Opus 5.5 <[email protected]> Signed-off-by: Wes Morgan <[email protected]> --------- Signed-off-by: Wes Morgan <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 24, 2026
Closed
henrywang
added a commit
to henrywang/Berthly
that referenced
this pull request
Oct 25, 2026
Closes #207. ## Premise correction #207 assumed the Run sheet's network entries were free text, so `alias=` already worked if typed. They're pickers, so the syntax could never be entered. The PARITY.md line from #217 that repeated this is corrected here. ## What - **Run sheet:** each network row gets an **Aliases** field (comma- or space-separated). It's sent as `--network <name>,alias=A,alias=B` (container 1.6.0, apple/container#2390). Empty rows are still dropped. - **Validation before submit** uses upstream's public `Parser.network`, so malformed aliases show an inline error and disable Run. This check is syntax-only. The daemon enforces the placement rules in its non-exported `AliasPolicy`, and they still surface at create time, which can be after a pull. The help text spells them out: - aliases must be fully qualified unless a default DNS domain is set - a `.name` subtree alias must sit below the hostname or an exact alias - **Showing aliases:** - `Container.networkAliases` is read from `configuration.networks[].options.aliases`. - The container detail's Networks row reads e.g. `default (api.test, .api.test)`. - The network page's endpoint list now fills in aliases for derived endpoints. Before, these were always empty. - **Mock:** parses specs the same way. The mock's `withRuntimeReset` now carries `networkAliases`, so stop and start don't drop them. - **Lint ratchet:** `mockInspectData` moved into an extension to keep `MockContainerService` under the `type_body_length` limit. It's moved, not refactored. - No daemon-version gate, since the floor is 1.6.1. ## Testing - **Unit:** `NetworkAliasTests` covers split, spec building, accepted and rejected aliases, round-trip parse, the live `networkAliases(from:)` mapping, derived endpoint aliases, the detail description, and mock persistence across stop and start. Full `BerthlyTests` passes. - **UI (mock):** `RunSheetNetworkAliasUITests` checks that a malformed alias shows the error and disables Run, and that fixing it re-enables Run. - **E2E (real 1.6.1 daemon):** - New `NetworkAliasJourneyTests`: aliases typed in the Run sheet are stored in `configuration.networks[0].options.aliases` and listed in the detail's Networks row. - Name resolution isn't tested: containers only resolve each other's names with a configured DNS domain, which needs an admin prompt. - `testNetworkAttachedViaUIVerifiedInTerminal` and `testRunOptionsReachDaemon` still pass. - No `berthly-e2e` resources were left behind. - `swiftlint lint --strict`: clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
3 of 4 tasks
1 task done
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.
Type of Change
Motivation and Context
Closes #457.
A container can now declare additional DNS names for a network attachment with a repeatable
aliasproperty on--network, including subtree aliases that match every name below a domain:With the default domain
test, this container answers togateway.testby its name, toapi.testby the exact alias, and toweb.gateway.test,a.b.gateway.testand every other name belowgateway.testby the subtree alias. The motivating case is a gateway container in front of a local Kubernetes cluster that answers for*.gateway.test, with an ingress controller routing on theHostheader.An alias is an exact name, or a name with a leading dot that matches every name below it. A name without a dot gets the default domain, as container names do. A subtree alias must be below a name the same attachment owns, and exact names are unique across all containers, so a container cannot claim another container's namespace. The rules for one attachment are checked when a container is created, again when a stored container starts, and again by the network helper when it registers the aliases. See
docs/architecture/dns.mdfor the design, the invariants and the security considerations.Notes for reviewers
Foowas never found by the lowercased queries the DNS server receives.--networkoption are easiest to read together.NetworksService.lookupheld the networks state lock while calling the helpers, so a DNS answer could wait on a network create or delete. It now calls the helpers without the lock and skips a network that cannot answer. The alias work does not depend on it, but the new integration tests exposed the stall.lookup(name:)returns aNetworkMatch(the attachment and how the name matched), andallocatetakes the aliases. The helper and its client ship together.Known limitation
DNS responses echo a lowercased question and owner name even when the client sent mixed case, because
DNSNamelowercases labels when a query is decoded. This predates the change and is described in the architecture document.Testing
Unit tests cover the rule parser, validation, helper registration and matching, the helper protocol, cross-network selection and alias qualification.
TestCLINetworkAliasstarts containers and queries the DNS server directly.