Skip to content

Disable telemetry for unauthenticated GHES gh api requests using absolute hostnames - #14337

Merged
williammartin merged 1 commit into
trunkfrom
williammartin-ghes-api-telemetry
Sep 3, 2026
Merged

Disable telemetry for unauthenticated GHES gh api requests using absolute hostnames#14337
williammartin merged 1 commit into
trunkfrom
williammartin-ghes-api-telemetry

Conversation

@williammartin

@williammartinwilliammartin commented Sep 3, 2026

Copy link
Copy Markdown
Member

Description

gh api builds a specialized HTTP client to support command-specific cache and verbose behavior. This API Client was not provided with a TelemetryDisabler at construction time. It was therefore possible for gh api --hostname or gh api <absolute url> to emit telemetry unexpectedly under extremely narrow conditions:

  1. User is logged into a non-GHES host (e.g. github.com or GHEC with DR), otherwise global auth check fails:
➜ GH_CONFIG_DIR=/tmp gh api --hostname ghe.example.com /
To get started with GitHub CLI, please run: gh auth login
Alternatively, populate the GH_TOKEN environment variable with a GitHub API authentication token.
  1. No GHES hosts are logged into, otherwise mightBeGHESUser disables telemetry:

returnslices.ContainsFunc(cfg.Authentication().Hosts(), func(hoststring) bool {
returnghauth.IsEnterprise(host)
})

  1. No enterprise-token environment variable is set, otherwise mightBeGHESUser disables telemetry:

ifos.Getenv("GH_ENTERPRISE_TOKEN") !=""||os.Getenv("GITHUB_ENTERPRISE_TOKEN") !="" {
returntrue
}

Under these circumstances, an unauthenticated request using gh api could send telemetry if sampled at a 1% chance:

➜ GH_TELEMETRY=log gh api --hostname ghe.io /
Telemetry payload:
{
"events": [
{
"type": "command_invocation",
"dimensions": {
"accessible_colors": "false",
"accessible_prompter": "false",
"agent": "",
"architecture": "arm64",
"ci": "false",
"color_labels": "false",
"command": "gh api",
"device_id": "160e44ae-38df-4bc5-9bae-0d9a126573b3",
"flags": "hostname",
"github_actions": "false",
"invocation_id": "1e13fd5a-9110-4287-817c-e8c55cd3ebf6",
"is_tty": "true",
"os": "darwin",
"spinner_disabled": "false",
"timestamp": "2026-09-03T13:55:18.399Z",
"version": "2.98.0"
}
}
]
}

How did you test this change?

Before

See above

After

➜ GH_TELEMETRY=log ./bin/gh api --hostname ghe.io /
Telemetry payload: none

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.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

CopilotAI balanced review requested due to automatic review settings September 3, 2026 13:48
@williammartinwilliammartin changed the title Disable telemetry for GHES gh api requestsDisable telemetry for unauthenticated GHES gh api requestsSep 3, 2026

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

🟡 Changes recommended

The exported HTTP client injection contract must be preserved before approval.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 High severity

New issues introduced by this change (1)
SeverityFinding
High severitypkg/​cmd/​api/​api.go — 🛑 Requirement: Preserve the exported HTTP client injection contract. Changing this field from a…
What changed in this PR

Routes telemetry suppression into gh api’s specialized HTTP client for GHES requests.

Changes:

  • Propagates the telemetry disabler through command factories.
  • Configures API clients to suppress GHES telemetry.
  • Adds GHES and GitHub.com regression tests.

Blocking issue: 🛑 Critical (2 votes) — Preserve the exported HttpClient injection signature in ApiOptions; changing it breaks existing consumers. Capture TelemetryDisabler in the default closure or use a separate unexported factory.

FileDescription
pkg/​cmdutil/​factory.goExposes the telemetry disabler.
pkg/​cmd/​factory/​default.goInitializes the new factory field.
pkg/​cmd/​api/​api.goPasses telemetry configuration into the API client.
pkg/​cmd/​api/​api_test.goTests hostname and absolute-URL telemetry behavior.

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

Comment threadpkg/cmd/api/api.go
@williammartin
williammartin marked this pull request as ready for review September 3, 2026 14:15
@williammartin
williammartin requested a review from a team as a code ownerSeptember 3, 2026 14:15
@williammartinwilliammartin changed the title Disable telemetry for unauthenticated GHES gh api requestsDisable telemetry for unauthenticated GHES gh api requests using absolute hostnamesSep 3, 2026

@babakksbabakks 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

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@williammartin
williammartinforce-pushed the williammartin-ghes-api-telemetry branch from 6b30ab7 to 4a75987CompareSeptember 3, 2026 15:14
@williammartin
williammartin merged commit 45437bc into trunkSep 3, 2026
11 checks passed
@williammartin
williammartin deleted the williammartin-ghes-api-telemetry branch September 3, 2026 15:24
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.

4 participants

@williammartin@babakks@BagToad