Skip to content

Add proxy-protocol listener on acmesolver - #9412

Merged
cert-manager-prow[bot] merged 10 commits into
cert-manager:masterfrom
ercomcom:add-proxyprotocol-acmesolver
Nov 24, 2026
Merged

cert-manager-prow[bot] merged 10 commits into
cert-manager:masterfrom
ercomcom:add-proxyprotocol-acmesolver

Conversation

@shakapark

@shakapark shakapark commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Motivation

ACME challenges failed in our production infra due to istio configuration that force proxy-protocol between istio-ingressgateway and downstream services.
With the go-proxyproto module, proxy-protocol header is required.

Kind

/kind feature

Release Note

Add a new flag --proxy-protocol on acmesolver binary to enable the proxy header on listener

@cert-manager-prow

Copy link
Copy Markdown
Contributor

@shakapark: The label(s) kind/release, kind/note cannot be applied, because the repository doesn't have them.

Details

In response to this:

Pull Request Motivation

ACME challenges failed in our production infra due to istio configuration that force proxy-protocol between istio-ingressgateway and downstream services.
The go-proxyproto module accept all requests, with or without proxy-protocol.

Kind

/kind

Release Note

NONE

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@cert-manager-prow cert-manager-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. area/acme Indicates a PR directly modifies the ACME Issuer code area/acme/http01 Indicates a PR modifies ACME HTTP01 provider code needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 1, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

Hi @shakapark. Thanks for your PR.

I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@cert-manager-prow cert-manager-prow Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 1, 2026
@shakapark
shakapark force-pushed the add-proxyprotocol-acmesolver branch from 32fb217 to dc3004c Compare October 1, 2026 15:43
@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. and removed dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. labels Oct 1, 2026
@wallrj
wallrj requested a balanced review from Copilot October 10, 2026 06:29

Copilot AI 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.

🟡 Changes recommended

The new network path lacks integration coverage and needs minor dependency and dead-code cleanup.

3 open findings
What changed in this PR

Adds optional PROXY protocol support to the ACME HTTP-01 solver while retaining ordinary HTTP compatibility.

Changes:

  • Wraps the solver listener with go-proxyproto.
  • Adds HTTP/2-aware serving and dependency metadata.
File Description
pkg/​issuer/​acme/​http/​solver/​solver.go Adds the PROXY protocol listener.
go.mod Declares go-proxyproto.
go.sum Adds dependency checksums.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/issuer/acme/http/solver/solver.go Outdated
Comment on lines +74 to +78
proxyListener := &proxyproto.Listener{
Listener: netListener,
ReadHeaderTimeout: h.Server.ReadHeaderTimeout,
ConnPolicy: func(proxyproto.ConnPolicyOptions) (proxyproto.Policy, error) {
return proxyproto.USE, nil
Comment thread go.mod Outdated
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pires/go-proxyproto v0.15.0
Comment thread pkg/issuer/acme/http/solver/solver.go Resolved
@wallrj
wallrj self-requested a review October 11, 2026 07:57

@wallrj wallrj 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.

Thank you for the PR. The problem is real and go-proxyproto is a reasonable choice of library, but we cannot merge this as written. The PROXY header must be opt-in, and the HTTP/2 helper should go.

What needs to change

  1. Make PROXY protocol opt-in. The listener accepts a PROXY header from any peer, on every HTTP-01 challenge pod, for every user. The PROXY specification and the library's own README both say that is unsafe on a listener reachable by untrusted clients. Please add an acmesolver flag (for example --proxy-protocol), default off, and wire it from the HTTP-01 solver configuration so users whose ingress sends the header can turn it on.
  2. Drop helper/http2. h.Server.Serve(proxyListener) is all the solver needs. The helper picks HTTP/1 or HTTP/2 from the PROXY v2 ALPN TLV, which breaks when a proxy relays the client's h2 ALPN while speaking HTTP/1.1 upstream. It also starts its own goroutine, which makes Shutdown racy. Details inline.
  3. Add /kind feature, a release note and an issue. This changes the wire behaviour of every challenge pod and adds a dependency. Users need to see it in the release notes, and reviewers need an issue that describes the Istio setup.

Smaller points are inline.

A workaround you can use today

Istio's DestinationRule.trafficPolicy.proxyProtocol is set per host. If you scope it so that it does not match the cm-acme-http-solver-* Services, the gateway will stop sending the header to the solver pods and the challenges will pass without any change to cert-manager. See https://istio.io/latest/docs/reference/config/networking/destination-rule/#TrafficPolicy-ProxyProtocol.

Evidence and prior art

The library says a blanket USE policy is unsafe. The README at the version this PR pins: https://github.com/pires/go-proxyproto/blob/v0.15.0/README.md#security. It quotes section 2 of the PROXY specification, which says the receiver "MUST not try to guess" whether a header is present and must filter by source: https://www.haproxy.org/download/2.9/doc/proxy-protocol.txt.

Every other Kubernetes component makes this opt-in and source-gated.

Project Setting
ingress-nginx use-proxy-protocol ConfigMap key, https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#use-proxy-protocol
Traefik (uses go-proxyproto) entryPoints.<name>.proxyProtocol.trustedIPs, https://doc.traefik.io/traefik/routing/entrypoints/#proxyprotocol
Envoy and Istio Gateway proxy_protocol listener filter, https://www.envoyproxy.io/docs/envoy/latest/configuration/listeners/listener_filters/proxy_protocol
HAProxy accept-proxy per bind, https://docs.haproxy.org/2.9/configuration.html#5.1-accept-proxy

None of them auto-detect.

The dependency itself looks fine. github.com/pires/go-proxyproto v0.15.0 is Apache-2.0, tagged 2026-07-09 at commit bd986c0a, and its only dependency is golang.org/x/net, which cert-manager already requires at the same version. go mod tidy -diff on this branch is clean. Caddy and Traefik both depend on it. The two historical advisories (GHSA for a DoS before 0.5.0 and descriptor exhaustion before 0.6.1) are both mitigated by the ReadHeaderTimeout this PR sets.

Related report: #7749 asked for the same thing with nginx proxy_protocol and went stale.

[Claude Fable 5.1]

Comment thread pkg/issuer/acme/http/solver/solver.go Outdated
proxyListener := &proxyproto.Listener{
Listener: netListener,
ReadHeaderTimeout: h.Server.ReadHeaderTimeout,
ConnPolicy: func(proxyproto.ConnPolicyOptions) (proxyproto.Policy, error) {

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.

This accepts a PROXY header from any peer that can reach the pod. Anything in the cluster, or anything the Service exposes, can send PROXY TCP4 1.2.3.4 ... and the server will treat that as the client address. Today challengeHandler does not read RemoteAddr, so the impact is limited to logs and to future code. But it ships to every cert-manager user, by default, to serve one mesh configuration.

The library's README says a USE policy "is not safe for listeners reachable by untrusted clients without a trusted-source policy": https://github.com/pires/go-proxyproto/blob/v0.15.0/README.md#security

Please gate this behind an acmesolver flag that defaults to off, wired from the HTTP-01 solver configuration or a controller flag. Every other Kubernetes component that supports PROXY protocol works that way (ingress-nginx use-proxy-protocol, Traefik trustedIPs, Envoy listener filter).

Comment thread pkg/issuer/acme/http/solver/solver.go Outdated
},
}

return h2proxy.NewServer(&h.Server, nil).Serve(proxyListener)

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.

Please replace this with return h.Server.Serve(proxyListener). The HTTP/2 helper causes two problems and solves none, because ACME servers validate HTTP-01 over HTTP/1.1 and never negotiate h2c on cleartext.

It breaks when a proxy relays the client's ALPN. serveConn dispatches on the PROXY v2 ALPN TLV: https://github.com/pires/go-proxyproto/blob/v0.15.0/helper/http2/http2.go#L164-L190. Envoy with pass_through_tlvs, or HAProxy with send-proxy-v2-ssl, forwards the TLS client's h2 while sending HTTP/1.1 upstream. The helper then runs the h2 server on a plaintext HTTP/1.1 stream and the challenge request fails. Any other ALPN value closes the connection with unsupported protocol.

It makes Shutdown racy. NewServer registers its pipe listener with http.Server from a goroutine: https://github.com/pires/go-proxyproto/blob/v0.15.0/helper/http2/http2.go#L55-L58. cmd/acmesolver/app/app.go:65 calls s.Shutdown on SIGTERM. If that runs before the goroutine has called h1.Serve, Shutdown finds no tracked listeners and returns, the helper stays in Accept on the real socket, Listen never returns, and the pod only exits when the kubelet kills it after terminationGracePeriodSeconds. With ListenAndServe the server tracked its own listener and this could not happen.

http.Server.Serve(proxyListener) has neither problem and is one line.

Comment thread pkg/issuer/acme/http/solver/solver.go Outdated

proxyListener := &proxyproto.Listener{
Listener: netListener,
ReadHeaderTimeout: h.Server.ReadHeaderTimeout,

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.

Copying the 32 second ReadHeaderTimeout here doubles the slowloris window that the G112 comment above claims to bound. A client that connects and sends nothing holds a goroutine for 32 seconds while go-proxyproto waits for a PROXY header, then another 32 seconds while net/http waits for request headers.

The library's own default is 10 seconds: https://github.com/pires/go-proxyproto/blob/v0.15.0/protocol.go#L28. Leaving this field unset gives you that default.

Comment thread pkg/issuer/acme/http/solver/solver.go Outdated
}

return h.Server.ListenAndServe()
// return h.Server.ListenAndServe()

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.

Please delete this commented-out line. Git history keeps the old call.

Comment thread pkg/issuer/acme/http/solver/solver.go Outdated
return h.Server.ListenAndServe()
// return h.Server.ListenAndServe()

netListener, err := net.Listen("tcp", h.Server.Addr)

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.

There is no test for the new listening path. TestSolver calls challengeHandler directly, so a regression in the listener wiring (policy, protocol dispatch, shutdown chain) would only be caught by the e2e suite, which never sends a PROXY header.

Please add a socket-level test that starts Listen on port 0 and sends a plain GET, a v1-prefixed GET and a v2-prefixed GET, and asserts that the key is returned for each. Once the feature is behind a flag, also assert that a PROXY-prefixed request fails when the flag is off.

Comment thread go.mod Outdated
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pires/go-proxyproto v0.15.0

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.

This is a direct dependency, so it belongs in the first require block with the other direct dependencies, not in the // indirect block. go mod tidy -diff is clean on this branch, so CI will not fail over it. It is only readability.

@shakapark
shakapark marked this pull request as draft October 13, 2026 08:46
@cert-manager-prow cert-manager-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 13, 2026
@shakapark

Copy link
Copy Markdown
Contributor Author

/kind feature

@cert-manager-prow cert-manager-prow Bot added kind/feature Categorizes issue or PR as related to a new feature. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Oct 13, 2026
@shakapark
shakapark force-pushed the add-proxyprotocol-acmesolver branch from f5add0f to aa59047 Compare October 15, 2026 15:02
@cert-manager-prow cert-manager-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 15, 2026
@shakapark
shakapark marked this pull request as ready for review October 21, 2026 10:41
@shakapark
shakapark force-pushed the add-proxyprotocol-acmesolver branch from f236e95 to fbdcbf5 Compare November 12, 2026 13:23
@shakapark
shakapark requested a review from wallrj November 12, 2026 13:49

@wallrj wallrj 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.

Thank you, the solver side is now in good shape: the Serve split, the race-free test, the REQUIRE comment and the flag-on, no-header case all look right. Three things remain, all in the controller wiring.

  1. The controller flag does not reach the pod yet. cmd/controller/app/controller.go copies each solver option from the config into ACMEOptions by hand. See ACMEHTTP01SolverRunAsNonRoot around lines 327 to 342 on master. This PR does not touch that file, so ACMEHTTP01SolverProxyProtocol is always false and --proxy-protocol is never added. The e2e jobs pass only because none of them turn the flag on.
  2. CI fails on stale generated files. make-test fails TestRoundTripTypes because the conversion code was not regenerated for the new field. make-verify fails because three LICENSES files are missing github.com/pires/go-proxyproto,Apache-2.0. Running make generate should fix both.
  3. Please add a test for pod.go. Check that --proxy-protocol appears in the container arguments when the option is set, and not otherwise. That test would have caught point 1.

One small inline suggestion on the flag help text.

[Claude Fable 5.1]

Comment thread cmd/controller/app/options/options.go Outdated

fs.StringVar(&c.ACMEHTTP01Config.SolverRuntimeClassName, "acme-http01-solver-runtime-class-name", c.ACMEHTTP01Config.SolverRuntimeClassName, "RuntimeClassName to apply to ACME HTTP01 solver pods")

fs.BoolVar(&c.ACMEHTTP01Config.SolverProxyProtocol, "acme-http01-solver-proxy-protocol", c.ACMEHTTP01Config.SolverProxyProtocol, "Defines the ability to run the http01 solver with ProxyProtocol")

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.

Please make the help text say what the flag does to users' traffic, for example:

"If true, ACME HTTP-01 solver pods require a PROXY protocol v1 or v2 header on every connection. Only enable this if every connection to the solver pods comes through a proxy that sends the header."

fmt.Sprintf("--key=%s", ch.Spec.Key),
}
if s.ACMEOptions.ACMEHTTP01SolverProxyProtocol {
podArgs = append(podArgs, "--proxy-protocol")

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.

This branch is never taken today, because cmd/controller/app/controller.go does not copy SolverProxyProtocol into ACMEOptions. Please wire it there, and add a test in pod_test.go for both values of the option.

@shakapark
shakapark force-pushed the add-proxyprotocol-acmesolver branch from fbdcbf5 to 19ce53c Compare November 13, 2026 10:26
@shakapark

shakapark commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for your support
I have errors with the command make generate
F1113 11:27:11.766283 7002 main.go:75] Error discovering license URL: getting file URL in library github.com/pavlo-v-chernykh/keystore-go/v4: source.ModuleInfo(ctx, "github.com/pavlo-v-chernykh/keystore-go/v4", "v4.5.0"): doURL(ctx, client, "HEAD", "https://github.com/pavlo-v-chernykh/keystore-go/raw/v4.5.0/v4/go.mod"): Head "https://github.com/pavlo-v-chernykh/keystore-go/raw/v4.5.0/v4/go.mod": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) make: *** [make/_shared/licenses/01_mod.mk:55: LICENSES] Error 1 make: *** Deleting file 'LICENSES'

Edit: It was caused by my personnel setup, it's fixed

@shakapark
shakapark requested a review from wallrj November 13, 2026 11:30
@cert-manager-prow cert-manager-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 21, 2026

@wallrj wallrj 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.

Thank you. The controller flag now reaches the solver pod, the generated files are current, and the pod test and help text are as requested. Three things remain before I can approve.

  1. Test_listenSolver fails about one run in ten. I ran it 300 times at 8db6f3b, without the race detector, and the case "header sent without --proxy-protocol" failed 31 times. The patch below passed 2000 runs, and 500 with -race.
  2. make verify fails on three lint findings. The patch below fixes them.
  3. The branch needs a rebase. cmd/acmesolver/go.mod, go.sum and LICENSES conflict with master. After the rebase, please run go mod tidy in cmd/acmesolver and then make generate.
Why the test fails
  • The test writes the PROXY header to the connection (solver_test.go#L325) and then sends the HTTP request with client.Do (#L337). When the flag is off, the server can read the header alone, reply 400 and close the connection before the request is sent. The client then fails with readLoopPeekFailLocked or connection reset by peer. The patch sends the header and the request in one write and reads the reply with http.ReadResponse.
  • There is also a data race, which go test -race reports in about 2 runs in 30. Serve assigns h.Server in its goroutine (solver.go#L69) while the cleanup calls solver.Server.Close() (solver_test.go#L293). The patch closes the listener instead and waits for Serve to return.
The lint findings

From the make-verify log:

pkg/issuer/acme/http/pod_test.go:330:6: embedlit: embedded field type can be removed from struct literal (modernize)
pkg/issuer/acme/http/solver/solver.go:54:23: net.Listen must not be called. use (*net.ListenConfig).Listen (noctx)
pkg/issuer/acme/http/solver/solver_test.go:290:25: net.Listen must not be called. use (*net.ListenConfig).Listen (noctx)

The patch gives Listen a context argument, in the same way as pkg/server/listener.go. With the patch applied on top of master, golangci-lint v2.15.0 reports 0 issues in pkg/issuer/acme/http/... and in cmd/acmesolver.

Patch for all of the above (apply with git apply at 8db6f3b)
diff --git a/cmd/acmesolver/app/app.go b/cmd/acmesolver/app/app.go
index 4f3d8b2f8..91cbaca0c 100644
--- a/cmd/acmesolver/app/app.go
+++ b/cmd/acmesolver/app/app.go
@@ -67,7 +67,7 @@ func NewACMESolverCommand(_ context.Context) *cobra.Command {
 				}
 			}()
 
-			if err := s.Listen(log); err != nil && !errors.Is(err, http.ErrServerClosed) {
+			if err := s.Listen(runCtx, log); err != nil && !errors.Is(err, http.ErrServerClosed) {
 				return err
 			}
 
diff --git a/pkg/issuer/acme/http/pod_test.go b/pkg/issuer/acme/http/pod_test.go
index 10991eee3..8aaf83cd2 100644
--- a/pkg/issuer/acme/http/pod_test.go
+++ b/pkg/issuer/acme/http/pod_test.go
@@ -196,6 +196,8 @@ func TestEnsurePod(t *testing.T) {
 	scPod.Spec.ImagePullSecrets = []corev1.LocalObjectReference{}
 	scPod.Spec.Tolerations = []corev1.Toleration{}
 
+	ppACMEOptions := acmeOptions
+	ppACMEOptions.ACMEHTTP01SolverProxyProtocol = true
 	ppPod := pod.DeepCopy()
 	ppPod.Spec.Containers[0].Args = []string{
 		fmt.Sprintf("--listen-port=%d", acmeSolverListenPort),
@@ -339,14 +341,7 @@ func TestEnsurePod(t *testing.T) {
 				PartialMetadataObjects: []runtime.Object{},
 				ExpectedActions:        []testpkg.Action{testpkg.NewAction(coretesting.NewCreateAction(corev1.SchemeGroupVersion.WithResource("pods"), testNamespace, ppPod))},
 				Context: &controller.Context{
-					ACMEOptions: controller.ACMEOptions{
-						HTTP01SolverResourceRequestCPU:    cpuRequest,
-						HTTP01SolverResourceRequestMemory: memoryRequest,
-						HTTP01SolverResourceLimitsCPU:     cpuLimit,
-						HTTP01SolverResourceLimitsMemory:  memoryLimit,
-						ACMEHTTP01SolverRunAsNonRoot:      true,
-						ACMEHTTP01SolverProxyProtocol:     true,
-					},
+					ACMEOptions: ppACMEOptions,
 				},
 			},
 		},
diff --git a/pkg/issuer/acme/http/solver/solver.go b/pkg/issuer/acme/http/solver/solver.go
index e626725a3..681f9be96 100644
--- a/pkg/issuer/acme/http/solver/solver.go
+++ b/pkg/issuer/acme/http/solver/solver.go
@@ -17,6 +17,7 @@ limitations under the License.
 package solver
 
 import (
+	"context"
 	"fmt"
 	"net"
 	"net/http"
@@ -50,8 +51,9 @@ type HTTP01Solver struct {
 	http.Server
 }
 
-func (h *HTTP01Solver) Listen(log logr.Logger) error {
-	ln, err := net.Listen("tcp", fmt.Sprintf(":%d", h.ListenPort))
+func (h *HTTP01Solver) Listen(ctx context.Context, log logr.Logger) error {
+	lc := net.ListenConfig{}
+	ln, err := lc.Listen(ctx, "tcp", fmt.Sprintf(":%d", h.ListenPort))
 	if err != nil {
 		return err
 	}
diff --git a/pkg/issuer/acme/http/solver/solver_test.go b/pkg/issuer/acme/http/solver/solver_test.go
index c21591531..8f2ea113f 100644
--- a/pkg/issuer/acme/http/solver/solver_test.go
+++ b/pkg/issuer/acme/http/solver/solver_test.go
@@ -17,7 +17,8 @@ limitations under the License.
 package solver
 
 import (
-	"context"
+	"bufio"
+	"bytes"
 	"io"
 	"net"
 	"net/http"
@@ -196,13 +197,6 @@ func Test_parseHost(t *testing.T) {
 	}
 }
 
-type proxyConnDialer struct {
-	c net.Conn
-}
-
-func (pcd proxyConnDialer) Dial(ctx context.Context, network, addr string) (net.Conn, error) {
-	return pcd.c, nil
-}
 func Test_listenSolver(t *testing.T) {
 	cases := map[string]struct {
 		solverPort           int
@@ -287,10 +281,20 @@ func Test_listenSolver(t *testing.T) {
 				Key:           tc.solverKey,
 			}
 
-			ln, err := net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(solver.ListenPort))
+			lc := net.ListenConfig{}
+			ln, err := lc.Listen(t.Context(), "tcp", "127.0.0.1:"+strconv.Itoa(solver.ListenPort))
 			require.NoError(t, err)
-			go func() { _ = solver.Serve(logr.Discard(), ln) }()
-			t.Cleanup(func() { _ = solver.Server.Close() })
+			done := make(chan struct{})
+			go func() {
+				defer close(done)
+				_ = solver.Serve(logr.Discard(), ln)
+			}()
+			// Close the listener, not solver.Server: Serve assigns
+			// solver.Server in the other goroutine.
+			t.Cleanup(func() {
+				_ = ln.Close()
+				<-done
+			})
 
 			addr := ln.Addr().(*net.TCPAddr)
 			conn, err := net.DialTCP("tcp", nil, addr)
@@ -308,6 +312,11 @@ func Test_listenSolver(t *testing.T) {
 				t.Fatal(err)
 			}
 
+			// Send the optional PROXY header and the request in one write.
+			// If they are written separately, a server without
+			// --proxy-protocol can reply 400 and close the connection
+			// before the request has been sent.
+			var buf bytes.Buffer
 			if tc.requestProxyProtocol {
 				header := &proxyproto.Header{
 					Version:           tc.proxyProtocolVersion,
@@ -322,19 +331,14 @@ func Test_listenSolver(t *testing.T) {
 						Port: 2000,
 					},
 				}
-				_, err = header.WriteTo(conn)
-				if err != nil {
-					t.Fatal(err)
-				}
-			}
-
-			client := &http.Client{
-				Transport: &http.Transport{
-					DialContext: proxyConnDialer{conn}.Dial,
-				},
+				_, err = header.WriteTo(&buf)
+				require.NoError(t, err)
 			}
+			require.NoError(t, r.Write(&buf))
+			_, err = conn.Write(buf.Bytes())
+			require.NoError(t, err)
 
-			resp, err := client.Do(r)
+			resp, err := http.ReadResponse(bufio.NewReader(conn), r)
 			if err != nil {
 				if !(strings.Contains(err.Error(), tc.expectedErrorKey) && tc.expectedErrorKey != "") {
 					t.Fatal(err)

One small request: the doc comment on SolverProxyProtocol in both types.go files could say what the help text says, namely that solver pods then require a PROXY header on every connection.

[Claude Fable 5.2]

@shakapark
shakapark force-pushed the add-proxyprotocol-acmesolver branch from 8db6f3b to 84118b1 Compare November 23, 2026 10:24
@lunarwhite

Copy link
Copy Markdown
Member

/label tide/merge-method-squash

@cert-manager-prow cert-manager-prow Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Nov 23, 2026
@shakapark
shakapark force-pushed the add-proxyprotocol-acmesolver branch from 84118b1 to a974c71 Compare November 23, 2026 10:45
@cert-manager-prow cert-manager-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 23, 2026
@wallrj

wallrj commented Nov 23, 2026

Copy link
Copy Markdown
Member

Thank you for applying the patch and rebasing. Everything from my reviews is now addressed at 9a74067, and all four Prow jobs pass.

I also ran Test_listenSolver locally at this commit: 300 runs with -race and 2000 without, with no failures.

/lgtm
/approve

[Claude Fable 5.2]

@cert-manager-prow cert-manager-prow Bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 23, 2026

@wallrj wallrj 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.

All review points are addressed at 9a74067.

[Claude Fable 5.2]

@cert-manager-prow
cert-manager-prow Bot merged commit 9e37523 into cert-manager:master Nov 24, 2026
6 checks passed
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wallrj

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

The pull request process is described 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

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/acme/http01 Indicates a PR modifies ACME HTTP01 provider code area/acme Indicates a PR directly modifies the ACME Issuer code area/api Indicates a PR directly modifies the 'pkg/apis' directory dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. ok-to-test release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants