-
-
Notifications
You must be signed in to change notification settings - Fork 289
feat: add on-demand signature generation #1108
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
ferhatelmas
wants to merge
1
commit into
master
Choose a base branch
from
ferhat/signatures
base: master
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,90 @@ | ||
| ALTER TABLE storage.objects | ||
| ADD COLUMN IF NOT EXISTS signature bytea; | ||
|
ferhatelmas marked this conversation as resolved.
|
||
|
|
||
|
ferhatelmas marked this conversation as resolved.
|
||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM pg_constraint | ||
| WHERE conname = 'objects_signature_length' | ||
| AND conrelid = 'storage.objects'::regclass | ||
| ) THEN | ||
| ALTER TABLE storage.objects | ||
| ADD CONSTRAINT objects_signature_length | ||
| CHECK (signature IS NULL OR octet_length(signature) = 32) | ||
| NOT VALID; | ||
| END IF; | ||
| END $$; | ||
|
|
||
| DROP TRIGGER IF EXISTS update_objects_updated_at ON storage.objects; | ||
|
|
||
| -- Keep this list in sync with all non-generated storage.objects columns except signature. | ||
| -- Generated columns such as path_tokens are intentionally omitted. | ||
| -- The explicit row comparison avoids converting every updated object row to jsonb. | ||
| CREATE TRIGGER update_objects_updated_at | ||
| BEFORE UPDATE ON storage.objects | ||
| FOR EACH ROW | ||
| WHEN ( | ||
| ROW( | ||
| NEW.id, | ||
| NEW.bucket_id, | ||
| NEW.name, | ||
| NEW.owner, | ||
| NEW.created_at, | ||
| NEW.updated_at, | ||
| NEW.last_accessed_at, | ||
| NEW.metadata, | ||
| NEW.version, | ||
| NEW.owner_id, | ||
| NEW.user_metadata | ||
| ) | ||
| IS DISTINCT FROM | ||
| ROW( | ||
| OLD.id, | ||
| OLD.bucket_id, | ||
| OLD.name, | ||
| OLD.owner, | ||
| OLD.created_at, | ||
| OLD.updated_at, | ||
| OLD.last_accessed_at, | ||
| OLD.metadata, | ||
| OLD.version, | ||
| OLD.owner_id, | ||
| OLD.user_metadata | ||
| ) | ||
|
ferhatelmas marked this conversation as resolved.
|
||
| ) | ||
| EXECUTE PROCEDURE update_updated_at_column(); | ||
|
|
||
| CREATE OR REPLACE FUNCTION storage.enforce_objects_signature_client_writes() | ||
| RETURNS trigger | ||
| AS $$ | ||
| DECLARE | ||
| anon_role text = COALESCE(current_setting('storage.anon_role', true), 'anon'); | ||
| authenticated_role text = COALESCE(current_setting('storage.authenticated_role', true), 'authenticated'); | ||
| effective_role text = COALESCE(NULLIF(current_setting('role', true), 'none'), current_user); | ||
| BEGIN | ||
| IF effective_role = anon_role OR effective_role = authenticated_role THEN | ||
| IF TG_OP = 'INSERT' AND NEW.signature IS NOT NULL THEN | ||
| RAISE EXCEPTION 'Only storage service roles can set object signatures' | ||
| USING ERRCODE = '42501'; | ||
| END IF; | ||
|
|
||
| IF TG_OP = 'UPDATE' | ||
| AND NEW.signature IS NOT NULL | ||
| AND NEW.signature IS DISTINCT FROM OLD.signature | ||
| THEN | ||
| RAISE EXCEPTION 'Only storage service roles can set object signatures' | ||
| USING ERRCODE = '42501'; | ||
| END IF; | ||
|
ferhatelmas marked this conversation as resolved.
|
||
| END IF; | ||
|
|
||
| RETURN NEW; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
| DROP TRIGGER IF EXISTS enforce_objects_signature_client_writes ON storage.objects; | ||
|
|
||
| CREATE TRIGGER enforce_objects_signature_client_writes | ||
| BEFORE INSERT OR UPDATE ON storage.objects | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION storage.enforce_objects_signature_client_writes(); | ||
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,6 @@ | ||
| -- postgres-migrations disable-transaction | ||
|
|
||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_objects_missing_signature_bucket_id_name | ||
| ON storage.objects (bucket_id, name) | ||
| INCLUDE (version) | ||
| WHERE signature IS NULL; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.