Repository navigation
Add test for row policy with parallel replicas on the default path - #110318
devcrafter wants to merge 12 commits into
Conversation
Add a stateless test confirming that parallel replicas respects a row policy on the default path (serialize_query_plan=0), where each replica receives the query as an AST, re-plans it and re-applies its own row policy. Both parallel_replicas_local_plan modes are covered: the initiator participating as a local replica, and all reading happening on the remote replicas. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [1e8ce68] Summary: ❌
AI ReviewSummaryThis PR adds two stateless regression tests plus a secret-backed Final Verdict✅ No new findings. |
Address review comment on PR #110318: the test only checked the final count()/sum() results, so it did not prove the query stayed on the parallel-replicas path (enable_parallel_replicas=1 can silently fall back to a local read). Make the test prove path usage, mirroring 02950_parallel_replicas_used_count: pin automatic_parallel_replicas_mode=0, use enable_parallel_replicas=2 (throw if parallel replicas cannot be used instead of falling back), tag each query with a log_comment and assert ProfileEvents['ParallelReplicasUsedCount'] > 0 via system.query_log for both parallel_replicas_local_plan modes. Review comment: #110318 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review comment on PR #110318: the existing 04538 test only used a `TO ALL` policy, which every user (including a fallback identity) matches, so it cannot catch a bug where the parallel-replica read nodes lose the caller identity and evaluate the policy as the wrong principal. Add a role-scoped test that binds row policies to roles and runs the query as a dedicated user with `SET ROLE`, over parallel replicas. This requires an interserver-secret cluster (the initiating user's identity and roles are only forwarded to remote nodes in interserver mode) that also has several replicas per shard so parallel replicas engage - none existed, so add `test_cluster_one_shard_three_replicas_localhost_secret` to the stateless config. The test reads with `parallel_replicas_local_plan = 0` so the reading happens on the remote replicas (with a local plan the initiator reads the data itself, already under the active role, and the remote-side role propagation is never exercised). It also asserts the parallel-replicas path was actually used (`ParallelReplicasUsedCount > 0`). This is a regression guard for the role-propagation fix in #110867: verified locally that the test fails (narrow role leaks rows outside its policy) on a pre-fix binary and passes on a binary containing that fix. Review comment: #110318 (comment) Related: #110867 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds stateless regression tests to ensure parallel replicas correctly enforce row policies on the default (AST) planning path, and that SET ROLE-activated roles are honored on remote read nodes when using an interserver-secret cluster (guarding behavior fixed in #110867).
Changes:
- Added a SQL stateless test covering row-policy enforcement on the default parallel-replicas path (
serialize_query_plan = 0) for bothparallel_replicas_local_planmodes. - Added a shell stateless test covering role-scoped row policies over parallel replicas, using a new interserver-secret test cluster.
- Extended test cluster configuration with
test_cluster_one_shard_three_replicas_localhost_secret.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/04612_pr_row_policy_role_scope.sh | New shell test for role-scoped row policies over parallel replicas on an interserver-secret cluster. |
| tests/queries/0_stateless/04612_pr_row_policy_role_scope.reference | Expected output for the new role-scoped policy test. |
| tests/queries/0_stateless/04538_pr_row_policy_default_path.sql | New SQL test for row policy enforcement on the default (AST) parallel-replicas path. |
| tests/queries/0_stateless/04538_pr_row_policy_default_path.reference | Expected output for the new default-path policy test. |
| tests/config/config.d/clusters.xml | Adds a new 1-shard/3-replica localhost cluster with <secret> for interserver authentication. |
Comments suppressed due to low confidence (1)
tests/queries/0_stateless/04538_pr_row_policy_default_path.sql:43
- Same as above: disable parallel replicas for the
system.query_logverification query to keep the assertion independent from parallel-replicas eligibility of the log table itself.
SELECT ProfileEvents['ParallelReplicasUsedCount'] > 0 FROM system.query_log
WHERE event_date >= yesterday() AND type = 'QueryFinish'
AND log_comment = '04538_local_plan_0' AND is_initial_query = 1
AND current_database = currentDatabase()
ORDER BY event_time DESC LIMIT 1;
Address review comment on PR #110318: with a single default mark, `ParallelReplicasUsedCount > 0` did not prove that the `parallel_replicas_local_plan = 1` case exercised both the initiator's local read and a remote replica - one participant can read the whole mark and the test still passes. Asserting `ParallelReplicasUsedCount > 1` is not viable: on the single-node `test_cluster_one_shard_three_replicas_localhost` the in-process local replica grabs the whole working set, so the count stays 1 regardless of granularity (flaky `3, 1, 1` even with `index_granularity = 1` and `parallel_replicas_mark_segment_size = 1`). Assert the plan structure instead, which is deterministic: with `parallel_replicas_local_plan = 1` the plan is a union of the initiator local read (`ReadFromMergeTree`) and the remote replicas (`ReadFromRemoteParallelReplicas`); with `parallel_replicas_local_plan = 0` only the remote read is present. A regression that drops either branch from the default-path plan is caught. Review comment: #110318 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Address two review comments on PR #110318: - 04612: the final system.query_log probe returned every matching QueryFinish row for the two log_comment values, so a retry in the same database printed more than the referenced 2 rows. Collapse to the latest row per log_comment with `ORDER BY log_comment, event_time_microseconds DESC` + `LIMIT 1 BY log_comment`. - 04538: the local_plan_0 verifier inherited the session-level `enable_parallel_replicas = 2`, unlike the local_plan_1 verifier, so the probe itself was subject to strict parallel-replicas planning. Add `SETTINGS enable_parallel_replicas = 0` to it as well. Also bound both tests' query_log probes to `event_time >= now() - toIntervalMinute(30)` so they cannot match stale entries from earlier runs. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address review comment on PR #110318: the setup block created the p_narrow / p_admin row policies without dropping them first. Row-policy access entities are not removed by `DROP TABLE` or `DROP ROLE`, so if the test aborted after creating the policies, a retry in the same database threw ACCESS_ENTITY_ALREADY_EXISTS before it could exercise the role-propagation path. Add `DROP ROW POLICY IF EXISTS p_narrow, p_admin ON <db>.logs` in the setup, mirroring 04538. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…se/ClickHouse into test-pr-row-policy-default-path
|
Can you also add this testcase. It fails for me locally: #!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
# A user whose SELECT comes from a role loses it on the replicas when parallel replicas ship an
# `IN` subquery over a cluster with an interserver secret. The secret makes the replicas re-check
# access as the initial user, and the user's roles are not applied there, so only grants held
# directly survive. The same user reads the same tables fine in every other combination, which the
# three cases below pin down.
#
# `parallel_replicas_local_plan = 0` and `prefer_localhost_replica = 0` keep the initiator from
# serving the read itself, and `index_granularity` is pinned so there are enough granules to spread:
# otherwise the coordinator can hand all the work to the local replica, nothing is shipped, and the
# denial does not happen at all.
USER="u_${CLICKHOUSE_DATABASE}"
ROLE="r_${CLICKHOUSE_DATABASE}"
$CLICKHOUSE_CLIENT -m --query "
DROP TABLE IF EXISTS t_outer;
DROP TABLE IF EXISTS t_inner;
CREATE TABLE t_outer (a UInt64) ENGINE = MergeTree ORDER BY a SETTINGS index_granularity = 1024;
CREATE TABLE t_inner (b UInt64) ENGINE = MergeTree ORDER BY b SETTINGS index_granularity = 1024;
INSERT INTO t_outer SELECT number FROM numbers(100000);
INSERT INTO t_inner SELECT number FROM numbers(1000);
DROP USER IF EXISTS $USER;
DROP USER IF EXISTS ${USER}_direct;
DROP ROLE IF EXISTS $ROLE;
CREATE ROLE $ROLE;
GRANT SELECT ON ${CLICKHOUSE_DATABASE}.* TO $ROLE;
CREATE USER $USER IDENTIFIED WITH no_password;
GRANT $ROLE TO $USER;
SET DEFAULT ROLE $ROLE TO $USER;
CREATE USER ${USER}_direct IDENTIFIED WITH no_password;
GRANT SELECT ON ${CLICKHOUSE_DATABASE}.* TO ${USER}_direct;
"
PR="SETTINGS enable_parallel_replicas = 1, automatic_parallel_replicas_mode = 0, max_parallel_replicas = 3,
cluster_for_parallel_replicas = 'test_cluster_one_shard_three_replicas_secret',
parallel_replicas_for_non_replicated_merge_tree = 1,
parallel_replicas_local_plan = 0, prefer_localhost_replica = 0"
echo '--- role-granted user, IN subquery over parallel replicas ---'
$CLICKHOUSE_CLIENT --user "$USER" --query "SELECT count() FROM t_outer WHERE a IN (SELECT b FROM t_inner) $PR"
echo '--- same user, plain scan over parallel replicas ---'
$CLICKHOUSE_CLIENT --user "$USER" --query "SELECT count() FROM t_outer $PR"
echo '--- same user, IN subquery without parallel replicas ---'
$CLICKHOUSE_CLIENT --user "$USER" --query "SELECT count() FROM t_outer WHERE a IN (SELECT b FROM t_inner) SETTINGS enable_parallel_replicas = 0, automatic_parallel_replicas_mode = 0"
echo '--- same query, grant held directly instead of through a role ---'
$CLICKHOUSE_CLIENT --user "${USER}_direct" --query "SELECT count() FROM t_outer WHERE a IN (SELECT b FROM t_inner) $PR"
$CLICKHOUSE_CLIENT -m --query "
DROP USER IF EXISTS $USER;
DROP USER IF EXISTS ${USER}_direct;
DROP ROLE IF EXISTS $ROLE;
DROP TABLE t_outer;
DROP TABLE t_inner;
" |
|
Dear @nickitat, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Related: #110867
Add stateless tests confirming that parallel replicas respects row policies.
Motivation: row policies for parallel replicas are only applied on the replica that plans the read. On the default path each replica receives the query as an AST, re-plans it and re-applies its own row policy, so the filter is enforced. These tests lock in that behavior and guard against regressions.
04538_pr_row_policy_default_path.sqlcovers the default path (serialize_query_plan=0) with aTO ALLpolicy, for bothparallel_replicas_local_planmodes, and asserts the parallel-replicas path was actually used (ParallelReplicasUsedCount > 0).serialize_query_planis pinned to0so the test stays on the default path even under thedistributed_planCI configuration, which enables it by default.04612_pr_row_policy_role_scope.shcovers the identity/role-scoped path: a policy bound to a role, the query run as a dedicated user withSET ROLE, over parallel replicas on an interserver-secret cluster (addedtest_cluster_one_shard_three_replicas_localhost_secret, since role/identity is only propagated to remote read nodes in interserver mode). It is a regression guard for the role-propagation fix in Propagate current roles to remote read nodes #110867.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):