Skip to content

schemachange: check the recorded owner's schema USAGE before discarding a dropped table's run - #738

Draft
Kiran01bm wants to merge 1 commit into
kiran01bm/pd96-owner-access-per-doorfrom
kiran01bm/pd219-discard-gone-owner-usage
Draft

Kiran01bm wants to merge 1 commit into
kiran01bm/pd96-owner-access-per-doorfrom
kiran01bm/pd219-discard-gone-owner-usage

Conversation

@Kiran01bm

Copy link
Copy Markdown
Collaborator

Discarding a stopped run whose table has since been dropped now checks that the table's recorded owner can reach the schema before it drops anything, as discarding a run on a table that still exists does.

Why

A copy-and-swap run that stops leaves a half-built copy of the table behind, and pg-sprite discard cleans it up. The copy is dropped as the table's owner, so that owner needs access (USAGE) to the schema. The parent PR makes the discard of a table that still exists check this first. The discard of a table someone has dropped since the run stopped did not, so it could fail with "permission denied" part-way through.

What

  • Runner.DiscardGone calls preflight.CheckCopySwapOwnerUsage for the owner and schema the checkpoint row records, after it has found the shadow and before the first drop. A run with no shadow left is not checked.
  • CheckCopySwapOwnerUsage now takes the owner, schema and table names rather than a CopySwapShape, since a dropped table has no shape to prove. Runner.Discard passes its shape's names.
  • One container test: the owner loses USAGE after the table is dropped. The discard is refused with a PrivilegeError granting USAGE alone, and the copy and the row are still there. Once USAGE is granted again, the discard drops both. It fails on the parent branch.
  • engine-role.md says DiscardGone makes the same check.

Stacked on #736; merge that first.

Before / after

A run on app.orders (owned by orders_owner) stopped while verifying. Then the table was dropped, and orders_owner lost USAGE on schema app.

pg-sprite discard app.orders     (the table is gone; the shadow copy and the row remain)

Before
  check the recorded owner's access   not checked
  drop the copy as orders_owner       ERROR permission denied for schema app
  result                              the discard fails part-way

After
  check the recorded owner's access   orders_owner has no USAGE on app
  result                              refused before anything is dropped:
                                      "GRANT USAGE ON SCHEMA app TO orders_owner"

Discarding a run whose table was dropped drops the shadow as the owner the
row records; without USAGE on the schema it failed part-way with permission
denied instead of refusing before anything was dropped.
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