Skip to content

feat(policy): add search support to ListKeys#3558

Merged
c-r33d merged 6 commits into
search-term-implfrom
dspx-2741-listkeys-search
Jun 3, 2026
Merged

feat(policy): add search support to ListKeys#3558
c-r33d merged 6 commits into
search-term-implfrom
dspx-2741-listkeys-search

Conversation

@c-r33d

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

Copy link
Copy Markdown
Contributor

Summary

  • Adds ListKeys RPC search support by wiring request search into the policy DB list query.
  • Applies escaped, case-insensitive matching in the KAS key SQL path and adds integration coverage for search behavior, wildcard literals, empty search, whitespace handling, and pagination after filtering.

Summary by CodeRabbit

Release Notes

  • New Features

    • Search capability for KAS registry keys by key ID.
    • Search input automatically trims leading and trailing whitespace.
    • Wildcard characters in search queries are properly escaped.
    • Search results work seamlessly with existing filters and pagination.
  • Tests

    • Added comprehensive test coverage for search functionality.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

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: 4554264b-9b30-4a26-9da2-fc4aafbce1c6

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
📝 Walkthrough

Walkthrough

This PR adds substring search filtering to KAS registry key listing. The source SQL query gains an optional @search parameter matching kask.key_id via case-insensitive ILIKE with escape handling; the generated Go client wires the parameter and updates struct/method signatures; the business logic extracts search terms from requests; and integration tests validate search behavior including ID matching, filter composition, whitespace handling, wildcard escaping, and pagination.

Changes

KAS Registry Key Search

Layer / File(s) Summary
SQL query definition with search parameter
service/policy/db/queries/key_access_server_registry.sql
The source listKeys query adds an optional @search parameter that filters kask.key_id using case-insensitive ILIKE with ESCAPE '\' escape handling when non-NULL.
Generated SQL client wiring and struct
service/policy/db/key_access_server_registry.sql.go
The generated listKeysParams struct adds a Search pgtype.Text field; SQL placeholder indices are renumbered; the WHERE clause includes the optional ILIKE predicate on kask.key_id; and the listKeys method call passes arg.Search in the correct parameter position.
Database client search implementation
service/policy/db/key_access_server_registry.go
PolicyDBClient.ListKeys extracts the search term from the request's Search.Term field via pgtypeSubstringSearchPattern and passes it to the generated query via listKeysParams.Search.
Search integration tests and test helpers
service/integration/kas_registry_key_test.go
Six new test methods validate search behavior: ID matching, combination with KAS filters, empty query equivalence, whitespace trimming, SQL wildcard literal escaping, and pagination applied after filtering. Helper functions provision test KAS servers and keys with predictable identifiers, and extract key ID slices for cleanup.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • opentdf/platform#3552: Adds substring search support for ListNamespaces using the same pgtypeSubstringSearchPattern/ILIKE-escape pattern and validates empty-query and pagination-after-filtering behavior analogously to this PR's ListKeys implementation.

Suggested reviewers

  • elizabethhealy

Poem

🐰 A rabbit hops through keys today,
With search that filters all the way,
ILIKE with escape so neat,
Pagination makes it sweet,
Tests ensure the search won't stray!

🚥 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 'feat(policy): add search support to ListKeys' directly and accurately describes the main change: adding search functionality to the ListKeys RPC, which is the primary objective across all modified files.
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 dspx-2741-listkeys-search

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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 github-actions Bot added comp:db DB component comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) size/s labels Jun 1, 2026
@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 search capabilities to the ListKeys RPC, allowing users to filter keys by ID. The changes involve updating the database query layer to support partial, case-insensitive matching while ensuring that special characters are properly escaped. Additionally, the integration test suite has been expanded to validate the new search functionality across various edge cases and pagination scenarios.

Highlights

  • Search Support: Implemented search functionality for the ListKeys RPC by integrating request search terms into the policy database query.
  • Query Refinement: Added case-insensitive, escaped matching for key IDs in the SQL path to ensure robust and secure search behavior.
  • Integration Testing: Added comprehensive integration tests covering wildcard literals, empty search terms, whitespace handling, and pagination after filtering.
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 we list with search in mind, / A specific match we hope to find. / With SQL tweaks and tests in place, / We search the list at steady pace.

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 search functionality for listing Key Access Server (KAS) keys. It updates the database queries to support a search term parameter that filters keys by ID using a case-insensitive LIKE match with wildcard escaping. Additionally, a comprehensive suite of integration tests has been added to verify search behavior, including combining search with other filters, handling empty queries, whitespace, wildcards, and pagination. No review comments were provided, so there is no additional feedback.

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.

@github-actions

github-actions Bot commented Jun 1, 2026

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 194.373131ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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.854226ms
Throughput 232.10 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 46.601439825s
Average Latency 464.369913ms
Throughput 107.29 requests/second

@c-r33d c-r33d force-pushed the dspx-2741-listkeys-search branch from f891fba to 0bd2c0e Compare June 3, 2026 14:27
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

X-Test Failure Report

govulncheck-failure-0

@c-r33d c-r33d marked this pull request as ready for review June 3, 2026 14:32
@c-r33d c-r33d requested review from a team as code owners June 3, 2026 14:32
@c-r33d

c-r33d commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

github-actions Bot commented Jun 3, 2026

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 140.219736ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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.842067ms
Throughput 281.82 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 35.793778194s
Average Latency 356.157289ms
Throughput 139.69 requests/second

@github-actions

github-actions Bot commented Jun 3, 2026

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 169.826989ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 411.328249ms
Throughput 243.11 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 42.786181624s
Average Latency 426.527276ms
Throughput 116.86 requests/second

@github-actions

github-actions Bot commented Jun 3, 2026

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 183.735391ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 409.91481ms
Throughput 243.95 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.85365801s
Average Latency 446.753716ms
Throughput 111.47 requests/second

@c-r33d

c-r33d commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: 1

🤖 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/integration/kas_registry_key_test.go`:
- Around line 819-831: Test_ListKeys_SearchTrimsWhitespace_Succeeds currently
only verifies left-trimming by passing " "+keyID; extend the test to also verify
trailing-space and whitespace-only inputs so both TrimSpace behaviors are
covered. Update the test (using the existing createListKeysSearchTestKeys helper
and ListKeys call) to include: a ListKeys request with Search.Term set to
keyID+" " (trailing space) and another with Search.Term set to " " (or multiple
spaces) to ensure a whitespace-only query returns the same single result; assert
NoError, Len==1, returned key ID equals keyIDsByKID[keyID], and pagination
total==1 for each case.
🪄 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: e389b9ce-bb1d-41c0-a755-4b3360632afa

📥 Commits

Reviewing files that changed from the base of the PR and between bb38767 and 6d62d91.

📒 Files selected for processing (4)
  • service/integration/kas_registry_key_test.go
  • service/policy/db/key_access_server_registry.go
  • service/policy/db/key_access_server_registry.sql.go
  • service/policy/db/queries/key_access_server_registry.sql

Comment thread service/integration/kas_registry_key_test.go
@c-r33d c-r33d force-pushed the dspx-2741-listkeys-search branch from 6d62d91 to bea7b8e Compare June 3, 2026 15:32
@github-actions

github-actions Bot commented Jun 3, 2026

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 141.215834ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 359.255406ms
Throughput 278.35 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 34.374480134s
Average Latency 342.444314ms
Throughput 145.46 requests/second

Comment thread service/integration/kas_registry_key_test.go Outdated
Comment thread service/integration/kas_registry_key_test.go Outdated
elizabethhealy
elizabethhealy previously approved these changes Jun 3, 2026
@policy-bot-opentdf policy-bot-opentdf Bot dismissed stale reviews from elizabethhealy June 3, 2026 18:17

Invalidated by push of a064ce2

@github-actions

github-actions Bot commented Jun 3, 2026

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 139.727816ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 348.427003ms
Throughput 287.00 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 33.713528301s
Average Latency 335.810706ms
Throughput 148.31 requests/second

@github-actions

github-actions Bot commented Jun 3, 2026

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.

@c-r33d c-r33d merged commit 8b33e1c into search-term-impl Jun 3, 2026
34 of 35 checks passed
@c-r33d c-r33d deleted the dspx-2741-listkeys-search branch June 3, 2026 18:41
c-r33d added a commit that referenced this pull request Jun 15, 2026
## Summary
- Adds ListKeys RPC search support by wiring request search into the
policy DB list query.
- Applies escaped, case-insensitive matching in the KAS key SQL path and
adds integration coverage for search behavior, wildcard literals, empty
search, whitespace handling, and pagination after filtering.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

* **New Features**
  * Search capability for KAS registry keys by key ID.
  * Search input automatically trims leading and trailing whitespace.
  * Wildcard characters in search queries are properly escaped.
  * Search results work seamlessly with existing filters and pagination.

* **Tests**
  * Added comprehensive test coverage for search functionality.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Chris Reed <creed@virtru.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:db DB component comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) size/s

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants