-
Notifications
You must be signed in to change notification settings - Fork 373
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
NotSameLabel Match or Invert match for SameLabel #6424
Comments
@Dyanngg could you take a look at this? |
@jsalatiel if you look at the documentation https://github.com/antrea-io/antrea/blob/main/docs/antrea-network-policy.md#antrea-networkpolicy, the namespace-scoped |
Hi @Dyanngg, the problem with KNP ( and the reason why we always forced the developers to avoid it ) is the implicit isolation when anything selects a pod. That goes way different from what you see in common firewalls. |
@jsalatiel We discussed this at our community meeting this week, and at the moment we do not believe that this is something we should add to the API, for the reasons described above. Writing a policy like this one (your example): apiVersion: crd.antrea.io/v1alpha1
kind: ClusterNetworkPolicy
spec:
priority: 3
tier: SecurityOps
egress:
# ORG1
- name: org1
action: Drop
appliedTo:
- namespaceSelector:
matchLabels:
org: 'org1'
to:
- namespaceSelector:
matchExpressions:
- { key: env, operator: NotIn, values: [ org1 ] }
# ORG2
- name: org2
action: Drop
appliedTo:
- namespaceSelector:
matchLabels:
org: 'org2'
to:
- namespaceSelector:
matchExpressions:
- { key: env, operator: NotIn, values: [ org2 ] }
# ORG3
- name: org3
action: Drop
appliedTo:
- namespaceSelector:
matchLabels:
org: 'org3'
to:
- namespaceSelector:
matchExpressions:
- { key: env, operator: NotIn, values: [ org3 ] } does not scale very well from an implementation perspective, for the same reason that this policy would not scale very well if it were supported: apiVersion: crd.antrea.io/v1beta1
kind: ClusterNetworkPolicy
metadata:
name: 201-isolate-by-env
spec:
priority: 1
tier: SecurityOps
appliedTo:
- namespaceSelector:
matchExpressions:
- { key: org, operator: Exists }
egress:
- action: Drop
to:
- namespaces:
notSameLabels: [org] @Dyanngg can correct me if I am wrong, but actually writing apiVersion: crd.antrea.io/v1alpha1
kind: ClusterNetworkPolicy
spec:
priority: 3
tier: SecurityOps
name: org1
appliedTo:
- namespaceSelector:
matchLabels:
org: 'org1'
egress:
- name: org1-to-org2
action: Drop
to:
- namespaceSelector:
matchLabels:
org: 'org2'
- name: org1-to-org3
action: Drop
to:
- namespaceSelector:
matchLabels:
org: 'org3' You would end up with |
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment, or this will be closed in 90 days |
Now that antrea 2.0 has been released with new features I have started tryinng to simplify my netpolicies.
Reading the documentation I saw the SameLabels matcher and I thought that it would help me to reduce a pretty big acnp I have, but unfortunately I could not make that work because actually I would need an invert match for that. I will write an use case here using the org label ( for tenants ) that you have in documentation.
Scenario:
One has a cluster with several tenants and these tenants can never cross communicate. They can only talk to the same tenant. There is also a need of deny all in baseline tier. Dev team in any org/tenant can create ANP in application tier only, being denied any other tier or ACNP creation by a policy engine.
The cluster operator, to comply with those requirements, have created an ACNP in SecurityOps tier with the following ( antrea 1.14) :
( Since there is no dynamic matching, it has to match any org by name, so I will do some simplification in the scope of this example: 3 orgs and only egress )
That policy works pretty well:
The problem with the policy is that it is not scalable. Every new org needs a hardcoded in the policy file and that can grow too much.
So I decided to check if SameLabels matcher could help. First I tried directly the example from the docs:
The traffic between orgs is indeed blocked, but the traffic inside the same org will be accepted by default ( ignoring the deny all from baseline tier )
So i tried a bit different
In this case the traffic from different orgs would be dropped and the traffic from the same org would reach the baseline tier and be dropped, the problem is that the Pass for the sameLabel will make all other tiers be skipped including any ANP in application tier created by the developers.
So I was thinking if antrea could implement a notSameLabels operator that would allow the following rule:
That should work dropping any traffic when "org" exists in the namespace and they do not match and since that's dynamic any new org added would work without requiring changes to the acnp.
The text was updated successfully, but these errors were encountered: