aws / aws/amazon-network-policy-controller-k8s

Strict conditions in the code for adding a Service `ClusterIP` as a `NetworkPeer`

Open
#194 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
54
Forks
28
PR merge metrics
No merged PRs in 30d

Description

_The following is a question and should be treated as such_

### Policy enforcement in the code

1. For the destination Service ClusterIP to be whitelisted by a NetworkPolicy the requirements is that the set of labels in the `.spec.selector `in the Service definition ALL match with the set of labels in the `.spec.egress[].to[].podSelector.matchLabels` (of the `NetworkPolicy`) ([code](https://github.com/aws/amazon-network-policy-controller-k8s/blob/main/pkg/resolvers/endpoints.go#L420-L424))
2. If the NetworkPolicy lists ports on which traffic is allowed, then in addition to the above requirement, the service Port must match with Container Port of the destination Pods. ([code](https://github.com/aws/amazon-network-policy-controller-k8s/blob/main/pkg/resolvers/endpoints.go#L443-L446)).
3. The above item no. 2, also goes back to the [last requirement](https://docs.aws.amazon.com/eks/latest/userguide/cni-network-policy.html#cni-network-policy-considerations) for the NetworkPolicies. As an example, an UI pod can reach the Backend Pod on the containerPort: 8080 if the `NetworkPolicy` allows/opens up the traffic on port 8080. But this packet transit won’t happen via the Backend Service if the port defined in the Service spec accepts traffic at port 80.

### Can an alternate approach be used here?

Is the approach presented below possible? I can easily sense that the below logic, using pods, that can come in and go during scaling, may not be an ideal approach. But nevertheless, I am curious and request validation.

1. Find all the pods that the `NetworkPolicy` could potentially target using the selectors - Let’s call the list X
2. Find all the pods that the Service targets - Let’s call this list Y
3. Whitelist the Service `ClusterIP` if X ⊆ Y

Image

Image

Contributor guide

Open the contributing guide

Research direction

Read pkg/resolvers/endpoints.go around lines 420-446 and the linked EKS NetworkPolicy considerations first. Compare the current selector and port checks with the proposed X ⊆ Y pod-set approach; completion would require a maintainer-confirmed decision about support for this behavior and, if accepted, a scoped implementation plan.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
networking, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.