Skip to content

Commit e5edb70

Browse files
wfe/features: Deprecate UseKvLimitsForNewOrder (#7765)
Default code paths that depended on this flag to be true. Part of #5545
1 parent 844334e commit e5edb70

File tree

8 files changed

+9
-165
lines changed

8 files changed

+9
-165
lines changed

features/features.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Config struct {
2929
CertCheckerRequiresCorrespondence bool
3030
ECDSAForAll bool
3131
CheckRenewalExemptionAtWFE bool
32+
UseKvLimitsForNewAccount bool
3233

3334
// ServeRenewalInfo exposes the renewalInfo endpoint in the directory and for
3435
// GET requests. WARNING: This feature is a draft and highly unstable.
@@ -104,11 +105,6 @@ type Config struct {
104105
// fqdnSets tables at Finalize time.
105106
UseKvLimitsForNewOrder bool
106107

107-
// UseKvLimitsForNewAccount when enabled, causes the key-value rate limiter
108-
// to be the authoritative source of rate limiting information for
109-
// new-account callers and disables the legacy rate limiting checks.
110-
UseKvLimitsForNewAccount bool
111-
112108
// DisableLegacyLimitWrites when enabled, disables writes to:
113109
// - the newOrdersRL table at new-order time, and
114110
// - the certificatesPerName table at finalize time.

ra/ra.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -415,58 +415,6 @@ func (ra *RegistrationAuthorityImpl) checkRegistrationIPLimit(ctx context.Contex
415415
return nil
416416
}
417417

418-
// checkRegistrationLimits enforces the RegistrationsPerIP and
419-
// RegistrationsPerIPRange limits
420-
func (ra *RegistrationAuthorityImpl) checkRegistrationLimits(ctx context.Context, ip net.IP) error {
421-
// Check the registrations per IP limit using the CountRegistrationsByIP SA
422-
// function that matches IP addresses exactly
423-
exactRegLimit := ra.rlPolicies.RegistrationsPerIP()
424-
if exactRegLimit.Enabled() {
425-
started := ra.clk.Now()
426-
err := ra.checkRegistrationIPLimit(ctx, exactRegLimit, ip, ra.SA.CountRegistrationsByIP)
427-
elapsed := ra.clk.Since(started)
428-
if err != nil {
429-
if errors.Is(err, berrors.RateLimit) {
430-
ra.rlCheckLatency.WithLabelValues(ratelimit.RegistrationsPerIP, ratelimits.Denied).Observe(elapsed.Seconds())
431-
ra.log.Infof("Rate limit exceeded, RegistrationsPerIP, by IP: %q", ip)
432-
}
433-
return err
434-
}
435-
ra.rlCheckLatency.WithLabelValues(ratelimit.RegistrationsPerIP, ratelimits.Allowed).Observe(elapsed.Seconds())
436-
}
437-
438-
// We only apply the fuzzy reg limit to IPv6 addresses.
439-
// Per https://golang.org/pkg/net/#IP.To4 "If ip is not an IPv4 address, To4
440-
// returns nil"
441-
if ip.To4() != nil {
442-
return nil
443-
}
444-
445-
// Check the registrations per IP range limit using the
446-
// CountRegistrationsByIPRange SA function that fuzzy-matches IPv6 addresses
447-
// within a larger address range
448-
fuzzyRegLimit := ra.rlPolicies.RegistrationsPerIPRange()
449-
if fuzzyRegLimit.Enabled() {
450-
started := ra.clk.Now()
451-
err := ra.checkRegistrationIPLimit(ctx, fuzzyRegLimit, ip, ra.SA.CountRegistrationsByIPRange)
452-
elapsed := ra.clk.Since(started)
453-
if err != nil {
454-
if errors.Is(err, berrors.RateLimit) {
455-
ra.rlCheckLatency.WithLabelValues(ratelimit.RegistrationsPerIPRange, ratelimits.Denied).Observe(elapsed.Seconds())
456-
ra.log.Infof("Rate limit exceeded, RegistrationsByIPRange, IP: %q", ip)
457-
458-
// For the fuzzyRegLimit we use a new error message that specifically
459-
// mentions that the limit being exceeded is applied to a *range* of IPs
460-
return berrors.RateLimitError(0, "too many registrations for this IP range")
461-
}
462-
return err
463-
}
464-
ra.rlCheckLatency.WithLabelValues(ratelimit.RegistrationsPerIPRange, ratelimits.Allowed).Observe(elapsed.Seconds())
465-
}
466-
467-
return nil
468-
}
469-
470418
// NewRegistration constructs a new Registration from a request.
471419
func (ra *RegistrationAuthorityImpl) NewRegistration(ctx context.Context, request *corepb.Registration) (*corepb.Registration, error) {
472420
// Error if the request is nil, there is no account key or IP address
@@ -485,20 +433,6 @@ func (ra *RegistrationAuthorityImpl) NewRegistration(ctx context.Context, reques
485433
return nil, berrors.MalformedError("invalid public key: %s", err.Error())
486434
}
487435

488-
// Check IP address rate limits.
489-
var ipAddr net.IP
490-
err = ipAddr.UnmarshalText(request.InitialIP)
491-
if err != nil {
492-
return nil, berrors.InternalServerError("failed to unmarshal ip address: %s", err.Error())
493-
}
494-
495-
if !features.Get().UseKvLimitsForNewAccount {
496-
err = ra.checkRegistrationLimits(ctx, ipAddr)
497-
if err != nil {
498-
return nil, err
499-
}
500-
}
501-
502436
// Check that contacts conform to our expectations.
503437
err = validateContactsPresent(request.Contact, request.ContactsPresent)
504438
if err != nil {

ra/ra_test.go

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -628,90 +628,6 @@ func TestNewRegistrationBadKey(t *testing.T) {
628628
test.AssertError(t, err, "Should have rejected authorization with short key")
629629
}
630630

631-
func TestNewRegistrationRateLimit(t *testing.T) {
632-
_, _, ra, _, cleanUp := initAuthorities(t)
633-
defer cleanUp()
634-
635-
// Specify a dummy rate limit policy that allows 1 registration per exact IP
636-
// match, and 2 per range.
637-
ra.rlPolicies = &dummyRateLimitConfig{
638-
RegistrationsPerIPPolicy: ratelimit.RateLimitPolicy{
639-
Threshold: 1,
640-
Window: config.Duration{Duration: 24 * 90 * time.Hour},
641-
},
642-
RegistrationsPerIPRangePolicy: ratelimit.RateLimitPolicy{
643-
Threshold: 2,
644-
Window: config.Duration{Duration: 24 * 90 * time.Hour},
645-
},
646-
}
647-
648-
// Create one registration for an IPv4 address
649-
mailto := "mailto:[email protected]"
650-
reg := &corepb.Registration{
651-
Contact: []string{mailto},
652-
ContactsPresent: true,
653-
Key: newAcctKey(t),
654-
InitialIP: parseAndMarshalIP(t, "7.6.6.5"),
655-
}
656-
// There should be no errors - it is within the RegistrationsPerIP rate limit
657-
_, err := ra.NewRegistration(ctx, reg)
658-
test.AssertNotError(t, err, "Unexpected error adding new IPv4 registration")
659-
test.AssertMetricWithLabelsEquals(t, ra.rlCheckLatency, prometheus.Labels{"limit": ratelimit.RegistrationsPerIP, "decision": ratelimits.Allowed}, 1)
660-
// There are no overrides for this IP, so the override usage gauge should
661-
// contain 0 entries with labels matching it.
662-
test.AssertMetricWithLabelsEquals(t, ra.rlOverrideUsageGauge, prometheus.Labels{"limit": ratelimit.RegistrationsPerIP, "override_key": "7.6.6.5"}, 0)
663-
664-
// Create another registration for the same IPv4 address by changing the key
665-
reg.Key = newAcctKey(t)
666-
667-
// There should be an error since a 2nd registration will exceed the
668-
// RegistrationsPerIP rate limit
669-
_, err = ra.NewRegistration(ctx, reg)
670-
test.AssertError(t, err, "No error adding duplicate IPv4 registration")
671-
test.AssertEquals(t, err.Error(), "too many registrations for this IP: see https://letsencrypt.org/docs/too-many-registrations-for-this-ip/")
672-
test.AssertMetricWithLabelsEquals(t, ra.rlCheckLatency, prometheus.Labels{"limit": ratelimit.RegistrationsPerIP, "decision": ratelimits.Denied}, 1)
673-
674-
// Create a registration for an IPv6 address
675-
reg.Key = newAcctKey(t)
676-
reg.InitialIP = parseAndMarshalIP(t, "2001:cdba:1234:5678:9101:1121:3257:9652")
677-
678-
// There should be no errors - it is within the RegistrationsPerIP rate limit
679-
_, err = ra.NewRegistration(ctx, reg)
680-
test.AssertNotError(t, err, "Unexpected error adding a new IPv6 registration")
681-
test.AssertMetricWithLabelsEquals(t, ra.rlCheckLatency, prometheus.Labels{"limit": ratelimit.RegistrationsPerIP, "decision": ratelimits.Allowed}, 2)
682-
683-
// Create a 2nd registration for the IPv6 address by changing the key
684-
reg.Key = newAcctKey(t)
685-
686-
// There should be an error since a 2nd reg for the same IPv6 address will
687-
// exceed the RegistrationsPerIP rate limit
688-
_, err = ra.NewRegistration(ctx, reg)
689-
test.AssertError(t, err, "No error adding duplicate IPv6 registration")
690-
test.AssertEquals(t, err.Error(), "too many registrations for this IP: see https://letsencrypt.org/docs/too-many-registrations-for-this-ip/")
691-
test.AssertMetricWithLabelsEquals(t, ra.rlCheckLatency, prometheus.Labels{"limit": ratelimit.RegistrationsPerIP, "decision": ratelimits.Denied}, 2)
692-
693-
// Create a registration for an IPv6 address in the same /48
694-
reg.Key = newAcctKey(t)
695-
reg.InitialIP = parseAndMarshalIP(t, "2001:cdba:1234:5678:9101:1121:3257:9653")
696-
697-
// There should be no errors since two IPv6 addresses in the same /48 is
698-
// within the RegistrationsPerIPRange limit
699-
_, err = ra.NewRegistration(ctx, reg)
700-
test.AssertNotError(t, err, "Unexpected error adding second IPv6 registration in the same /48")
701-
test.AssertMetricWithLabelsEquals(t, ra.rlCheckLatency, prometheus.Labels{"limit": ratelimit.RegistrationsPerIPRange, "decision": ratelimits.Allowed}, 2)
702-
703-
// Create a registration for yet another IPv6 address in the same /48
704-
reg.Key = newAcctKey(t)
705-
reg.InitialIP = parseAndMarshalIP(t, "2001:cdba:1234:5678:9101:1121:3257:9654")
706-
707-
// There should be an error since three registrations within the same IPv6
708-
// /48 is outside of the RegistrationsPerIPRange limit
709-
_, err = ra.NewRegistration(ctx, reg)
710-
test.AssertError(t, err, "No error adding a third IPv6 registration in the same /48")
711-
test.AssertEquals(t, err.Error(), "too many registrations for this IP range: see https://letsencrypt.org/docs/rate-limits/")
712-
test.AssertMetricWithLabelsEquals(t, ra.rlCheckLatency, prometheus.Labels{"limit": ratelimit.RegistrationsPerIPRange, "decision": ratelimits.Denied}, 1)
713-
}
714-
715631
func TestRegistrationsPerIPOverrideUsage(t *testing.T) {
716632
_, _, ra, _, cleanUp := initAuthorities(t)
717633
defer cleanUp()

test/config-next/ra.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@
130130
},
131131
"features": {
132132
"AsyncFinalize": true,
133-
"UseKvLimitsForNewOrder": true,
134-
"UseKvLimitsForNewAccount": true
133+
"UseKvLimitsForNewOrder": true
135134
},
136135
"ctLogs": {
137136
"stagger": "500ms",

test/config-next/wfe2.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@
130130
"ServeRenewalInfo": true,
131131
"TrackReplacementCertificatesARI": true,
132132
"CheckIdentifiersPaused": true,
133-
"UseKvLimitsForNewOrder": true,
134-
"UseKvLimitsForNewAccount": true
133+
"UseKvLimitsForNewOrder": true
135134
},
136135
"certProfiles": {
137136
"legacy": "The normal profile you know and love",

test/config/ra.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@
107107
}
108108
},
109109
"features": {
110-
"CheckRenewalExemptionAtWFE": true
110+
"CheckRenewalExemptionAtWFE": true,
111+
"UseKvLimitsForNewAccount": true
111112
},
112113
"ctLogs": {
113114
"stagger": "500ms",

test/config/wfe2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
"pendingAuthorizationLifetimeDays": 7,
107107
"features": {
108108
"ServeRenewalInfo": true,
109-
"CheckRenewalExemptionAtWFE": true
109+
"CheckRenewalExemptionAtWFE": true,
110+
"UseKvLimitsForNewAccount": true
110111
}
111112
},
112113
"syslog": {

wfe2/wfe.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,8 @@ func (wfe *WebFrontEndImpl) NewAccount(
792792
refundLimits, err := wfe.checkNewAccountLimits(ctx, ip)
793793
if err != nil {
794794
if errors.Is(err, berrors.RateLimit) {
795-
if features.Get().UseKvLimitsForNewAccount {
796-
wfe.sendError(response, logEvent, probs.RateLimited(err.Error()), err)
797-
return
798-
}
795+
wfe.sendError(response, logEvent, probs.RateLimited(err.Error()), err)
796+
return
799797
} else {
800798
wfe.log.Warning(err.Error())
801799
}

0 commit comments

Comments
 (0)