-
Notifications
You must be signed in to change notification settings - Fork 24
feat(policy): Restrict deletion of pc with used key. #2414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @c-r33d, 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!
Summary of Changes
Hello team,
Gemini here, providing a summary of this pull request by @c-r33d. The primary goal of this PR is to enforce a policy at the database level that prevents the deletion of a ProviderConfig if it is currently associated with a KeyAccessServerKey (a key). This shifts the responsibility for this check from the application code to the database's foreign key constraints, specifically using ON DELETE RESTRICT.
The changes involve adding a database migration to implement the foreign key constraint, removing the now redundant application-level check when creating a key, updating schema documentation, and adding/modifying tests to verify the new database-enforced behavior.
Highlights
- Application Logic Removal: The application-level check that previously fetched the
ProviderConfigwhen creating a key has been removed, as the database now handles the validation of theprovider_config_idexistence. - Testing: An existing test for creating a key with an invalid provider config is updated to expect a foreign key violation error instead of a 'not found' error. A new integration test is added specifically to verify that attempting to delete a
ProviderConfigthat is in use by a key results in a foreign key violation error. - Documentation: The database schema ER diagrams (both the migration-specific one and the main schema file) are updated to visually represent the new foreign key relationship between
key_access_server_keysandprovider_config.
Changelog
Click here to see the changelog
- service/integration/kas_registry_key_test.go
- Updated test
Test_CreateKasKey_ProviderConfigInvalid_Failto assert fordb.ErrForeignKeyViolation.Error()at line 100, reflecting the shift to database-level validation.
- Updated test
- service/integration/keymanagement_test.go
- Added import for
github.com/opentdf/platform/protocol/go/policy/kasregistryat line 12. - Added new test
Test_DeleteProviderConfig_InUse_Failsstarting at line 388 to specifically test theON DELETE RESTRICTbehavior.
- Added import for
- service/policy/db/key_access_server_registry.go
- Removed import for
github.com/opentdf/platform/protocol/go/policy/keymanagementat line 15. - Removed application logic that fetched the provider config before creating a key (lines 377-386).
- Updated the database insert statement in
CreateKeyto directly use the providedproviderConfigIDat line 403.
- Removed import for
- service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
- Added a new markdown file documenting the foreign key relationship between
key_access_server_keysandprovider_configusing a mermaid diagram (lines 1-21).
- Added a new markdown file documenting the foreign key relationship between
- service/policy/db/migrations/20250609000000_restrict_provider_deletion.sql
- Added a new SQL migration file to drop and re-add the foreign key constraint on
key_access_server_keys.provider_config_idwithON DELETE RESTRICT(lines 1-30).
- Added a new SQL migration file to drop and re-add the foreign key constraint on
- service/policy/db/schema_erd.md
- Updated the
key_access_server_keystable definition to markprovider_config_idas a foreign key (FK) at line 119. - Added the relationship line
key_access_server_keys }o--|| provider_config : "provider_config_id"to the ER diagram definition at line 252.
- Updated the
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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.
A foreign key, strong and true,
Links tables, old and new.
Delete restricted,
A rule respected,
Data integrity sees it through.
Footnotes
-
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. ↩
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
service/policy/db/migrations/20250609000000_restrict_provider_deletion.md
Show resolved
Hide resolved
There was a problem hiding this 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 effectively moves the responsibility of restricting the deletion of in-use provider configurations from the application layer to the database layer by utilizing an ON DELETE RESTRICT foreign key constraint. This is a good practice for ensuring data integrity.
The code changes, including the new SQL migration, updates to the ERD, and the new integration test, appear to correctly implement this feature. The removal of the application-level check in CreateKey is consistent with this approach, and the updated test in kas_registry_key_test.go reflects the change in error handling.
However, a significant concern is that the checklist items in the pull request description (unit tests, integration tests, documentation) are all unchecked. This needs to be addressed before merging.
Summary of Findings
- PR Checklist Incomplete: The pull request checklist indicates that unit tests, integration tests, and documentation have not been added or updated. Please ensure these are completed and the checklist is updated accordingly. This is important for maintaining code quality and ensuring the changes are well-understood and tested.
Merge Readiness
The core logic of restricting provider configuration deletion at the database level is well-implemented and tested with a new integration test. However, the PR checklist items for unit tests, integration tests, and documentation are currently unchecked. It's crucial to address these items to ensure comprehensive testing and proper documentation of the changes.
Therefore, I recommend that these checklist items be completed before this pull request is merged. I am not authorized to approve pull requests, so please ensure other reviewers also assess these changes.
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
Standard Benchmark Metrics Skipped or Failed |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Bulk Benchmark Results
TDF3 Benchmark Results:
NANOTDF Benchmark Results:
Standard Benchmark Metrics Skipped or Failed |
🤖 I have created a release *beep* *boop* --- ## [0.7.0](service/v0.6.0...service/v0.7.0) (2025-06-24) ### ⚠ BREAKING CHANGES * **policy:** disable kas grants in favor of key mappings ([#2220](#2220)) ### Features * **authz:** Add caching to keycloak ERS ([#2466](#2466)) ([f5b0a06](f5b0a06)) * **authz:** auth svc registered resource GetDecision support ([#2392](#2392)) ([5405674](5405674)) * **authz:** authz v2 GetBulkDecision ([#2448](#2448)) ([0da3363](0da3363)) * **authz:** cache entitlement policy within authorization service ([#2457](#2457)) ([c16361c](c16361c)) * **authz:** ensure logging parity between authz v2 and v1 ([#2443](#2443)) ([ef68586](ef68586)) * **core:** add cache manager ([#2449](#2449)) ([2b062c5](2b062c5)) * **core:** consume RPC interceptor request context metadata in logging ([#2442](#2442)) ([2769c48](2769c48)) * **core:** DSPX-609 - add cli-client to keycloak provisioning ([#2396](#2396)) ([48e7489](48e7489)) * **core:** ERS cache setup, fix cache initialization ([#2458](#2458)) ([d0c6938](d0c6938)) * inject logger and cache manager to key managers ([#2461](#2461)) ([9292162](9292162)) * **kas:** expose provider config from key details. ([#2459](#2459)) ([0e7d39a](0e7d39a)) * **main:** Add Close() method to cache manager ([#2465](#2465)) ([32630d6](32630d6)) * **policy:** disable kas grants in favor of key mappings ([#2220](#2220)) ([30f8cf5](30f8cf5)) * **policy:** Restrict deletion of pc with used key. ([#2414](#2414)) ([3b40a46](3b40a46)) * **sdk:** allow Connect-Protocol-Version RPC header for cors ([#2437](#2437)) ([4bf241e](4bf241e)) ### Bug Fixes * **core:** remove generics on new platform cache manager and client ([#2456](#2456)) ([98c3c16](98c3c16)) * **core:** replace opentdf-public client with cli-client ([#2422](#2422)) ([fb18525](fb18525)) * **deps:** bump github.com/casbin/casbin/v2 from 2.106.0 to 2.107.0 in /service in the external group ([#2416](#2416)) ([43afd48](43afd48)) * **deps:** bump github.com/opentdf/platform/protocol/go from 0.4.0 to 0.5.0 in /service ([#2470](#2470)) ([3a73fc9](3a73fc9)) * **deps:** bump github.com/opentdf/platform/sdk from 0.4.7 to 0.5.0 in /service ([#2473](#2473)) ([ad37476](ad37476)) * **deps:** bump the external group across 1 directory with 2 updates ([#2450](#2450)) ([9d8d1f1](9d8d1f1)) * **deps:** bump the external group across 1 directory with 2 updates ([#2472](#2472)) ([d45b3c8](d45b3c8)) * only request a token when near expiration ([#2370](#2370)) ([556d95e](556d95e)) * **policy:** fix casing bug and get provider config on update. ([#2403](#2403)) ([a52b8f9](a52b8f9)) * **policy:** properly formatted pem in test fixtures ([#2409](#2409)) ([54ffd23](54ffd23)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com>
Proposed Changes
1.) Update key_access_server_keys table to not allow deletion of in-use provider configurations
2.) Remove application level check for provider_configuration, in-favor or db level
Checklist
Testing Instructions