feat(policy)!: namespace Registered Resources#3111
Conversation
Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
Summary of ChangesHello, 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 fundamental support for namespacing Registered Resources across the system. The primary goal is to allow for greater organization and isolation of resources by associating them with specific namespaces. This involves significant changes to the data model, identifier handling, and service layer logic to ensure that resources can be uniquely identified and managed within their respective namespaces, while also maintaining compatibility with existing, non-namespaced resources. Highlights
🧠 New Feature in Public Preview: You can now enable Memory 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. Changelog
Activity
Using Gemini Code AssistThe 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
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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. Namespaces now define, Resources neatly align, No more global strife. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces namespace support for Registered Resources across the service layer, database queries, and migrations. It updates the identifier library to handle new namespaced FQN formats for registered resource values, while maintaining backward compatibility with the legacy format. The changes are well-supported by new integration and unit tests.
My review identifies a critical issue that could lead to a panic when handling legacy resources, and a medium-severity validation gap for namespaces in FQNs. I've provided suggestions to address both. Overall, the changes are well-structured and the test coverage is good.
There was a problem hiding this comment.
Code Review
This pull request introduces namespace support for Registered Resources, which is a significant and breaking change. The modifications span across the database layer with new migrations and updated queries, the identifier library for FQN parsing, and includes a comprehensive set of new integration and unit tests. Overall, the changes are well-structured. However, I've identified a few issues related to correctness and performance that should be addressed. Specifically, there's a bug in FQN generation that could break round-trip serialization, missing validation for namespace components in FQNs, and an inefficient query being used for namespace enforcement.
Note: Security Review did not run due to the size of the PR.
| rv, err := c.GetRegisteredResourceValue(ctx, ®isteredresources.GetRegisteredResourceValueRequest{ | ||
| Identifier: ®isteredresources.GetRegisteredResourceValueRequest_Id{ | ||
| Id: registeredResourceValueID, | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
To enforce same-namespace constraints, you're fetching the entire registered resource value using GetRegisteredResourceValue just to get the namespace ID. This is inefficient as GetRegisteredResourceValue executes a large and complex query.
A more performant approach would be to create a new, simple query to fetch only the namespace_id of the resource associated with the given resource value ID.
For example, you could add a query like this to service/policy/db/queries/registered_resources.sql:
-- name: getRegisteredResourceNamespaceByValueID :one
SELECT r.namespace_id
FROM registered_resources r
JOIN registered_resource_values v ON r.id = v.registered_resource_id
WHERE v.id = $1;Then, you can call this more efficient query here instead of GetRegisteredResourceValue.
There was a problem hiding this comment.
Instead of enforcing the same-namespace constraints using go and multiple sql queries, I've moved the constraints to a single sql query to simplify the go logic.
X-Test Failure Report✅ go-v0.9.0 |
Signed-off-by: Krish Suchak <suchak.krish@gmail.com>
X-Test Failure Report✅ go-v0.9.0 |
X-Test Failure Report✅ go-v0.9.0 |
…espace-rr-service
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Summary
Depends on #3110 (proto changes) being merged first.
This is part 2 of splitting #3106 into two PRs.
Test plan