Skip to content

Fix Arrow Flight Basic authentication for clients sending unpadded Base64 - #115085

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-arrowflight-basic-auth-nopadding
Aug 18, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-arrowflight-basic-auth-nopadding

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

The Arrow Flight server rejected clients that send the authorization: Basic <credentials> header with the Base64-encoded credentials not padded with =. The Go Flight client does exactly that — for example, the ADBC Flight SQL driver with the plain username/password options performs the AuthenticateBasicToken handshake this way, so connecting to ClickHouse failed with a meaningless error:

UNKNOWN: [FlightSQL] Unexpected error in RPC handling (Unknown; AuthenticateBasicToken). Vendor code: 2

The cause: Poco::Base64Decoder requires padding by default and throws Poco::DataFormatException, which escaped AuthMiddlewareFactory::StartCall (it only caught DB::Exception) into gRPC, which converted it to the generic UNKNOWN status above.

The fix:

  • Decode the credentials with the BASE64_NO_PADDING option, which accepts both padded and unpadded input, so Go-based Flight clients (including ADBC) can authenticate.
  • Convert a failed Base64 decode into a proper AUTHENTICATION_FAILED exception, reported to the client as an Unauthenticated Flight error with a clear message.
  • Catch the remaining exception types in StartCall so no exception can escape into gRPC and produce the meaningless Unexpected error in RPC handling status.

Verified end-to-end with adbc_driver_flightsql 1.12.0: connecting with plain username/password and running a query now works, while padded Basic credentials, Bearer tokens, and wrong-password errors behave as before.

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: accept Basic authentication credentials encoded in Base64 without padding, as sent by Go-based Flight clients such as the ADBC Flight SQL driver, and return a proper authentication error instead of a generic Unexpected error in RPC handling when the authorization header is malformed.

🤖 Generated with Claude Code


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

Version info

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

…se64

The Go Flight client (used, for example, by the ADBC Flight SQL driver
with the plain username/password options, which call
AuthenticateBasicToken) sends the credentials in the
'authorization: Basic <credentials>' header with the Base64 not padded
with '='. Poco::Base64Decoder requires padding by default and throws
Poco::DataFormatException, which escaped AuthMiddlewareFactory::StartCall
(it only caught DB::Exception) into gRPC, so such clients received a
meaningless 'UNKNOWN: Unexpected error in RPC handling' status instead
of authenticating successfully.

Decode the credentials with the BASE64_NO_PADDING option, which accepts
both padded and unpadded input, convert a failed decode into a proper
AUTHENTICATION_FAILED exception, and catch the remaining exception types
in StartCall so they are returned as proper Flight error statuses.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f8c83b4]

Summary: ✅


AI Review

Summary

This PR fixes the main Arrow Flight regression by accepting unpadded Base64 in Basic auth headers and by converting escaping exceptions into proper Flight errors. One malformed-credentials case still gets accepted as a successful login, so the malformed-header contract is not fully enforced yet.

Findings

⚠️ Majors

  • [src/Server/ArrowFlight/AuthMiddleware.cpp:101] A Base64 payload that decodes successfully but does not contain the mandatory user:password separator still falls through as {user, ""}. For example, authorization: Basic ZGVmYXVsdA decodes to default, so the npos branch authenticates it as the default user instead of rejecting the malformed header. Suggested fix: throw AUTHENTICATION_FAILED when credentials.find(':') == std::string::npos and add a regression test for that case.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: reject colonless decoded Basic credentials as malformed and add a focused regression test for that input.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.80% 86.80% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.20% 79.20% +0.00%

Changed lines: Changed C/C++ lines covered: 27/32 (84.38%) · 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 17, 2026
When an `authorization` header is present, reject it unless it is a supported `Basic` or `Bearer` header. This prevents malformed schemes from falling through to default authentication.
@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f8c83b46b with master c545616f6 (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 702.05 MiB 699.03 MiB -3.02 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

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

Job report

std::string credentials;
try
{
credentials = base64Decode(std::string(auth_str.substr(basic_prefix.size())), /* url_encoding = */ false, /* no_padding = */ true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This now fails cleanly when the Base64 itself is invalid, but a decoded Basic payload without the required : separator still authenticates instead of failing closed. For example, authorization: Basic ZGVmYXVsdA decodes to default; the npos branch below turns that into { "default", "" }, so a malformed header logs in as the default user rather than returning Unauthenticated.

Since this PR's contract is "malformed authorization headers become proper authentication errors", I think the no-: case needs to throw AUTHENTICATION_FAILED as well, with a regression test alongside test_basic_auth_malformed_base64.

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.

🕵 Addressed in #115347: colonless decoded Basic credentials now return Unauthenticated, with a focused integration regression test.

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

Amazing!

@alexey-milovidov alexey-milovidov self-assigned this Aug 18, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 18, 2026
Merged via the queue into master with commit f61ce92 Aug 18, 2026
181 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-arrowflight-basic-auth-nopadding branch August 18, 2026 18:02
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 18, 2026
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.

2 participants