Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnsproxy: bind dns proxy to localhost only #25309

Merged

Conversation

mhofstetter
Copy link
Member

@mhofstetter mhofstetter commented May 8, 2023

Currently the dns proxy binds to all interfaces.

With this commit, the dns proxy only gets bound to the localhost interfaces. Therefore, up to 4 DNS servers are created (udpv4, tcpv4, udpv6, tcpv6 - depending on the configuration) which all are using the same DNS handler.

Fixes parts of #23353

DNS Proxy binds to loopback interfaces only

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label May 8, 2023
@mhofstetter mhofstetter added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label May 8, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label May 8, 2023
@mhofstetter mhofstetter force-pushed the pr/mhofstetter/dns-proxy-explicit-listeners branch from aba89a7 to f0a8213 Compare May 8, 2023 09:24
@mhofstetter
Copy link
Member Author

/test

@mhofstetter mhofstetter force-pushed the pr/mhofstetter/dns-proxy-explicit-listeners branch from f0a8213 to 839791d Compare May 8, 2023 14:16
@mhofstetter mhofstetter marked this pull request as ready for review May 8, 2023 14:23
@mhofstetter mhofstetter requested review from a team as code owners May 8, 2023 14:23
@jrajahalme
Copy link
Member

/test

Copy link
Member

@jrajahalme jrajahalme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

pkg/fqdn/dnsproxy/proxy.go Outdated Show resolved Hide resolved
@mhofstetter mhofstetter force-pushed the pr/mhofstetter/dns-proxy-explicit-listeners branch from 839791d to f48014f Compare May 9, 2023 13:28
@mhofstetter
Copy link
Member Author

mhofstetter commented May 9, 2023

/test

Job 'Cilium-PR-K8s-1.26-kernel-net-next' failed:

Click to show.

Test Name

K8sDatapathConfig Host firewall With VXLAN and endpoint routes

Failure Output

FAIL: Error deleting resource /home/jenkins/workspace/Cilium-PR-K8s-1.26-kernel-net-next/src/github.com/cilium/cilium/test/k8s/manifests/host-policies.yaml: Cannot retrieve "cilium-hxhdn"'s policy revision: cannot get policy revision: ""

Jenkins URL: https://jenkins.cilium.io/job/Cilium-PR-K8s-1.26-kernel-net-next/2166/

If it is a flake and a GitHub issue doesn't already exist to track it, comment /mlh new-flake Cilium-PR-K8s-1.26-kernel-net-next so I can create one.

Then please upload the Jenkins artifacts to that issue.

Job 'Cilium-PR-K8s-1.26-kernel-net-next' failed:

Click to show.

Test Name

K8sDatapathServicesTest Checks N/S loadbalancing With host policy Tests NodePort

Failure Output

FAIL: Can not connect to service "tftp://192.168.56.12:31701/hello" from outside cluster (1/10)

Jenkins URL: https://jenkins.cilium.io/job/Cilium-PR-K8s-1.26-kernel-net-next/2175/

If it is a flake and a GitHub issue doesn't already exist to track it, comment /mlh new-flake Cilium-PR-K8s-1.26-kernel-net-next so I can create one.

Then please upload the Jenkins artifacts to that issue.

@mhofstetter
Copy link
Member Author

mhofstetter commented May 9, 2023

@mhofstetter mhofstetter force-pushed the pr/mhofstetter/dns-proxy-explicit-listeners branch from f48014f to efac03a Compare May 10, 2023 06:48
@mhofstetter
Copy link
Member Author

mhofstetter commented May 10, 2023

(after rebasing to main (without further changes))

/test

Copy link
Member

@pippolo84 pippolo84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks! 🚀
I've just left a comment inline regarding the servers shutdown.

pkg/fqdn/dnsproxy/proxy.go Show resolved Hide resolved
Currently the dns proxy is bound to all interfaces.

With this commit, the dns proxy only gets bound to the localhost
interfaces. Therefore, up to 4 DNS servers are created (udpv4, tcpv4,
udpv6, tcpv6 - depending on the configuration) which all are using the
same DNS handler.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
This commit introduces proper error propagation when errors occur during
sessionFactory.SetSocketOptions.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Currently, switching the localOnly property of a proxy rule doesn't get
reflected in the iptables rules. The checks for adding iptable rules don't
include the IP of a rule. Therefore, when upgrading, the old rule remains
in the table. The same applies for the check whether an outdated rule
should be deleted from the table.

This commit fixes this, and adds support for changing the localOnly
property of a proxy rule.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
This commit introduces the ipfamily type with its current
implementations v4 & v6. This way duplication can be avoided.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Currently, dns server goroutine would exit with log.fatal in case of
returning without an error from ActivateAndServe (in case of a properly
initiated shutdown).

This commit changes this behaviour to only fail fatally in case of a
returned error.

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
@mhofstetter mhofstetter force-pushed the pr/mhofstetter/dns-proxy-explicit-listeners branch from efac03a to 9215f5e Compare May 10, 2023 09:27
@mhofstetter
Copy link
Member Author

/test

Copy link
Member

@pippolo84 pippolo84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! 💯

christarazi added a commit to christarazi/cilium that referenced this pull request Sep 5, 2023
In a previous change [1], the bind address for the proxy changed from
0.0.0.0 to localhost. This broke restoring the old proxy port and caused
Cilium to always allocate a new proxy port.

Fix it by changing the regex string to include the new bind address as
well as the previously used "0.0.0.0" and "::", for
backwards-compatibility reasons on upgrade.

Found by code inspection.

[1]: cilium#25309

Fixes: 5304088 ("dnsproxy: bind dns proxy to localhost only")
Fixes: cilium#25309

Signed-off-by: Chris Tarazi <chris@isovalent.com>
youngnick pushed a commit that referenced this pull request Sep 10, 2023
In a previous change [1], the bind address for the proxy changed from
0.0.0.0 to localhost. This broke restoring the old proxy port and caused
Cilium to always allocate a new proxy port.

Fix it by changing the regex string to include the new bind address as
well as the previously used "0.0.0.0" and "::", for
backwards-compatibility reasons on upgrade.

Found by code inspection.

[1]: #25309

Fixes: 5304088 ("dnsproxy: bind dns proxy to localhost only")
Fixes: #25309

Signed-off-by: Chris Tarazi <chris@isovalent.com>
christarazi added a commit that referenced this pull request Sep 12, 2023
[ upstream commit 1f8e015 ]

In a previous change [1], the bind address for the proxy changed from
0.0.0.0 to localhost. This broke restoring the old proxy port and caused
Cilium to always allocate a new proxy port.

Fix it by changing the regex string to include the new bind address as
well as the previously used "0.0.0.0" and "::", for
backwards-compatibility reasons on upgrade.

Found by code inspection.

[1]: #25309

Fixes: 5304088 ("dnsproxy: bind dns proxy to localhost only")
Fixes: #25309

Signed-off-by: Chris Tarazi <chris@isovalent.com>
christarazi added a commit that referenced this pull request Sep 13, 2023
[ upstream commit 1f8e015 ]

In a previous change [1], the bind address for the proxy changed from
0.0.0.0 to localhost. This broke restoring the old proxy port and caused
Cilium to always allocate a new proxy port.

Fix it by changing the regex string to include the new bind address as
well as the previously used "0.0.0.0" and "::", for
backwards-compatibility reasons on upgrade.

Found by code inspection.

[1]: #25309

Fixes: 5304088 ("dnsproxy: bind dns proxy to localhost only")
Fixes: #25309

Signed-off-by: Chris Tarazi <chris@isovalent.com>
mhofstetter added a commit to mhofstetter/cilium that referenced this pull request Sep 15, 2023
PR cilium#25309 introduced a data race by sharing the sessionUDPFactory between the
DNS server instances for the different IP families (IPv4 & IPv6). This has been detected
by cilium#27979.

This commit fixes the data race by using dedicated instances of the sessionUDPFactory.

Fixes: cilium#28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
aanm pushed a commit that referenced this pull request Sep 18, 2023
PR #25309 introduced a data race by sharing the sessionUDPFactory between the
DNS server instances for the different IP families (IPv4 & IPv6). This has been detected
by #27979.

This commit fixes the data race by using dedicated instances of the sessionUDPFactory.

Fixes: #28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
mhofstetter added a commit to mhofstetter/cilium that referenced this pull request Sep 19, 2023
PR cilium#25309 introduced a data race by sharing the sessionUDPFactory between
the DNS server instances for the different IP families (IPv4 & IPv6).
This has been detected by cilium#27979.

This commit fixes the issue for the TCP servers too. It not set explicitly,
these are initialized with the default udp session factory to prevent nil
pointer exceptions. Therefore, an explicit noop udp session factory is set.

Fixes: cilium#28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
aanm pushed a commit that referenced this pull request Sep 25, 2023
PR #25309 introduced a data race by sharing the sessionUDPFactory between
the DNS server instances for the different IP families (IPv4 & IPv6).
This has been detected by #27979.

This commit fixes the issue for the TCP servers too. It not set explicitly,
these are initialized with the default udp session factory to prevent nil
pointer exceptions. Therefore, an explicit noop udp session factory is set.

Fixes: #28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
giorio94 pushed a commit that referenced this pull request Sep 26, 2023
[ upstream commit fb6bd90 ]

PR #25309 introduced a data race by sharing the sessionUDPFactory between the
DNS server instances for the different IP families (IPv4 & IPv6). This has been detected
by #27979.

This commit fixes the data race by using dedicated instances of the sessionUDPFactory.

Fixes: #28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
giorio94 pushed a commit that referenced this pull request Sep 26, 2023
[ upstream commit f73e1c5 ]

[ backporter's notes: switched cilium/dns import to miekg/dns, as v1.14
  was relying on a replace directive instead of pointing to the fork. ]

PR #25309 introduced a data race by sharing the sessionUDPFactory between
the DNS server instances for the different IP families (IPv4 & IPv6).
This has been detected by #27979.

This commit fixes the issue for the TCP servers too. It not set explicitly,
these are initialized with the default udp session factory to prevent nil
pointer exceptions. Therefore, an explicit noop udp session factory is set.

Fixes: #28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
aanm pushed a commit that referenced this pull request Sep 29, 2023
[ upstream commit fb6bd90 ]

PR #25309 introduced a data race by sharing the sessionUDPFactory between the
DNS server instances for the different IP families (IPv4 & IPv6). This has been detected
by #27979.

This commit fixes the data race by using dedicated instances of the sessionUDPFactory.

Fixes: #28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
aanm pushed a commit that referenced this pull request Sep 29, 2023
[ upstream commit f73e1c5 ]

[ backporter's notes: switched cilium/dns import to miekg/dns, as v1.14
  was relying on a replace directive instead of pointing to the fork. ]

PR #25309 introduced a data race by sharing the sessionUDPFactory between
the DNS server instances for the different IP families (IPv4 & IPv6).
This has been detected by #27979.

This commit fixes the issue for the TCP servers too. It not set explicitly,
these are initialized with the default udp session factory to prevent nil
pointer exceptions. Therefore, an explicit noop udp session factory is set.

Fixes: #28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
gandro pushed a commit to gandro/cilium that referenced this pull request Oct 10, 2023
[ upstream commit fb6bd90 ]

PR cilium#25309 introduced a data race by sharing the sessionUDPFactory between the
DNS server instances for the different IP families (IPv4 & IPv6). This has been detected
by cilium#27979.

This commit fixes the data race by using dedicated instances of the sessionUDPFactory.

Fixes: cilium#28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
gandro pushed a commit to gandro/cilium that referenced this pull request Oct 10, 2023
[ upstream commit f73e1c5 ]

[ backporter's notes: switched cilium/dns import to miekg/dns, as v1.14
  was relying on a replace directive instead of pointing to the fork. ]

PR cilium#25309 introduced a data race by sharing the sessionUDPFactory between
the DNS server instances for the different IP families (IPv4 & IPv6).
This has been detected by cilium#27979.

This commit fixes the issue for the TCP servers too. It not set explicitly,
these are initialized with the default udp session factory to prevent nil
pointer exceptions. Therefore, an explicit noop udp session factory is set.

Fixes: cilium#28156

Signed-off-by: Marco Hofstetter <marco.hofstetter@isovalent.com>
Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/proxy Impacts proxy components, including DNS, Kafka, Envoy and/or XDS servers. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants