L7/FQDN proxy traffic is dropped with IP_LOCAL_SOURCE when src_valid_mark=1 interacts with to-proxy fwmark 0x200
Is there an existing issue for this?
- I have searched the existing issues
Version
equal or higher than v1.20.1 and lower than v1.21.0
What happened?
Related:
- cilium/cilium#41991 — reports that
net.ipv4.conf.all.src_valid_mark=1breaks Cilium Gateway/TPROXY traffic when enabled by NetBird. The packet drop mechanism was not identified there. - cilium/cilium#46284 — independently observes the same Cilium to-proxy routing behavior, where mark 0x200 selects table 2004 and resolves the destination as local ... dev lo, but the failure mechanism in that issue is different.
- tailscale/tailscale#19796 — tracks the global side effects of Tailscale setting
net.ipv4.conf.all.src_valid_mark=1.
DNS fails only for pods using Cilium DNS L7/FQDN policy when:
net.ipv4.conf.all.src_valid_mark = 1The issue was originally exposed by Tailscale running on the node, but Tailscale is not required to reproduce it.
Changing only:
sysctl -w net.ipv4.conf.all.src_valid_mark=0
immediately makes DNS work again.
Tailscale enables src_valid_mark.
❯ git clone --depth=1 https://github.com/tailscale/tailscale
❯ cd tailscale
❯ rg src_valid_mark
wgengine/router/osrouter/router_linux.go
568: // Enable src_valid_mark so the kernel uses the packet's fwmark
573: if err := writeSysctl("net.ipv4.conf.all.src_valid_mark", "1"); err != nil {
574: r.logf("warning: failed to enable src_valid_mark: %v", err)
Current State
Affected endpoint:
Pod: 10.217.0.124
CoreDNS: 10.217.0.76
host veth: lxc65fcd145c213Cilium correctly redirects DNS to the DNS proxy:
FROM 1885 to-proxy
10.217.0.124 -> 10.217.0.76:53/UDP
to proxy-port 45867Relevant host state:
net.ipv4.conf.all.src_valid_mark = 1
net.ipv4.conf.lxc65fcd145c213.accept_local = 0
ip rule:
9: from all fwmark 0x200/0xf00 lookup 2004
table 2004:
local default dev loThe proxy mark changes the route of the pod source:
# ip route get 10.217.0.124
10.217.0.124 dev cilium_host src 10.217.0.62
# ip route get 10.217.0.124 mark 0x200
local 10.217.0.124 dev lo table 2004Kernel tracing shows the packet being dropped with:
kfree_skb:
location=ip_rcv_finish_core+0x233/0x360
reason: IP_LOCAL_SOURCEA/B Testing
The endpoint veth remained configured with: net.ipv4.conf.lxc65fcd145c213.accept_local = 0 No policy, pod, CoreDNS, or Cilium configuration was changed between the following tests.
src_valid_mark |
accept_local |
Reverse lookup with proxy mark | DNS | Drop |
|---|---|---|---|---|
0 |
0 |
mark excluded from source validation | works | none |
0 |
1 |
mark excluded from source validation | works | none |
1 |
0 |
0x200 -> table 2004 -> RTN_LOCAL |
timeout | IP_LOCAL_SOURCE |
1 |
1 |
0x200 -> table 2004 -> RTN_LOCAL |
works | none |
Possible Root cause
The observed path is:
DNS query from Pod
Pod -> CoreDNS
|
v
Cilium L7 DNS redirect
|
v
skb mark 0x200
MARK_MAGIC_TO_PROXY
|
| effective src_valid_mark=1
v
fib_validate_source()
|
| reverse source lookup includes skb->mark
v
RPDB rule pref 9
fwmark 0x200/0xf00 lookup 2004
|
v
table 2004
local default dev lo
|
v
reverse FIB result = RTN_LOCAL
|
| endpoint veth accept_local=0
v
SKB_DROP_REASON_IP_LOCAL_SOURCE
|
v
ip_rcv_finish_core()
|
v
DNS timeout__fib_validate_source() in Kernel source:
// source: net/ipv4/fib_frontend.c
/* Given (packet source, input interface) and optional (dst, oif, tos):
* - (main) check, that source is valid i.e. not broadcast or our local
* address.
* - figure out what "logical" interface this packet arrived
* and calculate "specific destination" address.
* - check, that packet arrived from expected physical interface.
* called with rcu_read_lock()
*/
static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst,
dscp_t dscp, int oif, struct net_device *dev,
int rpf, struct in_device *idev, u32 *itag)
{
// ...
// if `src_valid_mark=1`, fwmark is also applied in reverse lookup
fl4.flowi4_mark = IN_DEV_SRC_VMARK(idev) ? skb->mark : 0;
if (!fib4_rules_early_flow_dissect(net, skb, &fl4, &flkeys)) {
fl4.flowi4_proto = 0;
fl4.fl4_sport = 0;
fl4.fl4_dport = 0;
} else {
swap(fl4.fl4_sport, fl4.fl4_dport);
}
if (fib_lookup(net, &fl4, &res, 0))
goto last_resort;
if (res.type != RTN_UNICAST) {
if (res.type != RTN_LOCAL) {
reason = SKB_DROP_REASON_IP_INVALID_SOURCE;
goto e_inval;
// `RTN_LOCAL` and `accept_local=0` -> drop with reason `IP_LOCAL_SOURCE`
} else if (!IN_DEV_ACCEPT_LOCAL(idev)) {
reason = SKB_DROP_REASON_IP_LOCAL_SOURCE;
goto e_inval;
}
}
// ...How can we reproduce the issue?
- Prepare Kubernetes cluster (Single-Node cluster is recommended to reproduce easily)
- Install Cilium
- Run
sysctl -w net.ipv4.conf.all.src_valid_mark=1on the node. - Run commands to create test environment:
kubectl create ns cilium-test
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
labels:
run: curl
name: curl
namespace: cilium-test
spec:
containers:
- image: alpine/curl
name: curl
command:
- "sleep"
- "3600"
dnsPolicy: ClusterFirst
restartPolicy: Always
EOF
kubectl apply -f - <<EOF
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: test-rule
namespace: cilium-test
spec:
endpointSelector:
matchLabels:
run: curl
egress:
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: kube-system
k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
rules:
dns:
- matchPattern: "*"
EOFtry DNS lookup:
- Run
kubectl exec -n cilium-test curl -- nslookup google.com- It will fail
cilium-dbg:
- Get Endpoint of pod
curl - Run
kubectl -n kube-system exec -it cilium-<hash> -- cilium-dbg monitor --related-to="$EP" -v -v - In another terminal, Query DNS again
kernel tracing: 9. Run commands on the node:
TRACE=/sys/kernel/tracing
mkdir -p /sys/kernel/tracing/instances/cilium-srcmark
T=/sys/kernel/tracing/instances/cilium-srcmark
echo 0 > "$T/tracing_on"
echo > "$T/trace"
echo 1 > "$T/events/skb/kfree_skb/enable"
echo 1 > "$T/tracing_on"- Query DNS again:
kubectl -n cilium-test exec curl -- nslookup google.com - Stop tracing and find drop reason
IP_LOCAL_SOURCE:
echo 0 > "$T/tracing_on"
grep -i 'IP_LOCAL_SOURCE' "$T/trace"Cilium Version
1.20.1
Kernel Version
I tried with two versions:
- 6.18.43 (with v1.35-k3s1)
- 7.0.0-31-generic (with v1.37)
Kubernetes Version
I tried with two versions:
- v1.35.6+k3s1 (with Kernel 6.18.43)
- v1.37.0 (with Kernel 7.0.0)
Anything else?
Operational workaround for Tailscale users
For Tailscale users, an operational workaround is to avoid running tailscaled directly in the node host namespace and instead use the Tailscale Kubernetes Operator with a Connector/Subnet Router for Pod/Service CIDRs.
The Operator can also proxy access to the Kubernetes API server over the tailnet. Clients can configure kubectl with tailscale configure kubeconfig <proxy-hostname> and access the API server through the Operator/ProxyGroup, rather than relying on host-level Tailscale networking.
This isolates Tailscale's fwmark/sysctl behavior from Cilium's host routing state. It is only a deployment workaround, not a fix for the underlying src_valid_mark=1 interaction.
Code of Conduct
- I agree to follow this project's Code of Conduct
Source: cilium/cilium