Skip to content

Conversation

@alkalescent
Copy link
Contributor

@alkalescent alkalescent commented Jan 13, 2026

Proposed Changes

  • add SQL store for Casbin v2 (to support granular authz)

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

@alkalescent alkalescent requested review from a team as code owners January 13, 2026 00:20
@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 13, 2026
@gemini-code-assist
Copy link
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 framework by introducing a new, more granular system. The new approach enables resource-level access control by allowing services to define and extract specific dimensions from requests, which are then evaluated against policies. This is complemented by the ability to persist policies in a database, facilitating dynamic updates and improved operational flexibility.

Highlights

  • Fine-Grained Authorization (v2): Introduced a new version of the authorization system (v2) that supports fine-grained, resource-level access control using RPC methods and dynamic dimensions, moving beyond coarse-grained path-based authorization.
  • SQL-Backed Policy Storage: Implemented SQL-backed policy storage for Casbin v2, allowing authorization policies to be stored in a PostgreSQL database. This enables runtime policy management without requiring service restarts.
  • Pluggable Authorization Engine: Refactored the core authentication and authorization components to support a pluggable Authz.Authorizer interface, allowing for dynamic selection between different authorization engines and versions (e.g., Casbin v1 or v2).
  • Authorization Resolver Registry: Introduced an AuthzResolverRegistry that allows individual services to register specific methods for extracting authorization dimensions from incoming requests. This enables service-specific logic for resolving resource context.
  • Backwards Compatibility: Ensured backwards compatibility with the existing path-based (v1) authorization system, allowing for a phased migration to the new v2 model.
  • Enhanced Documentation: Added comprehensive documentation, including an Architectural Decision Record (ADR) for resource-level authorization, a guide for platform feature development, and details on configuring SQL policy storage.

🧠 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.


With code we build, a world unseen, Where access rules, both strict and keen. New policies bloom, a finer grain, To guard the data, through sun and rain.

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
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 pull request introduces a significant and well-designed enhancement to the authorization system, adding support for resource-level permissions via a new v2 authorization model. The changes are extensive, touching authentication, authorization, configuration, and service-level logic, but are well-structured and thoroughly documented.

Key improvements include:

  • A new authz package with a pluggable Authorizer interface, which is a great architectural improvement for future flexibility.
  • The introduction of an Inversion of Control (IoC) pattern for authorization "resolvers", allowing services to provide their own logic for extracting resource dimensions.
  • A new Casbin v2 model that supports fine-grained policies based on RPC and custom dimensions.
  • Support for storing Casbin policies in a SQL database, enabling runtime policy updates.
  • Comprehensive documentation, including new ADRs and developer guides, which will be invaluable for maintainability and onboarding.
  • Thoughtful implementation details, such as caching layers to mitigate performance impact and maintaining backward compatibility with the v1 authorization model.

The code is of high quality and demonstrates a solid understanding of software architecture principles. I have one minor suggestion for improving the clarity of an architectural diagram in the new ADR. Overall, this is an excellent contribution to the platform.

│ │ │ (IoC / "Hollywood Principle" - framework calls service) │ │ │
│ │ └─────────────────────────────────────────────────────────────┘ │ │
│ │ ┌─────────────────────────────────────────────────────────────┐ │ │
│ │ │ 3. Enforce → Casbin(sub, type, action, serialized_dims) │ │ │
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The diagram for the request flow seems to contain a small inconsistency with the v2 model described in the document. The enforcement step shows Casbin(sub, type, action, serialized_dims), which appears to be based on the v1 model.

According to the v2 model definition ((subject, rpc, dimensions)), the enforcement call should be Casbin(sub, rpc, serialized_dims). Updating the diagram to reflect this would improve clarity and consistency with the rest of the document.

Suggested change
│ │ │ 3. Enforce → Casbin(sub, type, action, serialized_dims) │ │ │
│ │ │ 3. Enforce → Casbin(sub, rpc, serialized_dims) │ │ │

@github-actions
Copy link
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Error permission_denied: permission denied
Total Time 14.558508ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Error permission_denied: permission denied
Total Time 13.968569ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 0
Failed Decrypts 100
Total Time 4.067894ms
Throughput 0.00 requests/second

Error Summary

Error Message Occurrences
failed to get allowlist from registry: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 1 occurrences

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 0
Failed Requests 5000
Concurrent Requests 50
Total Time 3.953941856s
Throughput 0.00 requests/second

Error Summary:

Error Message Occurrences
LoadTDF error: allowListFromKASRegistry failed: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 5000 occurrences

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 0
Failed Requests 5000
Concurrent Requests 50
Total Time 3.914074075s
Throughput 0.00 requests/second

Error Summary:

Error Message Occurrences
ReadNanoTDF error: LoadNanoTDF: allowListFromKASRegistry failed: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 5000 occurrences

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Error permission_denied: permission denied
Total Time 14.818559ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Error permission_denied: permission denied
Total Time 12.491767ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 0
Failed Decrypts 100
Total Time 2.858345ms
Throughput 0.00 requests/second

Error Summary

Error Message Occurrences
failed to get allowlist from registry: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 1 occurrences

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 0
Failed Requests 5000
Concurrent Requests 50
Total Time 3.903043308s
Throughput 0.00 requests/second

Error Summary:

Error Message Occurrences
LoadTDF error: allowListFromKASRegistry failed: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 5000 occurrences

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 0
Failed Requests 5000
Concurrent Requests 50
Total Time 4.129753461s
Throughput 0.00 requests/second

Error Summary:

Error Message Occurrences
ReadNanoTDF error: LoadNanoTDF: allowListFromKASRegistry failed: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 5000 occurrences

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Error permission_denied: permission denied
Total Time 11.356684ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Error permission_denied: permission denied
Total Time 12.904649ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 0
Failed Decrypts 100
Total Time 3.856191ms
Throughput 0.00 requests/second

Error Summary

Error Message Occurrences
failed to get allowlist from registry: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 1 occurrences

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 0
Failed Requests 5000
Concurrent Requests 50
Total Time 4.197095006s
Throughput 0.00 requests/second

Error Summary:

Error Message Occurrences
LoadTDF error: allowListFromKASRegistry failed: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 5000 occurrences

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 0
Failed Requests 5000
Concurrent Requests 50
Total Time 4.148479036s
Throughput 0.00 requests/second

Error Summary:

Error Message Occurrences
ReadNanoTDF error: LoadNanoTDF: allowListFromKASRegistry failed: kasregistry.ListKeyAccessServers failed: permission_denied: permission denied 5000 occurrences

@github-actions
Copy link
Contributor

@github-actions
Copy link
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

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

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 354.158974ms
Throughput 282.36 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 38.995057947s
Average Latency 388.187064ms
Throughput 128.22 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 27.665071827s
Average Latency 275.893591ms
Throughput 180.73 requests/second

@alkalescent alkalescent changed the base branch from main to DSPX-2185-casbin-stacked-pr January 13, 2026 02:35
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.

3 participants