Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions pkgs/fleet/crates/fleet/src/gh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,13 +1004,22 @@ impl TokenProvider for FleetTokenProvider {
fn token_for(&mut self, source: &TokenSource) -> Result<String, String> {
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);
Expand All @@ -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<String, String> {
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.
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 8 additions & 0 deletions pkgs/fleet/crates/fleet/src/gh_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ impl<B: Backend> Cache<B> {
/// `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>,
Expand Down