Skip to content

Commit 474fc7f

Browse files
authored
Partially revert "bdns, va: Remove DNSAllowLoopbackAddresses" (#8226)
This partially reverts #8203, which was landed as commit dea81c7. It leaves all of the boulder integration test environment changes in place, while restoring the DNSAllowLoopbackAddresses config key and its ability to influence the VA's behavior.
1 parent 0d7ea60 commit 474fc7f

File tree

4 files changed

+83
-36
lines changed

4 files changed

+83
-36
lines changed

bdns/dns.go

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ type Client interface {
4242

4343
// impl represents a client that talks to an external resolver
4444
type impl struct {
45-
dnsClient exchanger
46-
servers ServerProvider
47-
maxTries int
48-
clk clock.Clock
49-
log blog.Logger
45+
dnsClient exchanger
46+
servers ServerProvider
47+
allowRestrictedAddresses bool
48+
maxTries int
49+
clk clock.Clock
50+
log blog.Logger
5051

5152
queryTime *prometheus.HistogramVec
5253
totalLookupTime *prometheus.HistogramVec
@@ -134,18 +135,37 @@ func New(
134135
)
135136
stats.MustRegister(queryTime, totalLookupTime, timeoutCounter, idMismatchCounter)
136137
return &impl{
137-
dnsClient: client,
138-
servers: servers,
139-
maxTries: maxTries,
140-
clk: clk,
141-
queryTime: queryTime,
142-
totalLookupTime: totalLookupTime,
143-
timeoutCounter: timeoutCounter,
144-
idMismatchCounter: idMismatchCounter,
145-
log: log,
138+
dnsClient: client,
139+
servers: servers,
140+
allowRestrictedAddresses: false,
141+
maxTries: maxTries,
142+
clk: clk,
143+
queryTime: queryTime,
144+
totalLookupTime: totalLookupTime,
145+
timeoutCounter: timeoutCounter,
146+
idMismatchCounter: idMismatchCounter,
147+
log: log,
146148
}
147149
}
148150

151+
// NewTest constructs a new DNS resolver object that utilizes the
152+
// provided list of DNS servers for resolution and will allow loopback addresses.
153+
// This constructor should *only* be called from tests (unit or integration).
154+
func NewTest(
155+
readTimeout time.Duration,
156+
servers ServerProvider,
157+
stats prometheus.Registerer,
158+
clk clock.Clock,
159+
maxTries int,
160+
userAgent string,
161+
log blog.Logger,
162+
tlsConfig *tls.Config,
163+
) Client {
164+
resolver := New(readTimeout, servers, stats, clk, maxTries, userAgent, log, tlsConfig)
165+
resolver.(*impl).allowRestrictedAddresses = true
166+
return resolver
167+
}
168+
149169
// exchangeOne performs a single DNS exchange with a randomly chosen server
150170
// out of the server list, returning the response, time, and error (if any).
151171
// We assume that the upstream resolver requests and validates DNSSEC records
@@ -391,7 +411,7 @@ func (dnsClient *impl) LookupHost(ctx context.Context, hostname string) ([]netip
391411
a, ok := answer.(*dns.A)
392412
if ok && a.A.To4() != nil {
393413
netIP, ok := netip.AddrFromSlice(a.A)
394-
if ok && policy.IsReservedIP(netIP) == nil {
414+
if ok && (policy.IsReservedIP(netIP) == nil || dnsClient.allowRestrictedAddresses) {
395415
addrsA = append(addrsA, netIP)
396416
}
397417
}
@@ -409,7 +429,7 @@ func (dnsClient *impl) LookupHost(ctx context.Context, hostname string) ([]netip
409429
aaaa, ok := answer.(*dns.AAAA)
410430
if ok && aaaa.AAAA.To16() != nil {
411431
netIP, ok := netip.AddrFromSlice(aaaa.AAAA)
412-
if ok && policy.IsReservedIP(netIP) == nil {
432+
if ok && (policy.IsReservedIP(netIP) == nil || dnsClient.allowRestrictedAddresses) {
413433
addrsAAAA = append(addrsAAAA, netIP)
414434
}
415435
}

cmd/boulder-va/main.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,28 @@ func main() {
9999
tlsConfig, err := c.VA.TLS.Load(scope)
100100
cmd.FailOnError(err, "tlsConfig config")
101101

102-
resolver := bdns.New(
103-
c.VA.DNSTimeout.Duration,
104-
servers,
105-
scope,
106-
clk,
107-
c.VA.DNSTries,
108-
c.VA.UserAgent,
109-
logger,
110-
tlsConfig)
102+
var resolver bdns.Client
103+
if !c.VA.DNSAllowLoopbackAddresses {
104+
resolver = bdns.New(
105+
c.VA.DNSTimeout.Duration,
106+
servers,
107+
scope,
108+
clk,
109+
c.VA.DNSTries,
110+
c.VA.UserAgent,
111+
logger,
112+
tlsConfig)
113+
} else {
114+
resolver = bdns.NewTest(
115+
c.VA.DNSTimeout.Duration,
116+
servers,
117+
scope,
118+
clk,
119+
c.VA.DNSTries,
120+
c.VA.UserAgent,
121+
logger,
122+
tlsConfig)
123+
}
111124
var remotes []va.RemoteVA
112125
if len(c.VA.RemoteVAs) > 0 {
113126
for _, rva := range c.VA.RemoteVAs {

cmd/remoteva/main.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,28 @@ func main() {
108108
tlsConfig.ClientAuth = tls.VerifyClientCertIfGiven
109109
}
110110

111-
resolver := bdns.New(
112-
c.RVA.DNSTimeout.Duration,
113-
servers,
114-
scope,
115-
clk,
116-
c.RVA.DNSTries,
117-
c.RVA.UserAgent,
118-
logger,
119-
tlsConfig)
111+
var resolver bdns.Client
112+
if !c.RVA.DNSAllowLoopbackAddresses {
113+
resolver = bdns.New(
114+
c.RVA.DNSTimeout.Duration,
115+
servers,
116+
scope,
117+
clk,
118+
c.RVA.DNSTries,
119+
c.RVA.UserAgent,
120+
logger,
121+
tlsConfig)
122+
} else {
123+
resolver = bdns.NewTest(
124+
c.RVA.DNSTimeout.Duration,
125+
servers,
126+
scope,
127+
clk,
128+
c.RVA.DNSTries,
129+
c.RVA.UserAgent,
130+
logger,
131+
tlsConfig)
132+
}
120133

121134
vai, err := va.NewValidationAuthorityImpl(
122135
resolver,

va/config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ type Common struct {
2424
// DNSStaticResolvers is a list of DNS resolvers. Each entry must
2525
// be a host or IP and port separated by a colon. IPv6 addresses
2626
// must be enclosed in square brackets.
27-
DNSStaticResolvers []string `validate:"required_without=DNSProvider,dive,hostname_port"`
28-
DNSTimeout config.Duration `validate:"required"`
27+
DNSStaticResolvers []string `validate:"required_without=DNSProvider,dive,hostname_port"`
28+
DNSTimeout config.Duration `validate:"required"`
29+
DNSAllowLoopbackAddresses bool
2930

3031
AccountURIPrefixes []string `validate:"min=1,dive,required,url"`
3132
}

0 commit comments

Comments
 (0)