Skip to content

fix(rbac): dedup seeded scopes#2187

Merged
jordan-umusu merged 2 commits intomainfrom
fix/dedup-scope-seeding
Feb 25, 2026
Merged

fix(rbac): dedup seeded scopes#2187
jordan-umusu merged 2 commits intomainfrom
fix/dedup-scope-seeding

Conversation

@jordan-umusu
Copy link
Collaborator

@jordan-umusu jordan-umusu commented Feb 25, 2026

Problem

Registry action scopes were being seeded in two places: as platform scopes (organization_id = NULL) and again as per-organization custom scopes. Because both used the same scope
names, this created duplicate scope records and redundant role_scope links, which inflated RBAC data and made scope assignment non-canonical.

Solution

This PR makes platform scopes the single source of truth for registry actions and removes duplicate data paths:


Summary by cubic

Canonicalizes duplicate registry action scopes by remapping role-scope links to platform scopes and deleting redundant custom scopes. Seeding now inserts platform scopes only, and the migration is constrained to registry action scopes (execute) to avoid touching unrelated scopes.

  • Bug Fixes

    • Constrained dedupe to registry action scopes (resource=action, action=execute) using name+source_ref; remap role_scope links to platform scopes, drop stale custom links, and delete duplicate custom scope rows.
    • Updated seed_registry_scopes to seed platform scopes only; custom seeding paused until org-specific keys differ.
    • Adjusted tests to expect only platform insertions and zero custom duplicates; seeding remains idempotent.
  • Migration

    • Run database migrations (alembic upgrade head).
    • Downgrade is irreversible due to data cleanup.

Written for commit c098cd6. Summary will update on new commits.

@jordan-umusu jordan-umusu force-pushed the fix/dedup-scope-seeding branch from 069f520 to a6f8f9c Compare February 25, 2026 20:19
@jordan-umusu jordan-umusu marked this pull request as ready for review February 25, 2026 20:35
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="alembic/versions/c9e4f54f0a2b_canonicalize_duplicate_custom_scope_links.py">

<violation number="1" location="alembic/versions/c9e4f54f0a2b_canonicalize_duplicate_custom_scope_links.py:73">
P1: Migration queries lack a `source` filter, risking deletion of legitimate org-created custom scopes. All three steps match scopes solely by `name`, but the `scope` table has a `source` column (`'platform'` / `'custom'`). Adding a filter like `AND custom_scope.source = 'platform'` (if the seeding bug wrote duplicates with platform source) or an equivalent constraint would prevent accidental deletion of intentional org-specific custom scopes that coincidentally share a name with a platform scope. This is especially important given the migration is irreversible.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@daryllimyt daryllimyt left a comment

Choose a reason for hiding this comment

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

lgtm

@jordan-umusu jordan-umusu merged commit fe6d17a into main Feb 25, 2026
17 checks passed
@jordan-umusu jordan-umusu deleted the fix/dedup-scope-seeding branch February 25, 2026 23:27
daryllimyt pushed a commit that referenced this pull request Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants