Skip to content

HTTP proxy support for SSH in GitOps#4781

Merged
p-se merged 4 commits into
rancher:mainfrom
p-se:issue-3595
Mar 19, 2026
Merged

HTTP proxy support for SSH in GitOps#4781
p-se merged 4 commits into
rancher:mainfrom
p-se:issue-3595

Conversation

@p-se
Copy link
Copy Markdown
Contributor

@p-se p-se commented Mar 10, 2026

Refers to #3595

Additional Information

Checklist

  • I have updated the documentation via a pull request in the
    fleet-docs repository.

@p-se p-se requested a review from a team as a code owner March 10, 2026 11:12
Copilot AI review requested due to automatic review settings March 10, 2026 11:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds HTTP CONNECT proxy support for go-git SSH operations in Fleet GitOps flows by wiring go-git ProxyOptions from standard proxy environment variables and registering a custom x/net/proxy dialer for http:// (and https://) proxy URLs.

Changes:

  • Add ProxyOptions plumbing to go-git remote listing and the gitcloner CLI clone paths.
  • Introduce pkg/git/proxy.go implementing an HTTP CONNECT dialer and ProxyOptsFromEnvironment(...) helper.
  • Add unit tests for proxy option selection and CONNECT dialer behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.

File Description
pkg/git/remote.go Passes go-git ProxyOptions into ListOptions and initializes them from env in NewRemote.
pkg/git/proxy.go Registers proxy dialer types and implements CONNECT tunneling + env-based proxy option selection.
pkg/git/proxy_test.go Adds tests for CONNECT tunneling and proxy env parsing.
internal/cmd/cli/gitcloner/cloner.go Wires proxy options into go-git CloneOptions for CLI cloning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/git/proxy_test.go
Comment thread pkg/git/proxy_test.go
Comment thread pkg/git/proxy.go
Comment thread pkg/git/proxy.go
Comment thread pkg/git/proxy.go Outdated
Comment thread pkg/git/proxy_test.go
Comment thread pkg/git/proxy_test.go
Comment thread pkg/git/proxy_test.go
Comment thread pkg/git/proxy_test.go
Comment thread internal/cmd/cli/gitcloner/cloner.go
@p-se p-se force-pushed the issue-3595 branch 4 times, most recently from 842891b to cb12598 Compare March 11, 2026 13:40
@kkaempf kkaempf added this to the v2.14.1 milestone Mar 16, 2026
@thardeck thardeck requested review from thardeck and removed request for a team March 17, 2026 12:50
Comment thread pkg/git/proxy.go Outdated
return nil, fmt.Errorf("http connect proxy: write CONNECT request: %w", err)
}

resp, err := http.ReadResponse(bufio.NewReader(conn), req)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

bufio.NewReader (4096 bytes) could buffer bytes beyond the 200 response.
A size-1 reader only buffers what http.ReadResponse strictly needs and can't buffer ahead of the response end.

Suggested change
resp, err := http.ReadResponse(bufio.NewReader(conn), req)
resp, err := http.ReadResponse(bufio.NewReaderSize(conn, 1), req)

Comment thread pkg/git/proxy_test.go Outdated
func TestHTTPConnectDialer_ContextCancelled(t *testing.T) {
// Use a forward dialer that blocks until the context is done.
blocking := &recordingDialer{dial: func(network, addr string) (net.Conn, error) {
time.Sleep(5 * time.Second)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can' we use an Eventually here or at least a much lower sleep time because this is static and quite high?

Comment thread pkg/git/proxy_test.go Outdated
}
done <- struct{}{}
}()
<-done
Copy link
Copy Markdown
Collaborator

@thardeck thardeck Mar 17, 2026

Choose a reason for hiding this comment

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

nit: Only <-done once despite two piping goroutines sending - drain both or use WaitGroup.

Comment thread pkg/git/proxy_test.go Outdated
t.Fatalf("Write: %v", err)
}
buf := make([]byte, len(msg))
if _, err := io.ReadFull(conn, buf); err != nil && !errors.Is(err, io.ErrUnexpectedEOF) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tolerating io.ErrUnexpectedEOF means the buffer could be partially filled (e.g., all zeros), and string(buf) != msg would still fire - so the test doesn't silently pass wrong data. However, dropping the ErrUnexpectedEOF carve-out and asserting err == nil would make the test stronger as a signal that the TLS tunnel is working.
If the test server's connection teardown before io.ReadFull completes could result in a race condition, a sync.WaitGroup in startFakeTLSProxy to wait for the echo goroutines to finish first should be better than tolerating the partial-read error.

@p-se p-se requested a review from thardeck March 18, 2026 13:39
@weyfonk weyfonk modified the milestones: v2.14.1, v2.15.0 Mar 18, 2026
p-se added 2 commits March 19, 2026 12:17
TestHTTPConnectDialer_Dial timed out after 10 minutes because
handleProxyConn waited for both piping goroutines to signal done, but
the target→client goroutine blocked on targetConn.Read indefinitely
when the client closed its side. Added a sync.Once-guarded closeBoth()
that closes both connections when either direction finishes, so the
other goroutine unblocks immediately.
Replace the manual read/write loops and sync.Once/closeBoth with
io.Copy and a simple targetConn.Close() after the client→target
direction finishes — the same pattern already used in startFakeTLSProxy
in the same file.
@p-se p-se merged commit 6aa6856 into rancher:main Mar 19, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants