Repository navigation
feat(intercept): pinned dialer for WebFetch and the custom http tool (S3b 2.1) - #186
Merged
Merged
Conversation
…(S3b 2.1) In a gated scope, the two HTTP clients the platform owns connect only to addresses that a pin or a stored exemption covers at the moment of the connection, on every hop. - intercept.PinnedDialer(tool, scoped): the DialContext of both clients. It reads the target scope from the context net/http passes to the dial. Gate off, or no scope in a client built without one: plain dial, as today. A client built for a scope whose scope is missing at the dial fails closed with TARGET_GATE_UNAVAILABLE. - dialTarget runs the gate decision on the dialled host:port with a fresh lookup (block rules first, exemptions, pins, port precedence) and connects only to the addresses it compared, never to the name. Derived exemptions and name-only pins dial the address as received. An address no pin covers finds or opens the request (new_ip / no_pin, wait 0) and fails at once with TARGET_APPROVAL_PENDING. Redirect hops are dialled against the hop's own (host, port). - WebFetch (withWebFetch, now given the run context): DialContext set on every agent kind; DisableDirectRetry when the run's scope is gated. - Custom http tool: a direct call in a gated scope gets a DefaultTransport clone with the pinned dialer, no environment proxy and keep-alive off. Proxied calls are unchanged (the recording proxy is step 2.2). - Name-only: request reason says the platform does not bind the connection; the first-use pin_match row records the effective state. - Derived exemptions: a proxy URL without a port is listed with the port net/http dials (1080 for socks5) (OPEN-9). - go.mod: Norma v0.4.8 (DialContext, DisableDirectRetry).
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
S3b step 2.1 (plan v6, section 11): in a gated scope, WebFetch and the custom
httptool connect only to addresses that a pin or a stored exemption covers at the moment of the connection, on every hop. Gate off is unchanged.What changes
intercept.PinnedDialer(tool, scoped)(newintercept/target_dial.go): theDialContextof both clients. It reads the target scope from the context net/http passes to the dial (D-1).TARGET_GATE_UNAVAILABLE, nothing dialled.TARGET_GATE_UNAVAILABLE, plus one decided row where there is a store.dialTarget: runs the existing gate decision (targetCheck.run) on the dialledhost:portwith a fresh lookup (fresh). That covers block rules first, then exemptions, pins and port precedence. URL rules are not re-matched. Then it acts on what covered the target:new_ip/no_pin, wait bound 0, input{"dial":"host:port"}) and fail at once withTARGET_APPROVAL_PENDING.Redirect hops are dialled against the hop's own
(host, port)(D-5).targetCheck: fieldsfreshandchecked;checkedTarget.cover. Whenfreshis set, the second lookup before a request is skipped because the answer is already fresh.Name-only (D-2): the request reason adds "The platform does not bind the connection to these addresses."; the first-use
pin_matchrow recordspin.NameOnlyEffective || nameOnly.WebFetch:
withWebFetch(ctx, ...)on all four agent kinds setsDialContext: intercept.PinnedDialer("WebFetch", scoped)andDisableDirectRetry: gated(D-8).withWebFetchis kept (OPEN-7).Custom
httptool (D-6): newhttpToolTransport. A direct call in a gated scope gets ahttp.DefaultTransportclone with the pinned dialer,Proxy = niland keep-alive off. Gate off:client.Transportstays nil. Calls through a proxy (proxyoruse_recording_proxy) keep their transport without a dialer; the recording proxy is step 2.2.OPEN-9: a derived exemption URL without a port gets the port net/http dials. Only
socks5/socks5h→ 1080 was missing; http/https already had 80/443.Base-dialer seam:
Interceptor.SetBaseDialer(test seam, besideSetResolver).Norma:
go.modreplace moved togithub.com/BaaRai/Norma v0.4.8(19a39e5),go.sumbygo mod tidy, same form as chore: bump Norma to v0.4.7 #184.No schema change, no new table, no change in
guard.Tests
Named in plan 11.8:
interceptunit tests:TestPinnedDialGateOffIsPlainDial,TestPinnedDialScopeLostFailsClosed,TestPinnedDialScopeUnreadableFailsClosed,TestPinnedDialResolveFailureBlocksWithoutRequest,TestPinnedDialBlockRuleOnDialAddress.TestPinnedDialConnectsOnlyToPinnedAddresses,TestPinnedDialDerivedExemptionDialsByName,TestPinnedDialNameOnlyPinDialsByName,TestPinnedDialNormalisesLikeTheCheck,TestPinnedDialFreshLookupCollapsed,TestPinnedDialTriesAddressesInOrder.TestPinnedDialSeesScopeInDialContext(S1),TestPinnedDialHTTPSVerifiesName(S4),TestPinnedDialNoReuseAcrossCalls(S6),TestRedirectContextCarriesScope(S5).TestNameOnlyReasonSaysConnectionNotBound,TestPinUsedRecordsEffectiveNameOnly.interceptPostgreSQL tests:TestPinAddressChangedBetweenCheckAndDialNotReachable,TestPinnedDialPartialOverlapNotReachable,TestPinnedDialRevokedBetweenCheckAndDial,TestPinnedDialStoredExemptionDialsCheckedAddresses,TestPinnedDialIPLiteralPin,TestPinnedDialPortPrecedence,TestRedirectHopDialledAgainstHopPinNotOrigin(three cases),TestDialMismatchOpensOneNewIPRequest.agent:TestWebFetchDialerWiredOnEveryAgentKind,TestWebFetchGatedScopeHasNoDirectRetry,TestWebFetchProxiedDialIsTheProxy(S2),TestWebFetchRetryAfterLiveSwitchIsPinned.server:TestCustomHTTPDirectDialPinned,TestCustomHTTPGateOffTransportUnchanged,TestCustomHTTPRedirectHopDialPinned,TestCustomToolTestEndpointDialUngated,TestBypass_CustomHTTPProxyPeerNotPinned,TestTargetGateEndToEndDialRebindBlocked.Also added:
TestDerivedExemptionsDefaultProxyPort(OPEN-9).Changed tests:
TestWebFetchRedirectCheckWiredOnEveryAgentKindnow pins the origin127.0.0.1:<start port>before the run. The hooks in that test let every call through, so the gate never checked the origin, and the pinned dialer now refuses a target nobody pinned. The assertions are unchanged.TestWebFetchRedirectCheckOnDirectRetryis replaced byTestWebFetchGatedScopeHasNoDirectRetry: in a gated scope the direct retry no longer exists. With a refusing proxy that is a derived exemption, the fetch fails with the proxy error, the origin gets no request, and no request row is written.TestWebFetchRedirectGateOffUnchangedis kept as-is (plan nameTestWebFetchGateOffKeepsDirectRetry). It still compares with Norma's own tool output.Differences from the plan:
RequestTargetswrites through*db.DB) run against PostgreSQL rather than the fake store.checkedTarget.pinwas not added, because nothing reads it.Verification (WSL, go1.26.10, fresh PostgreSQL 16.15)
go build ./...: ok.go vet ./...: ok.go test -count=1 -p 1 ./...: all packages ok.go test -race -count=1 -p 1on the CI package list: all ok.Mutation checks (each reverted after):
TestPinnedDialScopeLostFailsClosedfails.TestWebFetchDialerWiredOnEveryAgentKindfail.TestWebFetchGatedScopeHasNoDirectRetryfails.TestCustomHTTPDirectDialPinnedfails.Left for 2.2
httptraffic that goes through the recording proxy, after the hook-order spike.Monitorproxy environment (D12).TestBypass_CustomHTTPProxyPeerNotPinnedflips for the recording-proxy half. An operator-writtenproxystays unbound (OPEN-6).Noted, not changed
httpProxyTransport(server/customtool.go:501) builds"http://" + s.m.ProxyAddr(), butProxyAddr()already returns a URL with a scheme (traffic/traffic.go:307-309, and a validatedglobal_proxy). Souse_recording_proxyproduceshttp://http://.... This bug predates this PR. The bypass test gives that path a barehost:portto document it.