Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NodeNetworkPolicy datapath #5658

Merged
merged 1 commit into from
Jan 12, 2024

Conversation

hongliangl
Copy link
Contributor

@hongliangl hongliangl commented Nov 2, 2023

This PR introduces support for the NodeNetworkPolicy datapath, extending Antrea
ClusterNetworkPolicy (ACNP). The implementation leverages iptables and ipset for
enforcing rules, safeguarding Kubernetes Nodes.

There are four key components to implement the data path:

  • Core iptables rule
    • Integrated into static chains ANTREA-POL-INGRESS-RULES (ingress) or
      ANTREA-POL-EGRESS-RULES (egress).
    • Matches an ipset that includes NodeNetworkPolicy rule source or
      destination IPs, or directly matches a single IP.
    • Targets an action or a service chain created for NodeNetworkPolicy
      rule with multiple services.
  • Service iptables chain
    • Created for NodeNetworkPolicy rule with multiple services.
  • Service iptables rules:
    • Added to the service chain for NodeNetworkPolicy rule, constructed from
      rule services.
  • From/To ipset:
    • Created for a NodeNetworkPolicy rule, containing source (ingress) or
      destination (egress) IPs.

Example ingress or egress core iptables rules organized by priorities:

:ANTREA-POL-INGRESS-RULES
-A ANTREA-POL-INGRESS-RULES -m set --match-set ANTREA-POL-RULE1-4 src -j ANTREA-POL-RULE1 -m comment --comment "Antrea: for rule RULE1, policy AntreaClusterNetworkPolicy:name1"
-A ANTREA-POL-INGRESS-RULES -m set --match-set ANTREA-POL-RULE2-4 src -p tcp --dport 8080 -j ACCEPT -m comment --comment "Antrea: for rule RULE2, policy AntreaClusterNetworkPolicy:name2"
-A ANTREA-POL-INGRESS-RULES -s 3.3.3.3/32 src -j ANTREA-POL-RULE3 -m comment --comment "Antrea: for rule RULE3, policy AntreaClusterNetworkPolicy:name3"
-A ANTREA-POL-INGRESS-RULES -s 4.4.4.4/32 -p tcp --dport 80 -j ACCEPT -m comment --comment "Antrea: for rule RULE4, policy AntreaClusterNetworkPolicy:name4"

Example service chain (for rule with multiple services)::

:ANTREA-POL-RULE1
-A ANTREA-POL-RULE1 -j ACCEPT -p tcp --dport 80
-A ANTREA-POL-RULE1 -j ACCEPT -p tcp --dport 443

Example ipset (for rule with multiple source or destination IPs)

Name: ANTREA-POL-RULE1-4
Type: hash:net
Revision: 6
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 472
References: 1
Number of entries: 2
Members:
1.1.1.1
1.1.1.2

Signed-off-by: Hongliang Liu lhongliang@vmware.com

@hongliangl hongliangl changed the title [WIP] Add support for HostNetworkPolicy [WIP] Add support for HostNetworkPolicy datapath Nov 3, 2023
@hongliangl hongliangl force-pushed the 20230828-bm-dfw-reboot branch 3 times, most recently from 621e5a0 to fa67a44 Compare November 9, 2023 11:42
@hongliangl hongliangl force-pushed the 20230828-bm-dfw-reboot branch 13 times, most recently from 3a18e52 to 2b2307f Compare November 15, 2023 08:04
@hongliangl hongliangl marked this pull request as ready for review November 15, 2023 08:04
@hongliangl hongliangl changed the title [WIP] Add support for HostNetworkPolicy datapath Add support for HostNetworkPolicy datapath Nov 15, 2023
@hongliangl hongliangl changed the title Add support for HostNetworkPolicy datapath Add support for NodeNetworkPolicy datapath Nov 15, 2023
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
port: 22
```

## Limitations
Copy link
Contributor

@Dyanngg Dyanngg Jan 4, 2024

Choose a reason for hiding this comment

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

General question: should we add more clarifications in the limitations section in terms of what it means to have a ipBlock specified in the ingress block of a node networkpolicy? This could cause a great deal of confusion for users. For example, consider a multi-cluster setup with non-overlapping CIDRs, pod-to-pod connectivity enabled with gateways. In case the node where the policy is applied to is not the gateway node, wouldn't the ingress ipBlock feature not work properly due to the SNAT at the gateway (if the user specify CIDRs from the other clusters)? In addition, out of cluster traffic tend to have similar issues due SNATs at cloud load balancers before they enter Nodes? @tnqn

Copy link
Member

Choose a reason for hiding this comment

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

This is not specific to Node networkpolicy. Even for Pod networkpolicy, SNAT can happen in many cases (lke NodePort traffic), I feel it's not too hard for users to get that if your traffic gets SNATed before reaching the endpoint, the policy will be enforced based on the translated IP. But adding a note to explain the SNAT and IPBlock stuff in https://github.com/antrea-io/antrea/blob/main/docs/antrea-network-policy.md#notes-and-constraints sounds good to me.

@hongliangl hongliangl force-pushed the 20230828-bm-dfw-reboot branch 2 times, most recently from c5a8f07 to d0f3bd5 Compare January 5, 2024 10:31
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
@hongliangl hongliangl force-pushed the 20230828-bm-dfw-reboot branch 4 times, most recently from 912aa68 to 795f130 Compare January 8, 2024 07:26
docs/feature-gates.md Outdated Show resolved Hide resolved
pkg/agent/route/route_linux.go Outdated Show resolved Hide resolved
pkg/agent/route/route_linux.go Outdated Show resolved Hide resolved
pkg/agent/route/route_linux.go Outdated Show resolved Hide resolved
Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

LGTM overall, a few nits.

docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
docs/antrea-node-network-policy.md Outdated Show resolved Hide resolved
@luolanzone
Copy link
Contributor

@hongliangl please help to update the PR summary to explain this PR.

@hongliangl
Copy link
Contributor Author

@hongliangl please help to update the PR summary to explain this PR.

Updated

docs/feature-gates.md Outdated Show resolved Hide resolved
pkg/agent/route/route_linux.go Outdated Show resolved Hide resolved
pkg/features/antrea_features.go Outdated Show resolved Hide resolved
@hongliangl
Copy link
Contributor Author

/test-all

This PR introduces support for the NodeNetworkPolicy datapath, extending Antrea
ClusterNetworkPolicy (ACNP). The implementation leverages iptables and ipset for
enforcing rules, safeguarding Kubernetes Nodes.

There are four key components to implement the data path:

- Core iptables rule
  - Integrated into static chains ANTREA-POL-INGRESS-RULES (ingress) or
    ANTREA-POL-EGRESS-RULES (egress).
  - Matches an ipset that includes NodeNetworkPolicy rule source or
    destination IPs, or directly matches a single IP.
  - Targets an action or a service chain created for NodeNetworkPolicy
    rule with multiple services.
- Service iptables chain
  - Created for NodeNetworkPolicy rule with multiple services.
- Service iptables rules:
  - Added to the service chain for NodeNetworkPolicy rule, constructed from
    rule services.
- From/To ipset:
  - Created for a NodeNetworkPolicy rule, containing source (ingress) or
   destination (egress) IPs.

Example ingress or egress core iptables rules organized by priorities:

```
:ANTREA-POL-INGRESS-RULES
-A ANTREA-POL-INGRESS-RULES -m set --match-set ANTREA-POL-RULE1-4 src -j ANTREA-POL-RULE1 -m comment --comment "Antrea: for rule RULE1, policy AntreaClusterNetworkPolicy:name1"
-A ANTREA-POL-INGRESS-RULES -m set --match-set ANTREA-POL-RULE2-4 src -p tcp --dport 8080 -j ACCEPT -m comment --comment "Antrea: for rule RULE2, policy AntreaClusterNetworkPolicy:name2"
-A ANTREA-POL-INGRESS-RULES -s 3.3.3.3/32 src -j ANTREA-POL-RULE3 -m comment --comment "Antrea: for rule RULE3, policy AntreaClusterNetworkPolicy:name3"
-A ANTREA-POL-INGRESS-RULES -s 4.4.4.4/32 -p tcp --dport 80 -j ACCEPT -m comment --comment "Antrea: for rule RULE4, policy AntreaClusterNetworkPolicy:name4"
```

Example service chain (for rule with multiple services)::

```
:ANTREA-POL-RULE1
-A ANTREA-POL-RULE1 -j ACCEPT -p tcp --dport 80
-A ANTREA-POL-RULE1 -j ACCEPT -p tcp --dport 443
```

Example ipset (for rule with multiple source or destination IPs)

```
Name: ANTREA-POL-RULE1-4
Type: hash:net
Revision: 6
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 472
References: 1
Number of entries: 2
Members:
1.1.1.1
1.1.1.2
```

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

@jianjuns @luolanzone do you have other comments?

@hongliangl
Copy link
Contributor Author

/test-all

@jianjuns
Copy link
Contributor

I have no extra comment.

@hongliangl
Copy link
Contributor Author

/test-ipv6-all

@hongliangl
Copy link
Contributor Author

/test-conformance

@tnqn tnqn merged commit 4eb1de4 into antrea-io:main Jan 12, 2024
51 of 54 checks passed
@hongliangl hongliangl deleted the 20230828-bm-dfw-reboot branch January 12, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants