@marcel91200 / caddy Mirror · read-only / commits / 4636109c
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 04:15 UTC

reverseproxy: Remove deprecated `lookup_srv` (#5396)

Francis Lavoie committed Apr 10, 2023 at 16:08 UTC 4636109ce17e6ba5f46e73b7b1f3ae82d076a625
5 files changed +18 -161
caddytest/integration/reverseproxy_test.go
+4 -91
@@ -40,11 +40,10 @@ func TestSRVReverseProxy(t *testing.T) {
40 "handle": [
41 {
42 "handler": "reverse_proxy",
43 - "upstreams": [
44 - {
45 - "lookup_srv": "srv.host.service.consul"
46 - }
47 - ]
43 + "dynamic_upstreams": {
44 + "source": "srv",
45 + "name": "srv.host.service.consul"
46 + }
47 }
48 ]
49 }
@@ -57,47 +56,6 @@ func TestSRVReverseProxy(t *testing.T) {
56 `, "json")
57 }
58
60 -func TestSRVWithDial(t *testing.T) {
61 - caddytest.AssertLoadError(t, `
62 - {
63 - "apps": {
64 - "pki": {
65 - "certificate_authorities": {
66 - "local": {
67 - "install_trust": false
68 - }
69 - }
70 - },
71 - "http": {
72 - "grace_period": 1,
73 - "servers": {
74 - "srv0": {
75 - "listen": [
76 - ":18080"
77 - ],
78 - "routes": [
79 - {
80 - "handle": [
81 - {
82 - "handler": "reverse_proxy",
83 - "upstreams": [
84 - {
85 - "dial": "tcp/address.to.upstream:80",
86 - "lookup_srv": "srv.host.service.consul"
87 - }
88 - ]
89 - }
90 - ]
91 - }
92 - ]
93 - }
94 - }
95 - }
96 - }
97 - }
98 - `, "json", `upstream: specifying dial address is incompatible with lookup_srv: 0: {\"dial\": \"tcp/address.to.upstream:80\", \"lookup_srv\": \"srv.host.service.consul\"}`)
99 -}
100 -
59 func TestDialWithPlaceholderUnix(t *testing.T) {
60
61 if runtime.GOOS == "windows" {
@@ -369,51 +327,6 @@ func TestReverseProxyWithPlaceholderTCPDialAddress(t *testing.T) {
327 tester.AssertResponse(req, 200, "Hello, World!")
328 }
329
372 -func TestSRVWithActiveHealthcheck(t *testing.T) {
373 - caddytest.AssertLoadError(t, `
374 - {
375 - "apps": {
376 - "pki": {
377 - "certificate_authorities" : {
378 - "local" : {
379 - "install_trust": false
380 - }
381 - }
382 - },
383 - "http": {
384 - "grace_period": 1,
385 - "servers": {
386 - "srv0": {
387 - "listen": [
388 - ":18080"
389 - ],
390 - "routes": [
391 - {
392 - "handle": [
393 - {
394 - "handler": "reverse_proxy",
395 - "health_checks": {
396 - "active": {
397 - "path": "/ok"
398 - }
399 - },
400 - "upstreams": [
401 - {
402 - "lookup_srv": "srv.host.service.consul"
403 - }
404 - ]
405 - }
406 - ]
407 - }
408 - ]
409 - }
410 - }
411 - }
412 - }
413 - }
414 - `, "json", `upstream: lookup_srv is incompatible with active health checks: 0: {\"dial\": \"\", \"lookup_srv\": \"srv.host.service.consul\"}`)
415 -}
416 -
330 func TestReverseProxyHealthCheck(t *testing.T) {
331 tester := caddytest.NewTester(t)
332 tester.InitServer(`
modules/caddyhttp/reverseproxy/caddyfile.go
+2 -17
@@ -15,7 +15,6 @@
15 package reverseproxy
16
17 import (
18 - "net"
18 "net/http"
19 "reflect"
20 "strconv"
@@ -142,15 +141,8 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
141 h.responseMatchers = make(map[string]caddyhttp.ResponseMatcher)
142
143 // appendUpstream creates an upstream for address and adds
145 - // it to the list. If the address starts with "srv+" it is
146 - // treated as a SRV-based upstream, and any port will be
147 - // dropped.
144 + // it to the list.
145 appendUpstream := func(address string) error {
149 - isSRV := strings.HasPrefix(address, "srv+")
150 - if isSRV {
151 - address = strings.TrimPrefix(address, "srv+")
152 - }
153 -
146 dialAddr, scheme, err := parseUpstreamDialAddress(address)
147 if err != nil {
148 return d.WrapErr(err)
@@ -165,14 +157,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
157 }
158 commonScheme = scheme
159
168 - if isSRV {
169 - if host, _, err := net.SplitHostPort(dialAddr); err == nil {
170 - dialAddr = host
171 - }
172 - h.Upstreams = append(h.Upstreams, &Upstream{LookupSRV: dialAddr})
173 - } else {
174 - h.Upstreams = append(h.Upstreams, &Upstream{Dial: dialAddr})
175 - }
160 + h.Upstreams = append(h.Upstreams, &Upstream{Dial: dialAddr})
161 return nil
162 }
163
modules/caddyhttp/reverseproxy/healthchecks.go
+1 -1
@@ -203,7 +203,7 @@ func (h *Handler) doActiveHealthCheckForAllHosts() {
203 }
204 addr.StartPort, addr.EndPort = hcp, hcp
205 }
206 - if upstream.LookupSRV == "" && addr.PortRangeSize() != 1 {
206 + if addr.PortRangeSize() != 1 {
207 h.HealthChecks.Active.logger.Error("multiple addresses (upstream must map to only one address)",
208 zap.String("address", networkAddr),
209 )
modules/caddyhttp/reverseproxy/hosts.go
+11 -38
@@ -17,7 +17,6 @@ package reverseproxy
17 import (
18 "context"
19 "fmt"
20 - "net"
20 "net/http"
21 "net/netip"
22 "strconv"
@@ -48,15 +47,6 @@ type Upstream struct {
47 // backends is down. Also be aware of open proxy vulnerabilities.
48 Dial string `json:"dial,omitempty"`
49
51 - // DEPRECATED: Use the SRVUpstreams module instead
52 - // (http.reverse_proxy.upstreams.srv). This field will be
53 - // removed in a future version of Caddy. TODO: Remove this field.
54 - //
55 - // If DNS SRV records are used for service discovery with this
56 - // upstream, specify the DNS name for which to look up SRV
57 - // records here, instead of specifying a dial address.
58 - LookupSRV string `json:"lookup_srv,omitempty"`
59 -
50 // The maximum number of simultaneous requests to allow to
51 // this upstream. If set, overrides the global passive health
52 // check UnhealthyRequestCount value.
@@ -74,9 +64,6 @@ type Upstream struct {
64 }
65
66 func (u Upstream) String() string {
77 - if u.LookupSRV != "" {
78 - return u.LookupSRV
79 - }
67 return u.Dial
68 }
69
@@ -110,35 +97,21 @@ func (u *Upstream) Full() bool {
97 }
98
99 // fillDialInfo returns a filled DialInfo for upstream u, using the request
113 -// context. If the upstream has a SRV lookup configured, that is done and a
114 -// returned address is chosen; otherwise, the upstream's regular dial address
115 -// field is used. Note that the returned value is not a pointer.
100 +// context. Note that the returned value is not a pointer.
101 func (u *Upstream) fillDialInfo(r *http.Request) (DialInfo, error) {
102 repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
103 var addr caddy.NetworkAddress
104
120 - if u.LookupSRV != "" {
121 - // perform DNS lookup for SRV records and choose one - TODO: deprecated
122 - srvName := repl.ReplaceAll(u.LookupSRV, "")
123 - _, records, err := net.DefaultResolver.LookupSRV(r.Context(), "", "", srvName)
124 - if err != nil {
125 - return DialInfo{}, err
126 - }
127 - addr.Network = "tcp"
128 - addr.Host = records[0].Target
129 - addr.StartPort, addr.EndPort = uint(records[0].Port), uint(records[0].Port)
130 - } else {
131 - // use provided dial address
132 - var err error
133 - dial := repl.ReplaceAll(u.Dial, "")
134 - addr, err = caddy.ParseNetworkAddress(dial)
135 - if err != nil {
136 - return DialInfo{}, fmt.Errorf("upstream %s: invalid dial address %s: %v", u.Dial, dial, err)
137 - }
138 - if numPorts := addr.PortRangeSize(); numPorts != 1 {
139 - return DialInfo{}, fmt.Errorf("upstream %s: dial address must represent precisely one socket: %s represents %d",
140 - u.Dial, dial, numPorts)
141 - }
105 + // use provided dial address
106 + var err error
107 + dial := repl.ReplaceAll(u.Dial, "")
108 + addr, err = caddy.ParseNetworkAddress(dial)
109 + if err != nil {
110 + return DialInfo{}, fmt.Errorf("upstream %s: invalid dial address %s: %v", u.Dial, dial, err)
111 + }
112 + if numPorts := addr.PortRangeSize(); numPorts != 1 {
113 + return DialInfo{}, fmt.Errorf("upstream %s: dial address must represent precisely one socket: %s represents %d",
114 + u.Dial, dial, numPorts)
115 }
116
117 return DialInfo{
modules/caddyhttp/reverseproxy/reverseproxy.go
-14
@@ -243,20 +243,6 @@ func (h *Handler) Provision(ctx caddy.Context) error {
243 h.logger.Warn("UNLIMITED BUFFERING: buffering is enabled without any cap on buffer size, which can result in OOM crashes")
244 }
245
246 - // verify SRV compatibility - TODO: LookupSRV deprecated; will be removed
247 - for i, v := range h.Upstreams {
248 - if v.LookupSRV == "" {
249 - continue
250 - }
251 - h.logger.Warn("DEPRECATED: lookup_srv: will be removed in a near-future version of Caddy; use the http.reverse_proxy.upstreams.srv module instead")
252 - if h.HealthChecks != nil && h.HealthChecks.Active != nil {
253 - return fmt.Errorf(`upstream: lookup_srv is incompatible with active health checks: %d: {"dial": %q, "lookup_srv": %q}`, i, v.Dial, v.LookupSRV)
254 - }
255 - if v.Dial != "" {
256 - return fmt.Errorf(`upstream: specifying dial address is incompatible with lookup_srv: %d: {"dial": %q, "lookup_srv": %q}`, i, v.Dial, v.LookupSRV)
257 - }
258 - }
259 -
246 // start by loading modules
247 if h.TransportRaw != nil {
248 mod, err := ctx.LoadModule(h, "TransportRaw")