Skip to content

Use API SSH URLs for repository clones - #14346

Merged
williammartin merged 2 commits into
trunkfrom
williammartin-ssh-certificate-authority
Sep 5, 2026
Merged

Use API SSH URLs for repository clones#14346
williammartin merged 2 commits into
trunkfrom
williammartin-ssh-certificate-authority

Conversation

@williammartin

@williammartinwilliammartin commented Sep 4, 2026

Copy link
Copy Markdown
Member

Fixes#14344

Description

gh repo clone reconstructs SSH remote URLs from the repository host, owner, and name. That drops the organization routing username GitHub includes when an organization has a usable SSH certificate authority, causing certificate authentication to fail on GHE.com.

This change requests the repository's authoritative sshUrl and uses it for SSH clones, SSH wiki clones, and fork upstream remotes. HTTPS cloning continues to use the existing URL formatter.

How did you test this change?

I configured an organization-scoped SSH certificate authority on test-prodweu01.ghe.com and ran the same clone command against williammartin-ssh-testing/ssh-test with the installed gh and a binary built from this branch. The installed version failed public-key authentication; the changed version cloned successfully.

Before

Installed gh fails SSH certificate authentication

After

Changed gh clones successfully with the organization SSH certificate

Key points

The API owns SSH routing semantics, so this does not try to reconstruct organization-specific usernames in the client. It returns an explicit error if an SSH clone response unexpectedly omits sshUrl. No feature detection is needed because Repository.sshUrl is supported across the GitHub products supported by gh.

Notes for reviewers

Start with remoteURL in pkg/cmd/repo/clone/clone.go, then review the GitHubRepo fragment and regression cases. Issue #14344 contains the original GHE.com failure.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @williammartin will read and reply directly. Name the account.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 635c0b51-d384-47de-bca4-121793a65152
CopilotAI balanced review requested due to automatic review settings September 4, 2026 12:15

CopilotAI 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 review overview

🟢 Approval recommended

The implementation matches the reported failure and comprehensively tests affected clone paths.

Review tier: Balanced
Findings: None

What changed in this PR

Uses API-provided SSH URLs so repository clones preserve organization-specific SSH routing.

Changes:

  • Uses sshUrl for SSH clones, wikis, and fork upstreams.
  • Adds missing-URL validation and regression coverage.
FileDescription
pkg/​cmd/​repo/​clone/​clone.goSelects authoritative SSH URLs.
pkg/​cmd/​repo/​clone/​clone_test.goTests SSH CA, wiki, upstream, and error cases.
api/​queries_repo.goRequests sshUrl.
api/​queries_repo_test.goVerifies SSH URL decoding.

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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee65cc7a-8eaf-4f12-8c00-a94930274a0e
@MartinodF

Copy link
Copy Markdown

Tested it on our tenant, works perfectly 🙏

@BagToadBagToad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@williammartin
williammartin merged commit 31e1704 into trunkSep 5, 2026
18 checks passed
@williammartin
williammartin deleted the williammartin-ssh-certificate-authority branch September 5, 2026 05:13
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh repo clone constructs an incorrect SSH URL for GHE.com repositories using organization SSH CAs

4 participants

@williammartin@MartinodF@BagToad