Skip to content

πŸ› Pin git source, GitHub token check and mail relay dials to checked addresses - #19288

Open
clubanderson wants to merge 1 commit into
v5from
fix/egress-pin-gitsource-ghe
Open

clubanderson wants to merge 1 commit into
v5from
fix/egress-pin-gitsource-ghe

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Why

Part of #18986 (egress audit, section 2). #19225 pinned the hub contribute and lite fetchers. It left two sites on #19221: pkg/knowledge/gitsource.go and the dashboard validateGitHubToken. A sweep for other server-side fetchers turned up one more sibling with the same check-then-dial gap, the hub mail relay.

What

  • Git knowledge sources (gitsource.go, gitsync.go): git runs as a subprocess, so the pinning goes through git. Every clone, ls-remote and pull now calls gitSourcePinArgs. It resolves the host once through gitSourceResolver (netguard.PinnedDialer.Targets) and refuses the fetch if any answer is barred, or if the lookup fails or returns nothing. Otherwise it returns -c http.curloptResolve=host:port:addr[,addr], so libcurl connects only to the checked addresses and never looks the name up again. Redirects were already refused (http.followRedirects=false). Periodic syncs are pinned too, so a source whose name later moves inward stops syncing. Under HIVE_ALLOW_PRIVATE_GIT_SOURCE=true (an intentionally private Git server), private, loopback and CGNAT answers are allowed and pinned. Link-local (metadata), multicast and unspecified answers stay refused.
  • Dashboard validateGitHubToken: now dials through githubTokenTransport, a netguard.PinnedDialer transport. For public api.github.com, every class isPrivateURL bars is refused. For a configured API URL (intentionally chosen, may be private), every dial is still pinned, but only link-local, multicast and unspecified answers are refused. Cross-host redirects are refused, so that allowance never follows a hop. A replaced non-*http.Transport http.DefaultTransport is still honoured, the same convention as the hub's pinnedOrReplacedDefault. TestMain routes the final connect through its loopback-only guard.
  • Hub mail relay (mail_relay.go): mailRelayClient checked the self-reported DashboardURL with spokeWebhookRelayGuard and then dialled through the default transport. It now uses pinnedFetchTransport, like spokeWebhookRelayClient.
  • Docs: security-model.md egress section. Changelog: changelog.d/security-19221-pin-git-sources-and-token-check.md.

Tests

Each test uses a resolver that answers public on the first lookup and private on later ones.

  • pkg/knowledge/gitsource_pin_test.go: validation passes on the public answer, then the pin and ls-remote refuse the rebound loopback answer with netguard.ErrRefused. The pin names exactly the checked address, from one lookup. Mixed, metadata, ::1, empty, unparseable and lookup-error answers are refused. Opt-in allows private (IPv6 is bracketed) but not metadata. Literal hosts are covered, including hex loopback. An end-to-end test runs real git (2.37+, otherwise skipped) against a .invalid host pinned to a local server, which proves git honours the pin.
  • pkg/dashboard/github_token_transport_test.go: the rebind between isPrivateURL and the dial is refused, and the loopback server gets no request. The default host dials only the checked address, after one lookup. Private, metadata, empty and lookup-error answers never dial. A configured loopback API works and configured metadata is refused. A cross-host redirect is refused.
  • pkg/hub/pinned_fetch_mail_test.go: the mail relay refuses the rebound address (502) and the loopback spoke gets no request.

Other fetchers found in the sweep, not changed here

  • pkg/knowledge/connector/http.go NewHTTPClient: pre-checks and redirect-checks, but uses the default transport. It is used for the Confluence base URL (set by connector editors) and for meeting-media links, which are allowlisted to trusted CDNs.
  • pkg/dashboard/gateways.go discover (fetchModelsWithHeaders): owner-only, isPrivateURL pre-check, not pinned.
  • pkg/inbox/transcription.go / audiostream.go: provider-minted presigned audio links, default client, no private check.
  • pkg/hub/webhook.go pushGitHubConfigToSpoke: dead code (no callers). It would be unguarded if it were wired up.
  • pkg/resolve/http.go: its dial guard only classifies IP literals. It is limited to the operator http_allowlist.

These sit outside the five files #19221 names, so they belong in a follow-up under #18986.

Fixes #19221

…cked addresses

Git knowledge sources validated the host with one DNS lookup and git
resolved it again on every clone, ls-remote and pull. Each git command
now resolves once, refuses barred or unresolvable answers, and pins git
with -c http.curloptResolve. The dashboard GitHub token check and the
hub mail relay now dial through a netguard.PinnedDialer transport.

Fixes #19221

Signed-off-by: Andy Anderson <andy@clubanderson.com>
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign danathar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#19253 ✨ customers: hub import disclosure, docs and consent views same files src/docs/security-model.md
#19266 πŸ› Sentinel judges the PR's current head and clears its own stale alert same files src/docs/security-model.md

@github-actions

Copy link
Copy Markdown
Contributor

Mutation testing

⏱️ The 900s mutation budget ran out, so 1 package(s) were not fully mutated and the results below do not cover them:

  • pkg/knowledge: cut short (partial, no report)

2 mutant(s) in changed files are not reached by any test (NOT COVERED). A maintainer may apply the mutation/acknowledged label to accept this.

File Line Mutation
src/pkg/dashboard/github_token_transport.go 17 ARITHMETIC_BASE
src/pkg/dashboard/github_token_transport.go 18 ARITHMETIC_BASE

Verdict: uncovered (#17349).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[scanner] egress audit: resolve-once and dial-pinning for server-side fetchers

1 participant