CNTRLPLANE-3010: Add API-side validation to enforce prefixPolicy is not set when username expression is used#2771
Conversation
…when username expression is used Signed-off-by: Shaza Aldawamneh <shaza.aldawamneh@hotmail.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@ShazaAldawamneh: This pull request references CNTRLPLANE-3010 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdded validation rules (gated by the ExternalOIDCWithUpstreamParity feature) that restrict combinations of OIDC claim-mapping fields: if a mapping uses a non-empty ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.11.3)Error: build linters: unable to load custom analyzer "kubeapilinter": tools/_output/bin/kube-api-linter.so, plugin: not implemented Comment |
|
Hello @ShazaAldawamneh! Some important instructions when contributing to openshift/api: |
…when username expression is used Signed-off-by: Shaza Aldawamneh <shaza.aldawamneh@hotmail.com>
|
@ShazaAldawamneh: This pull request references CNTRLPLANE-3010 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.22.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
Hey @ShazaAldawamneh - I left one question of curiosity but besides that I don't have any concerns :) I will point out that you may need to manually trigger jobs stuck on |
…when username expression is used Signed-off-by: Shaza Aldawamneh <shaza.aldawamneh@hotmail.com>
Signed-off-by: Shaza Aldawamneh <shaza.aldawamneh@hotmail.com>
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDC,rule="has(self.claim)",message="claim is required" | ||
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDCWithUIDAndExtraClaimMappings,rule="has(self.claim)",message="claim is required" | ||
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDCWithUpstreamParity,rule="has(self.claim) ? !has(self.expression) : has(self.expression)",message="precisely one of claim or expression must be set" | ||
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDCWithUpstreamParity,rule="has(self.expression) && size(self.expression) > 0 ? !has(self.prefixPolicy) || self.prefixPolicy != 'Prefix' : true",message="prefixPolicy must not be set to 'Prefix' when expression is set" |
There was a problem hiding this comment.
We could probably simplify this expression a bit to something like:
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDCWithUpstreamParity,rule="has(self.expression) && size(self.expression) > 0 ? !has(self.prefixPolicy) || self.prefixPolicy != 'Prefix' : true",message="prefixPolicy must not be set to 'Prefix' when expression is set" | |
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDCWithUpstreamParity,rule="size(self.?expression.orValue("")) > 0 && (self.?prefixPolicy.orValue("") == "" || self.?prefixPolicy.orValue("") == "NoPrefix")",message="prefixPolicy must not be set to 'Prefix' when expression is set" |
|
|
||
| // PrefixedClaimMapping configures a claim mapping | ||
| // that allows for an optional prefix. | ||
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDCWithUpstreamParity,rule="has(self.expression) && size(self.expression) > 0 ? !has(self.prefix) : true",message="prefix must not be set when expression is set" |
There was a problem hiding this comment.
Similar comment here, I think we could do something like:
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDCWithUpstreamParity,rule="has(self.expression) && size(self.expression) > 0 ? !has(self.prefix) : true",message="prefix must not be set when expression is set" | |
| // +openshift:validation:FeatureGateAwareXValidation:featureGate=ExternalOIDCWithUpstreamParity,rule="size(self.?expression.orValue("") > 0 && size(self.?prefix.orValue("")) == 0",message="prefix must not be set when expression is set" |
|
/lgtm Changes look good to me. Tests are passing fine. Issue was resolved with However, I am unsure whether these other tests will run after the lgtm. I hope so, so that we can get a definitive response on the viability of this. :) |
|
Scheduling tests matching the |
|
/lgtm cancel |
|
noticed that bryce had some concerns. :) |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
liouk
left a comment
There was a problem hiding this comment.
Just a couple of doc related observations.
| // +kubebuilder:validation:Enum={"", "NoPrefix", "Prefix"} | ||
| // +optional | ||
| // +unionDiscriminator | ||
| PrefixPolicy UsernamePrefixPolicy `json:"prefixPolicy"` |
There was a problem hiding this comment.
Current doc doesn't explain the expectation of the value of this field based on whether the expression is set or not, maybe worth adding something related.
| // Example: if `prefix` is set to "myoidc:" and the `claim` in JWT contains an array of strings "a", "b" and "c", the mapping will result in an array of string "myoidc:a", "myoidc:b" and "myoidc:c". | ||
| // | ||
| // +optional | ||
| Prefix string `json:"prefix"` |
There was a problem hiding this comment.
Similarly, should we add some text about what is expected in Prefix when the expression is set?
|
@ShazaAldawamneh: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Add a FeatureGateAwareXValidation rule to the UsernameClaimMapping type in the authentications.config.openshift.io CRD to reject configurations where prefixPolicy is set to Prefix when a username expression is also set.
Previously, this validation was only enforced at runtime in the CAO and HyperShift generation code. This change moves the validation to the API admission layer, providing stronger validation at resource creation/update time before the resource is persisted.
A prefixPolicy of Prefix is not applicable when using an expression-based username mapping since prefixes should be set directly within the expression itself if needed.
New test cases are added to the ExternalOIDCWithUpstreamParity CRD validation tests to cover: