Skip to content

feat: add scope enforcement metrics to RBAC authorizer#19991

Closed
ThomasK33 wants to merge 1 commit into
thomask33/09-26-add_token_scope_support_in_clifrom
thomask33/09-26-add_detailed_scope_auth_metrics
Closed

feat: add scope enforcement metrics to RBAC authorizer#19991
ThomasK33 wants to merge 1 commit into
thomask33/09-26-add_token_scope_support_in_clifrom
thomask33/09-26-add_detailed_scope_auth_metrics

Conversation

@ThomasK33
Copy link
Copy Markdown
Member

Add scope enforcement metrics to RBAC authorizer

This PR adds detailed metrics to track scope enforcement decisions in the RBAC authorizer. It helps us understand why requests are allowed or denied, particularly focusing on scope-based decisions versus role or ACL-based decisions.

The changes include:

  • New scopeDecision struct to track detailed authorization outcomes
  • Additional Prometheus metrics to track scope enforcement:
    • coderd_authz_scope_enforcement_total - Counts requests by decision type
    • coderd_authz_scope_enforcement_duration_seconds - Measures latency
    • coderd_authz_scope_allowlist_miss_total - Tracks allow-list misses
  • Updated Rego policy to expose structured decision data
  • Documentation with example PromQL queries for common analysis scenarios

These metrics will help us better understand authorization patterns and identify potential issues with scope configurations.

Copy link
Copy Markdown
Member Author

ThomasK33 commented Sep 26, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ThomasK33 ThomasK33 linked an issue Sep 26, 2025 that may be closed by this pull request
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch 2 times, most recently from 9d9f50a to a7dd13b Compare September 26, 2025 19:57
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch from f277494 to 51502b5 Compare September 28, 2025 10:53
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from a7dd13b to 8b7a31c Compare September 28, 2025 10:53
@ThomasK33 ThomasK33 marked this pull request as ready for review September 28, 2025 11:08
@ThomasK33 ThomasK33 requested a review from Emyrk as a code owner September 28, 2025 11:08
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from 8b7a31c to 7725526 Compare September 29, 2025 08:25
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch from 51502b5 to 9384a37 Compare September 29, 2025 08:25
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from 7725526 to e2539b7 Compare September 29, 2025 09:43
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch 2 times, most recently from 968cd55 to 23c8b74 Compare September 29, 2025 09:46
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from e2539b7 to 3bf5bf9 Compare September 29, 2025 09:46
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch 2 times, most recently from bf26332 to d817f31 Compare October 2, 2025 17:37
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch from fa49bdc to d7fcc25 Compare October 2, 2025 17:37
@ThomasK33 ThomasK33 marked this pull request as draft October 2, 2025 17:37
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch from d7fcc25 to c4f8c2a Compare October 3, 2025 17:59
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch 2 times, most recently from b076a30 to b020309 Compare October 6, 2025 09:42
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch 2 times, most recently from 6ec4b94 to d9f66ca Compare October 6, 2025 10:10
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch 2 times, most recently from 37cd2d3 to 807fafe Compare October 6, 2025 10:48
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch 2 times, most recently from 11f6a63 to 75d7b64 Compare October 6, 2025 11:24
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from 807fafe to 7b72854 Compare October 6, 2025 11:24
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch from 75d7b64 to f244193 Compare October 6, 2025 11:57
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from 7b72854 to 5a425af Compare October 6, 2025 11:57
@Emyrk Emyrk self-assigned this Oct 6, 2025
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from 5a425af to e408ecf Compare October 6, 2025 21:16
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch from f244193 to 2f3304e Compare October 6, 2025 21:16
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from e408ecf to ab2a24f Compare October 6, 2025 21:40
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch from 2f3304e to 1dae22e Compare October 6, 2025 21:40
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from ab2a24f to 802b588 Compare October 7, 2025 16:38
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch 2 times, most recently from 7eb739c to dc96969 Compare October 9, 2025 12:54
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from 802b588 to cb61426 Compare October 9, 2025 12:55
This change introduces new Prometheus metrics to provide detailed insights
into authorization decisions, particularly for API key scopes. These
metrics help administrators understand why a request was allowed or
denied by breaking down the outcome.

The new metrics are:
- `coderd_authz_scope_enforcement_total`: Classifies each authorization
  request by its outcome (e.g., scope_allow, scope_deny,
  allow_list_deny) and resource type.
- `coderd_authz_scope_enforcement_duration_seconds`: Measures the latency
  of scope enforcement decisions.
- `coderd_authz_scope_allowlist_miss_total`: Tracks requests denied
  specifically due to a resource not being in a scope's allow-list.

To implement this efficiently, a new `scope_metrics` rule was added to
the Rego policy. This allows the authorizer to gather detailed outcome
information in a single evaluation, avoiding redundant computations.

The documentation for Prometheus has been updated to include details and
example queries for the new metrics.
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_token_scope_support_in_cli branch from dc96969 to 521c665 Compare October 9, 2025 13:06
@ThomasK33 ThomasK33 force-pushed the thomask33/09-26-add_detailed_scope_auth_metrics branch from cb61426 to 06d4957 Compare October 9, 2025 13:06
@ThomasK33 ThomasK33 closed this Oct 9, 2025
@ThomasK33 ThomasK33 deleted the thomask33/09-26-add_detailed_scope_auth_metrics branch October 9, 2025 15:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telemetry/metrics: scope enforcement visibility

3 participants