Skip to content

Antalya 26.6: Row policies and stateless auth for swarm reads of object storage tables - #2990

Open
lizardoluis wants to merge 5 commits into
antalya-26.6from
lizardo/swarm-row-policy-iceberg
Open

lizardoluis wants to merge 5 commits into
antalya-26.6from
lizardo/swarm-row-policy-iceberg

Conversation

@lizardoluis

@lizardoluis lizardoluis commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

With object_storage_cluster (swarm), reads of object storage tables (for example Iceberg) had two problems:

  1. 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.
  2. 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.

Related: #1710

Changelog category (leave one):

  • 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>
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [f37b3e7]

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 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
@lizardoluis
lizardoluis requested a balanced review from Copilot December 3, 2026 12:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

2 open issues
What changed in this PR

This PR addresses row-policy enforcement and stateless authentication for object-storage swarm reads, including Iceberg.

Changes:

  • Adds row-policy predicates to dispatched queries and rejects unsupported query shapes.
  • Clears the initiating user for secret-protected clusters.
  • Adds integration coverage for tenant filtering and workers without initiating users.
File Description
tests/​integration/​test_database_iceberg/​test.py Adds row-policy and stateless-authentication regression tests.
tests/​integration/​test_database_iceberg/​configs/​cluster_swarm.xml Defines a secret-protected swarm test cluster.
src/​Storages/​IStorageCluster.cpp Adds policy forwarding and conditional initial-user clearing.

Review effort: Balanced

Comment thread src/Storages/IStorageCluster.cpp Resolved
Comment thread src/Storages/IStorageCluster.cpp Resolved
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues allow ARRAY JOIN to bypass row policies and worker-side dictHas calls to bypass the original user’s dictionary permissions.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/Storages/IStorageCluster.cpp Resolved
Comment on lines +1424 to +1425
if (!cluster->getSecret().empty())
new_context->setInitialUserName({});

@lizardoluis lizardoluis Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

High severity 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.

1 resolved since last review

Review effort: Balanced

@lizardoluis
lizardoluis marked this pull request as ready for review December 3, 2026 17:43
@lizardoluis
lizardoluis requested a review from ianton-ru December 3, 2026 19:58

@ianton-ru ianton-ru left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Comment thread src/Storages/IStorageCluster.cpp Outdated
namespace
{

void collectIdentifierNames(const ASTPtr & ast, NameSet & names)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a duplicate of IAST::collectIdentifierNames.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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.

Comment thread src/Storages/IStorageCluster.cpp Outdated
collectAliases(child, table_alias, aliases);
}

bool selectHasArrayJoin(const ASTSelectQuery & select_query)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, now uses ASTSelectQuery::arrayJoinExpressionList and checks that the result is not empty.

Comment thread src/Storages/IStorageCluster.cpp Outdated
collectIdentifierNames(child, names);
}

void collectAliases(const ASTPtr & ast, const String & table_alias, NameSet & aliases)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at QueryAliasesNoSubqueriesVisitor, can be used instead of this method.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants