Skip to content

feat(auth): support GitHub CLI credentials - #4960

Merged
mnriem merged 17 commits into
github:mainfrom
mnriem:mnriem-github-cli-auth
Oct 23, 2026
Merged

mnriem merged 17 commits into
github:mainfrom
mnriem:mnriem-github-cli-auth

Conversation

@mnriem

@mnriem mnriem commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Add a dedicated github-cli authentication mode backed by the fixed, shell-free gh auth token command.
  • Pass the first configured hostname (hosts[0]) to gh auth token --hostname and use that hostname as the cache key for successful or failed lookups in memory for the current process.
  • Treat every configured host or supported wildcard as an explicit destination authorized to receive that credential. Host-instance inference is intentionally not performed; use separate entries for different credentials.
  • Provide sanitized missing CLI, authentication, command failure, empty or malformed output, and timeout errors.
  • Document configuration, first-host ordering, enterprise behavior, and acquisition-failure versus HTTP fallback behavior.

Closes #4953

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest
  • Tested with a sample project (if applicable)

The exact template commands above were not run in this review round. Focused checks at 1dfc5244:

  • .venv/bin/python -m pytest tests/specify_cli/authentication -o addopts='' -q --disable-warnings — 326 passed, 33 warnings.
  • ruff check --isolated --select E4,E7,E9,F,S602,S604,S605 src/specify_cli/authentication/github.py tests/specify_cli/authentication/test_authentication.py — passed.

Coverage includes first-host selection and cache isolation, missing or relative executables, sanitized subprocess and malformed-token failures, registered-provider HTTP wiring, declared-host redirect preservation and unlisted-host stripping, and catalog failure handling.

Earlier validation reported by the original implementation (not rerun in full for this description update):

  • uvx ruff@0.15.0 check src tests — passed.
  • .venv/bin/python -m pytest tests/specify_cli/authentication/test_authentication.py -q — 204 passed.
  • LC_ALL=en_US.UTF-8 .venv/bin/python -m pytest tests -q — 12,212 passed, 71 skipped.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: Implemented on behalf of @mnriem with GitHub Copilot using GPT-5.6 Sol in autonomous mode for the original implementation and its reported validation. Subsequent review fixes, regression tests, documentation, and validation were authored and executed by GitHub Copilot using GPT-6.1 Sol, primarily in autonomous mode, with the first-host policy directed by @mnriem. This description update and review replies use GPT-6.1 Sol in interactive mode with explicit user authorization. Reasoning-effort settings were not explicitly selected in this session. No claim of human line-by-line review is made.

Add a dedicated github-cli authentication mode with host-aware token resolution, in-memory caching, sanitized failures, tests, and documentation.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 434e2508-0633-4d40-8e0d-5edb92cbc177
Copilot AI max review requested due to automatic review settings October 14, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Credential selection can send an enterprise token to public GitHub.

3 open findings
What changed in this PR

Adds GitHub CLI authentication to Specify, allowing developers to reuse gh credentials without storing a token in Specify configuration.

Changes:

  • Adds shell-free token lookup, in-memory caching, and sanitized errors.
  • Passes request hostnames through authentication providers.
  • Adds authentication tests and configuration documentation.

AI-generated review for the requester (identity unavailable) by GitHub Copilot (model unknown, autonomous); analysis and drafting.

File Description
tests/​specify_cli/​authentication/​test_authentication.py Tests CLI lookup, caching, failures, and request integration.
src/​specify_cli/​authentication/​http.py Passes request hostnames to providers.
src/​specify_cli/​authentication/​github.py Implements GitHub CLI credential resolution.
src/​specify_cli/​authentication/​config.py Updates a comment about field-free CLI modes.
src/​specify_cli/​authentication/​bitbucket.py Accepts the optional hostname argument.
src/​specify_cli/​authentication/​base.py Extends the provider interface with hostname context.
src/​specify_cli/​authentication/​azure_devops.py Adopts the updated provider signature.
docs/​reference/​authentication.md Documents GitHub CLI configuration and enterprise behavior.

🧠 Review effort: Max


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/specify_cli/authentication/github.py Outdated
Comment thread src/specify_cli/authentication/github.py Outdated
Comment thread src/specify_cli/authentication/github.py Outdated
Pass explicit GitHub CLI hostnames, map configured enterprise service hosts to their instance login, and route sanitized credential failures through existing URL error handling.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 434e2508-0633-4d40-8e0d-5edb92cbc177
Copilot AI max review requested due to automatic review settings October 14, 2026 17:22
@mnriem mnriem added the triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate label Oct 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread tests/specify_cli/authentication/test_authentication.py Outdated
Comment thread tests/specify_cli/authentication/test_authentication.py Outdated
Comment thread docs/reference/authentication.md Outdated
Keep sanitized GitHub CLI credential failures distinct from offline errors in release checks and upgrade output, prove no HTTP fallback occurs, and document terminal failure caching.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 434e2508-0633-4d40-8e0d-5edb92cbc177
Copilot AI max review requested due to automatic review settings October 14, 2026 17:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cross-instance redirects can forward the initial host’s credential instead of selecting the destination’s credential.

1 open finding
3 resolved since last review

🧠 Review effort: Max

Comment thread src/specify_cli/authentication/http.py Outdated
Prevent GitHub CLI tokens from following redirects to a different GitHub credential host while preserving authorization across public and configured enterprise aliases.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 434e2508-0633-4d40-8e0d-5edb92cbc177
Copilot AI max review requested due to automatic review settings October 14, 2026 18:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Credential-handling changes need human review because bundle error classification and redirect-security coverage remain unresolved.

3 open findings
1 resolved since last review

🧠 Review effort: Max

Comment thread src/specify_cli/authentication/github.py Outdated
Comment thread src/specify_cli/authentication/github.py
Comment thread src/specify_cli/authentication/http.py Outdated
Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 434e2508-0633-4d40-8e0d-5edb92cbc177
Copilot AI max review requested due to automatic review settings October 14, 2026 18:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The subprocess credential helper and shared HTTP changes need human security review.

4 open findings

🧠 Review effort: Max

Comment thread src/specify_cli/authentication/github.py Outdated
Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 434e2508-0633-4d40-8e0d-5edb92cbc177
Copilot AI max review requested due to automatic review settings October 14, 2026 19:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Security-sensitive authentication and redirect changes retain verified defects and require human review.

5 open findings
1 resolved since last review

🧠 Review effort: Max

Comment thread src/specify_cli/authentication/github.py
Comment thread src/specify_cli/authentication/github.py Outdated
Remove consumer-specific error handling, redirect policy changes, and shared provider API changes. Keep GitHub CLI host selection within the GitHub provider by treating each provider entry as one credential scope.

Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 434e2508-0633-4d40-8e0d-5edb92cbc177
Copilot AI max review requested due to automatic review settings October 14, 2026 20:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/specify_cli/authentication/github.py Outdated
Comment thread docs/reference/authentication.md Outdated
Comment thread src/specify_cli/authentication/github.py Outdated
Use hosts[0] as the credential hostname instead of inferring an instance from service prefixes. Document ordering and cover first-host selection, wildcard rejection, and cache isolation.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Classify GitHub CLI acquisition failures as URL errors so existing catalog handlers can warn and continue, while each affected HTTP request still fails without credential or anonymous fallback. Cache the sanitized reason without nesting URL-error wrappers. Add catalog-search regression, release-check, and redirect-wiring coverage; retain the approved first-host credential contract.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 23, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/reference/authentication.md Outdated
Comment thread src/specify_cli/authentication/github.py
Add the GitHub CLI credential mode alongside bearer and remove the redundant prose below the table.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 23, 2026 14:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/reference/authentication.md
Qualify the authentication process summary and HTTP helper docstrings: GitHub CLI acquisition errors stop the request immediately, whereas HTTP 401/403 after successful acquisition still permits matching-entry and anonymous fallback. No runtime behavior changes.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 23, 2026 15:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Malformed Unicode CLI output can bypass sanitized authentication errors and abort catalog operations or release checks.

1 open issue
4 resolved since last review

Review effort: Max

Comment thread src/specify_cli/authentication/github.py Outdated
Reject decoded non-ASCII CLI output through the sanitized malformed-token path before returning or caching credentials. Extend failure-cache regression coverage to Latin-1 and non-Latin-1 Unicode and document the restriction.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 23, 2026 16:35
@mnriem

mnriem commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

Fixed in 12fe353: GitHub CLI tokens are now required to be ASCII after trimming. Non-ASCII output takes the existing sanitized malformed-token path before any successful token is cached or passed to HTTP headers. Regression cases cover both Latin-1 and non-Latin-1 Unicode, identical repeated diagnostics, and a single subprocess invocation. Documentation now states this restriction. No base-class or shared HTTP changes.

The new Unicode cases failed before the fix and pass afterward. Validation: .venv/bin/python -m pytest tests/specify_cli/authentication tests/specify_cli/integrations/test_catalog.py tests/specify_cli/test_version_release.py tests/specify_cli/test_version_execution.py tests/specify_cli/test_operation_version.py -o addopts='' -q --disable-warnings — 506 passed. Targeted Ruff checks passed.

Posted on behalf of @mnriem by GitHub Copilot (GPT-6.1 Sol, interactive session with autonomous implementation; reasoning effort not explicitly selected). AI involvement: implementation, regression tests, documentation, validation, and comment drafting.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The credential-execution boundary and refreshed dependency hashes warrant final human validation beyond the available static evidence.

No open issues 🎉

1 resolved since last review

Review effort: Max

Keep sanitized GitHub CLI diagnostics in release checks and upgrade failure rendering. Treat authentication failures as definitive in bundle catalog fetching and reference validation, rather than availability fallbacks. Add regressions that failed before the fix and document the caller behavior; preserve the first-host contract and authentication base classes.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 23, 2026 17:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Credential subprocess execution and cross-module failure handling need maintainer review beyond the isolated verification performed here.

1 open issue

Review effort: Max

Comment thread tests/specify_cli/authentication/test_authentication.py Outdated
Normalize captured whitespace before checking authentication error details so Rich line wrapping does not make release-command tests depend on terminal width.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI max review requested due to automatic review settings October 23, 2026 17:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Subprocess-based credential acquisition and authentication-failure handling across shared request paths warrant final maintainer review.

No open issues 🎉

1 resolved since last review

Review effort: Max

@mnriem
mnriem merged commit 67e0f72 into github:main Oct 23, 2026
16 checks passed
@mnriem
mnriem deleted the mnriem-github-cli-auth branch October 23, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support GitHub CLI as a GitHub Authentication Mode

2 participants