feat(authzen): add contextual tuples support#251
feat(authzen): add contextual tuples support#251blairdrummond wants to merge 1 commit intoopenfga:mainfrom
Conversation
|
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe pull request introduces a new typed Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Signed-off-by: Blair Drummond <bdrummond@coreweave.com>
There was a problem hiding this comment.
Pull request overview
This PR adds contextual tuples support to the AuthZEN service by introducing a new Context message type that provides typed fields for OpenFGA-specific configuration alongside arbitrary additional context data. Previously, context was represented as an unstructured google.protobuf.Struct, which didn't allow proper type safety for consistency preferences and contextual tuples. The change enables consistency preference and contextual tuple configuration at the API level, bringing parity with the OpenFGA API.
Changes:
- Added new
Contextmessage with three fields: consistency preference, contextual tuples, and arbitrary data - Updated all context field references across 7 proto messages to use the new
Contexttype - Added required imports for OpenFGA proto dependencies
- Updated OpenAPI/Swagger documentation to reflect the new Context definition with proper JSON field names
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| authzen/v1/authzen_service.proto | Added Context message and updated all context field types from google.protobuf.Struct to Context |
| proto/authzen/v1/authzen_service.pb.validate.go | Generated validation code for the new Context message including ValidateAll and validation error types |
| docs/openapiv2/apidocs.swagger.json | Updated OpenAPI definitions to reference the new Context schema with openfga.dev-prefixed fields for consistency and tuples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/openapiv2/apidocs.swagger.json`:
- Around line 464-465: The request examples referencing "context" must be
updated to match the typed "Context" definition (symbol: Context) so that
arbitrary keys are stored under context.data rather than as top-level fields on
context; find the example objects used in the endpoints that currently show flat
context structures (examples near the changed refs) and wrap those arbitrary
key/value pairs into a nested data object (context.data = { ... }) while
preserving any explicit Context fields (e.g., locale, userId) at the top-level
of Context; ensure every example that switches "$ref": "#/definitions/Context"
is modified so the example shape conforms to the Context schema (move flat
entries into context.data).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 46cddf99-0b08-46da-ad5c-fa56975858d8
⛔ Files ignored due to path filters (1)
proto/authzen/v1/authzen_service.pb.gois excluded by!**/*.pb.go
📒 Files selected for processing (3)
authzen/v1/authzen_service.protodocs/openapiv2/apidocs.swagger.jsonproto/authzen/v1/authzen_service.pb.validate.go
| "$ref": "#/definitions/Context" | ||
| } |
There was a problem hiding this comment.
Request examples are now out of sync with the typed Context schema.
Lines 464/559/658/757/857 and 2760/2777 switch context to #/definitions/Context (Line 2618), where arbitrary keys belong under context.data. Several embedded endpoint examples still show flat context objects, which no longer match this schema.
Also applies to: 559-560, 658-659, 757-758, 857-858, 2618-2635, 2760-2761, 2777-2778
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/openapiv2/apidocs.swagger.json` around lines 464 - 465, The request
examples referencing "context" must be updated to match the typed "Context"
definition (symbol: Context) so that arbitrary keys are stored under
context.data rather than as top-level fields on context; find the example
objects used in the endpoints that currently show flat context structures
(examples near the changed refs) and wrap those arbitrary key/value pairs into a
nested data object (context.data = { ... }) while preserving any explicit
Context fields (e.g., locale, userId) at the top-level of Context; ensure every
example that switches "$ref": "#/definitions/Context" is modified so the example
shape conforms to the Context schema (move flat entries into context.data).
|
Hi @blairdrummond! Thanks for this! We thought about it when implementing it, but weren't sure if we should. nother approach we though of was to be able to map certain properties to contextual tuples. For example: Map the subject to But we are making too many assumptions (e.g. relation == object type), and if the relation does not exist, it will fail. We'd need you to add explicit mappings for AuthZEN calls, which increased complexity a lot. However, the value we see in AuthZEN is mostly being able to use it from infrastructure like API/MCP Gateways or Identity Providers. If add extensions they do not support, not sure if it will work. Why would you use AuthZEN instead of the OpenFGA API if you are coupling your implementation with OpenFGA? |
|
So a couple reasons... in no particular order...
|
|
If you had a specific OTEL component that logged this, how would you handle the contextual tuples? If you need to do something specific, why wouldn't you just have an OTEL component that logs OpenFGA calls? :) |
|
I'm less interested in telemetry regarding the context, except for maybe the size of the context object. I'm more interested in getting telemetry about the |
|
OK, that makes sense. I'll do some digging on how other AuthZEN products are handling this. |
|
(Converting to a draft while I go figure out the CLA stuff on my end, but feel free to borrow the idea. The PR is more of an inspiration for an approach rather than something I want merged as is) |
|
Sounds good, and yeah, the hardest part is in the openfga repo :). Not hard though. |
|
Yeah I did actually test those changes here! I wrote an actual functional test in another private repo as well |
I was reading the documentation on Authzen in the OpenFGA docs, and noticed that contextual tuples weren't supported. This is a pretty important feature, so I thought I'd take a look and see if it might be possible to add... I did a bit of prototyping and found this worked ok, but there are certainly trade-offs so just wanted to open up a draft to get thoughts
The gist is that I put consistency preferences and contextual tuples into the context of the authzen request. I modified the proto type so that we could get nice typing here.
Unfortunately this has the negative consequence of moving other context data into a
datasub-field... While this is kinda a bummer, I also don't think it really violates the spec, which doesn't really prescribe much about the structure of the context data.Section 5.4 / Context
The benefits of this is it basically brings about parity with the openfga api. You can see the relevant changes to the OpenFGA code-base to incorporate these changes here
blairdrummond/openfga@21dbf1e
Summary by CodeRabbit
Breaking Changes
Contextstructure.New Features