feat: forward guest DNS to Docker's embedded resolver#793
Conversation
✅ Deploy Preview for urunc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
25a6350 to
a743f29
Compare
a743f29 to
6723c67
Compare
|
Hey @cmainas, I have implemented the changes we discussed during our sync. Could you please take a look and review them? This will allow us to make any necessary changes before we extend this logic to other unikernels. |
c15a2e2 to
22a5784
Compare
On Docker user custom networks the DNS resolver (127.0.0.11) is loopback only and unreachable by the unikernel guest. Detect this case per container, expose the resolver via a virtual resolver IP using tc redirects between the tap and lo + a PREROUTING DNAT, and rewrite the guest's resolv.conf to point at that IP. Signed-off-by: Ali Mohamed <amx746@gmail.com>
22a5784 to
89b24e6
Compare
cmainas
left a comment
There was a problem hiding this comment.
Hello @alimx07 ,
thank you for all the changes and the fix. A few comments:
- In the e2e testing the docker network does not exist and therefore creating the contianer will fail. We need to setup the network. Maybe in https://github.com/urunc-dev/urunc/blob/main/tests/e2e/docker_test.go#L25 and also remove later.
- Let;s find a better name for loclahost.go. Maybe something like "dns_at_localhost.go"?
- I think I got confused with the
genericRulesanddockerRules. Have we found a case where we should apply thegenericRules(e.g. a CNI) rather thandockerRules? - We can wrap the execution of iptables in a function, instead of having cmd and cmd.Run in various places.
- We should check if we can obtain the information we gather form iptables from other sources (e.g. netlink).
- We can restructure the code and this logic in the network_dynamic.go (the only mode where these changes apply) and avoid re-opening the tap device etc. We can me use of https://github.com/urunc-dev/urunc/blob/main/pkg/network/network_dynamic.go#L23C6-L23C20 for passing information.
- We should also clean up all the rules we apply.
| StaticNet: false, | ||
| SideContainers: []string{}, | ||
| Skippable: false, | ||
| TestFunc: dnsResolveExternalTest, |
There was a problem hiding this comment.
We can make this matchTest. Look at https://github.com/urunc-dev/urunc/blob/main/tests/e2e/test_cases.go#L19 for example.
| if isDocker(resolvConf) { | ||
| f.custom = dockerRules | ||
| } |
There was a problem hiding this comment.
The decision if we are going to apply the "docerRules" should be based on the localhost detection as a nameserver and not if there is a "docker" string in /etc/reolv.conf
| // Rule: DNSServer stays empty unless the rules actually got installed. | ||
| if fwd != nil && networkType == "dynamic" { | ||
| if err := fwd.Apply(networkInfo.TapDevice, networkInfo.EthDevice.Interface); err != nil { | ||
| uniklog.Warnf("failed to apply localhost forwarding rules: %v", err) |
There was a problem hiding this comment.
nit: We can return here instead of using else.
| ipt, err := exec.LookPath("iptables") | ||
| if err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
nit: This should be placed in dnat.
| return err | ||
| } | ||
| dst := net.JoinHostPort(f.LoIP.String(), "53") | ||
| for _, proto := range []string{"udp", "tcp"} { |
There was a problem hiding this comment.
We are not going to have more than udp and tcp as protocols here, so it would be cleaner if we unfold the loop. As it happens in docker.go
There was a problem hiding this comment.
We can merge this file with "loclahost.go" or its new name.
Description
On Docker user custom networks the DNS resolver (127.0.0.11) is loopback only and unreachable by the unikernel guest. Detect this case per container, expose the resolver via a virtual resolver IP
configured by userusing tc redirects between the tap and lo , and rewrite the guest'sresolv.confto point at that IP in our unikernel islinuxone. Also we add a custom rules DNAT rules according to the enviroment (e.g. Docker -> PREROUTING DNAT(for DNS server ports))Two TC rules added on tap and lo:
src=ResolvIPinto TapRelated issues
How was this tested?
Tested in user custom docker network with urunc container
u1and normal oneu2:u1lookup ongithub.comu1lookup onu2u2lookup onu1LLM usage
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).