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 does not take effect if NetworkPolicy name is too long. #59

Closed
bakavets opened this issue Nov 23, 2023 · 5 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@bakavets
Copy link

bakavets commented Nov 23, 2023

What happened: NetworkPolicy does not take effect if NetworkPolicy name is too long.

Attach logs: N/A

What you expected to happen: NetworkPolicy should work regardless of the name length.

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

apiVersion: v1
kind: Namespace
metadata:
   name: dev
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kuber
  namespace: dev
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: app
        image: nginx
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-egress-evolution-reader-backend-evolution-reader-backend-dev
  namespace: dev
spec:
  podSelector:
    matchLabels:
      app: nginx
  egress:
    - ports:
        - protocol: UDP
          port: 53
        - protocol: TCP
          port: 53
      to:
        - podSelector:
            matchLabels:
              k8s-app: kube-dns
          namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: kube-system
    - ports:
        - protocol: TCP
          port: 443
      to:
        - ipBlock:
            cidr: 0.0.0.0/0
  policyTypes:
    - Egress

SSH to the pod and run the following commands inside it:

curl http://www.google.com and curl https://www.google.com

Both commands will succeed on ports 80 and 443, but NetworkPolicy does not allow 80 port.
If you change the NetworkPolicy name from allow-egress-evolution-reader-backend-evolution-reader-backend-dev to the shorter one e.g. allow-egress NetworkPolicy will work and port 80 will not be allowed for egress traffic only 443.

Network policy starts taking effect only if the name length is less or equal to 63.

Anything else we need to know?:
The issue was noticed after migrating Calico network policy enforcement to the native network policy engine of VPC CNI.
Network policies have been working before with Calico.
Calico was used in conjunction with VPC CNI only for the Network policy engine.

Environment:

  • Kubernetes version (use kubectl version): Server Version: v1.27.7-eks-4f4795d
  • CNI Version: v1.15.4-eksbuild.1
  • OS (e.g: cat /etc/os-release):
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
SUPPORT_END="2025-06-30"
  • Kernel (e.g. uname -a): Linux x86_64 GNU/Linux
@bakavets bakavets added the bug Something isn't working label Nov 23, 2023
@jayanthvn
Copy link
Contributor

Moving this to network policy agent repo..

@jayanthvn jayanthvn transferred this issue from aws/amazon-vpc-cni-k8s Nov 24, 2023
@achevuru
Copy link
Contributor

We don't enforce any limitations. We will check and get back on this.

@achevuru
Copy link
Contributor

achevuru commented Dec 7, 2023

Network policy controller currently places a 64 char limit on the custom resources it creates based on the Network Policy name. We will try to relax this restriction in the next release.

Moving this over to Network Policy controller repo.

@achevuru achevuru transferred this issue from aws/aws-network-policy-agent Dec 7, 2023
haouc added a commit that referenced this issue Dec 7, 2023
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. Ensure you have added the unit tests for your changes.
2. Ensure you have included output of manual testing done in the Testing
section.
3. Ensure number of lines of code for new or existing methods are within
the reasonable limit.
4. Ensure your change works on existing clusters after upgrade.
-->
**What type of PR is this?**

<!--
Add one of the following:
bug
cleanup
documentation
feature
-->
bug
**Which issue does this PR fix**:
#59 

**What does this PR do / Why do we need it**:
We revert a label improvement which can cause PE creation failure when
using long name for its network policy.

**If an issue # is not available please add steps to reproduce and the
controller logs**:


**Testing done on this change**:
<!--
output of manual testing/integration tests results and also attach logs
showing the fix being resolved
-->

**Automation added to e2e**:
<!--
List the e2e tests you added as part of this PR.
If no, create an issue with enhancement/testing label
-->

**Will this PR introduce any new dependencies?**:
<!--
e.g. new K8s API
-->

**Will this break upgrades or downgrades. Has updating a running cluster
been tested?**:


**Does this PR introduce any user-facing change?**:
<!--
If yes, a release note update is required:
Enter your extended release note in the block below. If the PR requires
additional actions
from users switching to the new release, include the string "action
required".
-->

```release-note

```

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
@haouc
Copy link
Contributor

haouc commented Dec 23, 2023

We are making a release to correct this limitation and will update when the release is available to all EKS clusters. Thanks.

@haouc haouc self-assigned this Dec 23, 2023
@haouc
Copy link
Contributor

haouc commented Jan 9, 2024

@bakavets EKS has updated platform version which include the latest version of this controller. Please check the regarding your clusters' platform version in the release note and verify if the issue is resolved. Thanks.

@haouc haouc closed this as completed Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants