Repository navigation
π Pin git source, GitHub token check and mail relay dials to checked addresses - #19288
clubanderson wants to merge 1 commit into
Conversation
β¦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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
Mutation testingβ±οΈ The 900s mutation budget ran out, so 1 package(s) were not fully mutated and the results below do not cover them:
2 mutant(s) in changed files are not reached by any test (NOT COVERED). A maintainer may apply the
Verdict: |
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.goand the dashboardvalidateGitHubToken. A sweep for other server-side fetchers turned up one more sibling with the same check-then-dial gap, the hub mail relay.What
gitsource.go,gitsync.go): git runs as a subprocess, so the pinning goes through git. Every clone,ls-remoteand pull now callsgitSourcePinArgs. It resolves the host once throughgitSourceResolver(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. UnderHIVE_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.validateGitHubToken: now dials throughgithubTokenTransport, anetguard.PinnedDialertransport. For publicapi.github.com, every classisPrivateURLbars 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.Transporthttp.DefaultTransportis still honoured, the same convention as the hub'spinnedOrReplacedDefault.TestMainroutes the final connect through its loopback-only guard.mail_relay.go):mailRelayClientchecked the self-reportedDashboardURLwithspokeWebhookRelayGuardand then dialled through the default transport. It now usespinnedFetchTransport, likespokeWebhookRelayClient.security-model.mdegress 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 andls-remoterefuse the rebound loopback answer withnetguard.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.invalidhost pinned to a local server, which proves git honours the pin.pkg/dashboard/github_token_transport_test.go: the rebind betweenisPrivateURLand 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.goNewHTTPClient: 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.godiscover (fetchModelsWithHeaders): owner-only,isPrivateURLpre-check, not pinned.pkg/inbox/transcription.go/audiostream.go: provider-minted presigned audio links, default client, no private check.pkg/hub/webhook.gopushGitHubConfigToSpoke: 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 operatorhttp_allowlist.These sit outside the five files #19221 names, so they belong in a follow-up under #18986.
Fixes #19221