Skip to content

CNTRLPLANE-3010: Add API-side validation to enforce prefixPolicy is not set when username expression is used#2771

Open
ShazaAldawamneh wants to merge 2 commits intoopenshift:masterfrom
ShazaAldawamneh:CNTRLPLANE-3010
Open

CNTRLPLANE-3010: Add API-side validation to enforce prefixPolicy is not set when username expression is used#2771
ShazaAldawamneh wants to merge 2 commits intoopenshift:masterfrom
ShazaAldawamneh:CNTRLPLANE-3010

Conversation

@ShazaAldawamneh
Copy link
Contributor

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:

  • Rejecting configurations where expression is set and prefixPolicy is Prefix
  • Allowing configurations where expression is set and prefixPolicy is NoPrefix

…when username expression is used

Signed-off-by: Shaza Aldawamneh <shaza.aldawamneh@hotmail.com>
@openshift-ci-robot
Copy link

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Mar 18, 2026
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 18, 2026

@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.

Details

In response to this:

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:

  • Rejecting configurations where expression is set and prefixPolicy is Prefix
  • Allowing configurations where expression is set and prefixPolicy is NoPrefix

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.

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 18, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

Important

Review skipped

Auto reviews are limited based on label configuration.

🚫 Review skipped — only excluded labels are configured. (1)
  • do-not-merge/work-in-progress

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 7e9a9b32-2b47-40d0-9b27-3b05a8fa3eeb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 18, 2026

Hello @ShazaAldawamneh! Some important instructions when contributing to openshift/api:
API design plays an important part in the user experience of OpenShift and as such API PRs are subject to a high level of scrutiny to ensure they follow our best practices. If you haven't already done so, please review the OpenShift API Conventions and ensure that your proposed changes are compliant. Following these conventions will help expedite the api review process for your PR.

@openshift-ci openshift-ci bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 18, 2026
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 18, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign joelspeed for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

…when username expression is used

Signed-off-by: Shaza Aldawamneh <shaza.aldawamneh@hotmail.com>
@openshift-ci-robot
Copy link

openshift-ci-robot commented Mar 18, 2026

@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.

Details

In response to this:

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:

  • Rejecting configurations where expression is set and prefixPolicy is Prefix
  • Allowing configurations where expression is set and prefixPolicy is NoPrefix

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.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 18, 2026

@ShazaAldawamneh: all tests passed!

Full PR test history. Your PR dashboard.

Details

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

@ShazaAldawamneh ShazaAldawamneh changed the title [WIP]: CNTRLPLANE-3010: Add API-side validation to enforce prefixPolicy is not set when username expression is used CNTRLPLANE-3010: Add API-side validation to enforce prefixPolicy is not set when username expression is used Mar 18, 2026
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 18, 2026
// +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"
Copy link
Contributor

Choose a reason for hiding this comment

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

We want this for groups also right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants