Skip to content

Match role scopes by index so authorizing a node doesn't scan every scope - #2646

Closed
shangyian wants to merge 1 commit into
DataJunction:mainfrom
shangyian:authz-scope-index
Closed

shangyian wants to merge 1 commit into
DataJunction:mainfrom
shangyian:authz-scope-index

Conversation

@shangyian

@shangyian shangyian commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Before, each node was compared against every scope. For endpoints that return tens of thousands of nodes, this checks a lot of scopes and could stall the worker serving it. With this change, each node generates its own few prefixes and looks them up in a set built from the scopes.

For example, let's say the caller has three scopes:

  • finance.*
  • marketing.campaigns.*
  • sales.revenue

The request is for the node ads.reports.daily.

Before

For this one node, the scan goes through every scope:

  1. Does finance.* cover ads.reports.daily? Check whether the name starts with finance.? no.
  2. Does marketing.campaigns.* cover it? Starts with marketing.campaigns.? No.
  3. Does sales.revenue match it exactly? No.

That's 3 comparisons, and all fail, so the node is denied or falls to the default policy. With 800 scopes it's 800 comparisons for one node, and the same again for each of the other 10K nodes one of these endpoints might return.

List endpoints (e.g., /dimensions/common/, /metrics/, /dimensions/) authorize every node they return, so a result returning tens of thousands of nodes could stall the worker serving it.

After

The scopes become two sets:

  • subtree prefixes: {finance, marketing.campaigns}
  • exact names: {sales.revenue}

For ads.reports.daily:

  1. Is ads.reports.daily in the exact set? No.
  2. Take the prefixes that end at a dot: ads, then ads.reports. Is either in the subtree set? No.

The number of lookups stays at 3 even with 800 scopes.

Test Plan

  • PR has an associated issue: #
  • make check passes
  • make test shows 100% unit test coverage

Deployment Plan

…cope

RBAC authorize compared each request against every scope the caller holds,
so a list endpoint returning tens of thousands of nodes cost
requests x scopes on the event loop. Scopes are now bucketed by resource
type and action once per call, and a request is matched by set lookups over
its name's prefixes.
@netlify

netlify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit be9041d
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/6adc2e16625e2ae3f0bb4b52

@shangyian shangyian closed this Oct 25, 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.

1 participant