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

Incorrect type for 'ports' field in "Network Policies" page examples #44825

Closed
WisePorterCloud opened this issue Jan 20, 2024 · 9 comments
Closed
Labels
language/en Issues or PRs related to English language needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/network Categorizes an issue or PR as relevant to SIG Network.

Comments

@WisePorterCloud
Copy link

I'am checking some samples about NetworkPolicy object and it seems to be bug in ports. According Kubernetes API reference it is array but in all samples published in https://kubernetes.io/docs/concepts/services-networking/network-policies/ there is ports as NetworkPolicyPort.

Example that it does not work properly (but without error during creation):

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: np
  namespace: space1
spec:
  podSelector: {}
  policyTypes:
    - Egress
  egress:
    - to:
      - namespaceSelector:
          matchLabels:
            kubernetes.io/metadata.name: space2
      ports:
        - protocol: TCP
          port: 53
        - protocol: UDP
          port: 53

Example that it works as expected:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: np
  namespace: space1
spec:
  podSelector: {}
  policyTypes:
    - Egress
  egress:
    - to:
      - namespaceSelector:
          matchLabels:
            kubernetes.io/metadata.name: space2
    - ports:
      - protocol: TCP
        port: 53
      - protocol: UDP
        port: 53
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Jan 20, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

SIG Docs takes a lead on issue triage for this website, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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/test-infra repository.

@dipesh-rawat
Copy link
Member

Page reported in issue: https://kubernetes.io/docs/concepts/services-networking/network-policies
/language en

@k8s-ci-robot k8s-ci-robot added the language/en Issues or PRs related to English language label Jan 20, 2024
@dipesh-rawat
Copy link
Member

/sig network

@k8s-ci-robot k8s-ci-robot added the sig/network Categorizes an issue or PR as relevant to SIG Network. label Jan 20, 2024
@dipesh-rawat
Copy link
Member

/retitle Incorrect type for 'ports' field in "Network Policies" page examples

@k8s-ci-robot k8s-ci-robot changed the title Network Policies Incorrect type for 'ports' field in "Network Policies" page examples Jan 20, 2024
@adityasamant25
Copy link
Contributor

Hi,
This is not a bug. It is as designed.
The hyphen has a significance.
Absence of the hyphen before ports signifies an AND condition between the to and ports rules.
Presence of the hyphen before ports signifies an OR condition between the to and ports rules.

Your first example translates to:
Allows all pods in namespace space1 to connect to all pods in namespaces with labels kubernetes.io/metadata.name: space2 on ports TCP 53 and UDP 53

Whereas the second example translates to:

Allows all pods in namespace space1 to connect to all pods in namespaces with labels kubernetes.io/metadata.name: space2 on all ports
** OR **
Allows all pods in namespace space1 to connect to all namespaces, pods and IP addresses on ports TCP 53 and UDP 53

Both are valid network policy definitions.
You need to configure the network policy based on the behaviour you need.

The below tool is handy if you want to translate the meaning of a network policy in a readable form.
https://orca.tufin.io/netpol/

@aakashdeshamne aakashdeshamne removed their assignment Jan 21, 2024
@WisePorterCloud
Copy link
Author

Hi, thank you so much for your explanation. It makes sense. Please can you reference me to the section in documentation where this is explained? I tried to find it out but without success.

Anyway we can close this ticket.

@adityasamant25
Copy link
Contributor

I'm not aware if the exact example you mentioned in this issue is documented.

There is a similar (not identical) scenario documented here:
https://kubernetes.io/docs/concepts/services-networking/network-policies/#behavior-of-to-and-from-selectors

@dipesh-rawat
Copy link
Member

Looks like the issue doesn't require any changes; the current documentation stands correct.

Anyway we can close this ticket.

Closing this issue in recognition of the issue reporter's indication to close it.

/close

@k8s-ci-robot
Copy link
Contributor

@dipesh-rawat: Closing this issue.

In response to this:

Looks like the issue doesn't require any changes; the current documentation stands correct.

Anyway we can close this ticket.

Closing this issue in recognition of the issue reporter's indication to close it.

/close

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/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/en Issues or PRs related to English language needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/network Categorizes an issue or PR as relevant to SIG Network.
Projects
None yet
Development

No branches or pull requests

5 participants