Skip to content

object_storage_cluster: enforce row policies and grants on swarm workers (secret-gated access marker) #3035

Backlog

Description

@minguyen9988

Problem

When a table is read through the object_storage_cluster setting, the initiator rewrites it into a table
function (icebergCluster(...), s3Cluster(...)) and ships that query text to the workers. Row policies and
SELECT grants are attached to database.table, not to the table function, so a worker cannot apply the
initial user’s row policy, and it authorises the read with the table function’s source grant (READ ON FILE /
READ ON S3) instead of SELECT on the source table. A user entitled only to a filtered view of the table can
read the underlying objects directly.

Current antalya-26.8 state

  • object_storage_cluster is declared at src/Core/Settings.cpp:9263 (String, default "").
    object_storage_cluster_enforce_access_on_workers has 0 occurrences in that file.
  • No marker type exists: src/Storages/ObjectStorage/ClusterAccessMarker.{h,cpp} are absent (the repository index returns no such path).
  • The rewrite site builds the table function with no table identity:
    src/Storages/ObjectStorage/StorageObjectStorageCluster.cpp:437-470 - createArgsWithAccessData(), then
    function_ast->setAlias(...), table_expression->database_and_table_name = nullptr.
  • The clustered read knows it drops the filter and says so (StorageObjectStorageCluster.cpp:890-895):
bool StorageObjectStorageCluster::appliesRowLevelFilterInRead(ContextPtr context) const
{
    /// A clustered read only ships query text to the swarm nodes, so the filter would be lost.
    /// A fallback read is served by `pure_storage`, which lowers it into the reading step.
    return pure_storage && readsFromPureStorage(context);
}

IStorage::appliesRowLevelFilterInRead defaults to !isRemote() and IStorageCluster::isRemote() is final
returning true (src/Storages/IStorageCluster.h:84), so a swarm read always answers false: the filter is
discarded by design.

The class itself is upstream - it backs s3Cluster/icebergCluster. What is Antalya-specific is the
object_storage_cluster setting and the engine-level swarm execution path built on it.

Proposed design

Carry the source table identity, plus a fingerprint of the initial user’s effective SELECT row policy, inside
the query text - not in a side channel.

  1. Marker keys appended to the table function’s SETTINGS argument (created when absent):
    object_storage_cluster_source_database, object_storage_cluster_source_table,
    object_storage_cluster_source_policy. All three required; a partial marker is ACCESS_DENIED.
  2. Fingerprint: hex sipHash128 of the formatted combined row-policy expression the planner would apply.
    Empty when the user has no policy or the combined filter is always true.
  3. Authenticity: the marker sits in query text the interserver secret hash already covers. A worker accepts
    it only in a secondary query whose cluster-secret hash it verified (QueryKind::SECONDARY_QUERY,
    interface TCP_INTERSERVER, non-empty initial_user). TCPHandler must reset the own claim of a client of the
    TCP_INTERSERVER interface, or the check is forgeable.
  4. Mismatch is a hard error. If the worker’s own fingerprint for that table differs, access entities are out
    of sync; refuse rather than read with the wrong policy.
  5. Setting object_storage_cluster_enforce_access_on_workers (Bool, default true). With it off, or
    with a cluster that has no <secret>, the initiator sends no marker and throws ACCESS_DENIED when the
    initial user has a non-trivial row policy - failing closed instead of reading unfiltered.

The marker is removed from the argument list before the storage settings are loaded, so an older worker never
sees these keys as unknown settings.

String ClusterAccessMarker::policyFingerprint(const String & database, const String & table, const ContextPtr & context)
{
    auto filter = context->getRowPolicyFilter(database, table, RowPolicyFilterType::SELECT_FILTER);
    if (!filter || !filter->expression || filter->isAlwaysTrue())
        return {};
    /// The formatted combined expression is what the planner applies; equal text means the same filter.
    return sipHash128String(filter->expression->formatWithSecretsOneLine());
}

void ClusterAccessMarker::verifyOnWorker(const Marker & marker, const ContextPtr & context)
{
    if (!isInterserverVerified(context))
        throw Exception(
            ErrorCodes::ACCESS_DENIED,
            "The object-storage cluster access marker for {}.{} is accepted only in a secondary query received "
            "from a cluster node authenticated with the cluster secret",
            marker.database, marker.table);

    auto local_fingerprint = policyFingerprint(marker.database, marker.table, context);
    if (local_fingerprint != marker.policy_fingerprint)
        throw Exception(
            ErrorCodes::ACCESS_DENIED,
            "Row policies of user {} on {}.{} differ between the initiator and this node (initiator fingerprint "
            "{} vs local {}): access entities are not in sync, refusing to read",
            context->getClientInfo().initial_user, marker.database, marker.table,
            marker.policy_fingerprint, local_fingerprint);
}

Wiring: insert the marker in updateQueryForDistributedEngineIfNeeded right after the table function AST is
built (the :437-470 block), guarded by getStorageID().hasDatabase(); extract and verify it in
TableFunctionObjectStorage::parseArguments before settings->loadFromQuery
(src/TableFunctions/TableFunctionObjectStorage.cpp:180-182), then read on behalf of the source table so
policies apply before PREWHERE. Add a regression test asserting the secret key appears in neither the
initiator’s nor the worker’s server log.

Cross-references

  • Antalya 26.6: Row policies and stateless auth for swarm reads of object storage tables #2990 - the bare row-policy gap on the same path, proposing additional_table_filters with no cross-node
    authenticity check. That is the lighter mitigation and can land first; this issue is the hardened form and
    should be reviewed as its successor, not a competitor. additional_table_filters exists on antalya-26.8
    only in src/Analyzer/** and src/Core/Settings.cpp, not in the cluster path, so the approach of #2990 is not
    implemented either.
  • Row policy for Iceberg and swarm #1710 - object-storage cluster read path, general context.
  • The materialized-view target case in the cluster SQL surface issue depends on this marker existing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions