feat: server-level GitHub machine credential for authenticated requests #109
Reference in New Issue
Block a user
Delete Branch "benvin/github-auth"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
Anonymous GitHub is capped at 60 requests/hour and cannot read private repositories. A machine credential usable by a free (non-enterprise) account is needed to lift the request budget to ~5000/hr and to read private-repo release assets.
Builds on the background syncer (#108, now merged to
master); this diff is the auth changes only.How
internal/githubauth: a process-wide GitHub credential delivered via env/secret, applied by default to every outbound GitHub request (releases scan, ranged asset-header GETs, and the generic-github byte proxy for private assets).GITHUB_TOKENsent asAuthorization: Bearer <token>.GITHUB_APP_ID+GITHUB_APP_INSTALLATION_ID+ private key (GITHUB_APP_PRIVATE_KEYinline PEM orGITHUB_APP_PRIVATE_KEY_PATH). Mint a short-lived RS256 JWT with stdlibcrypto/rsa(no new dependency), exchange it atPOST /app/installations/{id}/access_tokensfor a ~1h installation token, cache it, and single-flight a refresh a few minutes before expiry.AuthHeaders(byte proxy, github.com hosts only; the pre-signedobjects.githubusercontent.comredirect deliberately gets no Authorization).username/passwordoverrides the server credential; no credential configured stays anonymous (current behavior).getenvconvention; document PAT vs App setup, the free-account fine-grained PAT scopes (Contents:read + Metadata:read), precedence, and the rate-limit implication.Rate limit
Authenticated requests share the syncer's single global limiter — no second limiter is added. A token raises the effective GitHub ceiling (~5000/hr vs ~60/hr), so the limiter defaults stay safe.
Tests
internal/githubauthandinternal/provider/{rpm,generic}:Authorizationheader to releases + asset-header requests.Authorizationheader, requests still succeed anonymously.Verified fail-before/pass-after for the injection tests.
gofmt -l,go build ./...,go vet ./...,go test ./...all clean (26 packages).9b94f18d7ato8ced48901f