api icon indicating copy to clipboard operation
api copied to clipboard

Add EscapingExamples

Open mdbooth opened this issue 4 months ago • 7 comments

Adds a set of example which demonstrate the effects of escaping when generating validation rules. Specifically:

  • `` vs "" for rule quoting
  • "" vs r'' in CEL expressions

These tests justify the following general recommendations to avoid complex escaping:

  • Always prefer `` for validation rules
  • Always prefer r'' for strings in CEL expressions

mdbooth avatar Nov 07 '25 13:11 mdbooth

Pipeline controller notification This repository 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. Review these jobs and use /test <job> to manually trigger optional jobs most likely to be impacted by the proposed changes.

openshift-ci-robot avatar Nov 07 '25 13:11 openshift-ci-robot

Hello @mdbooth! 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[bot] avatar Nov 07 '25 13:11 openshift-ci[bot]

[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 deads2k for approval. For more information see the Code Review Process.

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

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

openshift-ci[bot] avatar Nov 07 '25 13:11 openshift-ci[bot]

@mdbooth: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/lint 73fa3337f3b04e05b535781292839ab47c79b408 link true /test lint

Full PR test history. Your PR dashboard.

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.

openshift-ci[bot] avatar Nov 07 '25 16:11 openshift-ci[bot]

@JoelSpeed The linter is rejecting because apparently Pattern is banned in this repo. That obviously make this example impossible to write.

However, I also don't think it's a good idea. Certainly CEL has a lot of validation functions which we should require folks to use in preference to custom patterns. And as discussed, format markers in preference to those with the security related carve-outs documents in https://github.com/openshift/api/pull/2574. But if you're validating something that doesn't follow a standard kubernetes pattern then using Pattern is clearer and more concise than doing the same thing in a CEL expression. Quite apart from anything else, as demonstrated in this PR there are fewer escaping-related footguns.

A quick grep for Pattern in this repo shows that most, but critically far from all, of them should not exist.

Not sure what to do with this. My recommendation would be to remove the prohibition on Pattern and replace it with a softer review requirement that it needs a good use case. If you really want to stick with a ban then I'd also have to update https://github.com/openshift/api/pull/2574 to document that, as well as removing it here.

mdbooth avatar Nov 10 '25 11:11 mdbooth

PR needs rebase.

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.

openshift-merge-robot avatar Nov 12 '25 09:11 openshift-merge-robot

Apart from needing a rebase, this an interesting and useful example, thanks!

We can override the linting that suggests we aren't allowed a pattern, but the pointer bits should be fixed

JoelSpeed avatar Nov 28 '25 16:11 JoelSpeed