Skip to content

Conversation

@rejain789
Copy link
Contributor

@rejain789 rejain789 commented Nov 2, 2025

Reason for Change:
This pr is solely for when NPM Lite is enabled. It adds logic to bypass IPSet creations and directly passes in IP cidr blocks to the acl's which is then sent to HNS. This bypass will take place with default deny and npm lite enabled

Issue Fixed:

Manual Testing
Test Setup

  • L1VH Node
  • 2 swiftv2 pods in the l1vh node (pod1 has ip 10.226.0.40/32 and pod2 has ip 10.226.0.49/32)
  • NPM Lite Enabled
  • Default Deny Enabled

Created a network policy as shown below:
image

Applied the policy and show the 2 allow in/out acl's created with ip cidrs instead of ipsets in hns as shown below:
image

Requirements:

Notes:

@rejain789 rejain789 changed the title [NPM Lite] Added logic to bypass ipsets for /32 cidrs with npm lite [NPM Lite] Added logic to bypass ipsets for cidr blocks with npm lite Nov 4, 2025
@rejain789 rejain789 marked this pull request as ready for review November 5, 2025 22:14
@rejain789 rejain789 requested a review from a team as a code owner November 5, 2025 22:14
Copy link
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 enhances NPM Lite mode on Windows to bypass IPSet creation for CIDR-based network policies by introducing direct IP address handling. When NPM Lite is enabled, the system now stores CIDR blocks directly in ACL policies rather than creating IPSets, improving efficiency for CIDR-only policies.

Key changes:

  • Added SrcDirectIPs and DstDirectIPs fields to ACLPolicy for direct CIDR storage
  • Introduced directPeerAndPortRule() function to handle CIDR-based policies without IPSet creation
  • Updated Windows ACL conversion logic to correctly map direct IPs to HNS Local/Remote addresses based on direction
  • Removed validation function npmLiteValidPolicy() and its associated test TestNpmLiteCidrPolicy()

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
npm/pkg/dataplane/policies/policy.go Added SrcDirectIPs and DstDirectIPs fields to ACLPolicy struct with documentation; reformatted comment example
npm/pkg/dataplane/policies/policy_windows.go Modified convertToAclSettings() to handle direct IP addresses for NPM Lite, with conditional logic for Local/Remote address mapping based on traffic direction
npm/pkg/controlplane/translation/translatePolicy.go Added directPeerAndPortRule() function for direct CIDR handling; removed npmLiteValidPolicy() validation function; updated translateRule() to use direct CIDR path when NPM Lite is enabled
npm/pkg/controlplane/translation/translatePolicy_test.go Removed TestNpmLiteCidrPolicy() test covering CIDR validation with npm lite

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

Comment on lines +399 to +401
if portKind == namedPortType {
return ErrUnsupportedNamedPort
}
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

The check for namedPortType is redundant since checkForNamedPortType() already validates this on line 384 and would return an error. This unreachable code should be removed.

Suggested change
if portKind == namedPortType {
return ErrUnsupportedNamedPort
}

Copilot uses AI. Check for mistakes.
}
dstPortStr := getPortStrFromPorts(acl.DstPorts)

// HNS has confusing Local and Remote address defintions
Copy link

Copilot AI Nov 5, 2025

Choose a reason for hiding this comment

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

Corrected spelling of 'defintions' to 'definitions'.

Suggested change
// HNS has confusing Local and Remote address defintions
// HNS has confusing Local and Remote address definitions

Copilot uses AI. Check for mistakes.
@rejain789 rejain789 changed the title [NPM Lite] Added logic to bypass ipsets for cidr blocks with npm lite [NPM Lite] Bypassing IPSets for IP CIDR Block Based Network Policies Nov 5, 2025
dstListStr := getAddrListFromSetInfo(acl.DstList)
var srcListStr, dstListStr string
// Check if we have direct IPs (NPM Lite /32 bypass)
if len(acl.SrcDirectIPs) > 0 || len(acl.DstDirectIPs) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

this check is also done on line 139, is it possible to converge into the same block?

if npmLiteToggle {
err = directPeerAndPortRule(npmNetPol, direction, ports, peer.IPBlock.CIDR, npmLiteToggle)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

+ error wrapping here


// Handle ports
if portKind == namedPortType {
return ErrUnsupportedNamedPort
Copy link
Member

Choose a reason for hiding this comment

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

I would also wrap this with some additional context from the npmNetPol in case you're doing a trace later on

return nil
}

func directPeerAndPortRule(npmNetPol *policies.NPMNetworkPolicy, direction policies.Direction, ports []networkingv1.NetworkPolicyPort, cidr string, npmLiteToggle bool) error {
Copy link
Member

Choose a reason for hiding this comment

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

probably include Allow somewhere in this func to be extra explicit

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.

3 participants