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

fix(k8spsphostnetworkingports): CEL fixes for hostNetwork variable and message #589

Conversation

julianKatz
Copy link
Contributor

@julianKatz julianKatz commented Aug 29, 2024

My updates to the suite.yaml file yielded an unexpected failure due to an incorrect CEL expression:

        unexpected number of violations: got 1 violations but want none: got messages [failed expression: (has(request.operation) && request.operation == "UPDATE") ||
(!has(variables.params.hostNetwork) || !variables.params.hostNetwork ? (has(variables.anyObject.spec.hostNetwork) && !variables.anyObject.spec.hostNetwork) : true)]

By contrast, a run of gator verify -v . --enable-k8s-native-validation=false yielded a fully passing suite.yaml.

This failed expression was actually failing due to its messageExpression, as non-primitive types cannot be combined with strings as in some interpreted languages (like rego). Unfortunately the compiler does not indicate that the messageExpression is the source of the problem.

Once the message was fixed, I resolved the incorrect violation expression to fix the bug in the handling of params.hostNetwork.

@julianKatz julianKatz requested a review from a team as a code owner August 29, 2024 00:22
@julianKatz julianKatz force-pushed the k8spsphostnetworkingports-exemptImages branch 2 times, most recently from bbaf6c3 to 8b43806 Compare August 29, 2024 01:01
@julianKatz julianKatz force-pushed the k8spsphostnetworkingports-exemptImages branch 3 times, most recently from 1acb967 to 7266367 Compare August 30, 2024 18:44
Copy link
Contributor

@apeabody apeabody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @julianKatz!

Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

message

My updates to the suite.yaml file yielded an expected failure due to an
incorrect CEL expression:

```
        unexpected number of violations: got 1 violations but want none: got messages [failed expression: (has(request.operation) && request.operation == "UPDATE") ||
(!has(variables.params.hostNetwork) || !variables.params.hostNetwork ? (has(variables.anyObject.spec.hostNetwork) && !variables.anyObject.spec.hostNetwork) : true)]
```

By contrast, a run of `gator verify -v .
--enable-k8s-native-validation=false` yielded a fully passing
suite.yaml.

This expression was actually failing due to its `messageExpression`, as
non-primitive types cannot be combined with strings as in some
interpreted languages (like rego).  Unfortunately the compiler does not
indicate that the messageExpression is the source of the problem.

Once the message was fixed, I resolved the incorrect violation
expression to fix the bug in the handling of params.hostNetwork.

Signed-off-by: juliankatz <[email protected]>
@julianKatz julianKatz force-pushed the k8spsphostnetworkingports-exemptImages branch from 7266367 to fc386d9 Compare August 30, 2024 20:13
@apeabody apeabody merged commit 525a005 into open-policy-agent:master Aug 30, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants