Skip to content

Refuse to install test configs when destination aliases the source - #111250

Merged
alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
edugomz:fix-praktika-config-install-alias
Oct 1, 2026
Merged

alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
edugomz:fix-praktika-config-install-alias

Conversation

@edugomz

@edugomz edugomz commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #90883

Problem

tests/config/install.sh deletes DEST_SERVER_PATH/config.d with rm -rf, then repopulates it with symlinks derived from SRC_PATH/config.d.

If DEST_SERVER_PATH is set up so its config.d resolves to the same directory as the repo's own tests/config/config.d (for example a bind mount pointing /etc/clickhouse-server back at the source tree), that rm -rf deletes the tracked source configs instead of just clearing generated symlinks.

This also explains the <async>0</async> / <async>1</async> flip reported in the issue: after the config.d wipe, the four sed-generated files (logger_trace.xml, keeper_port.xml, storage_conf.xml, storage_conf_02944.xml) get rewritten in place with randomized values, leaving git status dirty on the tracked source tree.

Fix

Resolve both paths with readlink -f and compare them before the destructive step.
If they alias, the script exits with an error instead of running.

Changelog category (leave one):

  • CI Fix or Improvement

Changelog entry:


Workflow [PR]
Sync PR [sync-upstream/pr/111250]

Version info

  • Merged into: 26.10.1.1132-master (included in 26.10 and later)

@edugomz
edugomz marked this pull request as ready for review July 21, 2026 15:55
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 4, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 28, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot closed this Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9d46cfd]

Summary: ✅


AI Review

Summary

This PR hardens tests/config/install.sh against source-tree aliasing by rejecting installs whose main destination directories resolve to the repo's tests/config tree. That closes the earlier config.d, users.d, and client-path cases, but one destructive path is still open in the --db-replicated flow, so the PR is not safe to merge yet.

Findings

❌ Blockers

  • [tests/config/install.sh:15-16] The new refusal loop still does not cover the extra config trees created under --db-replicated. Later the script derives "$DEST_SERVER_PATH"/../clickhouse-server1 and .../clickhouse-server2 and then cp -r, rm, and > into them, but neither sibling path is checked before use. If either sibling directory is a symlink or bind mount to tests/config or one of its subdirectories, the source tree is still overwritten. I reproduced this with clickhouse-server1 -> tests/config: the guard passed, config.d/logger_trace.xml in the source copy changed, and generated files such as config.d/default_compression_codec.xml were created in the source tree. Suggested fix: after parsing options, extend the alias refusal to the replicated sibling directories before entering the USE_DATABASE_REPLICATED block.
Final Verdict

Status: ❌ Block

Minimum required action: protect the --db-replicated output directories (clickhouse-server1 and clickhouse-server2) with the same alias check before the script writes into them.

LLVM Coverage Report

Measured on commit 9d46cfd.

Metric Baseline Current Δ
Lines 87.90% 87.90% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +201 lines in 66 files (-94 lines lost coverage) · Details

Full report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 28, 2026
Comment thread tests/config/install.sh Resolved
alexey-milovidov and others added 2 commits September 28, 2026 12:59
`readlink -f` only resolves symlinks, so a bind mount of `tests/config`
(or its `config.d`) onto the destination slipped past the guard and
`rm -rf` still wiped the tracked source configs. `-ef` compares device
and inode, catching both symlinks and bind mounts. Also refuse when the
destination server directory itself is the source directory.

Addresses review: ClickHouse#111250 (comment)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=111250&sha=6c5784dbcfd305d289faa5f06cd24f51a1ee770d&name_0=PR&name_1=Stress%20test%20%28amd_msan%29 (Logical error: '!part.empty()' (STID: 2508-3010) in QueryAnalyzer::resolveArrayJoin via buildRowPolicyFilterIfNeeded) and provide a fix in a separate PR. If the fix is already in progress, link it here. This PR only touches tests/config/install.sh, so it is unrelated; master was merged into the branch in the meantime.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. This is a bug on master, unrelated to this PR. CREATE ROW POLICY does not substitute query parameters in its filter (the filters are not in ASTCreateRowPolicyQuery::children, so ReplaceQueryParameterVisitor never visits them), so the fuzzed {fuzz_param_0:Identifier} was stored in the row policy of 05257_memory_prewhere_global_in_sets_built_in_place. When the table is read, QueryTreeBuilder turns the unsubstituted placeholder into an identifier with an empty part, and the ARRAY JOIN type mismatch message converts that node back to ASTIdentifier, which asserts. It reproduces on master without the fuzzer:

CREATE TABLE t (k UInt64) ENGINE = Memory;
CREATE TABLE keys (k UInt64) ENGINE = Memory;
CREATE ROW POLICY p ON t USING k IN (SELECT k FROM keys LEFT ARRAY JOIN 'abc', {x:Identifier}) TO ALL;
SELECT * FROM t; -- Logical error: '!part.empty()'

The same path is also reachable in a single query through additional_table_filters. The fix substitutes the parameters in row policy filters and makes the query tree builder throw UNKNOWN_QUERY_PARAMETER for an unsubstituted Identifier parameter. It is implemented and tested; I will link the PR here when it opens.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is in #122688.

…e root

Check all four pairings of the destination root / `config.d` against the
source root / `config.d` with `-ef`, so that a setup where only
`DEST_SERVER_PATH/config.d` is the same directory as `tests/config` no
longer lets `rm -rf` wipe the tracked configs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, thanks — tracking the msan '!part.empty()' fix in #122688.

Comment thread tests/config/install.sh Resolved
…ses the source

The guard only covered `DEST_SERVER_PATH` and its `config.d`, but the script also writes into
`DEST_SERVER_PATH/users.d` and `DEST_CLIENT_PATH`. Check every mutated destination directory
against the source root and each of its subdirectories.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread tests/config/install.sh Resolved
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 1, 2026
Merged via the queue into ClickHouse:master with commit 1ed3fcc Oct 1, 2026
149 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 1, 2026
maxjustus pushed a commit to maxjustus/ClickHouse that referenced this pull request Oct 1, 2026
… the source

With `--db-replicated`, `tests/config/install.sh` copies the installed server
configs into `$DEST_SERVER_PATH/../clickhouse-server1` and `.../clickhouse-server2`
and then removes and rewrites files there. The source-alias guard added in
ClickHouse#111250 did not check these sibling
directories, so a symlink or bind mount from one of them back to `tests/config`
still rewrote the tracked configs.

Factor the guard into `refuse_if_dest_aliases_source` and also call it for the
replica directories, right after they are created, so `..` resolves the same way
as for the subsequent `cp`/`rm`/redirects.

Related: ClickHouse#111250

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-testing Test content only (no production code). pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local praktika runs can leave the repository in modified state

4 participants