Skip to content

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

Open
mnriem wants to merge 12 commits into
github:mainfrom
mnriem:mnriem-github-cli-auth
Open

mnriem wants to merge 12 commits into
github:mainfrom
mnriem:mnriem-github-cli-auth

Conversation

@mnriem

@mnriem mnriem commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a dedicated github-cli authentication mode backed by the fixed, shell-free gh auth token command
  • resolve GitHub Enterprise credentials for the request hostname and cache successful or failed lookups in memory for the current process
  • provide sanitized missing CLI, authentication, command failure, empty output, and timeout errors
  • document configuration and enterprise behavior

Closes #4953

Validation

  • uvx [email protected] 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 assistance disclosure

Implemented on behalf of @mnriem with GitHub Copilot using GPT-5.6 Sol in autonomous mode. Copilot traced the authentication flow, implemented the changes, added tests and documentation, and ran the validation commands listed above.

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 <[email protected]>

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 <[email protected]>

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 <[email protected]>

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 <[email protected]>

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
def _acquire_via_gh_cli(hostname: str) -> str:
"""Run the fixed GitHub CLI token command for *hostname*."""
resolved = shutil.which("gh")
if not resolved or not os.path.isabs(resolved):
Comment thread src/specify_cli/authentication/http.py Outdated
_StripAuthOnRedirect(
entry.hosts,
redirect_validator,
auth_hostname_validator,
Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous)

Co-authored-by: Copilot App <[email protected]>

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 <[email protected]>

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 <[email protected]>

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.

exact_hosts = {
host.lower()
for host in entry.hosts
if "*" not in host
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 <[email protected]>
Copilot AI max review requested due to automatic review settings October 22, 2026 22:18
Upgrade only opentelemetry-api from 1.45.0 to 1.45.1 and regenerate its hashes to resolve CVE-2026-114603 in the committed audit snapshot.

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

Co-authored-by: Copilot App <[email protected]>

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
Comment thread tests/specify_cli/authentication/test_authentication.py Outdated
Copilot AI max review requested due to automatic review settings October 22, 2026 22:32

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.

Exercise build_request and open_url with the registered GitHub provider and an isolated credential cache. Verify bearer headers and fail-fast acquisition errors, and cover sanitized cached PermissionError and UnicodeDecodeError failures.

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

Co-authored-by: Copilot App <[email protected]>
Copilot AI max review requested due to automatic review settings October 22, 2026 22:46

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
Reject embedded CR and LF after trimming CLI output, before returning or caching a token. Cache only the sanitized failure diagnostic and cover CR, LF, and CRLF regressions.

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

Co-authored-by: Copilot App <[email protected]>
Copilot AI max review requested due to automatic review settings October 23, 2026 13:25

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

GitHub CLI lookup failures bypass existing catalog error handling and can abort searches instead of skipping a failed catalog.

3 open issues
2 resolved since last review

Review effort: Max

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 <[email protected]>
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 on lines 62 to +64

The `github` provider supports `bearer` tokens and `github-cli` credentials
acquired on demand from GitHub CLI.
@staticmethod
def _credential_hostname(entry: AuthConfigEntry) -> str:
"""Use the first configured host for GitHub CLI credential acquisition."""
hostname = entry.hosts[0]

This branch has not been deployed

No deployments
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