diff --git a/agent/config/runtime.go b/agent/config/runtime.go index a6021b4a1a..86e7d0e52c 100644 --- a/agent/config/runtime.go +++ b/agent/config/runtime.go @@ -1674,7 +1674,6 @@ func cleanRetryJoin(a string) string { func sanitize(name string, v reflect.Value) reflect.Value { typ := v.Type() switch { - // check before isStruct and isPtr case isNetAddr(typ): if v.IsNil() { @@ -1689,6 +1688,8 @@ func sanitize(name string, v reflect.Value) reflect.Value { return reflect.ValueOf("unix://" + x.String()) case *net.IPAddr: return reflect.ValueOf(x.IP.String()) + case *net.IPNet: + return reflect.ValueOf(x.String()) default: return v } diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index ad18b199e4..e592a5c7bc 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -5660,6 +5660,14 @@ func TestConfigDecodeBytes(t *testing.T) { } } +func parseCIDR(t *testing.T, cidr string) *net.IPNet { + _, x, err := net.ParseCIDR(cidr) + if err != nil { + t.Fatalf("CIDRParse: %v", err) + } + return x +} + func TestSanitize(t *testing.T) { rt := RuntimeConfig{ BindAddr: &net.IPAddr{IP: net.ParseIP("127.0.0.1")}, @@ -5670,6 +5678,10 @@ func TestSanitize(t *testing.T) { &net.UDPAddr{IP: net.ParseIP("1.2.3.4"), Port: 5678}, }, DNSSOA: RuntimeSOAConfig{Refresh: 3600, Retry: 600, Expire: 86400, Minttl: 0}, + AllowWriteHTTPFrom: []*net.IPNet{ + parseCIDR(t, "127.0.0.0/8"), + parseCIDR(t, "::1/128"), + }, HTTPAddrs: []net.Addr{ &net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 5678}, &net.UnixAddr{Name: "/var/run/foo"}, @@ -6009,7 +6021,10 @@ func TestSanitize(t *testing.T) { "Version": "", "VersionPrerelease": "", "Watches": [], - "AllowWriteHTTPFrom": [] + "AllowWriteHTTPFrom": [ + "127.0.0.0/8", + "::1/128" + ] }` b, err := json.MarshalIndent(rt.Sanitized(), "", " ") if err != nil {