Skip to content

Commit e9286ab

Browse files
committed
proxy: use dnssec
1 parent 3171cb4 commit e9286ab

6 files changed

Lines changed: 39 additions & 5 deletions

File tree

proxy/cache_internal_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func TestServeCached(t *testing.T) {
5757
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
5858
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
5959
TrustedProxies: defaultTrustedProxies,
60+
DNSSECEnabled: true,
6061
CacheEnabled: true,
6162
})
6263

@@ -374,6 +375,7 @@ func TestCacheExpirationWithTTLOverride(t *testing.T) {
374375
},
375376
TrustedProxies: defaultTrustedProxies,
376377
CacheEnabled: true,
378+
DNSSECEnabled: true,
377379
CacheMinTTL: 20,
378380
CacheMaxTTL: 40,
379381
})

proxy/pending_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func TestPendingRequests(t *testing.T) {
117117
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
118118
CacheSizeBytes: testCacheSize,
119119
CacheEnabled: true,
120+
DNSSECEnabled: true,
120121
EnableEDNSClientSubnet: true,
121122
})
122123
require.NoError(t, err)

proxy/proxy.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,14 @@ func (p *Proxy) handleExchangeResult(
668668
}
669669
}
670670

671-
// addDO adds EDNS0 RR if needed and sets DO bit of msg to true.
672-
func addDO(msg *dns.Msg) {
671+
// addDO adds EDNS0 RR if needed and sets DO bit of msg to true. msg must not
672+
// be nil.
673+
func (p *Proxy) addDO(msg *dns.Msg) {
674+
if !p.DNSSECEnabled {
675+
// Do nothing if DNSSEC is disabled in the proxy.
676+
return
677+
}
678+
673679
if o := msg.IsEdns0(); o != nil {
674680
if !o.Do() {
675681
o.SetDo()
@@ -715,7 +721,7 @@ func (p *Proxy) Resolve(ctx context.Context, dctx *DNSContext) (err error) {
715721

716722
// On cache miss request for DNSSEC from the upstream to cache it
717723
// afterwards.
718-
addDO(dctx.Req)
724+
p.addDO(dctx.Req)
719725
}
720726

721727
var ok bool
@@ -794,6 +800,12 @@ func (p *Proxy) cacheWorks(dctx *DNSContext) (ok bool) {
794800
// Don't cache the requests intended for local upstream servers, those
795801
// should be fast enough as is.
796802
reason = "requested address is private"
803+
case !p.DNSSECEnabled && !dctx.doBit:
804+
// Don't cache the responses without DNSSEC RRs if DNSSEC is disabled
805+
// and DO bit is not set, since those responses may differ from the ones
806+
// with DNSSEC RRs and thus may be not the desired result for user. In
807+
// case DNSSEC is enabled in the proxy, the DO bit will be enforced.
808+
reason = "dnssec disabled"
797809
case dctx.Req.CheckingDisabled:
798810
// Also don't lookup the cache for responses with DNSSEC checking
799811
// disabled since only validated responses are cached and those may be

proxy/proxy_internal_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ func TestProxy_Resolve_dnssecCache(t *testing.T) {
504504
UpstreamConfig: &UpstreamConfig{Upstreams: []upstream.Upstream{u}},
505505
TrustedProxies: defaultTrustedProxies,
506506
CacheEnabled: true,
507+
DNSSECEnabled: true,
507508
CacheSizeBytes: defaultCacheSize,
508509
})
509510

@@ -978,6 +979,7 @@ func TestExchangeCustomUpstreamConfigCache(t *testing.T) {
978979
UpstreamConfig: newTestUpstreamConfig(t, defaultTimeout, testDefaultUpstreamAddr),
979980
TrustedProxies: defaultTrustedProxies,
980981
CacheEnabled: true,
982+
DNSSECEnabled: true,
981983
})
982984

983985
servicetest.RequireRun(t, prx, testTimeout)
@@ -1107,6 +1109,7 @@ func TestECSProxy(t *testing.T) {
11071109
Upstreams: []upstream.Upstream{u},
11081110
},
11091111
TrustedProxies: defaultTrustedProxies,
1112+
DNSSECEnabled: true,
11101113
EnableEDNSClientSubnet: true,
11111114
CacheEnabled: true,
11121115
})
@@ -1216,6 +1219,7 @@ func TestECSProxyCacheMinMaxTTL(t *testing.T) {
12161219
TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
12171220
UpstreamConfig: &UpstreamConfig{Upstreams: []upstream.Upstream{u}},
12181221
TrustedProxies: defaultTrustedProxies,
1222+
DNSSECEnabled: true,
12191223
EnableEDNSClientSubnet: true,
12201224
CacheEnabled: true,
12211225
CacheMinTTL: 20,
@@ -1309,6 +1313,7 @@ func TestProxy_Resolve_withOptimisticResolver(t *testing.T) {
13091313
CacheOptimistic: true,
13101314
CacheOptimisticAnswerTTL: testOptimisticTTL,
13111315
CacheOptimisticMaxAge: testOptimisticMaxAge,
1316+
DNSSECEnabled: true,
13121317
},
13131318
logger: testLogger,
13141319
pendingRequests: newDefaultPendingRequests(),

proxy/proxy_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,37 +93,50 @@ func TestProxy_Resolve_cache(t *testing.T) {
9393
wantCachedWithConf assert.BoolAssertionFunc
9494
wantCachedGlobal assert.BoolAssertionFunc
9595
name string
96+
dnssecEnabled bool
9697
prxCacheEnabled bool
9798
}{{
9899
customUpstreamConf: nil,
99100
wantCachedWithConf: assert.True,
100101
wantCachedGlobal: assert.True,
101102
name: "global_cache",
103+
dnssecEnabled: true,
102104
prxCacheEnabled: true,
103105
}, {
104106
customUpstreamConf: newCustomUpstreamConfig(ups, true),
105107
wantCachedWithConf: assert.True,
106108
wantCachedGlobal: assert.False,
107109
name: "custom_cache",
110+
dnssecEnabled: true,
108111
prxCacheEnabled: false,
109112
}, {
110113
customUpstreamConf: newCustomUpstreamConfig(ups, false),
111114
wantCachedWithConf: assert.False,
112115
wantCachedGlobal: assert.False,
113116
name: "custom_cache_only_upstreams",
117+
dnssecEnabled: true,
114118
prxCacheEnabled: false,
115119
}, {
116120
customUpstreamConf: newCustomUpstreamConfig(ups, true),
117121
wantCachedWithConf: assert.True,
118122
wantCachedGlobal: assert.False,
119123
name: "two_caches_enabled",
124+
dnssecEnabled: true,
120125
prxCacheEnabled: true,
121126
}, {
122127
customUpstreamConf: nil,
123128
wantCachedWithConf: assert.False,
124129
wantCachedGlobal: assert.False,
125-
name: "two_caches_disabled",
130+
name: "proxy_cache_disabled",
131+
dnssecEnabled: true,
126132
prxCacheEnabled: false,
133+
}, {
134+
customUpstreamConf: nil,
135+
wantCachedWithConf: assert.False,
136+
wantCachedGlobal: assert.False,
137+
name: "dnssec_disabled",
138+
dnssecEnabled: false,
139+
prxCacheEnabled: true,
127140
}}
128141

129142
for _, tc := range testCases {
@@ -132,6 +145,7 @@ func TestProxy_Resolve_cache(t *testing.T) {
132145
UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
133146
UpstreamConfig: upsConf,
134147
CacheEnabled: tc.prxCacheEnabled,
148+
DNSSECEnabled: tc.dnssecEnabled,
135149
})
136150
require.NoError(t, err)
137151
require.NotNil(t, p)

proxy/proxycache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (p *Proxy) replyFromCache(d *DNSContext) (hit bool) {
5656
}
5757
if d.Req != nil {
5858
minCtxClone.Req = d.Req.Copy()
59-
addDO(minCtxClone.Req)
59+
p.addDO(minCtxClone.Req)
6060
}
6161

6262
go p.shortFlighter.resolveOnce(minCtxClone, key, p.logger)

0 commit comments

Comments
 (0)