Skip to content

Reject malformed Arrow Flight Basic credentials - #115347

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix/arrowflight-reject-colonless-basic
Aug 21, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix/arrowflight-reject-colonless-basic

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

Reject decoded Arrow Flight Basic credentials that omit the required : separator, preventing them from falling through as the default user with an empty password. Adds an integration regression test.

Related: #115085

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 into CHANGELOG.md):

Arrow Flight server: reject malformed Basic authentication credentials that omit the username/password separator.


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

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a83953a]

Summary: ✅


AI Review

Summary

This PR makes Arrow Flight Basic authentication fail closed when the decoded credentials omit the required : separator, instead of treating them as <username>, "" and potentially authenticating the default user. I did not find a material correctness or coverage issue in the current diff: AuthMiddlewareFactory::StartCall is the only Arrow Flight credential parser on the server side, and the new integration test exercises the affected header path end to end.

Missing context / blind spots
  • ⚠️ Full PR CI is still pending as of 2026-08-20; I did not wait for the remaining jobs or run the Arrow Flight integration suite locally.
Final Verdict

✅ No material issues found in the current diff.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a83953a94 with master 12e8fa319 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.42 MiB 701.36 MiB -3.05 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

8 translation units recompiled, 12 s compile time in total, 8 of them have a recent master baseline.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115347&sha=8f516dc1cbcbb245067015d849f29908c312cebc&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29. It reproduces the huge index_granularity allocator exception already addressed by #108650; please link any updated fix if that PR is superseded.

@groeneai

Copy link
Copy Markdown
Collaborator

Not superseded: #108650 is still the only fix for this signature, and it is still open.

The row is STID 1367-1ab3, the write path. The fuzzer-injected index_granularity = 9223372036854775806 reaches MergeTreeDataPartWriterWide::validateColumnOfFixedSize, which passes it directly to deserializeBinaryBulk as the row count (src/Storages/MergeTree/MergeTreeDataPartWriterWide.cpp:750 at master 581c15c46), and PODArray padding turns it into the reported 9223372036854775933 (2^63-2 + 64 + 63). That call is still unbounded at master, so nothing has landed for it since #108650 was opened.

#108650 reads the validation column in bounded batches instead of resizing to the untrusted per-mark granularity. It has had no review since 2026-06-26, and its base is 25045 commits behind master, so its two red checks (Bugfix validation (functional tests, amd64), Stress test (arm_debug)) are from that stale base. I will refresh the base so its CI is current and the PR is reviewable.

@groeneai

Copy link
Copy Markdown
Collaborator

Base refreshed: #108650 is now 75 commits behind master instead of 25045, and CI is running on the fresh head db03a99a267ff76bc9367d8a0e33f9ccaec1af30. Master merge, no rebase, so your merge commit a1568e16 is untouched. No submodule pins moved (git -c diff.ignoreSubmodules=none diff origin/master..HEAD is 3 files, 0 contrib/ lines).

The fix still applies: master's three unbounded deserializeBinaryBulk call sites in validateColumnOfFixedSize are the three the PR patches, and no new one appeared. Re-verified both directions on the refreshed tree, debug build:

  • pre-fix binary: SIGABRT, Too large size (9223372036854776060) passed to allocator, via validateColumnOfFixedSize
  • fixed binary: passes, exact reference match

While re-validating I found the regression test could go green with the fix reverted. The validator only runs on a plain DEFAULT serialization, the test runner randomizes ratio_of_defaults_for_sparse_serialization down to 0, and the inserted UInt8 data has 391 default values, so a sparse column skipped the check entirely. Measured on a pre-fix binary: ratio 0 returns normally, ratio 1 aborts. The setting is now pinned, and I added a granule larger than one read batch, which the original case never crossed. 50 randomized plus 50 non-randomized runs, all green.

@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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Aug 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 21, 2026
Merged via the queue into master with commit 350486a Aug 21, 2026
176 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix/arrowflight-reject-colonless-basic branch August 21, 2026 17:58
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
@clickgapai

Copy link
Copy Markdown
Contributor
Reproducer

Shell reproducer — set BIN to a ClickHouse binary path and run with bash; requires the referenced test fixtures from the repo.

#!/bin/bash
BIN="${BIN:-./clickhouse}"  # path to the ClickHouse binary under test
# Arrow Flight: Basic credentials WITHOUT the ':' separator must be rejected.
# Pre-fix they were parsed as {username=<whole string>, password=""}, so
# "Basic base64('default')" authenticated as the passwordless `default` user.
set -uo pipefail

WORK=$(mktemp -d /tmp/afrepro.XXXXXXXX)
SRV_PID=""
cleanup() { [ -n "$SRV_PID" ] && kill -9 "$SRV_PID" 2>/dev/null; rm -rf "$WORK"; }
trap cleanup EXIT

python3 -c 'import pyarrow.flight' 2>/dev/null || { echo "INCONCLUSIVE: pyarrow.flight not importable"; exit 2; }

read -r TCP_PORT AF_PORT <<<"$(python3 - <<'PY'
import socket
def free():
    s = socket.socket(); s.bind(("127.0.0.1", 0)); p = s.getsockname()[1]; s.close(); return p
print(free(), free())
PY
)"

cat > "$WORK/users.xml" <<XML
<clickhouse>
    <profiles><default></default></profiles>
    <quotas><default></default></quotas>
    <users>
        <default>
            <password></password>
            <profile>default</profile>
            <quota>default</quota>
            <networks><ip>::/0</ip></networks>
        </default>
    </users>
</clickhouse>
XML

cat > "$WORK/config.xml" <<XML
<clickhouse>
    <logger><level>trace</level><console>0</console><log>$WORK/ch.log</log><errorlog>$WORK/err.log</errorlog></logger>
    <listen_host>127.0.0.1</listen_host>
    <tcp_port>$TCP_PORT</tcp_port>
    <arrowflight_port>$AF_PORT</arrowflight_port>
    <path>$WORK/data/</path>
    <tmp_path>$WORK/tmp/</tmp_path>
    <user_files_path>$WORK/user_files/</user_files_path>
    <format_schema_path>$WORK/schemas/</format_schema_path>
    <user_directories><users_xml><path>$WORK/users.xml</path></users_xml></user_directories>
    <mark_cache_size>268435456</mark_cache_size>
</clickhouse>
XML

"$BIN" server --config-file="$WORK/config.xml" >"$WORK/stdout.log" 2>&1 &
SRV_PID=$!

for _ in $(seq 1 60); do
    python3 -c "
import socket,sys
s=socket.socket(); s.settimeout(1)
sys.exit(0 if s.connect_ex(('127.0.0.1',$AF_PORT))==0 else 1)" && break
    kill -0 "$SRV_PID" 2>/dev/null || break
    sleep 1
done

python3 -c "
import socket,sys
s=socket.socket(); s.settimeout(1)
sys.exit(0 if s.connect_ex(('127.0.0.1',$AF_PORT))==0 else 1)" || {
    echo "INCONCLUSIVE: Arrow Flight port never opened (feature absent / not built)"
    grep -iE "arrowflight|arrow flight" "$WORK/ch.log" "$WORK/stdout.log" 2>/dev/null | tail -3
    exit 2
}

timeout 60 python3 - "$AF_PORT" <<'PY'
import base64, sys
import pyarrow.flight as flight

port = sys.argv[1]
client = flight.FlightClient(f"grpc://127.0.0.1:{port}")

def get(cred):
    opts = flight.FlightCallOptions(headers=[(b"authorization", f"Basic {cred}".encode())])
    return client.do_get(flight.Ticket(b"SELECT 1"), opts).read_all()

# Sanity: well-formed credentials must work, otherwise the verdict is meaningless.
try:
    get(base64.b64encode(b"default:").decode())
except Exception as e:
    print("INCONCLUSIVE: well-formed Basic auth failed:", type(e).__name__, str(e)[:200])
    sys.exit(30)

# The bug: same base64, no ':' separator.
try:
    t = get(base64.b64encode(b"default").decode())
    print("BUG: 'Basic base64(\"default\")' (no separator) authenticated, SELECT 1 returned", t.num_rows, "row(s)")
    sys.exit(10)
except (flight.FlightUnavailableError, flight.FlightTimedOutError) as e:
    print("INCONCLUSIVE: transport failure -", type(e).__name__, str(e)[:200])
    sys.exit(30)
except Exception as e:
    # Any rejection counts as clean: 25.8/26.3 reject with an IOError status,
    # the fix rejects with Unauthenticated. Only authenticating is the bug.
    print("CLEAN: rejected -", type(e).__name__, str(e).splitlines()[0][:200])
    sys.exit(20)
PY
RC=$?

case "$RC" in
    10) exit 1 ;;
    20) exit 0 ;;
    124) echo "TIMEOUT"; exit 2 ;;
    *) exit 2 ;;
esac

Results:

  • Reproduces on: 26.7, 26.6, 26.5
  • Does not reproduce on: 26.3, 25.8
  • Tested versions: master, 26.7, 26.6, 26.5, 26.3, 25.8
  • Also tested (unsupported, context only): 26.2 clean
  • Fix merged on master (not re-verified: tested master build predates this PR's merge — a clean verdict is not attributable to the fix). The releases listed above still have the bug and need the backport.

Backport the fix to 26.7, 26.6, 26.5.

CC component owner: @yakov-olkhovskiy @vitlibar

Analysis metadata

comp-arrow-flight · Severity P2 · Finding phase_d_pr115347

  • Verified against master build 7e1c82b83712 (aarch64)
  • Could not test: master
Introducing change: not identified
  • The one boundary found was rejected — PR changes DeltaLake snapshot caching and S3 credentials handling, but the bug is about Arrow Flight Basic authentication credential parsing which is unrelated to these subsystems. — a coincidental boundary, not the cause.
  • The source-build bisect converged to Add Arrow Flight SQL support #91170, but it is not the introducer (see above) — not attributing it.
  • Secondary components: comp-testing

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

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

4 participants