Skip to content

feat(policy): Add kas_uri dimenstion to ListKeys.#3663

Open
c-r33d wants to merge 3 commits into
mainfrom
key-apis-authz-v2
Open

feat(policy): Add kas_uri dimenstion to ListKeys.#3663
c-r33d wants to merge 3 commits into
mainfrom
key-apis-authz-v2

Conversation

@c-r33d

@c-r33d c-r33d commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

1.) Add kas_uri dimension to ListKeys rpc.

Summary by CodeRabbit

  • New Features

    • Added support for listing KAS keys through the registry API.
    • Expanded access control so key listings can be authorized by KAS URI, KAS ID, or KAS name, with results filtered to the allowed KAS scope.
    • Updated BDD coverage and policy examples to reflect the new listing behavior.
  • Bug Fixes

    • Improved authorization handling for empty, missing, or invalid list responses to prevent incorrect access decisions.

@c-r33d c-r33d requested review from a team as code owners June 25, 2026 00:35
@github-actions github-actions Bot added the comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) label Jun 25, 2026
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@c-r33d, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 19 minutes and 2 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: af646e1b-5ae3-4d1a-bf93-22252dde4243

📥 Commits

Reviewing files that changed from the base of the PR and between 901a089 and cee99ea.

📒 Files selected for processing (5)
  • service/policy/kasregistry/authz_resolver.go
  • service/policy/kasregistry/authz_resolver_test.go
  • service/policy/kasregistry/key_access_server_registry.go
  • tests-bdd/cukes/steps_kasregistry.go
  • tests-bdd/features/authz-v2.feature
📝 Walkthrough

Walkthrough

The PR extends KAS registry authorization to cover ListKeys requests, derives authz resources from returned KAS URIs, registers the new resolver, and adds unit and BDD coverage for filtered and unfiltered listing cases.

Changes

KAS ListKeys authorization

Layer / File(s) Summary
ListKeys authz resolution
service/policy/kasregistry/authz_resolver.go
ListKeys now uses the shared KAS authz DB client, resolves request context for ListKeys, and derives authorization resources from returned key URIs.
Resolver registration and unit tests
service/policy/kasregistry/key_access_server_registry.go, service/policy/kasregistry/authz_resolver_test.go
The registry registers ListKeys authz, and the resolver test double plus unit tests cover ListKeys request handling and error cases.
BDD authz coverage
tests-bdd/cukes/resources/platform.authz_v2.template, tests-bdd/cukes/steps_kasregistry.go, tests-bdd/features/authz-v2.feature
BDD policy rules, steps, and scenarios add ListKeys authorization coverage for URI-filtered, ID-filtered, and unfiltered listing.

Sequence Diagram(s)

sequenceDiagram
  participant KeyAccessServerRegistry
  participant listKeysAuthzResolver
  participant keyAuthzDBClient
  KeyAccessServerRegistry->>listKeysAuthzResolver: resolve ListKeys authz context
  listKeysAuthzResolver->>keyAuthzDBClient: ListKeys(request)
  keyAuthzDBClient-->>listKeysAuthzResolver: ListKeysResponse
  listKeysAuthzResolver->>listKeysAuthzResolver: derive distinct KAS URI resources
  listKeysAuthzResolver-->>KeyAccessServerRegistry: resolverCtx.Resources
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • opentdf/platform#3614: Adds the KAS GetKey authorization resolver and registry wiring that this PR extends to ListKeys.

Suggested labels

comp:db, comp:authorization

Suggested reviewers

  • alkalescent
  • elizabethhealy

Poem

I hopped by the KAS with a basket of keys,
ListKeys went wiggle and followed the breeze.
URIs twinkled, the authz rules sang,
Wildcards and filters all gave a soft clang.
🐰✨ The rabbit says: “More keys, less thump!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a kas_uri dimension to ListKeys policy handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch key-apis-authz-v2

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.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 introduces authorization support for the ListKeys RPC by incorporating the kas_uri dimension. It ensures that requests to list keys are properly authorized based on the associated KAS URI, improving security for multi-tenant or multi-KAS environments. The changes include updates to the authorization resolver registry, new logic for resolving resource dimensions from ListKeys responses, and comprehensive BDD test cases to verify the new authorization rules.

Highlights

  • Authorization Enhancement: Added the kas_uri dimension to the ListKeys RPC, enabling fine-grained authorization based on the KAS URI.
  • Resolver Implementation: Implemented listKeysAuthzResolver to resolve authorization context for ListKeys requests by inspecting returned key URIs.
  • Testing and Validation: Expanded BDD test coverage to include scenarios for URI-specific KAS role authorization and default listing behavior.
New Features

🧠 You can now enable Memory (public preview) 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 the 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 counterproductive. 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.


The keys are listed, one by one, With URI checks, the work is done. Authorization now is tight, Ensuring access stays just right.

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.

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

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.

Code Review

This pull request implements authorization resolution for the ListKeys RPC in the Key Access Server (KAS) registry. It introduces the listKeysAuthzResolver to extract and authorize KAS URIs returned from the database, registers the resolver, and adds comprehensive unit and BDD tests to validate the new authorization logic. The feedback suggests adding defensive nil checks in resolveListKeysReturnedKeyURIs and listedKASKeyIDs to prevent potential nil pointer dereference panics when handling KAS keys.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread service/policy/kasregistry/authz_resolver.go
Comment thread tests-bdd/cukes/steps_kasregistry.go 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 216.764016ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 426.594414ms
Throughput 234.41 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.577121743s
Average Latency 454.401121ms
Throughput 109.70 requests/second

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@service/policy/kasregistry/authz_resolver.go`:
- Around line 113-127: `resolveListKeysAuthzResources` currently authorizes a
separate `dbClient.ListKeys` result from the one later used by
`KeyAccessServerRegistry.ListKeys`, which can create a snapshot mismatch. Change
the flow so the handler and authz path share the exact same `ListKeys` response,
or move the authz resource derivation into the single DB read performed by
`KeyAccessServerRegistry.ListKeys`, and keep `resolveListKeysReturnedKeyURIs`
working from that authorized response.

In `@tests-bdd/cukes/steps_kasregistry.go`:
- Around line 173-219: The `listedKASKeysContainOnly` check is using
`listedKASKeyIDs`, which turns the response into a set and hides duplicate
entries. Update `listedKASKeysContainOnly` to compare the expected IDs against
the actual `ListKeysResponse` contents as a count-aware slice or multiset, so
duplicate rows are detected instead of being collapsed. Keep the fix localized
to `listedKASKeysContainOnly` and the helper it relies on (`listedKASKeyIDs`) so
the BDD assertion validates both membership and multiplicity.
- Around line 110-155: The ListKeys step methods are leaving stale
`listKASKeysResponse` data in the `KasRegistryStepDefinitions` scenario context
when a later call fails or returns nil. Update `iListKASKeys`,
`iListKASKeysForURI`, and `iListKASKeysByStoredKASID` to clear or reset the
recorded `listKASKeysResponse` before each
`scenarioContext.SDK.KeyAccessServerRegistry.ListKeys` request, so assertions
never read an older payload from a previous successful call.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2189c5ac-6de6-4a28-80f5-edb5d832dfb2

📥 Commits

Reviewing files that changed from the base of the PR and between 03021fa and 901a089.

📒 Files selected for processing (6)
  • service/policy/kasregistry/authz_resolver.go
  • service/policy/kasregistry/authz_resolver_test.go
  • service/policy/kasregistry/key_access_server_registry.go
  • tests-bdd/cukes/resources/platform.authz_v2.template
  • tests-bdd/cukes/steps_kasregistry.go
  • tests-bdd/features/authz-v2.feature

Comment thread service/policy/kasregistry/authz_resolver.go
Comment thread tests-bdd/cukes/steps_kasregistry.go
Comment thread tests-bdd/cukes/steps_kasregistry.go
@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 203.838213ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 412.734929ms
Throughput 242.29 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.41721363s
Average Latency 452.775914ms
Throughput 110.09 requests/second

@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 103.274942ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 240.525548ms
Throughput 415.76 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 25.579783623s
Average Latency 254.553193ms
Throughput 195.47 requests/second

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

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

See the workflow run for details.

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

Labels

comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant