Skip to content

Conversation

@ryanulit
Copy link
Contributor

@ryanulit ryanulit commented Jun 5, 2025

Proposed Changes

  • add GetEntitlementsRegisteredResources method to pdp access v2 logic
  • add test coverage
  • policy ListRegisteredResources API behavior update to provide ActionAttributeValues back on RegisteredResourceValues in list

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

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.

Hello @ryanulit, 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!

Summary of Changes

Hello! Gemini here, providing a summary of this pull request to help everyone get up to speed quickly.

This PR introduces support for registered resources within the authorization service's Policy Decision Point (PDP) logic. Specifically, it adds the capability to fetch and process registered resources and their associated action-attribute values to determine entitlements for entities identified by a registered resource value FQN. The core change involves modifying the PDP to load registered resources into memory and implementing the GetEntitlementsRegisteredResource method. While the structure for GetDecisionRegisteredResource is added, its full implementation is noted as a future task.

Highlights

  • Registered Resource Support: Adds the foundational logic within the PDP to handle registered resources as a type of entity for entitlement checks.
  • GetEntitlements Implementation: Implements the GetEntitlementsRegisteredResource method to calculate entitlements for a given registered resource value FQN based on its defined action-attribute values, including support for comprehensive hierarchy.
  • Data Loading: Modifies the PDP initialization to fetch all registered resources from the policy service and store their values in memory for efficient lookup.
  • Validation and Testing: Adds new validation functions for registered resources and values, along with comprehensive unit tests for the new entitlement logic and validation.
  • GetDecision Placeholder: Includes a placeholder method GetDecisionRegisteredResource which is not yet fully implemented.

Changelog

Click here to see the changelog
  • service/internal/access/v2/helpers.go
    • Added new error types ErrInvalidRegisteredResource (line 19) and ErrInvalidRegisteredResourceValue (line 20) for validation failures related to registered resources.
  • service/internal/access/v2/just_in_time_pdp.go
    • Imported strings (line 8) and registeredresources protocol (line 17).
    • Modified NewJustInTimePDP (lines 68-72) to fetch all registered resources using a new helper method and pass them to the NewPolicyDecisionPoint constructor.
    • Updated the GetDecision method (lines 103-113) to handle the RegisteredResourceValueFqn case, calling the new pdp.GetDecisionRegisteredResource (currently a placeholder).
    • Updated the GetEntitlements method (lines 164-168) to handle the RegisteredResourceValueFqn case, calling the new pdp.GetEntitlementsRegisteredResource.
    • Added fetchAllRegisteredResources method (lines 288-313) to retrieve all registered resources from the policy service with pagination support.
  • service/internal/access/v2/pdp.go
    • Imported slices (line 8) and identifier (line 12).
    • Added allRegisteredResourceValuesByFQN map (line 52) to the PolicyDecisionPoint struct to store registered resource values by their FQN.
    • Modified NewPolicyDecisionPoint (lines 72-73) to accept allRegisteredResources as an argument.
    • Added logic in NewPolicyDecisionPoint (lines 130-143) to validate registered resources and populate the allRegisteredResourceValuesByFQN map.
    • Added a placeholder GetDecisionRegisteredResource method (lines 248-255).
    • Implemented the GetEntitlementsRegisteredResource method (lines 330-390) to calculate and return entitlements for a given registered resource value FQN.
  • service/internal/access/v2/pdp_test.go
    • Added createRegisteredResourceValueFQN helper function (lines 45-50).
    • Added variables for test registered resource value FQNs (lines 92-98).
    • Added fields for test registered resources and values to the PDPTestSuite struct (lines 140-146).
    • Initialized test registered resources and values in SetupTest (lines 356-468) and created their FQNs (lines 470-475).
    • Updated TestNewPolicyDecisionPoint (lines 498, 523, 530) and other existing tests (Test_GetDecision_MultipleResources line 553, Test_GetDecision_PartialActionEntitlement lines 749, 861, Test_GetDecision_CombinedAttributeRules_SingleResource line 908, Test_GetDecision_AcrossNamespaces line 1268, Test_GetEntitlements line 1563, Test_GetEntitlements_AdvancedHierarchy line 1862) to pass registered resources (or an empty slice) to NewPolicyDecisionPoint.
    • Added the Test_GetEntitlementsRegisteredResource test suite (lines 1932-2091) with various test cases for the new entitlement logic.
  • service/internal/access/v2/validators.go
    • Added validateRegisteredResource function (lines 106-113) to validate registered resource objects.
    • Added validateRegisteredResourceValue function (lines 122-129) to validate registered resource value objects.
  • service/internal/access/v2/validators_test.go
    • Added TestValidateRegisteredResource test suite (lines 286-323).
    • Added TestValidateRegisteredResourceValue test suite (lines 325-362).
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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 new resource type,
Entitlements take flight.
Code flows, tests pass,
Through the review glass,
Merging soon, shining bright.

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 significant new functionality for handling registered resources within the authorization service, particularly for entitlement decisions. The changes to fetch, store, and process these resources in NewJustInTimePDP and NewPolicyDecisionPoint are logical. The new GetEntitlementsRegisteredResource method and its tests are well-implemented.

However, a critical issue is that the GetDecisionRegisteredResource method, which is essential for the GetDecision flow for registered resources, is currently not implemented and returns an error. This needs to be addressed for the feature to be complete as per the PR title.

I've also included a suggestion to enhance validation during PDP initialization for better robustness.

Please address the critical issue and consider the suggestion. Also, it would be beneficial to update the PR checklist regarding documentation and integration tests once the feature is fully implemented.

Summary of Findings

  • Missing Core Functionality Implementation: The GetDecisionRegisteredResource method in pdp.go is not implemented and returns an error, despite being called by the GetDecision flow. This is critical as it prevents the primary goal of the PR (GetDecision support for registered resources) from functioning.
  • Early Validation of Registered Resource Values: Registered resource values (policy.RegisteredResourceValue) are not validated during the NewPolicyDecisionPoint initialization. Adding this validation would improve robustness by ensuring all cached resource values are valid upfront.
  • PR Checklist Update Needed: The PR description checklist items for unit tests (partially complete), integration tests, and documentation are unchecked. These should be reviewed and updated as the feature is finalized.

Merge Readiness

This pull request has made substantial progress in adding support for registered resources. However, due to the critical issue of the GetDecisionRegisteredResource method not being implemented, I recommend that these changes not be merged until this core functionality is complete and tested. Addressing the medium-severity validation suggestion would also enhance the code's robustness. As a reviewer, I am not authorized to approve pull requests; please ensure further review and approval from authorized maintainers after the necessary changes are made.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2025

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 474.549439ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 311.309508ms

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 486.543216ms
Throughput 205.53 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 52.751630948s
Average Latency 524.210243ms
Throughput 94.78 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 4946
Failed Requests 54
Concurrent Requests 50
Total Time 43.167706095s
Average Latency 425.562536ms
Throughput 114.58 requests/second

Error Summary:

Error Message Occurrences
ReadNanoTDF error: getNanoRewrapKey: rewrapError: internal: internal error
rpc error: code = Internal desc = could not perform access
54 occurrences

Standard Benchmark Metrics Skipped or Failed

@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2025

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 446.498256ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 278.280258ms

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 377.661356ms
Throughput 264.79 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 57.653783482s
Average Latency 573.641262ms
Throughput 86.72 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 4930
Failed Requests 70
Concurrent Requests 50
Total Time 48.376746114s
Average Latency 479.394839ms
Throughput 101.91 requests/second

Error Summary:

Error Message Occurrences
ReadNanoTDF error: getNanoRewrapKey: rewrapError: internal: internal error
rpc error: code = Internal desc = could not perform access
70 occurrences

Standard Benchmark Metrics Skipped or Failed

Copy link
Contributor

@jakedoublev jakedoublev left a comment

Choose a reason for hiding this comment

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

Have not reviewed tests yet and would prefer to review again after the diff is simplified by merging #2358, but this looks great so far.

@ryanulit
Copy link
Contributor Author

ryanulit commented Jun 5, 2025

/gemini review

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 adds support for registered resources in GetDecision and GetEntitlements flows. The changes include fetching all registered resources, updating the Policy Decision Point (PDP) to utilize them, and implementing new methods for decisions and entitlements based on registered resource value FQNs. New error types, helper functions, and validators have also been added, along with test coverage for some of the new functionality.

The core logic for integrating registered resources seems well-structured. My main concerns are around the handling of attribute hierarchy within the new GetDecisionRegisteredResource method and the need for dedicated unit tests for this critical function.

Summary of Findings

  • Hierarchy Handling in GetDecisionRegisteredResource: A TODO comment in service/internal/access/v2/pdp.go (line 323) questions whether attribute hierarchy should be populated for entitlements derived from RegisteredResourceValue within the GetDecisionRegisteredResource method. This is critical for consistent authorization behavior, especially since GetEntitlementsRegisteredResource does support comprehensive hierarchy. Clarification or implementation is needed.
  • Missing Unit Tests for GetDecisionRegisteredResource: The new PolicyDecisionPoint.GetDecisionRegisteredResource method, a key component for registered resource-based decisions, lacks dedicated unit tests. Comprehensive test coverage is needed to ensure its correctness across various scenarios.

Merge Readiness

The pull request introduces valuable functionality for registered resources. However, due to the high severity issues identified—specifically the unresolved question about hierarchy handling in GetDecisionRegisteredResource and the missing unit tests for this core decision logic—I recommend that these points be addressed before merging. As a reviewer, I am not authorized to approve pull requests, but addressing these concerns will significantly improve the robustness and clarity of the new features. The existing tests for GetEntitlementsRegisteredResource are a great start!

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2025

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 431.909036ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 280.636416ms

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 349.877924ms
Throughput 285.81 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 57.553327571s
Average Latency 572.310915ms
Throughput 86.88 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 4938
Failed Requests 62
Concurrent Requests 50
Total Time 49.748174777s
Average Latency 492.122783ms
Throughput 99.26 requests/second

Error Summary:

Error Message Occurrences
ReadNanoTDF error: getNanoRewrapKey: rewrapError: internal: internal error
rpc error: code = Internal desc = could not perform access
62 occurrences

Standard Benchmark Metrics Skipped or Failed

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2025

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 474.928887ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 280.483621ms

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 350.78546ms
Throughput 285.07 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 52.946498386s
Average Latency 526.7213ms
Throughput 94.43 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 4944
Failed Requests 56
Concurrent Requests 50
Total Time 44.296745827s
Average Latency 437.55892ms
Throughput 111.61 requests/second

Error Summary:

Error Message Occurrences
ReadNanoTDF error: getNanoRewrapKey: rewrapError: internal: internal error
rpc error: code = Internal desc = could not perform access
56 occurrences

Standard Benchmark Metrics Skipped or Failed

elizabethhealy and others added 5 commits June 23, 2025 11:50
### Proposed Changes

Add cleanup for underlying Ristretto cache by tracking and explicitly
closing it to avoid goroutine leaks and ensure proper resource release.

Details:
Modified cache.Manager to store a reference to the underlying
*ristretto.Cache.
Added a Close() method to Manager that calls .Close() on the underlying
Ristretto cache.

Why:
Ristretto starts background goroutines and allocates internal buffers
that aren't automatically cleaned up. Explicitly calling .Close()
ensures proper shutdown, especially important in tests and long-running
services

### 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
### Proposed Changes

* enables sloglint
* updates settings to prefer `slog.Attr` over arbitrary key/values
* lint fixes throughout
* removes `request` logs and `token` logs where we were previously
logging them

### 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
@jakedoublev jakedoublev requested review from a team as code owners June 23, 2025 18:50
jakedoublev and others added 2 commits June 23, 2025 12:22
…Values on RegisteredResourceValues (#2469)

### 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
@jakedoublev jakedoublev enabled auto-merge June 23, 2025 19:26
@github-actions
Copy link
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 519.275123ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 344.604865ms

Standard Benchmark Metrics Skipped or Failed

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 349.37116ms
Throughput 286.23 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 37.676942189s
Average Latency 374.431174ms
Throughput 132.71 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 26.111317978s
Average Latency 260.302772ms
Throughput 191.49 requests/second

@github-actions
Copy link
Contributor

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 550.536434ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 5000
Denied Decision Requests 0
Total Time 345.311699ms

Standard Benchmark Metrics Skipped or Failed

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 351.38512ms
Throughput 284.59 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 39.111340352s
Average Latency 389.398695ms
Throughput 127.84 requests/second

NANOTDF Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 27.25807026s
Average Latency 271.703721ms
Throughput 183.43 requests/second

@jakedoublev jakedoublev disabled auto-merge June 23, 2025 19:47
@jakedoublev jakedoublev enabled auto-merge June 23, 2025 19:48
@alkalescent
Copy link
Contributor

alkalescent commented Jun 23, 2025

prob needs at least one maintainer approval who didn't touch this PR
(e.g. Sean and Ryan S are disqualified bc technically they authored the squashed PR commits that got merged into this branch)

@strantalis strantalis disabled auto-merge June 23, 2025 19:57
@jakedoublev jakedoublev enabled auto-merge June 23, 2025 20:16
@strantalis strantalis disabled auto-merge June 23, 2025 20:43
@strantalis strantalis merged commit 5405674 into main Jun 23, 2025
29 of 30 checks passed
@strantalis strantalis deleted the DSPX-895-auth-svc-rr-get-decision-support branch June 23, 2025 20:44
github-merge-queue bot pushed a commit that referenced this pull request Jun 24, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.7.0](service/v0.6.0...service/v0.7.0)
(2025-06-24)


### ⚠ BREAKING CHANGES

* **policy:** disable kas grants in favor of key mappings
([#2220](#2220))

### Features

* **authz:** Add caching to keycloak ERS
([#2466](#2466))
([f5b0a06](f5b0a06))
* **authz:** auth svc registered resource GetDecision support
([#2392](#2392))
([5405674](5405674))
* **authz:** authz v2 GetBulkDecision
([#2448](#2448))
([0da3363](0da3363))
* **authz:** cache entitlement policy within authorization service
([#2457](#2457))
([c16361c](c16361c))
* **authz:** ensure logging parity between authz v2 and v1
([#2443](#2443))
([ef68586](ef68586))
* **core:** add cache manager
([#2449](#2449))
([2b062c5](2b062c5))
* **core:** consume RPC interceptor request context metadata in logging
([#2442](#2442))
([2769c48](2769c48))
* **core:** DSPX-609 - add cli-client to keycloak provisioning
([#2396](#2396))
([48e7489](48e7489))
* **core:** ERS cache setup, fix cache initialization
([#2458](#2458))
([d0c6938](d0c6938))
* inject logger and cache manager to key managers
([#2461](#2461))
([9292162](9292162))
* **kas:** expose provider config from key details.
([#2459](#2459))
([0e7d39a](0e7d39a))
* **main:** Add Close() method to cache manager
([#2465](#2465))
([32630d6](32630d6))
* **policy:** disable kas grants in favor of key mappings
([#2220](#2220))
([30f8cf5](30f8cf5))
* **policy:** Restrict deletion of pc with used key.
([#2414](#2414))
([3b40a46](3b40a46))
* **sdk:** allow Connect-Protocol-Version RPC header for cors
([#2437](#2437))
([4bf241e](4bf241e))


### Bug Fixes

* **core:** remove generics on new platform cache manager and client
([#2456](#2456))
([98c3c16](98c3c16))
* **core:** replace opentdf-public client with cli-client
([#2422](#2422))
([fb18525](fb18525))
* **deps:** bump github.com/casbin/casbin/v2 from 2.106.0 to 2.107.0 in
/service in the external group
([#2416](#2416))
([43afd48](43afd48))
* **deps:** bump github.com/opentdf/platform/protocol/go from 0.4.0 to
0.5.0 in /service
([#2470](#2470))
([3a73fc9](3a73fc9))
* **deps:** bump github.com/opentdf/platform/sdk from 0.4.7 to 0.5.0 in
/service ([#2473](#2473))
([ad37476](ad37476))
* **deps:** bump the external group across 1 directory with 2 updates
([#2450](#2450))
([9d8d1f1](9d8d1f1))
* **deps:** bump the external group across 1 directory with 2 updates
([#2472](#2472))
([d45b3c8](d45b3c8))
* only request a token when near expiration
([#2370](#2370))
([556d95e](556d95e))
* **policy:** fix casing bug and get provider config on update.
([#2403](#2403))
([a52b8f9](a52b8f9))
* **policy:** properly formatted pem in test fixtures
([#2409](#2409))
([54ffd23](54ffd23))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com>
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.

10 participants