Skip to content

Install tgz: give the target of a dangling symlink the packaged mode - #112766

Merged
alexey-milovidov merged 12 commits into
masterfrom
install-tgz-dangling-symlink-mode
Aug 9, 2026
Merged

alexey-milovidov merged 12 commits into
masterfrom
install-tgz-dangling-symlink-mode

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #111960, which addresses the remaining unresolved review finding there.

In the tgz installer (doinst.sh), a destination that is a symlink is written through so that an installation keeping its configs or binaries elsewhere keeps the indirection after an upgrade. When the symlink is dangling, however, there is no destination inode to preserve: the shell redirection creates the target with the umask of the installation, unrelated to the mode, the ownership or the label of the packaged file. A symlinked binary path would install as a non-executable file owned by whoever built the tarball.

Such a destination is now handled by renaming the packaged file to where the link points: the link keeps its indirection, and the installed file gets exactly the metadata a fresh installation gives it (chown -h root:root and restorecon), with no extra disk space. The whole chain is followed - a link pointing at another link keeps both, the way a redirection did, and only the final referent is created - and a symlink loop is reported and fails the installation instead of looping forever. A symlink to an existing file is still written through, so its inode, ownership and extended attributes survive an upgrade.

The Install tgz over a dangling symlink test now runs the installation under umask 077 and asserts the mode and the ownership of the installed target, and Install tgz over a chain of dangling symlinks covers a destination link pointing at another dangling link through relative hops. Verified additionally with a fake-root simulation of the generated doinst.sh: before the change the dangling-symlink targets came out 0600 instead of 0644/0755, after it they carry the packaged mode, while the write-through, hard-link and fresh-install paths are unchanged.

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Installing a tgz package over a dangling symlink now gives the created target the mode and the ownership from the package instead of a umask-derived mode, and keeps every level of the symlink chain.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Related: #111960

Version info

  • Merged into: 26.8.1.1051 (included in 26.8 and later)

Follow-up to #111960. When the destination is a symlink whose target does
not exist yet, `doinst.sh` wrote through it with a shell redirection, which
creates the target with the `umask` of the installation and with no relation
to the mode, the ownership or the label of the packaged file - a symlinked
binary path would install as a non-executable file owned by the builder.

There is no destination inode to preserve in that case, so the packaged file
is renamed to where the link points instead: the link keeps its indirection,
and the installed file gets the metadata it has in the package, the same way
a fresh installation does. A symlink to an existing file is still written
through, so its inode, ownership and attributes survive an upgrade.

`Install tgz over a dangling symlink` now installs under `umask 077` and
asserts the mode and the ownership of the installed target.

Verified with a fake-root simulation of the generated `doinst.sh`: before the
change the dangling-symlink targets came out `0600` instead of `0644`/`0755`,
after it they carry the packaged mode, while the write-through, hard-link and
fresh-install paths are unchanged.

Related: #111960
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7829d32]

Summary: ✅


AI Review

Summary

This PR changes the tgz installer so that installing over a dangling destination symlink creates the final referent with the packaged metadata while preserving the symlink indirection. At the current head, the earlier review concerns are addressed: the script now follows the whole symlink chain, fails loudly on missing parent directories and loops, returns resolved paths byte-for-byte under dash, and the regression suite covers those cases. I do not see a remaining correctness or packaging-contract violation in the touched code.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 31, 2026
Comment thread packages/build Resolved
The dangling-symlink branch of `doinst.sh` resolved a single `readlink` hop, so a destination
symlink pointing at another symlink had that second link replaced by a regular file: the
installation still destroyed a level of indirection that writing through the destination with
`cat` used to keep, because a redirection follows the chain to its end.

`resolve_symlink_chain` now follows every hop, resolving a relative hop against the directory
of the link it was read from, and only the final referent is created. A chain that never ends
- a symlink loop - is reported and fails the installation instead of looping forever, the same
way the previous `cat` failed with `ELOOP`.

Added `Install tgz over a chain of dangling symlinks` to `ci/jobs/install_check.py`, with
relative hops so that a hop resolved against the wrong directory is caught as well. Verified
with a fake-root simulation (`tmp/sim3/run.sh`): both links kept, `/real/config.xml` created
with the packaged mode, an absolute single-hop link still handled, no leftovers in the unpack
tree; `tmp/sim3/run_loop.sh` shows the loop case failing with `Too many levels of symbolic
links`.
@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement and removed pr-ci labels Aug 1, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master and re-ran CI.

The AI Review verdict is now ✅ Approve and all jobs are green except BuzzHouse (amd_msan), which is unrelated to this packaging change (this PR touches only packages/build and ci/jobs/install_check.py).

Root cause of that red, from the server log: BuzzHouse fuzzed SYSTEM ENABLE FAILPOINT attach_to_group_failure, which makes ThreadGroupSwitcher fail to attach. The switcher is noexcept and only logs the injected failure, so the thread continued with no thread group and the next executeQuery on it tripped Logical error: No thread group attached to the thread 138. The same failure hit #110514 in BuzzHouse (amd_debug) on the same day.

Fixed separately in #113002, which excludes that failpoint (and thread_group_switcher_post_attach_failure) from the set the fuzzer enables - they exist for the in-process unit test gtest_thread_group_switcher, not for injection from SQL.

Comment thread packages/build Resolved
bobrik pushed a commit to bobrik/ClickHouse that referenced this pull request Aug 2, 2026
BuzzHouse enables a random failpoint from \`system.fail_points\`. Two of them -
\`attach_to_group_failure\` and \`thread_group_switcher_post_attach_failure\` - deliberately break the
invariant that a query thread is attached to a thread group. \`ThreadGroupSwitcher\` is \`noexcept\` and
only logs the injected failure, so the thread carries on with no group and the next \`executeQuery\`
that runs on it fails with the \`No thread group attached to the thread\` logical error, e.g.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112766&sha=25a457c530e81c122d764503aa913d2d04eedbb1&name_0=PR&name_1=BuzzHouse%20%28amd_msan%29
(ClickHouse#112766). The same failure hit
ClickHouse#110514 in \`BuzzHouse (amd_debug)\` on the same day.

Both failpoints exist for the in-process unit test \`gtest_thread_group_switcher\`, which enables them
around a single controlled switch; they are not meaningful to inject from SQL. Exclude them from the
list the fuzzer picks from, like the other failpoints that legitimately take the server down.
…sing directory

Creating the parent directory of the symlink target with `mkdir -p` gave it
the `umask` of the installation and no defined ownership, so under a
restrictive `umask` the installed file could end up unreachable while
`doinst.sh` reported success. Writing through the link failed loudly in that
case before, so `doinst.sh` now reports the missing directory and exits
instead of materializing a half-usable tree.

Added `Install tgz over a symlink into a missing directory` to
`ci/jobs/install_check.py`.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Addressed the AI Review Major (packages/build:179) in 02e8e1cd621 and merged master.

The finding was real: mkdir -p "$(dirname -- "$linktarget")" turned a previously loud failure into a silent, potentially unusable install — the created directory got the umask of the installation and no defined ownership, so under umask 077 the 0644/0755 file inside it could still be unreachable while doinst.sh reported success.

Took the fail-fast option: when the directory a dangling destination points into does not exist, doinst.sh now prints

Cannot install <destpath>: it points at <linktarget>, but the directory <linkparent> does not exist

and exits, which is exactly what writing through the link did before this PR. Nothing is created on that path.

Added the regression test Install tgz over a symlink into a missing directory to ci/jobs/install_check.py. Verified locally with a fake-root simulation (user namespaces are unavailable here, so destinations are prefixed and chown is stubbed): the missing directory fails loudly both as the direct target and as the last hop of a symlink chain, /missing is not created, the link survives, and the dangling-link, chain-of-dangling-links and fresh-install cases still succeed with the packaged mode 644. shellcheck packages/build and ruff check are clean.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red on the previous run, Stress test (arm_debug) — Logical error: Not-ready Set is passed as the second argument for function 'in' (report) — is unrelated to this packaging-only change (it touches only packages/build and ci/jobs/install_check.py). CIDB shows this logical error hitting 2–7 PRs per day plus master runs for weeks. It is tracked by #107619 (same failure class; the exact-STID auto-issue #102803 was closed while the failure still recurs on master), with fixes in progress, e.g. #109722.

Merged master to re-run CI. The AI Review verdict is ✅ Approve and there are no unresolved review threads.

@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

No arm_release build profile data for commit 7829d32 - the build was skipped, reused from cache, or predates profile upload.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red, CI Tests (20 failures in ci/tests/test_lsan_ptrace_probe_filter.py, TypeError: stat: path should be string ... not NoneType from tests/clickhouse-test), was a master-wide breakage unrelated to this packaging-only PR: the failing test file was deleted on master in aa4d71a because it was blocking CI everywhere. Merged master to pull that in and re-roll CI. The AI verdict remains ✅ Approve and there are no unresolved review threads.

Comment thread packages/build Resolved
…ntf`

`resolve_symlink_chain` returned the resolved path with `echo`, but the
installer runs under `/bin/sh`, which is `dash` on Debian-based systems,
and `dash`'s `echo` expands backslash escapes: a dangling destination
whose target contains `\t` or `\n` was resolved to a mangled path, so
the installation either failed or created the file at the wrong place.
Every `echo` inside the generated script is now `printf '%s\n'` - the
`ls -ld` listing fed to `awk` in `keep_destination_inode` carries the
file name too, and the diagnostics should print paths byte-for-byte as
well. Added `Install tgz over a dangling symlink with a backslash in
the target` to `ci/jobs/install_check.py`.

#112766
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red on the last run, AST fuzzer (arm_asan_ubsan) — Logical error: Reading from materialized CTE 'A' before its materialization completed - DelayedPortsProcessor gate is missing in the query plan (report) — is unrelated to this packaging-only PR (it touches only packages/build and ci/jobs/install_check.py). The same failure class hits several PRs and master runs every day and is tracked by #113184 and #110176, with fixes already in progress (#113489, #113558, #113683).

Merged master to re-roll CI. The AI Review verdict is ✅ Approve and there are no unresolved review threads.

Comment thread ci/jobs/install_check.py Resolved
…ctory test

The `Install tgz over a symlink into a missing directory` test failed in the
deb image with `grep: /tmp/install.log: No such file or directory`, although
the shell redirection had just created that file. The install test images boot
systemd as PID 1 and deliberately keep `systemd-tmpfiles-setup` in
`sysinit.target.wants`; Ubuntu ships `D /tmp` in `tmpfiles.d/tmp.conf`, so the
container "boot" wipes `/tmp` concurrently with the test script that `docker
exec` starts right after `docker run --detach`. Write the log to `/root`
instead, which the boot-time cleanup never touches.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112766&sha=a4bf75a4c431a7eaefeae6afa53ea25bcf997aeb&name_0=PR&name_1=Install%20packages%20%28amd_release%29
PR: #112766
Address review: the `hops > 40` hard-fail branch of `resolve_symlink_chain`
in `doinst.sh` was only validated manually. The new `Install tgz over a
symlink loop` test points `/etc/clickhouse-client/config.xml` and
`/shared/config.xml` at each other, asserts the installation fails with
`Too many levels of symbolic links`, and checks that both links survive
unchanged.

PR: #112766
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Both items on a4bf75a4c43 are addressed:

  1. The only CI red, Install packages (amd_release) / Install tgz over a symlink into a missing directory, was a race in the test itself: the install-test images boot systemd as PID 1 and keep systemd-tmpfiles-setup enabled, and Ubuntu ships D /tmp in tmpfiles.d/tmp.conf, so the container boot wipes /tmp concurrently with the test script — here right between doinst.sh writing /tmp/install.log and grep reading it (the rpm run of the same test passed). Fixed in 9cbade9 by writing the log to /root, which the boot-time cleanup never touches. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112766&sha=a4bf75a4c431a7eaefeae6afa53ea25bcf997aeb&name_0=PR&name_1=Install%20packages%20%28amd_release%29
  2. The AI review Major (missing regression test for the hops > 40 symlink-loop failure path) is addressed in 7829d32 with Install tgz over a symlink loop, verified with a fake-root simulation of the generated doinst.sh.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Aug 9, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 9, 2026
Merged via the queue into master with commit 6cde32d Aug 9, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the install-tgz-dangling-symlink-mode branch August 9, 2026 21:10
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-build Pull request with build/testing/packaging improvement 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.

2 participants