-
Notifications
You must be signed in to change notification settings - Fork 37
Fix bug of adding temporal schema to types in alter priviledges of functions #367
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
Open
marioloko
wants to merge
1
commit into
pgplex:main
Choose a base branch
from
marioloko:issue_366
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| REVOKE EXECUTE ON FUNCTION create_entity(p_name text, p_kind entity_kind) FROM PUBLIC; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION create_entity(p_name text, p_kind entity_kind) TO app_user; |
16 changes: 16 additions & 0 deletions
16
testdata/diff/privilege/grant_function_custom_type/new.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'app_user') THEN | ||
| CREATE ROLE app_user; | ||
| END IF; | ||
| END $$; | ||
|
|
||
| CREATE TYPE entity_kind AS ENUM ('person', 'company', 'organization'); | ||
|
|
||
| CREATE FUNCTION create_entity(p_name text, p_kind entity_kind) | ||
| RETURNS uuid | ||
| LANGUAGE sql | ||
| AS $$ SELECT gen_random_uuid(); $$; | ||
|
|
||
| REVOKE ALL ON FUNCTION create_entity(text, entity_kind) FROM PUBLIC; | ||
| GRANT EXECUTE ON FUNCTION create_entity(text, entity_kind) TO app_user; |
13 changes: 13 additions & 0 deletions
13
testdata/diff/privilege/grant_function_custom_type/old.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'app_user') THEN | ||
| CREATE ROLE app_user; | ||
| END IF; | ||
| END $$; | ||
|
|
||
| CREATE TYPE entity_kind AS ENUM ('person', 'company', 'organization'); | ||
|
|
||
| CREATE FUNCTION create_entity(p_name text, p_kind entity_kind) | ||
| RETURNS uuid | ||
| LANGUAGE sql | ||
| AS $$ SELECT gen_random_uuid(); $$; |
26 changes: 26 additions & 0 deletions
26
testdata/diff/privilege/grant_function_custom_type/plan.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "version": "1.0.0", | ||
| "pgschema_version": "1.7.4", | ||
| "created_at": "1970-01-01T00:00:00Z", | ||
| "source_fingerprint": { | ||
| "hash": "bdbb0798afa7207ece90d61d6b44f6a7625cdcb9578888587c326d9c6ae8d22a" | ||
| }, | ||
| "groups": [ | ||
| { | ||
| "steps": [ | ||
| { | ||
| "sql": "REVOKE EXECUTE ON FUNCTION create_entity(p_name text, p_kind entity_kind) FROM PUBLIC;", | ||
| "type": "revoked_default_privilege", | ||
| "operation": "create", | ||
| "path": "revoked_default.FUNCTION.create_entity(p_name text, p_kind entity_kind)" | ||
| }, | ||
| { | ||
| "sql": "GRANT EXECUTE ON FUNCTION create_entity(p_name text, p_kind entity_kind) TO app_user;", | ||
| "type": "privilege", | ||
| "operation": "create", | ||
| "path": "privileges.FUNCTION.create_entity(p_name text, p_kind entity_kind).app_user" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| REVOKE EXECUTE ON FUNCTION create_entity(p_name text, p_kind entity_kind) FROM PUBLIC; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION create_entity(p_name text, p_kind entity_kind) TO app_user; |
18 changes: 18 additions & 0 deletions
18
testdata/diff/privilege/grant_function_custom_type/plan.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Plan: 2 to add. | ||
|
|
||
| Summary by type: | ||
| privileges: 1 to add | ||
| revoked default privileges: 1 to add | ||
|
|
||
| Privileges: | ||
| + app_user | ||
|
|
||
| Revoked default privileges: | ||
| + create_entity(p_name text, p_kind entity_kind) | ||
|
|
||
| DDL to be executed: | ||
| -------------------------------------------------- | ||
|
|
||
| REVOKE EXECUTE ON FUNCTION create_entity(p_name text, p_kind entity_kind) FROM PUBLIC; | ||
|
|
||
| GRANT EXECUTE ON FUNCTION create_entity(p_name text, p_kind entity_kind) TO app_user; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
strings.ReplaceAll(signature, schema+".", "")searches for the raw substring anywhere insignature. If the current schema name appears as a suffix of another schema's name, it will incorrectly mutate types from that other schema.Concrete example:
"app""myapp.some_type""myapp.some_type"contains the substring"app."(starting at position 2)"my" + "" + "some_type"→"mysome_type"← incorrectA safer approach is to anchor the match so it only fires when
schema.is preceded by a parameter boundary (open-paren, comma, or space):Or more simply, pre-compile the patterns with a leading
(?:^|[(,\s])assertion. The current approach is fine for common schema names that are not substrings of other schema names used in the same function signature, but it is a correctness risk for cross-schema type references in that edge case.