Skip to content

feat(policy): DSPX-2998 optionally namespace resource mappings#3567

Draft
alkalescent wants to merge 2 commits into
DSPX-2998-optional-namespace-resource-mappingsfrom
DSPX-2998-rm-namespace-service
Draft

feat(policy): DSPX-2998 optionally namespace resource mappings#3567
alkalescent wants to merge 2 commits into
DSPX-2998-optional-namespace-resource-mappingsfrom
DSPX-2998-rm-namespace-service

Conversation

@alkalescent
Copy link
Copy Markdown
Contributor

@alkalescent alkalescent commented Jun 4, 2026

Proposed Changes

Second PR in the stacked series for DSPX-2998. Implements the service side (AC1 + AC2). Stacked on #3565 (proto) — review/merge that first.

  • Migration adds a nullable namespace_id (FK to attribute_namespaces, ON DELETE CASCADE) + index to resource_mappings.
  • Resolve a mapping's owning namespace from namespace_id / namespace_fqn or its group; a grouped mapping must share its group's namespace (else ErrNamespaceMismatch).
  • Remove the old constraint that forced the mapped attribute value into the group's namespace, so mappings/groups may cross namespaces to the attribute values they map (per the Jira design comment).
  • Hydrate the namespace on get/list responses; add namespace_id / namespace_fqn filters to ListResourceMappings and namespace_fqn to ListResourceMappingGroups.
  • Enforce a namespace on create when namespaced_policy is enabled (namespace_id, namespace_fqn, or group_id satisfies it), matching the RR/Actions/SM pattern.
  • Adds/updates integration tests, including the now-allowed cross-namespace cases.

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

cd service && go test ./integration/ -run TestResourceMappingsSuite (requires Docker for testcontainers).

Related

Implement the service side of optional namespacing for resource mappings:

- Add a migration adding a nullable namespace_id (FK to attribute_namespaces,
  ON DELETE CASCADE) plus an index to resource_mappings.
- Resolve a mapping's owning namespace from namespace_id/namespace_fqn or its
  group; a grouped mapping must share the group's namespace.
- Remove the constraint forcing the mapped attribute value into the group's
  namespace, allowing mappings to cross namespaces to the values they map.
- Hydrate the namespace on get/list responses and add namespace_id/namespace_fqn
  filters to ListResourceMappings, plus namespace_fqn to ListResourceMappingGroups.
- Enforce a namespace on create when namespaced_policy is enabled (namespace_id,
  namespace_fqn, or group_id satisfies it).
- Update/extend integration tests for the new behavior.

Stacked on the proto PR (#3565).

Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 4, 2026

Important

Review skipped

Draft detected.

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: bee503f8-bfb6-4559-ac1c-dd457241ffa1

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DSPX-2998-rm-namespace-service

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.

@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 implements optional namespacing for resource mappings, enabling better multi-tenant isolation and management. It allows resource mappings to be explicitly associated with a namespace or inherited from a parent group, while decoupling the mapping's owning namespace from the namespace of the attribute values it maps. These changes include database schema migrations, updated query logic, and enhanced API support for filtering and retrieving namespace information.

Highlights

  • Database Schema Update: Added a nullable namespace_id column to the resource_mappings table with a cascading delete constraint and a corresponding index to support namespace-scoped queries.
  • Namespace Resolution Logic: Implemented logic to resolve and enforce namespace ownership for resource mappings, allowing mappings to cross namespaces to the attribute values they map while ensuring group-based mappings remain consistent with their parent group's namespace.
  • API and Query Enhancements: Updated ListResourceMappings and ListResourceMappingGroups to support filtering by namespace_id and namespace_fqn, and updated response hydration to include namespace details.
  • Namespace Enforcement: Added validation to CreateResourceMapping to enforce namespace requirements when namespaced_policy is enabled.
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 mapping now finds its own home, Across namespaces it's free to roam. With group or with ID, It's clear as can be, No longer in shadows to gloam.

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:db DB component comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) size/m labels Jun 4, 2026
Copy link
Copy Markdown
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 a nullable namespace_id column to the resource_mappings table, allowing resource mappings to be optionally namespaced independently of the mapped attribute value's namespace. It updates the database schema, models, and SQL queries to support this field, including new filtering capabilities by namespace ID or FQN when listing resource mappings and groups. Additionally, it implements namespace resolution and validation logic during resource mapping creation and updates, and enforces namespace requirements when the NamespacedPolicy configuration is enabled. Feedback on the changes highlights a potential issue in resolveResourceMappingNamespaceID where providing both namespaceID and namespaceFqn in a request results in the FQN being silently ignored without consistency validation.

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 on lines +380 to +391
switch {
case namespaceID != "":
if !pgtypeUUID(namespaceID).Valid {
return "", db.ErrUUIDInvalid
}
case namespaceFqn != "":
ns, err := c.GetNamespace(ctx, &namespaces.GetNamespaceRequest_Fqn{Fqn: namespaceFqn})
if err != nil {
return "", err
}
namespaceID = ns.GetId()
}
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.

medium

If both namespaceID and namespaceFqn are provided in the request, the switch statement will only execute the first case (namespaceID != "") and silently ignore namespaceFqn without validating that they match. Consider validating that they are consistent if both are provided, or returning an error to prevent unexpected behavior.

	if namespaceID != "" {
		if !pgtypeUUID(namespaceID).Valid {
			return "", db.ErrUUIDInvalid
		}
	}
	if namespaceFqn != "" {
		ns, err := c.GetNamespace(ctx, &namespaces.GetNamespaceRequest_Fqn{Fqn: namespaceFqn})
		if err != nil {
			return "", err
		}
		if namespaceID != "" && namespaceID != ns.GetId() {
			return "", db.ErrNamespaceMismatch
		}
		namespaceID = ns.GetId()
	}

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

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

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 421.207475ms
Throughput 237.41 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 43.712507415s
Average Latency 434.966577ms
Throughput 114.38 requests/second

Add a migration that backfills resource_mappings.namespace_id from the owning
group for existing grouped mappings created before the column existed, so
namespace filtering works on legacy data. Ungrouped mappings remain global.
Idempotent (only fills NULL rows). Adds an integration test for the backfill.

Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

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

Benchmark authorization.v2.GetMultiResourceDecision Results:

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

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 401.363132ms
Throughput 249.15 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 45.143871484s
Average Latency 450.043535ms
Throughput 110.76 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

⚠️ 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: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.

1 participant