kubernetes-network-policy-recipes icon indicating copy to clipboard operation
kubernetes-network-policy-recipes copied to clipboard

Document CIDR blocks

Open ahmetb opened this issue 7 years ago • 1 comments

ahmetb avatar Nov 08 '17 00:11 ahmetb

The Network Policy below allow access to all, exept internal networks (192.168.0.0/16 and 172.23.40.0/24)

kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: allow-external
  namespace: dmz
spec:
  podSelector: {}
  policyTypes:
  - Egress
  - Ingress
  egress:
  - to:
    - ipBlock:
        cidr: 0.0.0.0/0
        except:
        - 192.168.0.0/16
        - 172.23.42.0/24
    - namespaceSelector:
        matchLabels:
          name: dmz

de1m avatar Jul 11 '18 11:07 de1m

Can namespaceSelector and ipBlock really be combined ? According to https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#networkpolicypeer-v1-networking-k8s-io

ipBlock -- IPBlock defines policy on a particular IPBlock. If this field is set then neither of the other fields can be.

rhuss avatar Nov 30 '22 19:11 rhuss

I don't think anyone claimed they can be combined.

ahmetb avatar Dec 01 '22 00:12 ahmetb

@rhuss that documentation refers to NetworkPolicyPeer. The example above is NetworkPolicy

boredabdel avatar Dec 01 '22 10:12 boredabdel

@boredabdel NetworkPolicyPeer is a subtype that is used for the to: and from: field for egress and ingress rules, respectively (so it's the type of the to: field in this example). The documentation refers precisely to this example.

@ahmetb aren't both used at the same time in the example in https://github.com/ahmetb/kubernetes-network-policy-recipes/issues/6#issuecomment-404137084 ? 🤔 (my comment above was actually referring to this example here)

rhuss avatar Dec 07 '22 17:12 rhuss

No, they're separate independent "to" targets in an array that's additive?

ahmetb avatar Dec 07 '22 17:12 ahmetb

gotcha. sorry for the noise.

rhuss avatar Dec 07 '22 20:12 rhuss