Skip to content

Allow label scoped resources in POLICIES_STRING_REGEX - #7178

Open
Goyamjain06 wants to merge 6 commits into
pipe-cd:masterfrom
Goyamjain06:fix/7172-rbac-label-regex
Open

Allow label scoped resources in POLICIES_STRING_REGEX#7178
Goyamjain06 wants to merge 6 commits into
pipe-cd:masterfrom
Goyamjain06:fix/7172-rbac-label-regex

Conversation

@Goyamjain06

@Goyamjain06 Goyamjain06 commented Aug 15, 2026

Copy link
Copy Markdown
  • Fixes Label scoped RBAC policies are rejected by the role dialog, so roles that use them cannot be edited #7172
  • POLICIES_STRING_REGEX now accepts an optional {key:value,...} label block after each resource type, using the same shape as RESOURCES_LABELS_REGEX (used in parseRBACPolicies).
  • This stops the Add/Edit Role dialogs from rejecting label-scoped RBAC policies.
  • The label block requires at least one valid key:value pair and excludes ;, {, }, :, , from key/value characters, so a semicolon inside a label can no longer escape into the resources/actions separator (e.g. application{a=b;c:d} is rejected instead of being silently dropped by parseRBACPolicies), and empty ({}) or malformed ({garbage}) label blocks are rejected instead of passing validation.
  • Added web/src/constants/project.test.ts with 14 cases: no-label regression guard, label-scoped valid cases, and invalid formats (including the semicolon-escape and empty-label cases from review).
  • Verified: full make test/web suite passes (50 suites / 185 tests), including the add-role-dialog and edit-role-dialog tests.

Signed-off-by: Goyam Jain <goyam24224@iiitd.ac.in>
@netlify

netlify Bot commented Aug 15, 2026

Copy link
Copy Markdown

Deploy Preview for pipecd-site canceled.

Name Link
🔨 Latest commit 20dd7ac
🔍 Latest deploy log https://app.netlify.com/projects/pipecd-site/deploys/6a8ed4773699820009f064ce

Comment thread web/src/constants/project.ts Outdated
"resources=(" +
rbacResourceTypes()
.map((v) => v.replace(/\*/, "\\*"))
.map((v) => v.replace(/\*/, "\\*") + "(\\{[^}]*\\})?")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[^}]* also allows ;, which the parser can't handle. resources=application{a=b;c:d};actions=get passes validation but gets silently dropped by parseRBACPolicies, leaving the role with no policies

\\{[^;{}]*\\} fixes this while keeping the valid cases above. similarly, {} / {garbage} parse to empty labels, so the policy gets saved un-scoped. i think we should guard against that too

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for catching both of these — the semicolon-in-label escape and the empty/malformed label case. Fixed: the label block now excludes ;, {, }, :, , from key/value characters (so application{a=b;c:d} no longer escapes into the resources/actions separator), and it requires at least one valid key:value pair, so {} and {garbage} are rejected too. Pushed in ce7d41d.

])("matches policy with label scoped resources: %s", (policy) => {
expect(POLICIES_STRING_REGEX.test(policy)).toBe(true);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could you add resources=application{a=b;c:d};actions=get and resources=application{};actions=get to the invalid cases once the pattern is tightened? these are the cases where form validation and parseRBACPolicies currently disagree

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added both cases to the invalid-policy test list — resources=application{a=b;c:d};actions=get and resources=application{};actions=get — and confirmed the full suite still passes (50 suites / 185 tests) with all existing valid/invalid cases intact.

@areebahmeddd

Copy link
Copy Markdown

label block accept karta hai

Could you rewrite the description in English? a few lines are in Hinglish .. 🤔

…pty/malformed labels

Addresses review feedback from @areebahmeddd on pipe-cd#7178.

- The label block now requires at least one valid key:value pair and
  excludes ';', '{', '}', ':', ',' from key/value characters, so a
  semicolon inside a label can no longer escape into the
  resources/actions separator (e.g. application{a=b;c:d} is now
  rejected instead of being silently dropped by parseRBACPolicies).
- Empty ("{}") or malformed ("{garbage}") label blocks are now
  rejected instead of passing validation as bare/broken labels.
- Added the two invalid cases the reviewer requested to
  project.test.ts and confirmed all existing valid/invalid cases
  still pass.

Signed-off-by: Goyam Jain <goyam24224@iiitd.ac.in>
@Goyamjain06

Copy link
Copy Markdown
Author

Apologies for that — the description had a few lines in Hinglish. I've rewritten it fully in English while keeping the same technical content.

@Goyamjain06

Copy link
Copy Markdown
Author

Hi @areebahmeddd, just checking in on this one — I've updated the description as requested. Let me know if there are any further changes needed, or if this is ready for another look. Thanks for the feedback so far!

@areebahmeddd

Copy link
Copy Markdown

looks good. maybe @khanhtc1202 will give a final look and merge 🙂

@rahulshendre rahulshendre added the kind/bug Something isn't working as expected label Aug 26, 2026
rahulshendre
rahulshendre previously approved these changes Aug 26, 2026

@rahulshendre rahulshendre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM @Goyamjain06, thank you : )

Thanks @areebahmeddd for the review.

Copilot AI lite review requested due to automatic review settings August 26, 2026 11:23
@rahulshendre

Copy link
Copy Markdown
Contributor

cc @armistcxy @mohammedfirdouss

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the web UI RBAC policy-string validation so that label-scoped resources (e.g. application{env:prod}) are accepted by POLICIES_STRING_REGEX, unblocking Add/Edit Role dialogs from rejecting policies that the parser/formatter already supports.

Changes:

  • Extend POLICIES_STRING_REGEX to allow an optional {key:value(,key:value)*} label block after each resource type.
  • Add a dedicated unit test file covering valid label-scoped policies and several invalid formats.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
web/src/constants/project.ts Expands the RBAC policy regex with reusable label-pair/label-block subpatterns.
web/src/constants/project.test.ts Adds unit tests validating label-scoped policy strings and rejecting invalid forms.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread web/src/constants/project.ts Outdated
// A single label pair, e.g. "env:prod". Key/value exclude the characters
// that are structurally significant elsewhere in the grammar (`;{}:,`) so a
// label block can't accidentally swallow the resources/actions separator.
const LABEL_PAIR = "[^;{}:,]+:[^;{}:,]+";

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — fixed. LABEL_PAIR now excludes \s alongside ;{}:,, so a \n\n inside a label key/value can no longer act as a policy separator. Added a regression case for this (newline inside a label value) and reran the full suite — 186/186 passing. Pushed in 20dd7ac.

Comment on lines +30 to +32
"resources=application", // missing actions
"resources=application{a=b;c:d};actions=get", // semicolon escapes the label block
"resources=application{};actions=get", // empty label block

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — fixed. LABEL_PAIR now excludes \s alongside ;{}:,, so a \n\n inside a label key/value can no longer act as a policy separator. Added a regression case for this (newline inside a label value) and reran the full suite — 186/186 passing. Pushed in 20dd7ac.

…jection

Signed-off-by: Goyam Jain <goyam24224@iiitd.ac.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/web kind/bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Label scoped RBAC policies are rejected by the role dialog, so roles that use them cannot be edited

5 participants