Skip to content

Change to network policy behavior after version 1.2.3 #481

@stefansedich

Description

@stefansedich

What happened:
We utilize https://zero-to-jupyterhub.readthedocs.io/en/latest/ within our environments which manages a network policy for the Jupyterhub hub component, this has been operating without issue for a number of agent releases until we attempted to upgrade the agent from 1.2.3 to 1.2.7.

After this upgrade we began to experience connective issues from the hub component to the API server, after some investigation we have discovered that there has been a change in behavior since version 1.2.3 that changes how policies are handled.

I have created a minimal reproduction based on the Jupyter network policy that demonstrates this issue, the following will work without issue running version 1.2.3 of the agent and allow egress from the pod to the API server, however when running version 1.2.7 of the agent the egress will be blocked.

Attach logs

Can provide logs if they will be beneficial here however the reproduction above clearly demonstrates the change in behavior.

What you expected to happen:

The egress to the API server from the pod will not be blocked.

How to reproduce it (as minimally and precisely as possible):

#!/bin/bash

echo "Creating pod..."
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: demo
  labels:
    app: demo
spec:
  containers:
  - image: curlimages/curl:latest
    command:
      - "sleep"
      - "604800"
    imagePullPolicy: IfNotPresent
    name: curl
  restartPolicy: Always
EOF

echo "Waiting for pod to be ready..."
kubectl wait --for=condition=ready pod/demo --timeout=300s

echo "Pod is ready! Running curl command..."
kubectl exec demo -- curl -v --connect-timeout 3 https://172.20.0.1

echo "Applying network policy..."
kubectl apply -f - <<EOF
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: test
spec:
  podSelector:
    matchLabels:
      app: demo
  egress:
  - ports:
    - port: 53
      protocol: UDP
    - port: 53
      protocol: TCP
    to:
    - ipBlock:
        cidr: 172.16.0.0/12
  - to:
    - ipBlock:
        cidr: 0.0.0.0/0
        except:
        - 172.16.0.0/12
  - to:
    - ipBlock:
        cidr: 172.16.0.0/12
  policyTypes:
  - Egress
EOF

echo "Running curl command again after applying network policy..."
kubectl exec demo -- curl -v --connect-timeout 3 https://172.20.0.1

echo "Cleaning up - removing pod and network policy ..."
kubectl delete pod demo --force --grace-period=0
kubectl delete networkpolicy test

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version): 1.33.4
  • CNI Version: 1.20.4
  • Network Policy Agent Version: 1.2.7
  • OS (e.g: cat /etc/os-release):
  • Kernel (e.g. uname -a):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions