Skip to content

feat(auth): authenticate GitHub release downloads with per-host tokens - #102

Merged
albertodebortoli merged 7 commits into
mainfrom
feat/github-token-auth-for-tool-downloads
Jul 23, 2026
Merged

feat(auth): authenticate GitHub release downloads with per-host tokens#102
albertodebortoli merged 7 commits into
mainfrom
feat/github-token-auth-for-tool-downloads

Conversation

@albertodebortoli

@albertodebortoli albertodebortoli commented Jul 23, 2026

Copy link
Copy Markdown
Member

Description

  • Lets Luca download a Tool's release archive/executable from a private repository — on github.com or a GitHub Enterprise Server instance — by attaching a personal access token read from a per-host environment variable (LUCA_GITHUB_TOKEN for github.com, LUCA_GITHUB_TOKEN_<HOST> for any other host).
  • The token is only ever attached for non-github.com hosts: github.com release-asset downloads redirect to a separate presigned-URL storage host, and forwarding a token there would leak it. The api.github.com release-metadata lookup (used by luca install org/repo@version) is authenticated separately, always against the github.com token.
  • Also sends Accept: application/octet-stream on every release download. This enables a workaround for GitHub Enterprise Server instances sitting behind a browser-SSO gateway (e.g. Okta): the plain web download URL can be intercepted by the SSO gateway before it reaches GHE, but the /api/v3/.../releases/assets/{id} endpoint is typically exempt and requires this header to return raw bytes instead of JSON.
  • Deliberately out of scope: making the org/repo@version CLI shorthand host-configurable for GitHub Enterprise. That shorthand still only targets github.com; this PR only adds authentication for URLs already reachable today (the url: field on a Tool, which already accepts any host).

Type of Change

  • Feature
  • Bug fix
  • Maintenance / Refactor
  • Documentation
  • CI / Tooling
  • Other (specify)

How Has This Been Tested?

  • Added / updated unit tests (GitHubTokenResolverTests, plus new cases in DownloaderTests, ReleaseInfoProviderTests, FileDownloaderTests)
  • Manually tested locally (describe): verified a Lucafile url: entry pointing at a private GitHub Enterprise Server release asset downloads successfully with LUCA_GITHUB_TOKEN_<HOST> set; also verified the Accept: application/octet-stream + API-asset-URL workaround against an SSO-gated (Okta) GHE instance
  • Tested on macOS (arch: arm64 / x86_64)
  • Other

Screenshots / Demo (if applicable)

N/A

Checklist

  • Swift code builds locally (swift build)
  • Tests pass locally (swift test) — 580 tests passing
  • Code style / formatting respected
  • Documentation updated (README / comments) — README.md and Lucafile.md DocC article
  • Version / tag alignment considered (if release related)
  • PR title follows conventional style (optional)

CI Considerations

  • Affects build time notably
  • Requires new secrets / env vars — new optional LUCA_GITHUB_TOKEN / LUCA_GITHUB_TOKEN_<HOST> environment variables, documented in README.md
  • Alters release process

Breaking Changes?

  • No
  • Yes (describe impact and migration path)

Additional Notes

FileDownloading.download(from:) was changed to download(for:) (request-based instead of URL-only) to allow attaching headers to the asset-download request. This is an internal protocol used only by Downloader and SelfUpdater; both call sites were updated, and no public API changed.

@albertodebortoli albertodebortoli added the feature New feature or enhancement label Jul 23, 2026
@albertodebortoli albertodebortoli added this to the 0.23.0 milestone Jul 23, 2026
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Downloader.swift uses URLRequest, which lives outside Foundation on Linux.
@albertodebortoli
albertodebortoli marked this pull request as ready for review July 23, 2026 09:47
@albertodebortoli
albertodebortoli merged commit df65476 into main Jul 23, 2026
3 checks passed
@albertodebortoli
albertodebortoli deleted the feat/github-token-auth-for-tool-downloads branch July 23, 2026 09:48
albertodebortoli added a commit to LucaTools/lucatools.github.io that referenced this pull request Jul 23, 2026
Adds a new Tool Management page covering LUCA_GITHUB_TOKEN /
LUCA_GITHUB_TOKEN_<HOST> and the API-asset-URL workaround for GHE
instances behind an SSO gateway, per LucaTools/Luca#102.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant