Repository navigation
Add proxy-protocol listener on acmesolver - #9412
cert-manager-prow[bot] merged 10 commits into
Conversation
|
@shakapark: The label(s) DetailsIn response to this:
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. |
|
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 Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
32fb217 to
dc3004c
Compare
There was a problem hiding this comment.
🟡 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.
| proxyListener := &proxyproto.Listener{ | ||
| Listener: netListener, | ||
| ReadHeaderTimeout: h.Server.ReadHeaderTimeout, | ||
| ConnPolicy: func(proxyproto.ConnPolicyOptions) (proxyproto.Policy, error) { | ||
| return proxyproto.USE, nil |
| 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 |
wallrj
left a comment
There was a problem hiding this comment.
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
- 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. - 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'sh2ALPN while speaking HTTP/1.1 upstream. It also starts its own goroutine, which makesShutdownracy. Details inline. - 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]
| proxyListener := &proxyproto.Listener{ | ||
| Listener: netListener, | ||
| ReadHeaderTimeout: h.Server.ReadHeaderTimeout, | ||
| ConnPolicy: func(proxyproto.ConnPolicyOptions) (proxyproto.Policy, error) { |
There was a problem hiding this comment.
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).
| }, | ||
| } | ||
|
|
||
| return h2proxy.NewServer(&h.Server, nil).Serve(proxyListener) |
There was a problem hiding this comment.
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.
|
|
||
| proxyListener := &proxyproto.Listener{ | ||
| Listener: netListener, | ||
| ReadHeaderTimeout: h.Server.ReadHeaderTimeout, |
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| return h.Server.ListenAndServe() | ||
| // return h.Server.ListenAndServe() |
There was a problem hiding this comment.
Please delete this commented-out line. Git history keeps the old call.
| return h.Server.ListenAndServe() | ||
| // return h.Server.ListenAndServe() | ||
|
|
||
| netListener, err := net.Listen("tcp", h.Server.Addr) |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
|
/kind feature |
f5add0f to
aa59047
Compare
f236e95 to
fbdcbf5
Compare
wallrj
left a comment
There was a problem hiding this comment.
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.
- The controller flag does not reach the pod yet.
cmd/controller/app/controller.gocopies each solver option from the config intoACMEOptionsby hand. SeeACMEHTTP01SolverRunAsNonRootaround lines 327 to 342 on master. This PR does not touch that file, soACMEHTTP01SolverProxyProtocolis always false and--proxy-protocolis never added. The e2e jobs pass only because none of them turn the flag on. - CI fails on stale generated files.
make-testfailsTestRoundTripTypesbecause the conversion code was not regenerated for the new field.make-verifyfails because threeLICENSESfiles are missinggithub.com/pires/go-proxyproto,Apache-2.0. Runningmake generateshould fix both. - Please add a test for
pod.go. Check that--proxy-protocolappears 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]
|
|
||
| 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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
fbdcbf5 to
19ce53c
Compare
|
Thank you for your support Edit: It was caused by my personnel setup, it's fixed |
wallrj
left a comment
There was a problem hiding this comment.
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.
Test_listenSolverfails 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.make verifyfails on three lint findings. The patch below fixes them.- The branch needs a rebase.
cmd/acmesolver/go.mod,go.sumandLICENSESconflict with master. After the rebase, please rungo mod tidyincmd/acmesolverand thenmake 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, reply400and close the connection before the request is sent. The client then fails withreadLoopPeekFailLockedorconnection reset by peer. The patch sends the header and the request in one write and reads the reply withhttp.ReadResponse. - There is also a data race, which
go test -racereports in about 2 runs in 30.Serveassignsh.Serverin its goroutine (solver.go#L69) while the cleanup callssolver.Server.Close()(solver_test.go#L293). The patch closes the listener instead and waits forServeto 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]
8db6f3b to
84118b1
Compare
Signed-off-by: Shakapark <[email protected]>
Signed-off-by: Shakapark <[email protected]>
Signed-off-by: Shakapark <[email protected]>
Signed-off-by: Shakapark <[email protected]>
…s on Signed-off-by: Shakapark <[email protected]>
|
/label tide/merge-method-squash |
Signed-off-by: Shakapark <[email protected]>
…cmesolver pod Signed-off-by: Shakapark <[email protected]>
… the acme solver pod Signed-off-by: Shakapark <[email protected]>
Signed-off-by: Shakapark <[email protected]>
84118b1 to
a974c71
Compare
…re mandatory Signed-off-by: Shakapark <[email protected]>
|
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 /lgtm [Claude Fable 5.2] |
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |


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