Skip to content

Conversation

@bowei
Copy link
Contributor

@bowei bowei commented Dec 18, 2025

Changes to implement option #3 for the port matching

Example (from #297)

apiVersion: policy.networking.k8s.io/v1alpha2
kind: ClusterNetworkPolicy
metadata:
  name: cluster-wide-deny
spec:
  tier: Admin
  priority: 0
  subject:
    namespaces:
      matchLabels:
        kubernetes.io/metadata.name: sensitive-ns
  ingress:
    - action: Deny
      name: select-all-deny-all
      from:
      - pods:
          namespaceSelector:
            matchLabels: {}
          podSelector:
            matchLabels: {}
  protocols:
    - tcp:
        destinationPort:
          number: 8080
        flags: [syn] # future extension example
    - tcp:
        destinationPort:
          range:
            start: 8080
            end: 9090
    - udp:
        destinationPort:
          number: 8080
    - udp:
        destinationPort:
          number: 9090
    - namedPort: http
    - namedPort: monitoring
    - icmp: # that doesn't exist yet, but may be added
        type: 7
        code: 3

@netlify
Copy link

netlify bot commented Dec 18, 2025

Deploy Preview for kubernetes-sigs-network-policy-api ready!

Name Link
🔨 Latest commit fcfa3cd
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-sigs-network-policy-api/deploys/694440b07fd1b10007e7154a
😎 Deploy Preview https://deploy-preview-347--kubernetes-sigs-network-policy-api.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: bowei
Once this PR has been reviewed and has the lgtm label, please assign tssurya for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 18, 2025
@bowei bowei force-pushed the pr-option-3 branch 2 times, most recently from 5d51a1c to c347f62 Compare December 18, 2025 16:37
Example (from kubernetes-sigs#297)

apiVersion: policy.networking.k8s.io/v1alpha2
kind: ClusterNetworkPolicy
metadata:
  name: cluster-wide-deny
spec:
  tier: Admin
  priority: 0
  subject:
    namespaces:
      matchLabels:
        kubernetes.io/metadata.name: sensitive-ns
  ingress:
    - action: Deny
      name: select-all-deny-all
      from:
      - pods:
          namespaceSelector:
            matchLabels: {}
          podSelector:
            matchLabels: {}
  protocols:
    - tcp:
        destinationPort:
          number: 8080
        flags: [syn] # future extension example
    - tcp:
        destinationPort:
          range:
            start: 8080
            end: 9090
    - udp:
        destinationPort:
          number: 8080
    - udp:
        destinationPort:
          number: 9090
    - namedPort: http
    - namedPort: monitoring
    - icmp: # that doesn't exist yet, but may be added
        type: 7
        code: 3
@k8s-ci-robot
Copy link
Contributor

@bowei: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-network-policy-api-crd-e2e fcfa3cd link true /test pull-network-policy-api-crd-e2e

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

// if empty, it selects all Pods.
PodSelector metav1.LabelSelector `json:"podSelector"`
// UDP specific protocol matches.
UDP *ClusterNetworkPolicyProtocolUDP `json:"udp,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

sctp?

//
Protocol corev1.Protocol `json:"protocol"`
// ClusterNetworkPolicyProtocolTCP are TCP attributes to be matched.
type ClusterNetworkPolicyProtocolTCP struct {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can have one definition for now for tcp, udp and sctp? and then we can split if needed in the future


// NamespacedPod allows the user to select a given set of pod(s) in
// selected namespace(s).
type NamespacedPod struct {
Copy link
Member

Choose a reason for hiding this comment

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

why did you move it here?

// DestinationNamedPort selects a destination port on a pod based on the
// ContainerPort name. You can't use this in a rule that targets resources
// without named ports (e.g. Nodes or Networks).
DestinationNamedPort *ClusterNetworkPolicyProtocolNamedPort `json:"destinationNamedPort,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

// +kubebuilder:validation:Maximum=65535
//
Port int32 `json:"port"`
Number *int32 `json:"number,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

also a question about pointer vs non-pointer

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants