Просмотр исходного кода

Use port 53 when --resolver has no port (#2818)

* Use port 53 when --resolver has no port

Before this change, step-ca passed the --resolver value directly to
net.Dial. An address without a port, such as 1.1.1.1, caused all DNS
queries to fail with "missing port in address". ACME dns-01
validation then failed with a general DNS error.

Now, if the address has no port, step-ca adds port 53. Bare and
bracketed IPv6 addresses are supported. Addresses that include a
port do not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Remove the default port from the --resolver help text

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Carl Tashian 1 месяц назад
Родитель
Сommit
69d3c36fa1
3 измененных файлов с 46 добавлено и 0 удалено
  1. 6 0
      CHANGELOG.md
  2. 11 0
      commands/app.go
  3. 29 0
      commands/app_test.go

+ 6 - 0
CHANGELOG.md

@@ -32,6 +32,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 - Support for ML-DSA (FIPS 204) keys, available when built with Go 1.27 or
   newer. JOSE-based flows (JWK, JWS and JWT tokens) do not support ML-DSA yet.
 
+### Changed
+
+- `--resolver` now accepts an address without a port and uses port 53. Before,
+  an address without a port caused all DNS queries to fail with
+  `missing port in address`.
+
 ### Deprecated
 
 - Go 1.25 support. Go 1.26 or newer is now required.

+ 11 - 0
commands/app.go

@@ -102,6 +102,16 @@ Requires **--insecure** flag.`,
 
 var pidfile string
 
+// resolverAddress returns the given DNS resolver address with the default DNS
+// port (53) added when no port is present. Bare and bracketed IPv6 addresses
+// are supported.
+func resolverAddress(addr string) string {
+	if _, _, err := net.SplitHostPort(addr); err == nil {
+		return addr
+	}
+	return net.JoinHostPort(strings.Trim(addr, "[]"), "53")
+}
+
 // AppAction is the action used when the top command runs.
 func appAction(ctx *cli.Context) error {
 	passFile := ctx.String("password-file")
@@ -247,6 +257,7 @@ To get a linked authority token:
 
 	// replace resolver if requested
 	if resolver != "" {
+		resolver = resolverAddress(resolver)
 		net.DefaultResolver.PreferGo = true
 		net.DefaultResolver.Dial = func(_ context.Context, network, _ string) (net.Conn, error) {
 			return net.Dial(network, resolver)

+ 29 - 0
commands/app_test.go

@@ -0,0 +1,29 @@
+package commands
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func Test_resolverAddress(t *testing.T) {
+	tests := []struct {
+		addr string
+		want string
+	}{
+		{"1.1.1.1", "1.1.1.1:53"},
+		{"1.1.1.1:53", "1.1.1.1:53"},
+		{"1.1.1.1:5353", "1.1.1.1:5353"},
+		{"dns.example.com", "dns.example.com:53"},
+		{"dns.example.com:5353", "dns.example.com:5353"},
+		{"2606:4700:4700::1111", "[2606:4700:4700::1111]:53"},
+		{"[2606:4700:4700::1111]", "[2606:4700:4700::1111]:53"},
+		{"[2606:4700:4700::1111]:5353", "[2606:4700:4700::1111]:5353"},
+		{"::1", "[::1]:53"},
+	}
+	for _, tt := range tests {
+		t.Run(tt.addr, func(t *testing.T) {
+			assert.Equal(t, tt.want, resolverAddress(tt.addr))
+		})
+	}
+}