Skip to content

[spark][flink] Reject row-level operations and rewrites under query auth rules - #10906

Open
plusplusjiajia wants to merge 1 commit into
apache:masterfrom
plusplusjiajia:fix/reject-rewrites-under-query-auth-rules
Open

plusplusjiajia wants to merge 1 commit into
apache:masterfrom
plusplusjiajia:fix/reject-rewrites-under-query-auth-rules

Conversation

@plusplusjiajia

@plusplusjiajia plusplusjiajia commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Purpose

On a table with query auth, operations that read rows and write them back used the caller's row filter and column masks: masked values were stored as real data, hidden rows were deleted or lost in overwrites, and insert-only merges inserted hidden keys again.

These operations now fail when query auth gives the caller a row filter or a column mask. Users with full access are not affected, as in PyPaimon.

  • Spark: UPDATE, DELETE, MERGE INTO (including insert-only merges, which Spark plans as appends), TRUNCATE TABLE [PARTITION] and CompactChainTableProcedure.
  • Flink: SQL UPDATE / DELETE, truncation, and the Delete, MergeInto, DataEvolutionMergeInto, SortCompact, Rescale and CompactChainTable actions.

TableQueryAuthResult.rejectRewriteUnderQueryAuth checks when the operation is planned or the action is built, and also covers the fallback branch, the row tracking table of a Data Evolution table and the branches of a chain table, which may enable query auth separately.

A rule can still be added before the job reads the table, so the rewrites also write through rejectRewriteUnderQueryAuthOnCommit: a copy of the table with an internal commit.rewrite-operation option, whose TableCommitImpl authorizes again before each commit and truncation: the table it writes and the table loaded again from the catalog, as a read that loads the table again sees it. Query auth enabled, or a branch read with the table, after the job loaded the table is then also seen, such as the delta branch that chain table compaction reads. A rule that the read applied is then seen before anything is written, wherever the read is planned, also for an empty overwrite.

Known limitation: Spark writes an insert-only merge as an append to the target, so it is checked only when planned. A rule added between analysis and scan planning of that query can insert hidden keys again. Truncation does not read, so a rule added after its check is not enforced but cannot affect what it writes. A rule added and removed again before the commit is not seen.

Tests

  • SparkCatalogWithRestTest, Spark42CompatibilityTest (Spark 4.2 and 4.3): Spark operations are refused under a row filter or a column mask on append, primary-key and Data Evolution tables, with V1 and V2 writes, also when a UDF adds the rule while the statement runs, and work with full access.
  • RESTCatalogITCase: the Flink SQL operations (including TRUNCATE TABLE on primary-key and Data Evolution tables) and actions above are refused, also when the rule is added after the action is built or while the job runs, or query auth is enabled after the merge is built, or leaves no split to overwrite; full access works with dynamic table options disabled.
  • MockRESTCatalogTest#testRewriteCommitAuthorizesAgain: a rewrite commit and truncation fail when a rule is added after the write started. #testChainCompactionCommitAuthorizesDeltaBranch: the chain table compaction commit fails when only the delta branch enables query auth and a rule is added. TableQueryAuthResultTest.

🤖 Generated with Claude Code

@plusplusjiajia
plusplusjiajia force-pushed the fix/reject-rewrites-under-query-auth-rules branch 7 times, most recently from 958f7ed to 87e9164 Compare November 3, 2026 01:59
@plusplusjiajia
plusplusjiajia force-pushed the fix/reject-rewrites-under-query-auth-rules branch from 87e9164 to 7350806 Compare November 16, 2026 01:39
@plusplusjiajia
plusplusjiajia force-pushed the fix/reject-rewrites-under-query-auth-rules branch 4 times, most recently from a1bf2bd to 496f9e8 Compare November 24, 2026 03:34
@plusplusjiajia
plusplusjiajia marked this pull request as ready for review November 24, 2026 03:43
@plusplusjiajia
plusplusjiajia force-pushed the fix/reject-rewrites-under-query-auth-rules branch 4 times, most recently from 80476e8 to 92e4c11 Compare November 30, 2026 06:40
…uth rules

On a table with query auth, operations that read rows and write them
back used the caller's row filter and column masks: masked values were
stored as real data, hidden rows were deleted or lost in overwrites, and
insert-only merges inserted hidden keys again.

These operations now fail when query auth gives the caller a row filter
or a column mask; users with full access are not affected. This covers
Spark UPDATE, DELETE, MERGE INTO (including insert-only merges), TRUNCATE
TABLE [PARTITION] and CompactChainTableProcedure, and Flink SQL UPDATE,
DELETE and TRUNCATE TABLE and the Delete, MergeInto,
DataEvolutionMergeInto, SortCompact, Rescale and CompactChainTable
actions.

TableQueryAuthResult.rejectRewriteUnderQueryAuth checks when the
operation is planned or the action is built, including the fallback
branch, the row tracking table of a Data Evolution table and the
branches of a chain table. Since a rule can still be added before the
job reads the table, the rewrites also write through a copy of the
target with an internal commit.rewrite-operation option, whose
TableCommitImpl authorizes again before each commit and truncation. It
authorizes the table it writes and the table loaded again from the
catalog, so query auth enabled, or a branch read with the table, after
the job loaded the table is also seen, such as the delta branch that
chain table compaction reads and that may enable query auth separately.
The copy keeps the schema of a target pinned to a snapshot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@plusplusjiajia
plusplusjiajia force-pushed the fix/reject-rewrites-under-query-auth-rules branch from 92e4c11 to 87b6253 Compare November 30, 2026 10:11
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