-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix CNP/CCNP update when selectors change from nil to empty non-nil slices #33506
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
Conversation
/test |
Also, I think we should extend the proposed behavior to:
WDYT @christarazi ? |
6040abc
to
28796ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find, LGTM. Could you add a unit test similar to #33439 to actually test the expected behavior end to end?
Actually we already have a similar test to validate the generated policy map starting from an empty non-nil ToEndpoints slice: cilium/pkg/policy/l4_filter_test.go Lines 2274 to 2306 in 3f8ec1d
But I have added once more to test the propagation of rules update in the policy repository using the same CNP as in #33432 (see commit 8c2eee0) I did that because before the fix the update would have been discarded here: cilium/pkg/policy/k8s/cilium_network_policy.go Lines 39 to 41 in 3f8ec1d
Is this enough? I'm afraid a more comprehensive e2e test (from the policy watcher down to the policy map) might not be trivial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pippolo84 Great catch Fabio!
XorNil is a helper that returns true only if one of the two input slices is nil and the other is not. It is useful when comparing two slices and the semantic of a nil slice is different from the semantic of an empty non-nil one. Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
The semantic of a nil slice in one of the IngressCommonRule fields is different from the semantic of an empty non-nil slice. In order to compare two IngressCommonRule instances correctly, we add a custom DeepEqual method the explicitly checks for this case before calling the autogenerated method. This allows to correctly propagate CNP/CCNP updates when, for example, the FromEndpoints selector is changed from nil to an empty non-nil slice. In the latter case, the CNP should not select any identity, falling back to the default behavior (e.g: default deny for an allow policy). Fixes: e97df7b ("policy: Do not select any identity with ingress empty slices") Fixes: cilium#33432 Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
The semantic of a nil slice in one of the EgressCommonRule fields is different from the semantic of an empty non-nil slice. In order to compare two EgressCommonRule instances correctly, we add a custom DeepEqual method the explicitly checks for this case before calling the autogenerated method. This allows to correctly propagate CNP/CCNP updates when, for example, the ToEndpoints selector is changed from nil to an empty non-nil slice. In the latter case, the CNP should not select any identity, falling back to the default behavior (e.g: default deny for an allow policy). Fixes: 6ccd044 ("policy: Do not select any identity with egress empty slices") Fixes: cilium#33432 Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
Add a non regression test for GitHub issue cilium#33432: updating a CNP with a nil ToEndpoints slice to an empty non-nil ToEndpoints slice should result in the update not being discarded and the rules in the policy repository reporting the empty non-nil ToEndpoints slice. Related: cilium#33432 Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
8c2eee0
to
fc74339
Compare
/test |
As suggested in #33432, the autogenerated DeepEqual methods to compare
IngressCommonRule
structs andEgressCommonRule
structs do not take into account that a nil slice in one of the fields should not be compared equal to a empty non-nil slice in the same field.Since #29608, the semantic of a empty non-nil slice in both Ingress and Egress section of CNPs and CCNPs has been changed to not select any identity.
Therefore, a CNP with a nil ToEndpoints should not compare equal to a CNP with an empty non-nil ToEndpoints fields, otherwise the following update:
-->
is incorrectly discarded, instead of being propagated to the policy repository.
Related: #29608
Fixes: #33432