Repository navigation
[spark][flink] Reject row-level operations and rewrites under query auth rules - #10906
Draft
plusplusjiajia wants to merge 10 commits into
Draft
plusplusjiajia wants to merge 10 commits into
plusplusjiajia wants to merge 10 commits into
Conversation
plusplusjiajia
force-pushed
the
fix/reject-rewrites-under-query-auth-rules
branch
7 times, most recently
from
November 3, 2026 01:59
958f7ed to
87e9164
Compare
plusplusjiajia
force-pushed
the
fix/reject-rewrites-under-query-auth-rules
branch
from
November 16, 2026 01:39
87e9164 to
7350806
Compare
…uth rules On a table with query auth, operations that read rows and write data back did not respect the caller's row filter and column masks: - Spark UPDATE, DELETE and MERGE INTO on append and Data Evolution tables read the raw files, so UPDATE t SET note = ssn copied a masked column into a visible one, and rows hidden by the row filter were updated or deleted. - On primary-key tables, Spark and Flink UPDATE and MERGE INTO, and the Flink delete and merge-into actions, read the filtered, masked rows and wrote them back, so masked values were stored as real data and masked keys could delete rows hidden by the row filter. - Spark TRUNCATE TABLE, with or without a PARTITION clause, and Flink truncation removed the rows hidden by the row filter too. - Flink sort compaction and rescale, and Flink and Spark chain table compaction, overwrote partitions with the caller's filtered, masked rows, losing the hidden rows and storing the masks. These operations now fail when query auth gives the caller a row filter or a column mask, through a shared check next to the search rejection, TableQueryAuthResult.rejectRewriteUnderQueryAuth. Users with full access are not affected. The check also covers the fallback branch of a table with scan.fallback-branch. The Flink rewrite actions authorize again when their source plans the scan at job start or restores it from a checkpoint, including the postpone merge-on-read source, so rules added after the action was built are not missed, even when they leave no split to read. Rewrites that read the raw files, such as the Spark sort compaction, clustering and rescale procedures, are unchanged.
The Flink merge-into actions checked query auth only when the merge was built. MergeIntoProcedure and callers of buildDataStream() submit the job afterwards, so a row filter or column mask added in between was applied to the target scan, and the filtered, masked rows were written back. The Flink delete action had the same gap between its check and its scans of the target. The merge-into and delete actions now read the target with an internal scan.rewrite-operation table option, and the Flink table sources pass it to the execution-time check that sort compaction and rescale use. Through the row tracking table of a Data Evolution table, the check authorizes the data table behind it, so a filter that leaves no split is not missed. The Data Evolution merge also authorizes again before it commits, which covers a source with _ROW_ID that does not read the target. A table without query auth only reads the table option. Spark plans a merge with only WHEN NOT MATCHED clauses on a V2 table as an append over an anti join, without the row-level operation that checks query auth, so rows whose keys the row filter hid were inserted again. PaimonMergeInto and the Spark 4.1 rewrite now read the target with the same option, so the Paimon scan checks when it plans the splits. The option is removed from the relation Spark appends to, so the cache refresh after the write still matches cached reads. The branches of a chain table read with the main table's identifier, so chain table compaction missed rules set only on a branch. The rewrite check now also authorizes a table with its own branch.
plusplusjiajia
force-pushed
the
fix/reject-rewrites-under-query-auth-rules
branch
from
November 23, 2026 10:11
7350806 to
17e141c
Compare
Drop the second check when the job reads the target. It only covered a rule added between planning and reading, which the Spark V2 row-level operations and the Flink row-level sink never covered either, and it needed an internal scan.rewrite-operation option carried through the Spark relation, the Flink SQL hints and every Flink source, plus an optimizer rule and a new shim method to keep the option off the relation Spark writes to. Spark insert-only merges are now refused in PaimonMergeInto and Spark41MergeIntoRewrite, like the other row-level operations, and the Flink actions keep their check when they are built. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… rescale Sort compaction and rescale checked query auth only when the action was built. The job authorizes again when it plans the scan, so a rule added in between was applied to the read. A partition filter that prunes every partition gives an empty plan, and the overwrite then removed the data, for example with dynamic-partition-overwrite=false. Both actions now read the table with an internal scan.rewrite-operation option. The table scan checks the auth result it plans with before it lists any file, so a rule that leaves no split fails the job as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…actions The merge-into and delete actions checked query auth when they were built. MergeIntoProcedure and callers of buildDataStream() submit the job afterwards, and the job authorizes again when it plans the target scan, so a rule added in between was applied to the target rows, and the filtered, masked rows were written back. The actions now read the target with the scan.rewrite-operation option as an OPTIONS hint, so the target scan fails when the auth result it plans with has rules. This covers the alias view of MergeIntoAction and the row tracking table that the Data Evolution merge and delete read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The merge-into and delete actions passed scan.rewrite-operation to the target scan as an OPTIONS hint. With table.dynamic-table-options.enabled set to false, Flink rejects the hint, so the primary-key merge and delete failed in planning even for a user with full access. The actions now set the option as a paimon.<catalog>.<db>.<table>. table option in the table config of their own table environment, which the Paimon table factory reads without dynamic table options. It also reaches the row tracking table that the Data Evolution merge and delete read, so their existing hints are left as they were on master. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Spark 4.2 and 4.3, Spark42RowLevelCommandRewrite hands a merge on a V2 append table to Spark's native rewrite during resolution. A merge with only WHEN NOT MATCHED clauses becomes an append over an anti join, so neither the row-level operation nor PaimonMergeInto, which runs post hoc, checked query auth, and rows whose keys the row filter hid were inserted again. The rule now checks query auth before it rewrites an insert-only merge. Spark42CompatibilityTest, which both connectors run, covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AbstractFlinkTableFactory built the pattern for paimon.<catalog>.<db>.<table>.<key> options from the unquoted names. A legal table name such as t+1 did not match its own key, and the key was passed on whole as a global option, so the scan.rewrite-operation that the merge-into and delete actions set for their target was lost: a column mask added after the action started was applied to the target scan instead of failing it. Names with '.' or '+' could also match the options of other tables. The names and the prefix are now quoted with Pattern.quote. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The merge-into and delete actions set scan.rewrite-operation for their target as a paimon.<catalog>.<db>.<table>. option, which the table factory matches by the table name alone. A source on another branch of the target, such as t$branch_source, got the option too, so a merge failed when that branch had a legal row filter, though the target had full access. The table factory now also accepts a table name qualified with a branch, t$branch_<branch>, which reaches that branch and its system tables only, and the actions use it. The row tracking table of a Data Evolution target keeps the option, and fallback and chain branches are read through the target table itself. The delete action and the Data Evolution merge are now also tested with a rule added after they checked query auth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rewrites checked query auth when they were planned or built, and the sort compaction, rescale, merge-into and delete actions also marked the scan of their target so that it checked the rules it planned with. That covered only the reads that Paimon builds: the reads of Flink SQL UPDATE / DELETE and of Spark are planned by the engine, and the marker needed dynamic table options, quoted names and branch scoping in the Flink table factory. The rewrites now write through a copy of the target with an internal commit.rewrite-operation option instead, and TableCommitImpl authorizes again before each commit and truncation of such a table. A rule that the read applied was added before the read, so it is seen before anything is written, wherever the read is planned and also when an overwrite has nothing to write. A delegated table, such as one with a fallback branch, authorizes as a whole. This covers the Flink actions, the Flink SQL row-level sink, the Spark row-level commands, the Spark V2 row-level operations and chain table compaction in both engines. The scan marker and the table factory changes are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.
UPDATE,DELETE,MERGE INTO(including insert-only merges, which Spark plans as appends),TRUNCATE TABLE [PARTITION]andCompactChainTableProcedure.UPDATE/DELETE, truncation, and theDelete,MergeInto,DataEvolutionMergeInto,SortCompact,RescaleandCompactChainTableactions.TableQueryAuthResult.rejectRewriteUnderQueryAuthchecks 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.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 internalcommit.rewrite-operationoption, whoseTableCommitImplauthorizes again before each commit and truncation. 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 and actions above are refused, also when the rule is added after the action is built or while the job runs, 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.TableQueryAuthResultTest.🤖 Generated with Claude Code