Skip to content

Bugfix: tokenFromGHCLI not stripping api. from ghe.com hosts. Resolves #3188#3190

Merged
stevehipwell merged 7 commits intointegrations:mainfrom
clawster:clawster/issue3188
Feb 23, 2026
Merged

Bugfix: tokenFromGHCLI not stripping api. from ghe.com hosts. Resolves #3188#3190
stevehipwell merged 7 commits intointegrations:mainfrom
clawster:clawster/issue3188

Conversation

@clawster
Copy link
Copy Markdown
Contributor

Bugfix: tokenFromGHCLI not stripping api. from ghe.com hosts. Resolves #3188


Before the change?

  • tokenFromGHCLI only mapped api.github.com -> github.com before calling gh auth token --hostname
  • For GHEC hosts (api.<slug>.ghe.com), the api. prefix was not stripped, causing the CLI lookup to fail silently
  • The provider fell back to an unauthenticated client, resulting in 401 errors on all API calls

After the change?

  • Extended hostname mapping to strip the api. prefix for GHEC hosts using the existing GHECAPIHostMatch regex
  • The provider now correctly resolves credentials from gh CLI for GHEC (*.ghe.com) instances
  • Authenticated API calls now succeed when gh auth login --hostname my-enterprise.ghe.com has been completed

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

  • Yes
  • No

  • fix: resolve gh CLI token lookup for GHEC (.ghe.com) hosts
  • Add test cases

tokenFromGHCLI only mapped api.github.com → github.com before calling
`gh auth token --hostname`. For GHEC hosts (api.<slug>.ghe.com), the
api. prefix was not stripped, causing the CLI lookup to fail silently
and the provider to fall back to an unauthenticated client (401 errors).

Strip the api. prefix for GHEC hosts using the existing GHECAPIHostMatch
regex so the hostname matches how `gh` stores credentials.

Fixes integrations#3188
@github-actions
Copy link
Copy Markdown

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@clawster
Copy link
Copy Markdown
Contributor Author

Replaces PR#3189 (no changes, new fork)

@stevehipwell stevehipwell added the Type: Bug Something isn't working as documented label Feb 20, 2026
@stevehipwell stevehipwell added this to the v6.12.0 Release milestone Feb 20, 2026
Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @clawster, I've added a few comments.

Comment thread github/provider_test.go Outdated
Comment thread github/provider_test.go Outdated
Comment thread github/provider.go Outdated
clawster and others added 2 commits February 20, 2026 15:11
 - move hostname modification to separate function for easier testing
 - test omdified to only test ghCLIHostFromAPIHost() without OS specific scripts
 - line ending fixed
@clawster
Copy link
Copy Markdown
Contributor Author

Thanks for the review and suggestions, code updated

Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

LGTM

@stevehipwell
Copy link
Copy Markdown
Collaborator

@clawster could you please rebase?

@stevehipwell
Copy link
Copy Markdown
Collaborator

@clawster could you please rebase so we can get this merged?

@stevehipwell stevehipwell merged commit 1af72d4 into integrations:main Feb 23, 2026
7 checks passed
@clawster clawster deleted the clawster/issue3188 branch February 23, 2026 17:06
JiayangZhou pushed a commit to JiayangZhou/terraform-provider-github that referenced this pull request Apr 16, 2026
…integrations#3188 (integrations#3190)

* fix: resolve gh CLI token lookup for GHEC (.ghe.com) hosts

tokenFromGHCLI only mapped api.github.com → github.com before calling
`gh auth token --hostname`. For GHEC hosts (api.<slug>.ghe.com), the
api. prefix was not stripped, causing the CLI lookup to fail silently
and the provider to fall back to an unauthenticated client (401 errors).

Strip the api. prefix for GHEC hosts using the existing GHECAPIHostMatch
regex so the hostname matches how `gh` stores credentials.

Fixes integrations#3188

* Add test cases

* Code updates according to PR feedback
 - move hostname modification to separate function for easier testing
 - test omdified to only test ghCLIHostFromAPIHost() without OS specific scripts
 - line ending fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: tokenFromGHCLI fails to resolve token for GHEC (.ghe.com) hosts — causes silent fallback to unauthenticated client

3 participants