GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — [improve][client] PIP-478: drive the v5 authentication model natively in the client (Personal CI) by lhotari · Pull Request #252 · lhotari/pulsar Conversation
|
| Commit | Change |
|---|---|
f67d696c79f |
A v5-native NoAuthentication for the unauthenticated case, and the v5 AuthenticationFactory returns the v5-native token body instead of bridging AuthenticationToken backwards |
721be36355c |
The inversion. ClientCnx drives the v5 Authentication; V5ToV4AuthenticationAdapter is deleted (net −500 lines) |
Why "no auth" needed its own body. The generic v4→v5 bridge cannot represent it. LegacyV4CredentialAdapter advertises BinaryAuthDataProvider only for a plugin that actually produced command data, and the v4 AuthenticationDisabled produces none (AuthenticationDataNull is empty) — so a bridged no-auth plugin exposes no binary capability at all, indistinguishable from a plugin that cannot authenticate a binary connection. That is masked today only by an explicit instanceof AuthenticationDisabled escape in PulsarClientBuilderV5 which the inversion deletes; without this commit, the default unauthenticated deployment would stop connecting the moment the client drives v5 natively. Resolving the "none" method name to a v5-native body sits alongside the existing "tls" and "sasl" branches, keeps selection side-effect-free, and keeps the unauthenticated hot path free of both the v4 probe and the executor hop.
PulsarClientImpl resolves one v5 Authentication per client into a new transient slot on ClientConfigurationData, and ClientCnx opens one exchange per connection attempt against it. The instanceof AsyncAuthenticationDriver fork and the whole synchronous plugin path are gone, so credential I/O can no longer land on a Netty event loop by accident. The built-in shims hand over the v5-native body they already own through a new V5AuthenticationProvider seam rather than implementing AsyncAuthenticationDriver.
Three defects had to be fixed for this to be behaviour-preserving — each was found by an existing test, not by inspection:
"sasl" got a challenge handler (MutualAuthenticationTest). Any v4 plugin that can serve the binary transport can answer a challenge on it, so the credential adapter now advertises both.getCommandData(); v4's ClientCnx used authenticate(INIT_AUTH_DATA), whose default implementation returns getCommandData() — correct for single-pass plugins, and also correct for challenge plugins that only produce their first frame that way.authenticate() returned, empty included (TlsProducerConsumerTest.testTlsWithFakeAuthentication). The probe now decides only the HTTP capability, which has no universal fallback.Plugin lifecycle now has exactly one owner: the client starts and closes the v4 instance in conf, so the adapter driving it is created already-started and does not re-run configure/start/close. AuthenticationOAuth2.start() initializes the token flow, so a second start() is not a harmless no-op.
AsyncAuthenticationDriver, ClientAuthenticationServices(Aware) and DefaultClientAuthenticationServices — now that the client builds the AuthenticationInitContext itself, the late-binding marker has one remaining consumer (the OAuth2 flow's HTTP client factory).V5ToV4AuthenticationAdapter invariants that had no other home: the actionable serialization error, and fail-loud when a plugin exposes no binary capability.pip/pip-478.md updated — the PIP currently specifies V5ToV4AuthenticationAdapter as permanent and lists ClientAuthenticationServices(Aware) as new public API.HttpClient, BaseResource, PulsarAdmin). Its v5 seam AsyncHttpAuthenticationProvider has zero implementors today, so that is a first activation rather than a migration, and it is gated on a bridge for SASL-over-HTTP (AuthenticationSasl.authenticationStage(...) has no v5 counterpart).conf.authentication stays v4-typed. Every auth-provided TLS-material fold keys off the concrete v4 type, and the v5 SPI has no TLS-material carrier. Retyping that slot would silently drop the client certificate for AuthenticationTls — a failure that shows up only as a 401 at the broker.DirectProxyHandler, whose synchronous handshake PIP-478 explicitly leaves out of scope."none" branch fails both new assertions in V5AuthenticationLoaderTest.:pulsar-client-v5:test green; quickCheck green.Prepared with the assistance of Claude Code (Opus 5).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ication The v5 SPI has no body for the unauthenticated case, and the generic v4->v5 bridge cannot stand in for one. LegacyV4CredentialAdapter advertises BinaryAuthDataProvider only when the wrapped plugin actually produced command data, and the v4 AuthenticationDisabled produces none (AuthenticationDataNull is empty), so a bridged no-auth plugin exposes no binary capability at all — indistinguishable from a plugin that cannot authenticate a binary connection. That is currently masked by an explicit escape in PulsarClientBuilderV5, which drives AuthenticationDisabled raw on the v4 client. Once the client drives the v5 model natively that escape goes away, and the default unauthenticated deployment would stop connecting. Resolve the "none" method name to a new v5-native NoAuthentication instead, alongside the existing "tls" and "sasl" branches: side-effect-free selection, no v4 probe, no executor hop on the unauthenticated hot path. Also return the v5-native token body from the v5 AuthenticationFactory rather than bridging AuthenticationToken backwards through the legacy adapter — the offload the bridge performs exists for plugins that do credential I/O, which an in-memory token does not. Verified by mutation: removing the "none" branch fails both V5AuthenticationLoaderTest.blankClassNameLoadsDisabledAuthentication and theUnauthenticatedCaseCanDriveABinaryConnection. Assisted-by: Claude Code (Opus 5)
… in the client The client held a v4 Authentication and wrapped a v5 plugin backwards into it. Invert that: the client resolves exactly one v5 Authentication and drives every binary connection from it, and the only remaining bridge is v4 -> v5. There is no synchronous plugin path left on the connect/challenge routes, so credential I/O can no longer land on a Netty event loop by accident. The built-in shims (token, basic, OAuth2) hand over the v5-native body they already own through a new V5AuthenticationProvider seam, instead of implementing AsyncAuthenticationDriver; anything else is wrapped by LegacyV4AuthenticationAdapter. V5ToV4AuthenticationAdapter, SimpleAuthInitContext and SimpleAuthCallContext are deleted — the inversion removes more than it adds. conf.authentication deliberately stays v4-typed and populated with the raw plugin: every auth-provided TLS-material fold keys off the concrete v4 type, and the v5 SPI has no TLS carrier. Emptying it would silently drop the client certificate and surface only as a 401. The v5 body goes in a new transient slot beside it. Three defects had to be fixed for the inversion to be behaviour-preserving, each found by an existing test rather than by inspection: - The bridge selected its adapter by auth-method name, so only a plugin literally called "sasl" got a challenge handler. Every custom challenge/response plugin lost multi-round auth (MutualAuthenticationTest). Any v4 plugin that can serve the binary transport can answer a challenge on it, so the credential adapter now advertises both. - The bridge served the initial credential from getCommandData(), while v4's ClientCnx used authenticate(INIT_AUTH_DATA) — whose default implementation returns getCommandData(), so it is correct for single-pass plugins and also correct for challenge plugins that only produce their first frame that way. - The binary capability was gated on a probe, so a plugin reporting no command data could not connect at all — but v4 connected it fine, sending whatever authenticate() returned, empty included (TlsProducerConsumerTest.testTlsWithFakeAuthentication). The probe now decides only the HTTP capability, which has no universal fallback. Plugin lifecycle now has exactly one owner. The client starts and closes the v4 instance in conf, so the adapter that drives it is created in an already-started form and does not re-run configure/start/close — AuthenticationOAuth2.start() initializes the token flow, so a second start() is not a harmless no-op. Verified: :pulsar-client-original:test, :pulsar-client-v5:test, :pulsar-proxy ProxyTest + AutoCloseUselessClientConProxyTest, :pulsar-broker TlsProducerConsumerTest + V5TlsProducerConsumerTest + MutualAuthenticationTest, sanityCheck and quickCheck. Assisted-by: Claude Code (Opus 5)
…lient owns it Driving the v5 model natively means every legacy v4 plugin now goes through LegacyV4AuthenticationAdapter, which by design refuses to run a v4 call inline — the caller thread is a Netty event loop, and running credential I/O there is the stall PIP-478 exists to remove. It off-loads to the executor its init context supplies. Not every connection is opened by a PulsarClient, though. The proxy builds broker connections straight from a ClientConfigurationData, and so do embedders and tests, so no client-owned executor is bound and the context supplied none: the adapter then failed every call with "used before initializeAsync() completed". That refuses connections v4 made fine (ProxyAuthenticationTest, ProxySaslAuthenticationTest), and it only surfaced on the proxy because the built-in bodies never off-load. Supply a shared blocking executor for those callers instead. Running inline was the other option and is the wrong one: on that path the caller thread is an event loop too. The pool costs nothing when unused — no core threads, daemon threads retiring after a minute idle — and is created on first use. Verified by mutation: reverting this fails ProxySaslAuthenticationTest.testAuthentication with the same IllegalStateException CI reported. Assisted-by: Claude Code (Opus 5)
The previous commit handed the shared blocking executor to every plugin through the init context, which changed the built-in bodies too: a token the client already holds in memory started resolving on a worker thread instead of inline, so the connect continuation stopped running synchronously (ClientCnxAsyncAuthTest.refreshRepublishesCredentialWithout Disconnect). Off-loading buys a native body nothing and costs a thread hop per connect. Hand it only to the component that must off-load. The init context reports no executor when no client services are bound, and LegacyV4AuthenticationAdapter borrows the shared pool at the point of use. That also restores a distinction the previous commit collapsed, which LegacyV4AuthenticationAdapterTest.capabilityMethodBeforeInitializationFailsFast pins: being used before initializeAsync() has run is not the same as being initialized without an executor. In the first case the wrapped plugin has not been configured or started, so there is nothing valid to call and it still fails fast; only the second falls back. Assisted-by: Claude Code (Opus 5)
…lose Two lifecycle paths still saw only the v4 slot, so the authentication the client actually drives was left behind. Both were found by review — the second independently by Codex. updateAuthentication(), which cluster failover uses, replaced the v4 plugin but left conf.v5Authentication and conf.v5AuthenticationDriver pointing at the previous credential body. Every new connection then kept presenting the OLD cluster's credential, served by a plugin the same method had just closed, so failing over to a cluster that requires the replacement credential would not authenticate. Re-resolve both after starting the new plugin. Client shutdown closed only conf.getAuthentication(). A v5-native plugin configured through the v5 builder lives only in the v5 slot — the v4 slot still holds AuthenticationDisabled — so whatever it holds open (HTTP clients, executors, credential handles) leaked on every close. Closing the v5 slot is safe for the other cases: a body handed over by a built-in shim owns nothing, and a bridged adapter built for an already-started plugin deliberately leaves that plugin to its owner, which is the v4 close that follows. Verified by mutation: reverting the first fails ClientAuthenticationLifecycleTest.swappingTheAuthenticationSwapsWhatTheClientDrives with the stale credential, reverting the second fails closingTheClientClosesAV5NativePlugin. Assisted-by: Claude Code (Opus 5)
The shared blocking executor used SynchronousQueue with the default abort policy, so the ninth concurrent credential call was rejected outright. Every caller of that pool is a connection attempt on a path no PulsarClient owns — the proxy's broker connections — and before the inversion those ran inline, where saturation was impossible. A proxy fronting many clients with a legacy plugin would therefore turn a reconnect storm into failed connections rather than slower ones. Queue the excess instead: a fixed ceiling of threads created on demand, work beyond it waiting rather than aborting, and core threads allowed to time out so an unused pool still costs nothing. Also record on BasicAuthenticationV5's supplier constructor that the type is Serializable and a caller intending to serialize it must pass serializable suppliers. The v4 shim does not need to: the body it builds lives only in the client's transient slot. Assisted-by: Claude Code (Opus 5)
…ent configuration Review found a second entry point into the staleness the updateAuthentication fix addressed, and this one needs no failover to reach it. ClientBuilderImpl.build() hands the client the builder's OWN configuration object, and the client wrote the body it derived from the v4 slot back into that object. A second client from the same builder — or from a clone of it — then reused that body even after authentication(...) had been called again, so every CONNECT carried the previous credential while conf.getAuthentication() showed the new one. Wrong identity or a 401, with the configuration reading correctly. Stop writing the derived body back. The v5 slot now holds only what the v5 builder explicitly configured, and the body is derived on every resolution, so the answer is a function of the current configuration rather than of build history. Three review items alongside it: - Match the built-in AuthenticationDisabled by type rather than by the "none" method name. Bridging it works since the binary capability stopped being probe-gated; resolving it to NoAuthentication is about keeping the unauthenticated hot path free of an executor hop and a probe. Matching the name would also discard a third-party plugin that reports "none" and still serves a credential, downgrading it to anonymous silently. - V5AuthenticationProvider's javadoc named Athenz and SASL among the shims that hand over a v5-native body; neither has one, and both go through the bridge. - Remove the orphaned bare block left in bindAuthenticationServices when its guard became unconditional, correct the field comment that still claimed the HTTP client factory is null without an Aware plugin, and re-home the buildConnectCommand javadoc that a later insertion left dangling above resolveAuthDriver. Verified by mutation: restoring the write-back fails ClientAuthenticationLifecycleTest.aSecondClientFromTheSameBuilderUsesTheSecondCredential with the first client's credential. Assisted-by: Claude Code (Opus 5)
Review of the Athenz/SASL migration found that a v5-native body falls back to running its credential fetch inline when no client services are bound — and that the case this "degraded" fallback describes is not a plugin misused outside a client. It is the proxy, which builds broker connections straight from a ClientConfigurationData, and there the caller thread is a Netty event loop. The rationale for handing native bodies no executor was that a body serves a credential it already holds in memory, so a hop buys nothing. That is true of the basic body and a literal token, and false of every body that acquires anything: an OAuth2 access token costs a token-endpoint round trip, a file-backed token reads a file, and — once the plugin migration lands — a ZTS role-token fetch and a GSSAPI exchange with the KDC join them. A proxy reconnect storm against a slow identity provider would then stall every connection multiplexed on the affected event loops, which is the exact failure PIP-478 exists to remove. The v4→v5 bridge already borrows the shared pool for precisely this reason; the native path simply did not. Fall back to the shared blocking executor instead of running inline. Nothing changes for a client that owns an executor, which is every real PulsarClient. CredentialOffloadTest.withoutBoundExecutorRunsInlineOnCaller pinned the old behaviour and is rewritten to pin the new one, and ClientCnxAsyncAuthTest's refresh test now awaits the republished credential instead of assuming resolution completed on the calling thread. Found by review (Fable) of the stacked Athenz/SASL PR, where the same shape reaches the proxy through SASL and Athenz. Assisted-by: Claude Code (Opus 5)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.