Skip to content

Commit

Permalink
dnsproxy: Do not use original source when not possible
Browse files Browse the repository at this point in the history
Do not use original source for server running in the local node, or when
the destination is outside of the cluster, as there is a risk of missing
masquarade on the upstream connection.

Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
  • Loading branch information
jrajahalme committed Jan 10, 2024
1 parent 94f6553 commit 824e969
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/fqdn/dnsproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,8 @@ func (p *DNSProxy) ServeDNS(w dns.ResponseWriter, request *dns.Msg) {

var key string
// Do not use original source address if the source is known to be in the host networking
// namespace
if !ep.IsHost() && !epAddr.IsLoopback() {
// namespace, or the destination is known to be outside of the cluster, or is the local host
if !ep.IsHost() && !epAddr.IsLoopback() && ep.ID != uint16(identity.ReservedIdentityHost) && targetServerID.IsCluster() && targetServerID != identity.ReservedIdentityHost {
dialer.LocalAddr = w.RemoteAddr()
key = protocol + "-" + epIPPort + "-" + targetServerAddrStr
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/identity/numericidentity.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,13 @@ func (id NumericIdentity) IsWorld() bool {
return option.Config.IsDualStack() &&
(id == ReservedIdentityWorldIPv4 || id == ReservedIdentityWorldIPv6)
}

// IsCluster returns true if the identity is a cluster identity by excluding all
// identities that are known to be non-cluster identities.
// NOTE: keep this and bpf identity_is_cluster() in sync!
func (id NumericIdentity) IsCluster() bool {
if id.IsWorld() || id.HasLocalScope() {
return false
}
return true
}

0 comments on commit 824e969

Please sign in to comment.