acoustic-carpenter-78188
07/31/2026, 4:09 PMAsyncCommandAuthenticator (auth mode external_process) uses the stdout of the configured command verbatim as the bearer token. If that command is an interactive helper, it can exit 0 while printing a prompt rather than a token:
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=...
.strip() only removes the surrounding whitespace, so the interior newline survives into Authorization: Bearer <prompt>. connectrpc's pyqwest transport then rejects it:
ValueError: Invalid header value 'Bearer Please visit this URL to authorize this application: ...'
raised deep in _send_request_unary, far from the real cause. It gets wrapped as RuntimeError: SelectCluster failed for operation=1 → RuntimeSystemError: Upload failed for ..., which reads like an upload bug and is reported to Sentry as an SDK crash.
Confirmed the exact mechanism against the installed transport — pyqwest.Headers rejects newlines and NUL, and accepts spaces:
| value | result |
| ------------- | -------------------------------- |
| Bearer a\nb | ValueError: Invalid header value |
| Bearer a\x00b | ValueError: Invalid header value |
| Bearer a b | accepted (silent 401 later) |
| Bearer abc123 | accepted |
Fix
1. Reject at the source. Validate the command output before it becomes a credential and raise AuthenticationError with an actionable message. The output is deliberately not echoed back — it may contain a genuine token. AuthenticationError is already classified user-facing by _sentry._is_user_error, so this stops the Sentry noise as well as fixing the UX.
2. Un-poison the keyring. The bad token was written to the keyring before it was ever used in a request, so affected users stayed broken on every subsequent run — _do_refresh_credentials was never re-entered, so fixing only the command path would leave them wedged until they cleared the keyring by hand. get_auth_headers now treats a cached token that cannot be sent as a header as if there were no credentials; the normal unauthenticated path then triggers a refresh, which re-runs the command and surfaces the real error. This is a general guard, not command-specific.
Validation is a deliberate superset of what the transport rejects: a bearer token is a single opaque string (RFC 6750 restricts it to [A-Za-z0-9-._~+/=]), so rejecting all whitespace and non-latin-1 also converts what would be a confusing silent 401 into a clear message, with no risk of rejecting a legitimate token.
Two incidental fixes in the same function: the non-zero-exit AuthenticationError was being caught and re-wrapped by the generic except Exception handler, losing its specific message; and the debug log did " ".join(cmd_joined) on an already-joined string, logging the command character by character.
Testing
21 new tests in tests/flyte/remote/test_command_authenticator.py covering token validation, the prompt-as-token case (including that the message does not leak the output), empty/usage-message output, the non-zero-exit path, and both cached-token behaviours.
Verified the bug reproduces on unpatched main — the authenticator accepts the prompt as a token and builds the header from it — and that the fix rejects it. Full tests/flyte/remote/ suite: 487 passed; the 2 failures in test_trigger_create_offload.py are pre-existing on clean main and unrelated.
fixes FLYTE-SDK-6Y
flyteorg/flyte-sdk