Add ChatGPT token stdin authentication to exec-server (#59569)

## What changed

- Add `--chatgpt-token-stdin` for remote HTTPS registration and optional `--chatgpt-account-id`, which must match the token's account claim when present. Read a bounded, newline-terminated token from a pipe without persisting it to `auth.json`.
- Load managed configuration using the supplied account, enforce account restrictions, and preserve configured policy-server authentication. Skip ChatGPT policy lookup only for known plans that do not require managed configuration.
- Allow `--exit-on-stdin-close` to cancel pending policy loading, and redact the registration bearer from registry diagnostics.
- Reject incompatible stdin credential options, including flags placed on opposite sides of `forward`, and disallow ChatGPT token stdin authentication with `forward`.

## Testing

Add coverage for account-claim validation, policy selection, policy-server sign-in requirements, shutdown during policy loading, credential flag conflicts, and bearer redaction.

GitOrigin-RevId: b6b50565e1f150b96edf3cee796909a991f1b47f
This commit is contained in:
aagrawal-oai
2026-11-05 04:25:19 +00:00
committed by copyberry
parent 5c0b1ac71f
commit 529d965d80
17 changed files with 523 additions and 89 deletions
@@ -58,6 +58,17 @@ pub(crate) fn init(
(otel, telemetry)
}
pub(super) fn monitor_stdin_close() -> tokio::sync::oneshot::Receiver<()> {
let (sender, receiver) = tokio::sync::oneshot::channel();
std::thread::spawn(move || {
if let Err(error) = std::io::copy(&mut std::io::stdin().lock(), &mut std::io::sink()) {
tracing::warn!(%error, "Could not read exec-server parent lifetime pipe");
}
let _ = sender.send(());
});
receiver
}
pub(crate) async fn run_until_shutdown<F, E>(
run: F,
parent_lifetime: ParentLifetime,
@@ -69,18 +80,7 @@ where
let parent_disconnected = match parent_lifetime {
ParentLifetime::Independent => None,
ParentLifetime::MonitoredStdin(receiver) => Some(receiver),
ParentLifetime::StdinPipe => {
let (sender, receiver) = tokio::sync::oneshot::channel();
std::thread::spawn(move || {
if let Err(error) =
std::io::copy(&mut std::io::stdin().lock(), &mut std::io::sink())
{
tracing::warn!(%error, "Could not read exec-server parent lifetime pipe");
}
let _ = sender.send(());
});
Some(receiver)
}
ParentLifetime::StdinPipe => Some(monitor_stdin_close()),
};
let parent_disconnected = async {
match parent_disconnected {