Support Fine-grained Personal Access Tokens (PATs) in GEI to enable least-privilege CLI migrations
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- csharp, github
- Ambito
- authentication, backend-api-design
Direzione di ricerca
Start with the referenced GithubApi.cs, ArchiveUploader.cs, and the linked issues about token support to map which migration APIs reject GitHub App installation tokens and fine-grained PATs. The request spans GraphQL mutations, the REST export API, and archive storage, and proposes alternative migration workflows; completion would require agreeing on scope and delivering compatible support or documented fallback paths.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
1. Background & Scope (Distinction from #1420)
Currently, GitHub Enterprise Importer (GEI) strictly requires Personal Access Tokens (classic) with broad scopes (repo, admin:org, workflow) and does not support Fine-grained PATs (Official Documentation).
While #1420 requests support for GitHub App installation tokens for long-lived automated pipelines, this issue specifically focuses on why Fine-grained PAT support is essential for GEI.
2. Concrete Scenarios Where Classic PATs Are Problematic
A structural flaw of Classic PATs is that they cannot be scoped to a specific resource owner (organization) or repository—they grant repo and admin:org permissions across every organization and private repository the user can access (Official Documentation).
This creates severe security blockers in the following scenarios:
- Migrating only a specific organization or a subset of repositories
If an engineer belongs to multiple organizations (e.g., Production Org A, Department Org B, and Migration Target Org C), issuing a Classic PAT just to migrate a single repository in Org C produces a token that can read, write, and modify settings across all repositories in unrelated Orgs A and B (maximizing the blast radius if leaked). - Delegating migration work via the
Migratorrole
GEI provides aMigratorrole to delegate migrations to non-owner engineers or external migration partners. However, requiring the migrator to generate a Classic PAT means their token inevitably includes access to unrelated private repositories and organizations they happen to belong to. - Conflict with the "Restrict personal access tokens (classic)" policy
As explicitly stated in the GEI documentation, "You cannot use GitHub Enterprise Importer if your organization uses the 'Restrict personal access tokens (classic) from accessing your organizations' policy." Organizations enforcing this policy are forced to either weaken their security posture by allowing over-privileged Classic PATs or abandon using GEI altogether.
3. Why Fine-grained PATs Are Needed Instead of GitHub Apps (#1420)
-
GEI is used for short-lived migration scripts, where GitHub's own guidelines recommend Fine-grained PATs over GitHub Apps
- According to GitHub's official documentation (Choosing between a GitHub App or a personal access token), GitHub Apps are intended for long-lived integrations, whereas Personal Access Tokens (specifically Fine-grained PATs whenever possible) are recommended for short-lived scripts.
- For GEI's standard CLI workflow—generating a one-off
migrate.ps1script viagenerate-scriptand running it—registering a new GitHub App, managing private keys (PEM), and implementing JWT signing is excessive overhead. Fine-grained PATs preserve the existing CLI experience (GH_PAT/GH_SOURCE_PATenvironment variables) with zero additional setup.
-
Combining GEI's
Migratorrole with GitHub's default Fine-grained PAT approval flow- GEI provides the Migrator role so organization owners can delegate migrations to individual users or teams. However, installing a GitHub App requires Organization Owner privileges, and the
grantMigratorRoleAPI only acceptsUSERorTEAMas theactorType. Therefore, a delegated migrator cannot self-provision or use a GitHub App. - By contrast, since Fine-grained PATs became GA in March 2025, both Fine-grained PATs and the Organization Owner approval flow are enabled by default for all organizations. This allows a user with the
Migratorrole to request a Fine-grained PAT scoped strictly to the target organization/repositories with least-privilege permissions (such as therepository_creation:writepermission added on October 13, 2026), and run the CLI migration safely once approved by an Organization Owner.
- GEI provides the Migrator role so organization owners can delegate migrations to individual users or teams. However, installing a GitHub App requires Organization Owner privileges, and the
4. Related Issues & Community Feedback
The limitation of only accepting Classic PATs and legacy OAuth scopes has been raised repeatedly by users:
- #1283 (Open): Only classic PATs are accepted as authentication
- GitHub Community Discussion #162365: Fine-grained personal access token doesn't work
- #708 (Closed) / #1229 (Closed) / Discussion #1120:
createMigrationSourcefailing withFORBIDDENdue to strict Classic PAT scope requirements (['read:org', 'repo']/admin:org) - #20 (Open) / #1001 (Open): Discussions on validating PATs via legacy
X-OAuth-Scopesheaders - (Reference: Related requests/reports regarding GitHub App tokens: #1420 (Open), #1260 (Closed), #867 comment)
5. Technical Bottlenecks (①–③) and Proposed Solutions / Fallback Options
An inspection of the gh-gei codebase (GithubClient.cs, GithubApi.cs, ArchiveUploader.cs) and GitHub's API compatibility tables shows that the CLI itself merely passes the token as Authorization: Bearer <token>. Fine-grained PATs are blocked by three specific backend API bottlenecks:
| Bottleneck API | Why Fine-grained PATs Are Currently Blocked | Affected Migration Sources | Proposed Fix & Security-First Workaround / Compromise |
|---|---|---|---|
| ① Source Export API REST POST /orgs/{org}/migrations |
/orgs/{org}/migrations is not included in the Endpoints available for fine-grained personal access tokens. |
GHES / GHE.com only (Note: GitLab gl2gh, Bitbucket bbs2gh, and ADO ado2gh use their own native export APIs and do not call ①) |
[Fundamental Fix] Add Fine-grained PAT support (GH_SOURCE_PAT) to /orgs/{org}/migrations.[Workaround] Instead of the Migration API, read repository settings/metadata temporarily via standard REST/GraphQL APIs (already Fine-grained PAT compatible, similar to migrate-code-scanning-alerts). |
| ② Target Import API GraphQL createMigrationSourcestartRepositoryMigrationstartOrganizationMigration |
[Primary Blocker] The backend enforces legacy OAuth scope string checks (['read:org', 'repo']) and passes githubPat / accessToken directly to async backend workers. |
All Migration Sources (GitHub, GitLab, ADO, Bitbucket are all blocked here) |
[Fundamental Fix] Update the GraphQL mutations and async backend workers to accept Fine-grained PATs and fine-grained permissions (e.g., repository_creation:write).[Compromise / Fallback Mode] See details below. |
③ Archive Upload APIuploads.github.com/organizations/{id}/gei/archive |
Internal GEI endpoint with no Fine-grained PAT permission mapping. | When using --use-github-storage (GHES, GitLab, Bitbucket) |
[Fundamental Fix] Allow Fine-grained PATs (GH_PAT) on this endpoint.[Workaround Available Today] Bypass GitHub Owned Storage (③) by using --aws-bucket-name (S3) or --azure-storage-connection-string (Azure Blob) to pass pre-signed URLs. |
Details on Compromise / Fallback Mode for ② (Prioritizing Security Over Metadata Fidelity)
If updating the ② backend GraphQL mutations takes time, organizations that ban Classic PATs would benefit from a fallback mode (or official guidance) that trades mannequin attribution and original issue/PR timestamps for 100% Fine-grained PAT compatibility using standard APIs:
- Repository Creation & Git Push: Create the repository via
POST /orgs/{org}/repos(supported by Fine-grained PATs with the newrepository_creation:writepermission) and rungit push --mirror+git lfs push --all(preserving 100% of commit history and authors). - Settings Backup & Restore: Read and recreate branch protections, rulesets, team permissions, autolinks, and code/secret scanning alerts via standard REST APIs (all compatible with Fine-grained PATs).
- Issue & PR Recreation: Recreate issues, labels, milestones, and PRs via standard REST APIs (
POST /repos/{owner}/{repo}/issues,/pulls) using the Fine-grained PAT, embedding the original author and timestamp metadata into the body text.
6. Request
- Primary Request (Backend Fine-grained PAT Support):
Please update the authorization checks on ② GraphQL (createMigrationSource,startRepositoryMigration), ① REST (/orgs/{org}/migrations), and ③ GitHub Owned Storage (uploads.github.com) to accept Fine-grained PATs (GH_SOURCE_PATandGH_PAT) and fine-grained permissions such asrepository_creation:write. - Roadmap Sharing:
As stated in the March 2025 Fine-grained PAT GA announcement, GitHub's goal is "enabling organizations to eventually disable the use of PATs (Classic) for their resources." Could the team share whether Fine-grained PAT support for GEI is on the roadmap?
- Lingua principale
- C#
- Stelle
- 482
- Fork
- 151
- Merge medio
- 2g 18h
- PR unite (30g)
- 5
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di github/gh-gei
-
migrate-code-scanning-alerts fails with OverflowException: analysis IDs now exceed Int32.MaxValueAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
task
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
-
task
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
-
bbs2gh: support setting custom property values after repository migrationForse già presa @enyil l’ha presa 36 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
Tutte le issue di github/gh-gei
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
iokode/OpinionatedFramework#140 ·
-
accessibility effort: small enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pedersebastian/CustomBossChallenge#185 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
dotnet/command-line-api#2887 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
JiaFeiMiao-K-Cat/DiscImageStudio#331 ·
I maintainer di solito rispondono entro 1 giorno