Repository navigation
proxy: carry a patch making execInNetworkNamespace restore the calling THREAD's netns (/proc/thread-self), with the cross-pod landing proof signal (#1022) - #1028
Merged
Conversation
…ix (#1022, expected RED) Adds @envoy//test/common/network:exec_in_netns_thread_test through a carried patch and runs it (with utility_test) from //bazel/patches:carried_patch_tests, WITHOUT the utility.h fix, so the proxy CI run on this commit shows the test fails against the unpatched helper. The fix follows in the next commit. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…roc/thread-self), plus the cross-pod landing proof signal (#1022) The carried patch now fixes Network::Utility::execInNetworkNamespace: it records the namespace to return to from /proc/thread-self/ns/net (fallback /proc/self/task/<tid>/ns/net on ENOENT) instead of /proc/self/ns/net, which is the thread-group leader's namespace. setns(CLONE_NEWNET) is per thread, so a worker calling the helper while the main thread was briefly inside a pod netns "restored" itself into that pod's netns and kept creating upstream sockets there -- the hypothesised source of #1007's cross-pod L4 landings. ExecInNetnsTest.Basic's path expectation follows the new spelling. The previous commit ran the new exec_in_netns_thread_test without the fix: all three cases failed on both arches, including the real-kernel case ("worker restored into netns inode X (main thread's is X), expected its own Y"). Docs: runbook "Cross-pod L4 landings (#1007/#1022)" with the TCP-floor landing PromQL and the verify_san / inbound ssl_connection_error join; the soak README's zero-reading gates table gets the landing counter with rev242 as the negative control; proxy/README lists the third carried patch. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mechanism
Network::Utility::execInNetworkNamespace(source/common/network/utility.h~383 at the pinned726d7ac) records the namespace to return to by opening/proc/self/ns/net. In a multi-threaded process/proc/selfresolves to the thread-group leader, which is the main thread.setns(CLONE_NEWNET)moves only the calling thread.The main thread enters pod namespaces briefly and often: health-check connects every 5 s per local pod, and listener socket creation. If a worker calls the helper (every
app_<pod>connection) during one of those windows, it "restores" itself into that pod's netns and stays there until its next call. While it is stuck, its host-intended upstream sockets are created inside the pod. Redirect-all capture then diverts them to the pod's capture listener, and #1007'suse_original_dsthandoff passes them to the newest pod's inbound:18008listener, where the client's SAN check rejects them. That is the working explanation for #1007's cross-pod L4 landings. The talos proof below is what confirms or refutes it./proc/self/ns/netis the only place in the Envoy tree that saves and restores a netns this way. I grepped for/proc/self,ns/netandsetns, and everysetnscall site is inside this helper.The patch
proxy/bazel/patches/envoy-aether1022-exec-in-netns-thread-self.patchis the third entry insingle_version_override(patches=…). It is applied after #47743 and #47740, andgit apply --checkpasses on the three in order at726d7ac.utility.h: opens/proc/thread-self/ns/net. OnENOENT(kernels older than 3.17) it falls back to/proc/self/task/<gettid()>/ns/net. The error message names whichever path failed.utility_test.cc:ExecInNetnsTest.Basic's expected path string follows the new spelling.test/common/network:exec_in_netns_thread_test, in the patch's BUILD hunk.//bazel/patches:carried_patch_testsis a newtest_suitethat runs that test plusutility_testfrom the proxy workspace'sbazel test //....//...never reaches@envoytests on its own, so without this the test would not run in CI.Nothing is filed upstream. That is the maintainer's call, and #980 notes the third carried patch.
The test, and why it cannot pass vacuously
ExecInNetnsTest.Basicmocksopen()to hand back an opaque fd for any path. Under that mock every spelling "restores correctly", so the test can never catch this bug. The new test has three cases:WorkerReturnsToItsOwnNetnsWhileMainThreadIsInAnother(model, runs everywhere).open()/close()/setns()drive a model of the kernel's per-thread netns state. The model resolves/proc/self/ns/netto the leader's (getpid()) namespace,/proc/thread-self/ns/netto the calling thread's, and/proc/self/task/<tid>/ns/netto thread<tid>'s.setns()moves only the caller.pod-a, and a realstd::threadworker calls the helper intopod-b.host), not how the opened path is spelled. The path (/proc/thread-self/ns/net, opened by the worker's tid) is asserted as well./procviews apart from a non-main thread.FallsBackToTaskTidWhenThreadSelfIsAbsent(model)./proc/thread-selfreturnsENOENT. The test asserts the open sequence/proc/thread-self/ns/net, then/proc/self/task/<worker tid>/ns/net, thenpod-b, and that the worker ends inhost.RealKernelWorkerReturnsToItsOwnNetns(real kernel, compared by netnsst_ino).unshare(CLONE_NEWNET)first, then an unprivileged user namespace.setnses to n1, and the helper targets n3./proc/thread-self/ns/netinode after the call equals n1's inode, and that the main thread is still in n2.Shown red on the unpatched helper
The first commit (3e9a6d2) added the test without the
utility.hfix. Thatproxyrun failed on both arches (run 36359455791), with all three cases red:Green with the fix
The second commit (1072f91) makes
proxygreen on both legs (run 36360025650): amd64 9m36s, arm64 8m50s,Executed 8 out of 8 tests: 8 tests pass. That set includesexec_in_netns_thread_test,utility_testand//:image_teston the patched Envoy.Proof recipe for the next talos deploy
This is in the runbook section "Cross-pod L4 landings (#1007/#1022)" and in the soak README's zero-reading gates table.
verify_santicks.Charts are untouched. The proxy pin bot re-pins after merge.
Refs #1022. The talos deploy closes it, once the counter reads zero on the patched proxy.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr