Skip to content

Commit 78ce840

Browse files
authored
all-in-one: add hidden --debug-port flag to pin the debug listener port (#1462)
## Summary Adds a hidden `--debug-port` flag to the `all-in-one` command that overrides the auto-allocated ephemeral port for Pomerium's internal debug/admin listener. Today the debug/admin listener port is assigned by `AllocatePorts` and changes on every restart, so the debug endpoints (databroker browser, pprof, etc.) land on an unpredictable port. This flag lets you pin that listener to a fixed, stable port. The bind host remains `127.0.0.1`, and the flag is hidden since it's intended for development/debugging. When unset (the default), behavior is unchanged — the port stays ephemeral. ## Related issues <!-- none --> ## Checklist - [ ] reference any related issues - [ ] updated docs - [ ] updated unit tests - [ ] updated UPGRADING.md - [x] add appropriate tag (`improvement`) - [x] ready for review
1 parent a8f5594 commit 78ce840

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

cmd/all_in_one.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"net/url"
88
"os"
9+
"strconv"
910
"strings"
1011
"time"
1112

@@ -45,6 +46,7 @@ type allCmdOptions struct {
4546
debugPomerium bool
4647
debugEnvoy bool
4748
adminBindAddr string
49+
debugPort string
4850
configControllerShutdownTimeout time.Duration
4951
// healthProbeBindAddress must be externally accessible host:port
5052
healthProbeBindAddress string
@@ -116,6 +118,7 @@ const (
116118
debugEnvoy = "debug-envoy"
117119
debugAdminBindAddr = "debug-admin-addr"
118120
debugDumpConfigDiff = "debug-dump-config-diff"
121+
debugPort = "debug-port"
119122
configControllerShutdown = "config-controller-shutdown"
120123
)
121124

@@ -124,6 +127,7 @@ var hidden = []string{
124127
debugEnvoy,
125128
debugAdminBindAddr,
126129
debugDumpConfigDiff,
130+
debugPort,
127131
}
128132

129133
func (s *allCmd) setupFlags() error {
@@ -135,6 +139,7 @@ func (s *allCmd) setupFlags() error {
135139
flags.StringVar(&s.metricsBindAddress, metricsBindAddress, "", "host:port for aggregate metrics. host is mandatory")
136140
flags.StringVar(&s.healthProbeBindAddress, healthProbeBindAddress, "127.0.0.1:28080", "host:port for http health probes")
137141
flags.StringVar(&s.adminBindAddr, debugAdminBindAddr, "", "host:port for admin server")
142+
flags.StringVar(&s.debugPort, debugPort, "", "bind the debug/admin listener to this fixed port instead of an ephemeral one (127.0.0.1 only)")
138143
flags.StringVar(&s.serverAddr, "server-addr", ":8443", "the address the HTTPS server would bind to")
139144
flags.StringVar(&s.sshAddr, "ssh-addr", "", "the address the SSH server would bind to")
140145
flags.StringVar(&s.httpRedirectAddr, "http-redirect-addr", ":8080", "the address HTTP redirect would bind to")
@@ -267,6 +272,17 @@ func (s *allCmdParam) makeBootstrapConfig(ctx context.Context, opt allCmdOptions
267272

268273
s.cfg.AllocatePorts(*(*[7]string)(ports[:7]))
269274

275+
// Override the auto-allocated debug listener port with a fixed value when
276+
// requested, so the debug/admin endpoints (databroker browser, pprof, etc.)
277+
// are reachable on a stable, predictable port across restarts. The value is
278+
// a bare port number; the debug listener always binds to 127.0.0.1.
279+
if opt.debugPort != "" {
280+
if _, err := strconv.ParseUint(opt.debugPort, 10, 16); err != nil {
281+
return fmt.Errorf("--%s: %q is not a valid port number", debugPort, opt.debugPort)
282+
}
283+
s.cfg.DebugPort = opt.debugPort
284+
}
285+
270286
if opt.deriveTLS != "" {
271287
s.cfg.Options.DeriveInternalDomainCert = &opt.deriveTLS
272288
s.cfg.Options.GRPCInsecure = proto.Bool(false)

0 commit comments

Comments
 (0)