Skip to content

fix: support routine privilege diffs#292

Draft
dilame wants to merge 1 commit into
stripe:mainfrom
dilame:fix/routine-privileges
Draft

fix: support routine privilege diffs#292
dilame wants to merge 1 commit into
stripe:mainfrom
dilame:fix/routine-privileges

Conversation

@dilame

@dilame dilame commented Jun 5, 2026

Copy link
Copy Markdown

What changed

Adds schema tracking and migration generation for function/procedure EXECUTE privileges.

  • Fetches routine privileges from pg_proc, expanding ACLDEFAULT('f', proowner) so implicit PUBLIC EXECUTE is visible in the schema model.
  • Adds Privileges to Function and Procedure schema objects.
  • Generates GRANT/REVOKE EXECUTE ON FUNCTION/PROCEDURE statements for routine ACL drift.
  • Normalizes privileges after routine creation so a target schema that revoked default PUBLIC EXECUTE stays revoked.
  • Clears routine privileges during plan validation, matching table privilege behavior, because privilege statements are skipped when temp DB roles do not exist.

Why

PostgreSQL grants EXECUTE on functions/procedures to PUBLIC by default, often represented as proacl = NULL. Before this change, pg-schema-diff did not model routine ACLs, so it could miss drift where production still allowed PUBLIC EXECUTE but the declarative schema had revoked it and granted access only to a specific role.

Validation

Ran full test suite with PostgreSQL 17 server utilities and PostgreSQL 18 pg_dump for --restrict-key support:

go test ./...

Track function and procedure EXECUTE ACLs from pg_proc, including PostgreSQL's implicit PUBLIC EXECUTE default, so plans can revoke leaked routine access and grant the declared role-specific access.

Constraint: PostgreSQL stores default routine EXECUTE grants as NULL proacl, so schema fetch must expand ACLDEFAULT('f', owner).

Rejected: Treat has_function_privilege() as the diff source | it reports effective inherited access instead of declarative ACL state.

Confidence: high

Scope-risk: moderate

Directive: Keep routine privilege validation aligned with table privilege validation because privilege statements are skipped when roles are absent in temp DB.

Tested: go test ./... with PostgreSQL 17 server utilities and PostgreSQL 18 pg_dump for --restrict-key support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant