You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Antalya 26.6: Row policies and stateless auth for swarm reads of object storage tables - #2990
With object_storage_cluster (swarm), reads of object storage tables (for example Iceberg) had two problems:
Row policies were not enforced. The initiator planner skips the row policy filter when the storage returns the WithMergeableState stage, and the swarm nodes read through a table function, so a user with a row policy could read all rows.
Swarm nodes were not stateless. The sub-query carried the initial_user of the initiator, so every user had to exist on every swarm node, otherwise the query failed with UNKNOWN_USER or AUTHENTICATION_FAILED.
Changes:
Add the effective SELECT row policy expression of the table to the PREWHERE (if present) or WHERE of the query sent to the swarm nodes. A sent query that is not a single SELECT, or still contains a JOIN, throws NOT_IMPLEMENTED instead of being sent unfiltered.
When the cluster is protected by a <secret>, clear the initial user of the context used for the sub-query. The swarm node then skips user authentication and uses the existing interserver path, trusting the cluster secret. Access checks and the row policy are applied on the initiator.
Reject a sent query when one of its aliases shadows a column used by the row policy, since the injected policy shares the alias scope of the query. Aliases that only repeat the column are accepted.
Compute the sample header before the policy is injected, and skip the repeated access check in the analyze-only re-plan that the planner runs after a storage returns a stage beyond FetchColumns. That re-plan saw the policy columns as read by the user, so a user with SELECT on a single column was denied.
Reject ARRAY JOIN in a query sent to the swarm nodes while a row policy applies, because the injected WHERE runs after the expansion and would evaluate the policy on the expanded elements.
Not covered by this PR:
Queries with an alias that shadows a policy column are rejected with NOT_IMPLEMENTED instead of being isolated from the policy.
Clusters without a <secret>: the initial user is only cleared for secret-protected clusters.
Queries with a JOIN when a row policy applies: they throw NOT_IMPLEMENTED.
The object_storage_remote_initiator path.
Row policy expressions that depend on the user or on subqueries, such as currentUser().
Direct calls of icebergCluster(...) and s3Cluster(...).
The swarm node runs the sub-query without the original user, so operations that check access only at runtime, such as dictHas on a dictionary that exists only on the swarm node, run with full access there. Keeping the identity of the user on the workers is not done here.
Per-user quotas and profile settings on swarm nodes: the swarm node runs the sub-query without the original user, so they are not applied there.
Tests added in test_database_iceberg: row policy enforcement through object_storage_cluster, swarm nodes without the user and its policy, a scenario that mirrors the report, alias shadowing with both analyzers, and a user without a grant on the policy column.
Bug Fix (user-visible misbehavior in an official stable release)
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Apply row policies to object_storage_cluster reads of object storage tables, and do not require the initiating user to exist on swarm nodes of clusters protected by a secret.
Documentation entry for user-facing changes
Documentation is written (mandatory for new features)
`IStorageCluster::read` sent the user's query to the swarm nodes without
any row policy. The initiator planner skips the row policy filter when the
storage returns the `WithMergeableState` stage, and the swarm nodes read
through a table function, so a policy defined on the table never matched
there. A user with a row policy could read all rows with
`object_storage_cluster` set.
Add the effective `SELECT` row policy expression of the storage to the
`PREWHERE` (if present) or `WHERE` of the query sent to the swarm nodes.
Throw `NOT_IMPLEMENTED` if the sent query is not a single `SELECT` or still
contains a `JOIN`, instead of sending it unfiltered.
Add an integration test with a secret-protected cluster that checks that
`SELECT` and `count` through `object_storage_cluster` return only the rows
allowed by the row policy of each user.
Signed-off-by: Luís Lizardo <luis.lizardo@enterprisedb.com>
Swarm nodes are meant to be stateless, but the sub-query sent by
`IStorageCluster` carried the `initial_user` of the initiator. A node
without that user failed in `TCPHandler` with `UNKNOWN_USER` or
`AUTHENTICATION_FAILED`, so every user had to be created on every swarm
node.
When the cluster is protected by a `<secret>`, clear the initial user of the
context used for the sub-query. The swarm node then skips user
authentication and runs the sub-query through the existing interserver path,
trusting the cluster secret. Access checks and the row policy are applied on
the initiator.
Add integration tests where the user and its row policy exist only on the
initiator, including a scenario that mirrors the report.
Signed-off-by: Luís Lizardo <luis.lizardo@enterprisedb.com>
lizardoluis
changed the title
Antalya 26.6: Apply row policies to swarm reads of object storage tables
Antalya 26.6: Row policies and stateless auth for swarm reads of object storage tables
Dec 3, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Alias shadowing can bypass the injected policy and expose other tenants’ data, while sample-header access checks incorrectly reject permitted column-restricted queries.
Reject a query sent to swarm nodes when one of its aliases shadows a column
used by the row policy, because the injected policy shares the alias scope of
the query and `SELECT 1 AS tenant_id` turned `tenant_id = 1` into `1 = 1`.
Aliases that only repeat the column, such as `__table1.tenant_id AS tenant_id`,
are accepted.
Compute the sample header before the policy is injected, so the access check
of the original query does not see the policy.
Skip the repeated access check in the analyze-only re-plan that the planner
runs after a storage returns a stage beyond `FetchColumns`. That re-plan shares
the planner context with the outer pass, which has already added the policy
columns to the columns to read, so a user with `SELECT` on a single column was
denied for the policy column.
Add integration tests for the alias shadowing, with both analyzers, and for a
user that has no grant on the policy column.
Signed-off-by: Luís Lizardo <luis.lizardo@enterprisedb.com>
The reason will be displayed to describe this comment to others. Learn more.
Valid, and it follows from making the swarm stateless: the swarm node runs the sub-query without the original user, so checks done only at runtime, such as dictHas, run with full access there. I have not changed this and I listed it as a limitation in the PR description. Keeping the identity of the user on the workers without requiring the user to exist there is a larger design change, so it needs a decision.
`ASTSelectQuery::hasJoin` does not cover `ARRAY JOIN`. The row policy is
injected into the `WHERE` of the query sent to the swarm nodes, which is
evaluated after the `ARRAY JOIN`, so the policy saw the expanded elements
instead of the original column. For example, `USING empty(tags)` with
`ARRAY JOIN tags` evaluated `empty('')` instead of `empty([''])`.
Throw `NOT_IMPLEMENTED` for a query sent to the swarm nodes that contains an
`ARRAY JOIN` while a row policy applies, until policies are evaluated before
the expansion.
Add an integration test for both analyzers. With the new analyzer the
`ARRAY JOIN` runs above the storage read and returns only the rows allowed by
the policy.
Signed-off-by: Luís Lizardo <luis.lizardo@enterprisedb.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Combining the row policy with user predicates can expose forbidden rows through exception-based side channels, requiring a separate, non-mergeable policy filter before user expressions and a regression test.
Policy filtering exposes forbidden rows to user expressions
src/Storages/IStorageCluster.cpp:821
Combining the policy with the user's predicate allows user expressions to evaluate forbidden rows. With policy tenant_id = 1, WHERE throwIf(tenant_id = 2) = 0, short-circuit evaluation disabled, and query-plan optimizations disabled, the worker can reveal tenant 2's existence through an exception before the combined filter removes its rows. Preserve a separate policy filter that runs before user expressions and cannot be merged with them, and add this regression case.
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but try to look at additional_table_filters setting. It used to apply filters on remote nodes for distributed tables, may be possible to reuse this feature.
The reason will be displayed to describe this comment to others. Learn more.
Done, now uses IAST::collectIdentifierNames. It only returns the full identifier name, so I also add the part before the first dot to keep catching Nested style names such as n.x shadowed by an alias n.
The reason will be displayed to describe this comment to others. Learn more.
Can be replaced on ASTSelectQuery::arrayJoinExpressionList and checking that result is not epty.
Or add this method to ASTSelectquery class next to hasJoin (because here need only bool, result, not a full list of joins)
The reason will be displayed to describe this comment to others. Learn more.
Done, now uses QueryAliasesNoSubqueriesVisitor on a clone of the select (it modifies the AST), then applies the identity alias exemption on the collected aliases.
Collect policy identifiers with `IAST::collectIdentifierNames`, detect `ARRAY JOIN` with `ASTSelectQuery::arrayJoinExpressionList` and collect query aliases with `QueryAliasesNoSubqueriesVisitor` instead of local copies of the same logic.
Signed-off-by: Luís Lizardo <luis.lizardo@enterprisedb.com>
This branch has not been deployed
No deployments
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
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.
With
object_storage_cluster(swarm), reads of object storage tables (for example Iceberg) had two problems:WithMergeableStatestage, and the swarm nodes read through a table function, so a user with a row policy could read all rows.initial_userof the initiator, so every user had to exist on every swarm node, otherwise the query failed withUNKNOWN_USERorAUTHENTICATION_FAILED.Changes:
Add the effective
SELECTrow policy expression of the table to thePREWHERE(if present) orWHEREof the query sent to the swarm nodes. A sent query that is not a singleSELECT, or still contains aJOIN, throwsNOT_IMPLEMENTEDinstead of being sent unfiltered.When the cluster is protected by a
<secret>, clear the initial user of the context used for the sub-query. The swarm node then skips user authentication and uses the existing interserver path, trusting the cluster secret. Access checks and the row policy are applied on the initiator.Reject a sent query when one of its aliases shadows a column used by the row policy, since the injected policy shares the alias scope of the query. Aliases that only repeat the column are accepted.
Compute the sample header before the policy is injected, and skip the repeated access check in the analyze-only re-plan that the planner runs after a storage returns a stage beyond
FetchColumns. That re-plan saw the policy columns as read by the user, so a user withSELECTon a single column was denied.Reject
ARRAY JOINin a query sent to the swarm nodes while a row policy applies, because the injectedWHEREruns after the expansion and would evaluate the policy on the expanded elements.Not covered by this PR:
NOT_IMPLEMENTEDinstead of being isolated from the policy.<secret>: the initial user is only cleared for secret-protected clusters.JOINwhen a row policy applies: they throwNOT_IMPLEMENTED.object_storage_remote_initiatorpath.currentUser().icebergCluster(...)ands3Cluster(...).dictHason a dictionary that exists only on the swarm node, run with full access there. Keeping the identity of the user on the workers is not done here.Tests added in
test_database_iceberg: row policy enforcement throughobject_storage_cluster, swarm nodes without the user and its policy, a scenario that mirrors the report, alias shadowing with both analyzers, and a user without a grant on the policy column.Related: #1710
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Apply row policies to
object_storage_clusterreads of object storage tables, and do not require the initiating user to exist on swarm nodes of clusters protected by a secret.Documentation entry for user-facing changes