Skip to content

Simplify df.grant_usage/df.revoke_usage privilege helpers#242

Merged
pinodeca merged 1 commit into
mainfrom
simplify-grant-revoke-usage
Jun 18, 2026
Merged

Simplify df.grant_usage/df.revoke_usage privilege helpers#242
pinodeca merged 1 commit into
mainfrom
simplify-grant-revoke-usage

Conversation

@pinodeca

@pinodeca pinodeca commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Rationalizes the df.grant_usage() / df.revoke_usage() privilege helpers for the unreleased v0.2.3, removing defensive code that PostgreSQL already handles and making the two functions symmetric.

Changes

  • grant_usage
    • Drops the per-function GRANT EXECUTE allowlist. Ordinary df.* functions keep PostgreSQL's default PUBLIC EXECUTE, so USAGE ON SCHEMA df is the single access gate. Only the sensitive functions (df.http, df.grant_usage, df.revoke_usage) — which have PUBLIC EXECUTE revoked at install time — are granted explicitly.
    • Drops the redundant role-existence check (a named role that doesn't exist fails naturally on the first GRANT; granting to PUBLIC is a deliberate admin choice).
  • revoke_usage
    • Mirror of grant_usage (Option A): undoes only what grant_usage grants.
    • Drops the role-existence and self-revoke guards — PostgreSQL's grantor rules already prevent a non-superuser from removing another role's grants, so self-revoke is a harmless no-op.
  • Upgrade script (sql/pg_durable--0.2.2--0.2.3.sql): same CREATE OR REPLACE bodies as src/lib.rs.
  • E2E test 18 (18_delegated_grants.sql): adds schema/HTTP assertions (5b), asserts loss of schema USAGE after revoke (8), and verifies self-revoke is a harmless no-op (10).
  • Docs: USER_GUIDE.md — fixes the inaccurate self-revoke "safety measure" claim, notes that df.grant_usage('public') grants cluster-wide, and trims the stale per-function manual-grants list. docs/upgrade-testing.md — documents both simplifications.

pgspot gate

The 0.2.2 → 0.2.3 upgrade script is the first non-excluded upgrade script that defines functions. Scanned standalone (without the CREATE SCHEMA df that the install SQL emits, so pgspot can't prove df is extension-owned), the helper bodies tripped PS001/PS005/PS016.

  • Schema-qualified the grant_usage/revoke_usage bodies — pg_catalog.format(...), OPERATOR(pg_catalog.||), and SET search_path = pg_catalog, pg_temp — applied byte-identically in src/lib.rs and the upgrade script. The install SQL stays clean because pgspot suppresses those findings via the emitted CREATE SCHEMA df.
  • Allowlisted PS002 (unsafe CREATE OR REPLACE) for the two exact function signatures in scripts/run-pgspot.sh. PostgreSQL 14.5+ blocks the CREATE OR REPLACE attack inside extension scripts, so this is safe.

Upgrade & Migration

  • B1 (binary backward compat): Function signatures are unchanged; only bodies are simplified. Legacy installs may retain inert per-function EXECUTE grants, which are harmless.
  • All changes fold into the existing 0.2.2 → 0.2.3 upgrade script; no new SQL fixtures needed.

Testing

  • cargo fmt -p pg_durable -- --check
  • cargo build --features pg17 ✅ (only the pre-existing extract_host dead-code warning)
  • ./scripts/test-e2e-local.sh 18_delegated_grants --verbose ✅ (1 passed, 0 failed)
  • scripts/run-pgspot.sh sql/pg_durable--0.2.2--0.2.3.sql ✅ (gate passes; only the two allowlisted PS002 findings)

@pinodeca pinodeca mentioned this pull request Jun 17, 2026
8 tasks
Drop the explicit per-function EXECUTE allowlist from df.grant_usage()
and make df.revoke_usage() symmetric with it. Schema USAGE on df is the
real access gate for ordinary df.* functions, so the helpers now manage
schema USAGE, the table privileges, and EXECUTE only on the sensitive
functions (df.http, df.grant_usage, df.revoke_usage). Function
signatures are unchanged and existing privileges are unaffected.

Changes:
- src/lib.rs: simplified fresh-install bodies.
- sql/pg_durable--0.2.3--0.2.4.sql: CREATE OR REPLACE both helpers so
  pre-existing installs converge with fresh 0.2.4 installs.
- scripts/run-pgspot.sh: allow the two upgrade-script CREATE OR REPLACE
  PS002 findings (schema-qualified, scoped to these functions).
- docs/upgrade-testing.md: v0.2.3 -> v0.2.4 upgrade notes.
- CHANGELOG.md: 0.2.4 entry (#242).
- tests/e2e/sql/18_delegated_grants.sql: updated expectations.
- USER_GUIDE.md: refreshed grant/revoke documentation.
@pinodeca pinodeca force-pushed the simplify-grant-revoke-usage branch from 4844589 to e53a7a1 Compare June 18, 2026 15:04
@pinodeca pinodeca merged commit 7b4e812 into main Jun 18, 2026
12 checks passed
@pinodeca pinodeca deleted the simplify-grant-revoke-usage branch June 18, 2026 15:26
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