Skip to content

feat(core): add fine-grain authorization support#2999

Open
alkalescent wants to merge 29 commits into
DSPX-2185-casbin-stacked-prfrom
DSPX-2190-enrich-casbin
Open

feat(core): add fine-grain authorization support#2999
alkalescent wants to merge 29 commits into
DSPX-2185-casbin-stacked-prfrom
DSPX-2190-enrich-casbin

Conversation

@alkalescent
Copy link
Copy Markdown
Contributor

Proposed Changes

  • adds fine-grain authorization support
  • adds pluggable authorizer

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

@github-actions github-actions Bot added comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) docs Documentation comp:middleware:auth size/xl labels Jan 10, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @alkalescent, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the platform's authorization capabilities by introducing a new fine-grained system. It shifts the focus from broad path-based access to granular control based on specific RPC methods and dynamic resource attributes. This enhancement provides a more robust and flexible security model, allowing services to define and enforce access policies at a much finer level of detail, while ensuring a smooth transition and continued support for existing authorization rules.

Highlights

  • Fine-Grained Authorization (v2): Introduced a new fine-grained authorization system that moves beyond path-based RBAC to incorporate RPC methods and dynamic resource dimensions, enabling more precise access control.
  • Pluggable Authorizer Interface: Implemented a pluggable Authorizer interface, allowing for different authorization engines. The initial implementation uses Casbin, supporting both the legacy v1 (path-based) and the new v2 (RPC + dimensions) models.
  • Authorization Resolver Registry: Added an AuthzResolverRegistry and ResolverFunc mechanism. Services can now register resolver functions for their methods to extract resource-specific authorization dimensions (e.g., namespace, attribute) from incoming requests.
  • Attributes Service Integration: The Attributes service has been updated to implement AuthzResolverFunc for its methods, serving as a pilot for integrating the new fine-grained authorization pattern. This includes caching resolved data to prevent redundant database queries.
  • Backward Compatibility & Extensibility: The new system maintains backward compatibility with existing path-based (v1) policies and is designed for future extensibility to support other authorization engines like AWS Cedar or Open Policy Agent (OPA).
  • Enhanced Auditability: Authorization decisions are now logged with full context, including serialized resource dimensions, to improve governance and auditability.
  • Architectural Documentation: New architectural documentation has been added, detailing the platform's feature development patterns (Inversion of Control, Scoped Registries) and providing a comprehensive reference for the Authorization Resolver Registry.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A fine-grain net, so strong and new, Resources guarded, clear and true. No path alone, but context deep, Where access rules, the secrets keep.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that introduces a well-designed and robust fine-grained authorization system. The use of a pluggable authorizer interface, a resolver registry for service-specific logic, and the Inversion of Control pattern are all great architectural choices that will improve the platform's extensibility and maintainability. The code is clean, well-structured, and thoroughly tested. The accompanying documentation and ADRs are very detailed and helpful for understanding the new system. I have one high-severity comment regarding an inconsistency in the ADR document that should be addressed to avoid confusion. Overall, this is a fantastic contribution.

Comment thread adr/decisions/2026-01-02-authz-fine-grain-resource-support.md Outdated
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 202.924674ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 98.896912ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 388.064617ms
Throughput 257.69 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 39.940821362s
Average Latency 397.603981ms
Throughput 125.19 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 28.465411771s
Average Latency 283.298407ms
Throughput 175.65 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 199.197515ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 105.635047ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 371.118082ms
Throughput 269.46 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 39.126919105s
Average Latency 389.170461ms
Throughput 127.79 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 27.575414995s
Average Latency 274.853109ms
Throughput 181.32 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

@alkalescent
Copy link
Copy Markdown
Contributor Author

I chose a hybrid approach, using the platform cache manager for inter-request caching and keeping the resolver context for intra-request caching. The benefit of the resolver context is that the handlers don't need knowledge of the cache keys.

jrschumacher
jrschumacher previously approved these changes Jan 13, 2026
Copy link
Copy Markdown
Contributor

@jentfoo jentfoo left a comment

Choose a reason for hiding this comment

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

A couple defensive recommendations, the rolePrefix check is a critical fix.

Comment thread service/internal/auth/authz/casbin/casbin.go
Comment thread service/internal/auth/authz/casbin/casbin.go
Comment thread service/internal/auth/authz/casbin/casbin.go Outdated
Signed-off-by: Ryan Schumacher <jschumacher@virtru.com>
@policy-bot-opentdf policy-bot-opentdf Bot dismissed jrschumacher’s stale review March 5, 2026 16:12

Invalidated by push of 51e8779

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 197.032029ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 108.480866ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 383.22302ms
Throughput 260.94 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.788508727s
Average Latency 406.122321ms
Throughput 122.58 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 28.600179816s
Average Latency 285.097525ms
Throughput 174.82 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 190.069977ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 104.877017ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 372.105428ms
Throughput 268.74 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 39.691609158s
Average Latency 394.651107ms
Throughput 125.97 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 28.194611069s
Average Latency 280.859911ms
Throughput 177.34 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2026

Comment thread service/internal/auth/authn.go Outdated
return
}

// Build authorization request
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.

The gRPC gateway was removed, is this still needed?

1.) merge main

---------

Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Signed-off-by: Paul Flynn <pflynn@virtru.com>
Signed-off-by: strantalis <strantalis@virtru.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com>
Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
Signed-off-by: David Mihalcik <dmihalcik@virtru.com>
Signed-off-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
Signed-off-by: Diego <74568547+dsm20@users.noreply.github.com>
Signed-off-by: Dana Morris <dmorris@virtru.com>
Signed-off-by: Jeremy Haage <jeremy.haage@virtru.com>
Signed-off-by: Krish Suchak <ksuchak@virtru.com>
Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Co-authored-by: Krish Suchak <42231639+alkalescent@users.noreply.github.com>
Co-authored-by: Paul Flynn <43211074+pflynn-virtru@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Mary Dickson <mary.dickson@virtru.com>
Co-authored-by: dominic reed <dominic.reed@virtru.com>
Co-authored-by: Elizabeth Healy <35498075+elizabethhealy@users.noreply.github.com>
Co-authored-by: Sean Trantalis <18211470+strantalis@users.noreply.github.com>
Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jake Van Vorhis <83739412+jakedoublev@users.noreply.github.com>
Co-authored-by: Louie <85858507+el-virt@users.noreply.github.com>
Co-authored-by: dmihalcik-virtru <dmihalcik-virtru@users.noreply.github.com>
Co-authored-by: Krish Suchak <suchak.krish@gmail.com>
Co-authored-by: Dave Mihalcik <dmihalcik@virtru.com>
Co-authored-by: Artem A. <67011886+hi-artem@users.noreply.github.com>
Co-authored-by: Diego <74568547+dsm20@users.noreply.github.com>
Co-authored-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
Co-authored-by: Dillon Thompson <dj.thompson715@gmail.com>
Co-authored-by: Dana Morris <damorris25@gmail.com>
Co-authored-by: Nick <79929408+ntrevino-virtru@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: sievdokymov-virtru <100794336+sievdokymov-virtru@users.noreply.github.com>
Co-authored-by: Jeremy Haage <jeremy.haage@virtru.com>
Co-authored-by: Tim Tschampel <timothy.tschampel@gmail.com>
Co-authored-by: sujankota <sreddy@virtru.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: dmihalcik-virtru <38867245+dmihalcik-virtru@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@c-r33d c-r33d requested review from a team as code owners June 5, 2026 17:40
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 5, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e2153572-a889-45da-a4d6-b49687367af6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DSPX-2190-enrich-casbin

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Dependency Review

The following issues were found:

  • ❌ 1 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 175 package(s) with unknown licenses.
  • ⚠️ 11 packages with OpenSSF Scorecard issues.

View full job summary

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 184.644966ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 93.76977ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 455.439441ms
Throughput 219.57 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.708868061s
Average Latency 445.465811ms
Throughput 111.83 requests/second

### Proposed Changes

*

### Checklist

- [ ] I have added or updated unit tests
- [ ] I have added or updated integration tests (if appropriate)
- [ ] I have added or updated documentation

### Testing Instructions
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 183.492631ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 95.317914ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 571.310974ms
Throughput 175.04 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 43.874128041s
Average Latency 436.721357ms
Throughput 113.96 requests/second

## Summary

  Step 1 production-readiness security changes for PR #2999.

This wires the authz resolver registry into the server authenticator
path so v2 authorization can resolve request-specific resource
dimensions during interceptor authorization. It also adds default
Casbin v2 grouping statements for the built-in admin and standard roles,
without reintroducing deprecated `RoleMap` behavior.

  ## Changes

- Pass `AuthzResolverRegistry` from server startup into
`auth.NewAuthenticator`
- Share the same resolver registry between service registration and auth
enforcement
  - Add built-in v2 Casbin grouping statements:
    - `role:opentdf-admin -> role:admin`
    - `role:opentdf-standard -> role:standard`
  - Add unit coverage proving:
    - registered authz resolvers are invoked by v2 authorization
    - resolved resource context is passed into authorization
- default v2 policy allows `opentdf-admin` through grouping statements

  ## Verification

  Ran:

  ```sh
go test ./service/internal/auth/... ./service/internal/server/...
./service/pkg/server/...
```
  Also ran targeted tests for resolver invocation and default role grouping behavior.

  ## Notes

  Customer policy override behavior is preserved. A customer can still replace the built-in Casbin policy with server.auth.policy.csv and omit the default opentdf-admin role mapping if they do not want
  that role.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • examples
  • otdfctl
  • sdk
  • service
  • lib/fixtures
  • tests-bdd

See the workflow run for details.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 185.338862ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 101.783731ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 430.301721ms
Throughput 232.40 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.46758289s
Average Latency 452.71193ms
Throughput 109.97 requests/second

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:middleware:auth comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) docs Documentation size/xl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants