Skip to content

feat: add transparent-tunnel CNI mode for GPS VFP enforcement (Linux)#4319

Open
alam-tahmid wants to merge 1 commit intoAzure:masterfrom
alam-tahmid:tahmidalam/gps-config-plumbing
Open

feat: add transparent-tunnel CNI mode for GPS VFP enforcement (Linux)#4319
alam-tahmid wants to merge 1 commit intoAzure:masterfrom
alam-tahmid:tahmidalam/gps-config-plumbing

Conversation

@alam-tahmid
Copy link
Copy Markdown
Contributor

@alam-tahmid alam-tahmid commented Apr 7, 2026

Reason for Change:
 Add transparent-tunnel CNI mode that forces same-node pod-to-pod traffic through the host's
physical interface (and therefore through VFP) so Azure NSG rules are enforced on intra-node
communication. This implements GPS (GlobalPodSecurity) for Linux using iptables fwmark-based
policy routing, including:

  • A fix for a conntrack tuple collision bug that caused ~50% DNS packet loss on same-node
    ClusterIP UDP traffic (service CIDR RETURN rules inserted before MARK rule)
  • Race-safe shared ip rule management (tolerates "File exists" to avoid TOCTOU on concurrent
    pod creates; ref-counted cleanup using real iptables -S output patterns on delete)
  • Nil gateway early-exit to prevent partial setup that would black-hole all marked traffic

Issue Fixed:

Requirements:

Notes:

This is PR 1 of 2 for the GPS feature:

  1. This PRtransparent-tunnel mode + Linux iptables/ip-rule implementation
  2. PR 2 — Windows /32 host route implementation (separate PR)

The mode is opt-in via conflist: "mode": "transparent-tunnel". No behavioral change to existing
transparent or other modes.

Replaces the previous GlobalPodSecurity: true boolean flag approach with a dedicated CNI mode
that uses Go struct embedding (zero code copy from TransparentEndpointClient).

Copilot AI review requested due to automatic review settings April 7, 2026 16:52
@alam-tahmid alam-tahmid requested review from a team as code owners April 7, 2026 16:52
@alam-tahmid alam-tahmid requested a review from jpayne3506 April 7, 2026 16:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces GlobalPodSecurity configuration plumbing to carry a new boolean knob from CNI network config into endpoint metadata, and updates default CNI conflists to surface the option (defaulting to false).

Changes:

  • Added globalPodSecurity to CNI NetworkConfig (JSON) and plumbed it into network.EndpointInfo.
  • Extended network endpoint-related structs to carry GlobalPodSecurity.
  • Added unit tests for config unmarshalling and createEpInfo propagation, and updated default Linux/Windows conflists to include the flag (set to false).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
network/endpoint.go Adds GlobalPodSecurity fields to endpoint and EndpointInfo structs.
cni/network/network.go Wires NetworkConfig.GlobalPodSecurity into generated EndpointInfo.
cni/network/network_test.go Adds coverage to ensure createEpInfo propagates the flag into EndpointInfo.
cni/netconfig.go Adds GlobalPodSecurity to CNI JSON config (globalPodSecurity).
cni/netconfig_test.go Adds JSON unmarshal tests for globalPodSecurity defaulting/values.
cni/azure-windows.conflist Adds "globalPodSecurity": false to default Windows conflist.
cni/azure-linux.conflist Adds "globalPodSecurity": false to default Linux conflist.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread network/endpoint.go
@alam-tahmid alam-tahmid force-pushed the tahmidalam/gps-config-plumbing branch from b7af504 to 0d1ce9f Compare April 7, 2026 17:13
Copy link
Copy Markdown
Contributor

@QxBytes QxBytes left a comment

Choose a reason for hiding this comment

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

Assuming your iptables changes will be going in the existing transparent client endpoint code, (unless it's a new scenario)? Also assuming this change affects nodesubnet (no azure cns present)?

Comment thread cni/network/network.go Outdated
Comment thread cni/azure-linux.conflist Outdated
Comment thread network/endpoint.go Outdated
Comment thread cni/netconfig_test.go Outdated
@alam-tahmid alam-tahmid force-pushed the tahmidalam/gps-config-plumbing branch from 0d1ce9f to a951bf0 Compare April 16, 2026 17:58
@alam-tahmid alam-tahmid changed the title feat: add GlobalPodSecurity config plumbing feat: add transparent-tunnel CNI mode for GPS VFP enforcement (Linux) Apr 16, 2026
@alam-tahmid alam-tahmid force-pushed the tahmidalam/gps-config-plumbing branch 2 times, most recently from e051e3d to ecbdd88 Compare April 16, 2026 21:57
QxBytes
QxBytes previously approved these changes Apr 17, 2026
Copy link
Copy Markdown
Contributor

@QxBytes QxBytes left a comment

Choose a reason for hiding this comment

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

Just a note that for transparent-vlan I needed to run something for rp_filter. If you already tested and it works then should be fine but just bringing it to your attention if something pops up in the future.

Also for the ExecuteRawCommand it should be fine since you control the command input but just for future reference.

Comment thread network/transparent_tunnel_endpointclient_linux.go Outdated
//
// 3. IP rule + route — marked packets are routed via the host's physical
// interface, which forces them through VFP for NSG enforcement.
func (client *TransparentTunnelEndpointClient) addGPSTunnelRules() error {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lets not use GPS term in CNI code

Comment on lines +123 to +126
if err := client.iptablesClient.InsertIptableRule(
iptables.V4, iptables.Mangle, iptables.Prerouting, match, "RETURN",
); err != nil {
return errors.Wrapf(err, "failed to insert service CIDR RETURN rule for %s", cidr)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you explain why this is required?

Comment on lines +132 to +141
// 2. Fwmark MARK rule — append so it comes after RETURN rules.
markMatch := "-i " + hostVeth
markTarget := "MARK --set-mark " + markStr
if err := client.iptablesClient.AppendIptableRule(
iptables.V4, iptables.Mangle, iptables.Prerouting, markMatch, markTarget,
); err != nil {
return errors.Wrap(err, "failed to append GPS fwmark MARK rule")
}
logger.Info("GPS: added fwmark MARK rule",
zap.String("veth", hostVeth), zap.String("mark", markStr))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need iptable rule to mark packet? can we not add ip rule to lookup custome routing table based on pod cidr?

something like this:


ip rule add from 10.9.255.0/24 table 100
ip route add default via 10.9.255.1 dev eth1 table 100

// the add and tolerate "File exists" errors. This avoids a TOCTOU race where
// two concurrent pod creates both see the rule missing and both try to add it.
tableStr := strconv.Itoa(gpsTunnelRouteTable)
if _, err := client.plClient.ExecuteCommand(context.TODO(), "ip", "-4", "rule", "add", "fwmark", markStr, "lookup", tableStr); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also lets use netlink apis to do this..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants