From 44f837c2b79e33bec038e4be46c24c9906a98dd0 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 22 Nov 2026 10:38:19 +0000 Subject: [PATCH] fix(fleet): parse the personal token on the cache-daemon path too The gh cache daemon's personal op returns the resolved hosts.yml secret itself (it is a dumb secret cache for that op), but FleetTokenProvider used the daemon response as a finished token and only parsed the in-process copy. Whenever a daemon answered, gh got the whole 183-char hosts.yml as GH_TOKEN and refused it client-side: net/http: invalid header field value for "Authorization". Reads masked it (they fail over on any failure); writes surfaced it, since they repeat only on pre-execution refusals. Resolve the secret through via() on both paths and parse the oauth_token out of whichever copy answered, in one place (personal_token()). Document the wire-contract asymmetry in gh_cache.rs and add the regression test personal_token_is_the_parsed_token_not_the_secret. --- pkgs/fleet/crates/fleet/src/gh.rs | 48 +++++++++++++++++++++---- pkgs/fleet/crates/fleet/src/gh_cache.rs | 8 +++++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/pkgs/fleet/crates/fleet/src/gh.rs b/pkgs/fleet/crates/fleet/src/gh.rs index 881cf86f1a..5b41037e66 100644 --- a/pkgs/fleet/crates/fleet/src/gh.rs +++ b/pkgs/fleet/crates/fleet/src/gh.rs @@ -1004,13 +1004,22 @@ impl TokenProvider for FleetTokenProvider { fn token_for(&mut self, source: &TokenSource) -> Result { match source { TokenSource::Personal => { + // The `personal` op resolves the hosts.yml SECRET, + // not a finished token: the daemon is a dumb secret + // cache for this op (it never learns which secret + // personal means), and the process-local cache + // returns the same secret. Parse the token out of + // whichever copy answered. Parsing only the local + // copy once handed gh the whole hosts.yml as + // GH_TOKEN whenever a daemon answered, and gh + // refused it client-side: net/http: invalid header + // field value for "Authorization" — reads failed + // over to an App token and masked it; writes, which + // repeat only on pre-execution refusals, surfaced + // it (2026-11-22). let req = gh_cache::request("personal", None, None, Some(PERSONAL_SECRET_NAME)); - self.via(req, |cache| { - let hosts = cache.secret(PERSONAL_SECRET_NAME)?; - parse_hosts_yml_token(&hosts).ok_or_else(|| { - format!("secret '{PERSONAL_SECRET_NAME}' carries no oauth_token") - }) - }) + let hosts = self.via(req, |cache| cache.secret(PERSONAL_SECRET_NAME))?; + personal_token(&hosts) } TokenSource::AppInstallation { app, owner } => { let req = gh_cache::request("token", Some(app.slug()), Some(owner), None); @@ -1020,6 +1029,15 @@ impl TokenProvider for FleetTokenProvider { } } +/// The personal rotation token inside its hosts.yml secret: the +/// one place daemon-resolved and locally-resolved copies of the +/// secret converge, so neither path can skip the parse. +fn personal_token(hosts_yml: &str) -> Result { + parse_hosts_yml_token(hosts_yml).ok_or_else(|| { + format!("secret '{PERSONAL_SECRET_NAME}' carries no oauth_token") + }) +} + /// Extract the `oauth_token` value from gh's hosts.yml content. /// Line-shaped on purpose: the file is a small fixed-shape config, /// and a full YAML dependency for one string is not warranted. @@ -2111,6 +2129,24 @@ mod tests { assert_eq!(parse_hosts_yml_token("oauth_token: \n"), None); } + // oracle: the 2026-11-22 write-path break — a daemon answering + // the `personal` op returns the hosts.yml secret itself, and + // the value that reaches GH_TOKEN must be the parsed token: + // header-safe (no whitespace or control characters), never the + // multi-line file. A secret with no oauth_token is an error + // naming the secret, on either resolution path. + #[test] + fn personal_token_is_the_parsed_token_not_the_secret() { + let yml = "github.com:\n git_protocol: https\n users:\n dezren39:\n oauth_token: gho_0123456789abcdefghijklmnopqrstuv\n user: dezren39\n"; + let token = personal_token(yml).expect("token parses"); + assert_eq!(token, "gho_0123456789abcdefghijklmnopqrstuv"); + assert!( + token.chars().all(|c| c.is_ascii_alphanumeric() || c == '_'), + "token must be a valid Authorization header value: {token:?}" + ); + assert!(personal_token("github.com:\n user: x\n").is_err()); + } + // oracle: RFC 4648 base64url test vectors (padding dropped). #[test] fn base64url_vectors() { diff --git a/pkgs/fleet/crates/fleet/src/gh_cache.rs b/pkgs/fleet/crates/fleet/src/gh_cache.rs index 74b5ec0ab8..669f24c0a2 100644 --- a/pkgs/fleet/crates/fleet/src/gh_cache.rs +++ b/pkgs/fleet/crates/fleet/src/gh_cache.rs @@ -244,6 +244,14 @@ impl Cache { /// `jwt`, `token` or `status`; `app`/`owner` qualify `jwt`/`token`, /// and `name` carries the secret name for the `personal` op (so the /// daemon never hardcodes which secret personal means). +/// +/// Contract asymmetry, load-bearing: `jwt`/`token` responses carry +/// finished tokens, but a `personal` response carries the resolved +/// SECRET ITSELF (for the personal source that is the hosts.yml +/// file) in the `token` field — the daemon is a dumb secret cache +/// for this op and the client parses the credential out of it. +/// Treating a `personal` response as a finished token hands gh the +/// whole hosts.yml as GH_TOKEN (the 2026-11-22 write-path break). pub fn request( op: &str, app: Option<&str>,