Add configurable DNS search domains for supervised containers#6893
Add configurable DNS search domains for supervised containers#6893joshuaboniface wants to merge 4 commits into
Conversation
Allow operators to override the DNS search domain list written into every supervised container's /etc/resolv.conf (previously hardcoded to local.hass.io). The new `search_domains` option is persisted in dns.json and exposed via the DNS REST API. When no custom domains are configured the existing default (local.hass.io) is preserved for backward compatibility. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
66ddb1d to
81d4d04
Compare
|
This is a pretty significant breaking change. The Though how would the internal search domain have an impact on your larger network? Do you have routing setup to expose all containers on your lan? If so you may want to reconsider that, a lot of addons use host binding in lieu of traditional auth and assume they are unreachable outside the docker network. For example, any addon which uses ingress |
|
@mdegat01 Thank you for the feedback. It should only be breaking if the default is changed explicitly by the administrator; it remains The issue I ran into was simply, that the ESPHome Builder container could not resolve the short names of my devices. To provide a bit more detail...
The ESPHome Builder example is just one; another could be security cameras + Frigate, or other similar integrations. Last year, this all worked as expected, so at first I thought this might be a bug, but I wasn't able to find any commits that changed this behaviour in any of the main projects. At that point I began suspecting there was something deeper, and that's when I stumbled upon this. I won't claim to say that it's the best solution, but it does seem to work so far. I'm happy to have it always include "local.hass.io" and just append additional domains, if that is the better design, but I also haven't noticed any issues running this for a few months and with a number of apps communicating with each other. |
There was a problem hiding this comment.
Ok we're on the same page now, I understand your use case. Two things though:
- This is currently a breaking change because of the use case of inter-container communication I detailed in the comment below. Lets keep
local.hass.ioin the list so I can remove that label. - That
_create_container_configmethod is only run to set up a new container. Once the container exists you have to rebuild it to change its config. Fortunately we already encountered this use case when we had to change thePropagationModefor mounts so you can leverage an existing check here:
supervisor/supervisor/resolution/checks/docker_config.py
Lines 78 to 112 in b74b65a
If you update this _check_container method used in there:
supervisor/supervisor/resolution/checks/docker_config.py
Lines 13 to 52 in 15fdc6b
you can have it take a look at the DnsSearch option and ensure it reflects the current value of search_options then Supervisor should handle this part for you. It'll pop an repair for each container that is not setup correctly that can be used to easily rebuild the container when the user is ready since this issue has already been added:
https://github.com/home-assistant/core/blob/c22f10bf8742c9a4408e22cfce904e34e2e1d3a5/homeassistant/components/hassio/issues.py#L87
This is what the repair will say which is fortunately generic enough to still work fine for this use case 😆
https://github.com/home-assistant/core/blob/c22f10bf8742c9a4408e22cfce904e34e2e1d3a5/homeassistant/components/hassio/strings.json#L149-L161
This change will also handle plugins without any additional steps as they are automatically rebuilt without requiring user input.
Although just an FYI healthchecks are run once per hour so it may take up to an hour before Supervisor notices the config is out of date when you're doing testing. If you want it to notice faster you can add a call to healthcheck directly when search_domains changes via dns/options or dns/reset
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
agners
left a comment
There was a problem hiding this comment.
Just wanted to give a quick comment on this topic: DNS suffixes came up in the past, e.g. in home-assistant/plugin-dns#118. I definitely think we should support local DNS suffixes, but ideally also the ones learned through DHCP. Our DHCP client is on the OS side, so we'd have to transfer the information from NetworkManager to CoreDNS.
I am not very convinced that deploying CoreDNS as a Supervisor plug-in is a good solution for our DNS needs, exactly for such DHCP/DNS interactions it's rather cumbersome. I was considering dropping the DNS plug-in/CoreDNS in favor of just using systemd-resolved, but haven't gotten around to it.
Each additional features added to todays solution will make this transition a bit harder, so I am not very found of adding more features right now. But if apply toa systemd-resolved based solution cleanly, maybe it also won't be very hard to just migrate once we get around to make that transition 🤔 🤷 .
Always append DNS_SUFFIX to the effective search domain list at render time, stripping any user-supplied duplicate first. This guarantees local.hass.io is present in every container's resolv.conf and Docker DnsSearch config regardless of operator-configured search domains. Avoids the breaking change that removing `local.hass.io` will cause if an override is set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Interesting @agners I didn't see that - I only checked this repo not the DNS plugin repo. Thanks for that! Do you think simply reading from the host system's |
- Use set union for DnsSearch in container config per reviewer suggestion, ensuring local.hass.io is always present without assuming list ordering - Re-render Supervisor's resolv.conf immediately when search_domains changes via dns/options or dns/reset, not only at startup - Add DnsSearch validation to _check_container so the docker config health check flags containers whose DnsSearch no longer matches the configured search domains, triggering a rebuild suggestion Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Pushed changes for review feedback, going to do some local testing myself before marking ready for further review. I can also do up a PoC of the "read from the host resolv.conf" if we think this will be beneficial! Testing results:
|
Only check DnsSearch against configured search domains for containers that were started with DNS enabled (i.e. have a Dns key in HostConfig). Containers created with dns=False never receive DnsSearch and were incorrectly flagged on every health check cycle. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
So far so good, no issues to report from my side. I didn't do the "read resolv.conf" portion yet, but I think that could be a separate PR if we want it. Marking ready for review again! |
Proposed change
Currently, the HA Supervisor forces a DNS search domain of
local.hass.ioin/etc/resolv.confon all containers due to the Supervisor's management of the entire Docker stack on a host. However, there can be advanced usecases where someone might want a different DNS search domain, for instance to easily enable DNS short names within a different domain. In my case, my entire home automation network usesa.domain.tld, and thus, containers like the ESPHome Builder would simply fail to resolve any short names, since those hosts are not resolvable in thelocal.hass.iodomain.This PR, in combination with a peer PR in the CLI, allow operators to override the DNS search domain list written into every supervised container's /etc/resolv.conf (previously hardcoded to local.hass.io). The new
search_domainsoption is persisted in dns.json and exposed via the DNS REST API. When no custom domains are configured the existing default (local.hass.io) is preserved for backward compatibility.Type of change
Additional information
Checklist
ruff format supervisor tests)If API endpoints or add-on configuration are added/changed: