Skip to content

Add github-pat-install for the per-org PAT files - #25

Merged
natevick merged 1 commit into
mainfrom
norm/github-pat-install
Aug 21, 2026
Merged

Add github-pat-install for the per-org PAT files#25
natevick merged 1 commit into
mainfrom
norm/github-pat-install

Conversation

@natevick

Copy link
Copy Markdown
Owner

Adds ~/.local/bin/github-pat-install, a one-command installer for the per-org GitHub PATs that git-credential-github-org and the gh shim read.

Why

The four existing ~/.config/github-pats/<owner> files were created by hand. The failure mode that makes that worth fixing: the credential helper fails silently. With no readable token file it exits without a credential and lets git proceed unauthenticated — which on a private repo surfaces as a 404, not an auth error. A typo, a stray newline, or a wrong filename is indistinguishable from "that repo does not exist."

Written while adding a fifth org (offerlab) for OL-3431.

What it does

  • Hidden prompt; never takes the token as an argument — argv is visible to every user via ps
  • Validates the shape (github_pat_… / ghp_…) and rejects embedded whitespace
  • Writes 0600, no trailing newline, lowercased filename to match the helper's owner lookup
  • Refuses to clobber an existing token without confirmation
  • Reads stdin when not on a TTY, so it works piped as well as interactively

Then it verifies two separate things, because writing the file proves nothing:

  1. the credential helper chain actually resolves a token for that owner — exercising credential.useHttpPath → helper → file
  2. GitHub accepts it, reporting which account it authenticates as

Verified

Exercised in a sandbox GITHUB_PAT_DIR with fake tokens before this landed:

Case Result
No owner / invalid owner (../evil) refuses, writes nothing
Empty / malformed / whitespace-containing token refuses, writes nothing
Valid token 93 bytes, mode 600, no trailing newline, byte-identical to input
Existing file, answer N untouched (md5 compared)
Existing file, answer y replaced

A deliberately invalid token failed verification step 2 — a validity check that passes for a bogus token would be worse than no check at all.

CI's exact shellcheck invocations (install.sh home/*.sh, home/dot_local/bin/*, modify_settings.json) all pass locally. chezmoi cat against this source renders byte-identically to the already-installed live file, so applying this changes nothing on disk.

🤖 Generated with Claude Code

https://claude.ai/code/session_017XXtMcWtVAxm3BYXdxXiLW

The four existing ~/.config/github-pats/<owner> tokens were created by hand.
That is fine once and error-prone thereafter: the credential helper fails
SILENTLY when a token file is missing or malformed — it exits without a token
and lets git proceed unauthenticated, which on a private repo surfaces as a 404
rather than an auth error. A typo or stray newline is indistinguishable from
"that repo doesn't exist".

So this installs one properly: hidden prompt (never an argument — argv is
visible to every user via ps), validates the token shape and rejects embedded
whitespace, writes 0600 with no trailing newline, and refuses to clobber an
existing token without confirmation.

It then verifies two separate things, because writing the file proves nothing:

  1. that the credential helper chain actually resolves a token for that owner,
     exercising gitconfig's useHttpPath -> helper -> file; and
  2. that GitHub accepts it, reporting which account it authenticates as.

Both were exercised in a sandbox before this landed. Every refusal path was
confirmed to write nothing, the clobber prompt confirmed to leave the existing
file byte-identical, and a deliberately invalid token confirmed to FAIL check 2
— a validity check that passes for a bogus token would be worse than none.

Reads from stdin when not on a terminal, so it works piped as well as
interactively.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017XXtMcWtVAxm3BYXdxXiLW
@natevick
natevick merged commit f0ef1cd into main Aug 21, 2026
3 checks passed
@natevick
natevick deleted the norm/github-pat-install branch August 21, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant