Skip to content

feat(policy): add search support to ListSubjectMappings - #3555

Merged
c-r33d merged 4 commits into
search-term-implfrom
dspx-2738-listsubjectmappings-search
Jun 3, 2026
Merged

feat(policy): add search support to ListSubjectMappings#3555
c-r33d merged 4 commits into
search-term-implfrom
dspx-2738-listsubjectmappings-search

Conversation

@c-r33d

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

Copy link
Copy Markdown
Contributor

Summary

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

Summary by CodeRabbit

  • New Features
    • Subject mappings now support search filtering by attribute values and metadata labels
    • Search results can be combined with namespace filters for refined queries
    • Automatic whitespace trimming and special character handling ensure accurate searches
    • Result pagination works correctly with all filters applied

@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: 8e059dec-2762-402b-b01f-4f93f59e008e

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

Adds search filtering to ListSubjectMappings via a new CTE that centralizes namespace and FQN/label filtering, updates sqlc-generated bindings to wire the search parameter, integrates search term extraction in the service layer, and validates behavior with six integration tests covering matching, whitespace handling, wildcard escaping, and pagination.

Changes

Subject Mappings Search Implementation

Layer / File(s) Summary
SQL Query Refactoring with Filtered CTE
service/policy/db/queries/subject_mappings.sql
Introduces filtered_subject_mappings CTE that applies namespace filtering, FQN LIKE matching, and label ILIKE matching on subject mappings; selects distinct mapping IDs and computes totals from the filtered set; main query joins to this CTE to restrict results.
Generated SQL Bindings and Call-Site Wiring
service/policy/db/subject_mappings.sql.go
Updates sqlc-generated code: adds filtered_subject_mappings CTE structure to generated SQL string, adds Search field to listSubjectMappingsParams, reorders SQL placeholders (moves OFFSET/LIMIT earlier), and updates the Go call-site argument order to pass Offset, Limit, then Search at the end.
Service Layer Request Integration
service/policy/db/subject_mappings.go
Updates ListSubjectMappings to extract search term from r.GetSearch().GetTerm(), compute a substring pattern, and pass it to the query via listSubjectMappingsParams.Search.
Integration Tests for Search Behavior
service/integration/subject_mappings_test.go
Adds six test methods (SearchByAttributeValueFQNAndLabels, SearchTrimsWhitespace, SearchEscapesLikeWildcardLiterals, SearchCombinesWithNamespace, SearchEmptyQuery, SearchPaginationAppliesAfterFiltering) plus helper functions (createSearchSubjectMappingNamespace, createSearchSubjectMapping, deleteSearchSubjectMappingNamespace) to validate search filtering across FQN/label matching, whitespace handling, wildcard character escaping, namespace scoping, and pagination order.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • opentdf/platform#3255: Both PRs modify the same listSubjectMappings query and its sqlc-generated bindings in subject_mappings.sql/subject_mappings.sql.go, making correlated changes to parameter placeholder ordering and CTE structure.

Suggested reviewers

  • elizabethhealy

Poem

🐰 A search through the mappings we go,
With CTEs filtering high and low,
FQNs and labels, wildcards we tame,
Pagination counts without loss of name,
Tests hop along to prove all is right!
✨🔍

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely describes the main change: adding search support to the ListSubjectMappings feature, which aligns with the changeset's core objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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-2738-listsubjectmappings-search

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 the comp:db DB component label 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 ListSubjectMappings RPC. By integrating a new filtering layer into the underlying SQL query, the system now supports searching across multiple fields, including attribute FQNs, actions, and complex condition structures. This change improves the discoverability of subject mappings and includes robust integration tests to ensure search and pagination work as expected.

Highlights

  • Search Support: Added search functionality to the ListSubjectMappings RPC, allowing for case-insensitive, escaped matching across subject mapping fields.
  • Database Query Update: Updated the SQL query for subject mappings to include a filtering layer that handles the new search term, supporting lookups on FQNs, action names, and JSONB-based condition structures.
  • Integration Testing: Added comprehensive integration tests to verify search behavior, including wildcard handling, empty search queries, and correct pagination behavior 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 search is on, the query wide, With SQL logic as our guide. From FQN to action name, We find the mappings in the frame.

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.

@github-actions github-actions Bot added comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) size/m labels Jun 1, 2026

@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 subject mappings, allowing filtering by FQNs, actions, and nested JSONB conditions. It also adds comprehensive integration tests to verify the search behavior, including pagination and namespace combinations. A critical review comment points out a potential PostgreSQL runtime error when parsing JSONB keys that contain JSON null values, which can cause JSONB_ARRAY_ELEMENTS to fail on a scalar. It is recommended to use jsonb_typeof to verify that the JSONB values are arrays before expanding them.

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/db/queries/subject_mappings.sql Outdated
@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 182.693893ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 417.301566ms
Throughput 239.63 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.999405426s
Average Latency 447.537288ms
Throughput 111.11 requests/second

@c-r33d
c-r33d force-pushed the dspx-2738-listsubjectmappings-search branch from 6242e56 to f0cdc22 Compare June 3, 2026 12:14
@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 184.355363ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 456.535153ms
Throughput 219.04 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.337570358s
Average Latency 452.3345ms
Throughput 110.28 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 199.396953ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 418.848784ms
Throughput 238.75 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.928754796s
Average Latency 447.887029ms
Throughput 111.29 requests/second

c-r33d added 3 commits June 3, 2026 08:57
Signed-off-by: Chris Reed <creed@virtru.com>
Signed-off-by: Chris Reed <creed@virtru.com>
Signed-off-by: Chris Reed <creed@virtru.com>
@c-r33d
c-r33d force-pushed the dspx-2738-listsubjectmappings-search branch from a8e79d0 to 1a8d75b Compare June 3, 2026 13:57
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

X-Test Failure Report

@c-r33d
c-r33d marked this pull request as ready for review June 3, 2026 13:58
@c-r33d
c-r33d requested review from a team as code owners June 3, 2026 13:58
@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 190.954674ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 445.589707ms
Throughput 224.42 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.001059352s
Average Latency 448.446127ms
Throughput 111.11 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 192.513349ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 417.407755ms
Throughput 239.57 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 44.84319888s
Average Latency 447.125797ms
Throughput 111.50 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: 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/policy/db/queries/subject_mappings.sql`:
- Around line 132-139: The FQN search branch uses a case-sensitive LIKE, so
update the predicate that references fqns.fqn in the filtered_subject_mappings
query to perform a case-insensitive match (e.g., change the fqns.fqn LIKE
sqlc.narg('search')::TEXT ESCAPE '\' to use ILIKE or wrap with LOWER on both
sides) so it matches the lowercased bound search parameter from
sqlc.narg('search')::TEXT; ensure the change is applied in the same CASE branch
alongside the existing JSONB label ILIKE check.
🪄 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: 9df402c6-98a1-4741-bc07-7e07099e0bee

📥 Commits

Reviewing files that changed from the base of the PR and between bb38767 and 1a8d75b.

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

Comment thread service/policy/db/queries/subject_mappings.sql
jakedoublev
jakedoublev previously approved these changes Jun 3, 2026
Comment thread service/integration/subject_mappings_test.go Outdated
Comment thread service/integration/subject_mappings_test.go
Comment thread service/integration/subject_mappings_test.go
@policy-bot-opentdf
policy-bot-opentdf Bot dismissed jakedoublev’s stale review June 3, 2026 15:02

Invalidated by push of 7dacd7f

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

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 400.182697ms
Throughput 249.89 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 41.521854712s
Average Latency 413.219622ms
Throughput 120.42 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 b658796 into search-term-impl Jun 3, 2026
35 checks passed
@c-r33d
c-r33d deleted the dspx-2738-listsubjectmappings-search branch June 3, 2026 15:18
c-r33d added a commit that referenced this pull request Jun 15, 2026
## Summary
- Adds ListSubjectMappings RPC search support by wiring request search
into the policy DB list query.
- Applies escaped, case-insensitive matching in the subject mappings SQL
path and adds integration coverage for search behavior, wildcard
literals, empty search, and pagination after filtering.

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

## Summary by CodeRabbit

* **New Features**
* Subject mappings now support search filtering by attribute values and
metadata labels
* Search results can be combined with namespace filters for refined
queries
* Automatic whitespace trimming and special character handling ensure
accurate searches
  * Result pagination works correctly with all filters applied

<!-- 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/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants