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

NetworkPolicy: unable to allow ingress by CIDR #1764

Closed
mattfenwick opened this issue Jan 20, 2021 · 2 comments · Fixed by #1767
Closed

NetworkPolicy: unable to allow ingress by CIDR #1764

mattfenwick opened this issue Jan 20, 2021 · 2 comments · Fixed by #1767
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@mattfenwick
Copy link
Contributor

mattfenwick commented Jan 20, 2021

Describe the bug

A NetworkPolicy which allows ingress traffic by an IPBlock/CIDR does not allow traffic from the IPBlock on a KinD cluster running antrea-0.12.0.

To Reproduce

Create a KinD cluster:

#!/usr/bin/env bash

set -xv
set -e

CLUSTER=${CLUSTER:-netpol-antrea}

if [[ ! -d antrea ]] ; then
  git clone https://github.com/vmware-tanzu/antrea.git
fi
pushd antrea
  git checkout v0.12.0
  pushd ci/kind
    ./kind-setup.sh create "$CLUSTER"
  popd
popd

netpol.yaml:

  • NOTE: the cidr is chosen so that the first three octets match the first three octets of the IP of at least one of the pods in the setup
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: vary-ingress-28-0-0-0-10
  namespace: x
spec:
  ingress:
  - from:
    - ipBlock:
        cidr: 10.10.1.12/24
    ports:
    - port: 80
      protocol: TCP
  podSelector:
    matchLabels:
      pod: a
  policyTypes:
  - Ingress

Create netpol and pods and run probe using Cyclonus:

Namespace/pods:

Namespace x

  • labels: {"ns": "x"}
  • pods:
    • pod a
      • labels {"pod": "a"}
      • ip: 10.10.1.11
    • pod b
      • labels {"pod": "b"}
      • ip: 10.10.2.26
    • pod c
      • labels {"pod": "c"}
      • ip: 10.10.2.25
        Namespace y
  • labels: {"ns": "y"}
  • pods:
    • pod a
      • labels {"pod": "a"}
      • ip: 10.10.1.12
    • pod b
      • labels {"pod": "b"}
      • ip: 10.10.2.27
    • pod c
      • labels {"pod": "c"}
      • ip: 10.10.2.28
        Namespace z
  • labels: {"ns": "z"}
  • pods:
    • pod a
      • labels {"pod": "a"}
      • ip: 10.10.2.22
    • pod b
      • labels {"pod": "b"}
      • ip: 10.10.2.23
    • pod c
      • labels {"pod": "c"}
      • ip: 10.10.2.24

Expected

Expected connectivity matrix:

There are 9 pods, so 9x9 = 81 possible requests from pod to pod.
The pod issuing the request is in the left column; the pod receiving the request is in the top row.
An X means the request was denied; a . means the request was allowed.

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  -  | X/A | X/B | X/C | Y/A | Y/B | Y/C | Z/A | Z/B | Z/C |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| x/a | .   | .   | .   | .   | .   | .   | .   | .   | .   |
| x/b | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| x/c | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| y/a | .   | .   | .   | .   | .   | .   | .   | .   | .   |
| y/b | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| y/c | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| z/a | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| z/b | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| z/c | X   | .   | .   | .   | .   | .   | .   | .   | .   |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

Actual behavior

Connectivity on kube/antrea:

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|  -  | X/A | X/B | X/C | Y/A | Y/B | Y/C | Z/A | Z/B | Z/C |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
| x/a | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| x/b | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| x/c | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| y/a | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| y/b | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| y/c | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| z/a | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| z/b | X   | .   | .   | .   | .   | .   | .   | .   | .   |
| z/c | X   | .   | .   | .   | .   | .   | .   | .   | .   |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

Versions:
Please provide the following information:

  • Antrea version: v0.12.0

  • KinD version 0.9.0

  • Kubernetes version:

     kubectl version
     Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-12T01:08:32Z", GoVersion:"go1.15.4", Compiler:"gc", Platform:"darwin/amd64"}
     Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.1", GitCommit:"206bcadf021e76c27513500ca24182692aabd17e", GitTreeState:"clean", BuildDate:"2020-09-14T07:30:52Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"} 
    
  • Container runtime: containerd from KinD v0.9.0

  • Linux kernel version on the Kubernetes Nodes (uname -r): 4.19.121-linuxkit

Additional context

@mattfenwick mattfenwick added the kind/bug Categorizes issue or PR as related to a bug. label Jan 20, 2021
@tnqn
Copy link
Member

tnqn commented Jan 20, 2021

@mattfenwick Thanks for catching it!
This was caused by the non-standard CIDR 10.10.1.12/24 used in the policy. Apparently K8s allows it, however, OVS rejects it and it was then ignored:

E0120 16:44:25.220545       1 entry.go:314] Received OpenFlow1.3 error: OFPBMC_BAD_WILDCARDS on message OFPT_EXPERIMENTER

I've made a quick fix #1767 for it.

@tnqn tnqn added this to the Antrea v0.13.0 release milestone Jan 20, 2021
@mattfenwick
Copy link
Contributor Author

🎉 🎉 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants