Skip to content

Commit a8cdaf8

Browse files
ratelimit: Remove legacy registrations per IP implementation (#7760)
Part of #7671
1 parent 65de9fb commit a8cdaf8

File tree

22 files changed

+1089
-1780
lines changed

22 files changed

+1089
-1780
lines changed

cmd/contact-auditor/main_test.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package notmain
33
import (
44
"context"
55
"fmt"
6-
"net"
76
"os"
87
"strings"
98
"testing"
@@ -133,37 +132,31 @@ func (tc testCtx) addRegistrations(t *testing.T) {
133132
"e":"AQAB"
134133
}`)
135134

136-
initialIP, err := net.ParseIP("127.0.0.1").MarshalText()
137-
test.AssertNotError(t, err, "Couldn't create initialIP")
138-
139135
regA = &corepb.Registration{
140-
Id: 1,
141-
Contact: []string{emailA},
142-
Key: jsonKeyA,
143-
InitialIP: initialIP,
136+
Id: 1,
137+
Contact: []string{emailA},
138+
Key: jsonKeyA,
144139
}
145140
regB = &corepb.Registration{
146-
Id: 2,
147-
Contact: []string{emailB},
148-
Key: jsonKeyB,
149-
InitialIP: initialIP,
141+
Id: 2,
142+
Contact: []string{emailB},
143+
Key: jsonKeyB,
150144
}
151145
regC = &corepb.Registration{
152-
Id: 3,
153-
Contact: []string{emailC},
154-
Key: jsonKeyC,
155-
InitialIP: initialIP,
146+
Id: 3,
147+
Contact: []string{emailC},
148+
Key: jsonKeyC,
156149
}
157150
// Reg D has a `tel:` contact ACME URL
158151
regD = &corepb.Registration{
159-
Id: 4,
160-
Contact: []string{tel},
161-
Key: jsonKeyD,
162-
InitialIP: initialIP,
152+
Id: 4,
153+
Contact: []string{tel},
154+
Key: jsonKeyD,
163155
}
164156

165157
// Add the four test registrations
166158
ctx := context.Background()
159+
var err error
167160
regA, err = tc.ssa.NewRegistration(ctx, regA)
168161
test.AssertNotError(t, err, "Couldn't store regA")
169162
regB, err = tc.ssa.NewRegistration(ctx, regB)

cmd/expiration-mailer/main_test.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"errors"
1010
"fmt"
1111
"math/big"
12-
"net"
1312
"strings"
1413
"testing"
1514
"text/template"
@@ -462,20 +461,10 @@ func TestFindExpiringCertificates(t *testing.T) {
462461
}
463462

464463
func makeRegistration(sac sapb.StorageAuthorityClient, id int64, jsonKey []byte, contacts []string) (*corepb.Registration, error) {
465-
var ip [4]byte
466-
_, err := rand.Reader.Read(ip[:])
467-
if err != nil {
468-
return nil, err
469-
}
470-
ipText, err := net.IP(ip[:]).MarshalText()
471-
if err != nil {
472-
return nil, fmt.Errorf("formatting IP address: %s", err)
473-
}
474464
reg, err := sac.NewRegistration(context.Background(), &corepb.Registration{
475-
Id: id,
476-
Contact: contacts,
477-
Key: jsonKey,
478-
InitialIP: ipText,
465+
Id: id,
466+
Contact: contacts,
467+
Key: jsonKey,
479468
})
480469
if err != nil {
481470
return nil, fmt.Errorf("storing registration: %s", err)

cmd/id-exporter/main_test.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/base64"
1010
"fmt"
1111
"math/big"
12-
"net"
1312
"os"
1413
"testing"
1514
"time"
@@ -276,38 +275,32 @@ func (tc testCtx) addRegistrations(t *testing.T) {
276275
"e":"AQAB"
277276
}`)
278277

279-
initialIP, err := net.ParseIP("127.0.0.1").MarshalText()
280-
test.AssertNotError(t, err, "Couldn't create initialIP")
281-
282278
// Regs A through C have `mailto:` contact ACME URL's
283279
regA = &corepb.Registration{
284-
Id: 1,
285-
Contact: []string{emailA},
286-
Key: jsonKeyA,
287-
InitialIP: initialIP,
280+
Id: 1,
281+
Contact: []string{emailA},
282+
Key: jsonKeyA,
288283
}
289284
regB = &corepb.Registration{
290-
Id: 2,
291-
Contact: []string{emailB},
292-
Key: jsonKeyB,
293-
InitialIP: initialIP,
285+
Id: 2,
286+
Contact: []string{emailB},
287+
Key: jsonKeyB,
294288
}
295289
regC = &corepb.Registration{
296-
Id: 3,
297-
Contact: []string{emailC},
298-
Key: jsonKeyC,
299-
InitialIP: initialIP,
290+
Id: 3,
291+
Contact: []string{emailC},
292+
Key: jsonKeyC,
300293
}
301294
// Reg D has a `tel:` contact ACME URL
302295
regD = &corepb.Registration{
303-
Id: 4,
304-
Contact: []string{tel},
305-
Key: jsonKeyD,
306-
InitialIP: initialIP,
296+
Id: 4,
297+
Contact: []string{tel},
298+
Key: jsonKeyD,
307299
}
308300

309301
// Add the four test registrations
310302
ctx := context.Background()
303+
var err error
311304
regA, err = tc.ssa.NewRegistration(ctx, regA)
312305
test.AssertNotError(t, err, "Couldn't store regA")
313306
regB, err = tc.ssa.NewRegistration(ctx, regB)

core/objects.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ type Registration struct {
109109
// Agreement with terms of service
110110
Agreement string `json:"agreement,omitempty"`
111111

112-
// InitialIP is the IP address from which the registration was created
113-
InitialIP net.IP `json:"initialIp"`
114-
115112
// CreatedAt is the time the registration was created.
116113
CreatedAt *time.Time `json:"createdAt,omitempty"`
117114

db/map_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestTableFromQuery(t *testing.T) {
122122
expectedTable string
123123
}{
124124
{
125-
query: "SELECT id, jwk, jwk_sha256, contact, agreement, initialIP, createdAt, LockCol, status FROM registrations WHERE jwk_sha256 = ?",
125+
query: "SELECT id, jwk, jwk_sha256, contact, agreement, createdAt, LockCol, status FROM registrations WHERE jwk_sha256 = ?",
126126
expectedTable: "registrations",
127127
},
128128
{
@@ -134,15 +134,15 @@ func TestTableFromQuery(t *testing.T) {
134134
expectedTable: "authz2",
135135
},
136136
{
137-
query: "insert into `registrations` (`id`,`jwk`,`jw k_sha256`,`contact`,`agreement`,`initialIp`,`createdAt`,`LockCol`,`status`) values (null,?,?,?,?,?,?,?,?);",
137+
query: "insert into `registrations` (`id`,`jwk`,`jw k_sha256`,`contact`,`agreement`,`createdAt`,`LockCol`,`status`) values (null,?,?,?,?,?,?,?,?);",
138138
expectedTable: "`registrations`",
139139
},
140140
{
141-
query: "update `registrations` set `jwk`=?, `jwk_sh a256`=?, `contact`=?, `agreement`=?, `initialIp`=?, `createdAt`=?, `LockCol` =?, `status`=? where `id`=? and `LockCol`=?;",
141+
query: "update `registrations` set `jwk`=?, `jwk_sh a256`=?, `contact`=?, `agreement`=?, `createdAt`=?, `LockCol` =?, `status`=? where `id`=? and `LockCol`=?;",
142142
expectedTable: "`registrations`",
143143
},
144144
{
145-
query: "SELECT COUNT(*) FROM registrations WHERE initialIP = ? AND ? < createdAt AND createdAt <= ?",
145+
query: "SELECT COUNT(*) FROM registrations WHERE ? < createdAt AND createdAt <= ?",
146146
expectedTable: "registrations",
147147
},
148148
{

grpc/pb-marshalling.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,6 @@ func RegistrationToPB(reg core.Registration) (*corepb.Registration, error) {
222222
if err != nil {
223223
return nil, err
224224
}
225-
ipBytes, err := reg.InitialIP.MarshalText()
226-
if err != nil {
227-
return nil, err
228-
}
229225
var contacts []string
230226
// Since the default value of corepb.Registration.Contact is a slice
231227
// we need a indicator as to if the value is actually important on
@@ -248,7 +244,6 @@ func RegistrationToPB(reg core.Registration) (*corepb.Registration, error) {
248244
Contact: contacts,
249245
ContactsPresent: contactsPresent,
250246
Agreement: reg.Agreement,
251-
InitialIP: ipBytes,
252247
CreatedAt: createdAt,
253248
Status: string(reg.Status),
254249
}, nil
@@ -260,11 +255,6 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) {
260255
if err != nil {
261256
return core.Registration{}, err
262257
}
263-
var initialIP net.IP
264-
err = initialIP.UnmarshalText(pb.InitialIP)
265-
if err != nil {
266-
return core.Registration{}, err
267-
}
268258
var createdAt *time.Time
269259
if !core.IsAnyNilOrZero(pb.CreatedAt) {
270260
c := pb.CreatedAt.AsTime()
@@ -289,7 +279,6 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) {
289279
Key: &key,
290280
Contact: contacts,
291281
Agreement: pb.Agreement,
292-
InitialIP: initialIP,
293282
CreatedAt: createdAt,
294283
Status: core.AcmeStatus(pb.Status),
295284
}, nil

grpc/pb-marshalling_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ func TestRegistration(t *testing.T) {
181181
Key: &key,
182182
Contact: &contacts,
183183
Agreement: "yup",
184-
InitialIP: net.ParseIP("1.1.1.1"),
185184
CreatedAt: &createdAt,
186185
Status: core.StatusValid,
187186
}
@@ -212,7 +211,6 @@ func TestRegistration(t *testing.T) {
212211
Key: &key,
213212
Contact: &contacts,
214213
Agreement: "yup",
215-
InitialIP: net.ParseIP("1.1.1.1"),
216214
CreatedAt: nil,
217215
Status: core.StatusValid,
218216
}

mocks/sa.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"crypto/x509"
77
"errors"
88
"math/rand/v2"
9-
"net"
109
"os"
1110
"time"
1211

@@ -113,7 +112,6 @@ func (sa *StorageAuthorityReadOnly) GetRegistration(_ context.Context, req *sapb
113112
return goodReg, nil
114113
}
115114

116-
goodReg.InitialIP, _ = net.ParseIP("5.6.7.8").MarshalText()
117115
goodReg.CreatedAt = timestamppb.New(time.Date(2003, 9, 27, 0, 0, 0, 0, time.UTC))
118116
return goodReg, nil
119117
}
@@ -323,16 +321,6 @@ func (sa *StorageAuthorityReadOnly) CountCertificatesByNames(_ context.Context,
323321
return &sapb.CountByNames{}, nil
324322
}
325323

326-
// CountRegistrationsByIP is a mock
327-
func (sa *StorageAuthorityReadOnly) CountRegistrationsByIP(_ context.Context, _ *sapb.CountRegistrationsByIPRequest, _ ...grpc.CallOption) (*sapb.Count, error) {
328-
return &sapb.Count{}, nil
329-
}
330-
331-
// CountRegistrationsByIPRange is a mock
332-
func (sa *StorageAuthorityReadOnly) CountRegistrationsByIPRange(_ context.Context, _ *sapb.CountRegistrationsByIPRequest, _ ...grpc.CallOption) (*sapb.Count, error) {
333-
return &sapb.Count{}, nil
334-
}
335-
336324
// CountOrders is a mock
337325
func (sa *StorageAuthorityReadOnly) CountOrders(_ context.Context, _ *sapb.CountOrdersRequest, _ ...grpc.CallOption) (*sapb.Count, error) {
338326
return &sapb.Count{}, nil

ra/ra.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -386,47 +386,10 @@ type finalizationCAACheckEvent struct {
386386
Rechecked int `json:",omitempty"`
387387
}
388388

389-
// noRegistrationID is used for the regID parameter to GetThreshold when no
390-
// registration-based overrides are necessary.
391-
const noRegistrationID = -1
392-
393-
// registrationCounter is a type to abstract the use of `CountRegistrationsByIP`
394-
// or `CountRegistrationsByIPRange` SA methods.
395-
type registrationCounter func(context.Context, *sapb.CountRegistrationsByIPRequest, ...grpc.CallOption) (*sapb.Count, error)
396-
397-
// checkRegistrationIPLimit checks a specific registraton limit by using the
398-
// provided registrationCounter function to determine if the limit has been
399-
// exceeded for a given IP or IP range
400-
func (ra *RegistrationAuthorityImpl) checkRegistrationIPLimit(ctx context.Context, limit ratelimit.RateLimitPolicy, ip net.IP, counter registrationCounter) error {
401-
now := ra.clk.Now()
402-
count, err := counter(ctx, &sapb.CountRegistrationsByIPRequest{
403-
Ip: ip,
404-
Range: &sapb.Range{
405-
Earliest: timestamppb.New(limit.WindowBegin(now)),
406-
Latest: timestamppb.New(now),
407-
},
408-
})
409-
if err != nil {
410-
return err
411-
}
412-
413-
threshold, overrideKey := limit.GetThreshold(ip.String(), noRegistrationID)
414-
if count.Count >= threshold {
415-
return berrors.RegistrationsPerIPAddressError(0, "too many registrations for this IP")
416-
}
417-
if overrideKey != "" {
418-
// We do not support overrides for the NewRegistrationsPerIPRange limit.
419-
utilization := float64(count.Count+1) / float64(threshold)
420-
ra.rlOverrideUsageGauge.WithLabelValues(ratelimit.RegistrationsPerIP, overrideKey).Set(utilization)
421-
}
422-
423-
return nil
424-
}
425-
426389
// NewRegistration constructs a new Registration from a request.
427390
func (ra *RegistrationAuthorityImpl) NewRegistration(ctx context.Context, request *corepb.Registration) (*corepb.Registration, error) {
428391
// Error if the request is nil, there is no account key or IP address
429-
if request == nil || len(request.Key) == 0 || len(request.InitialIP) == 0 {
392+
if request == nil || len(request.Key) == 0 {
430393
return nil, errIncompleteGRPCRequest
431394
}
432395

@@ -457,7 +420,6 @@ func (ra *RegistrationAuthorityImpl) NewRegistration(ctx context.Context, reques
457420
Contact: request.Contact,
458421
ContactsPresent: request.ContactsPresent,
459422
Agreement: request.Agreement,
460-
InitialIP: request.InitialIP,
461423
Status: string(core.StatusValid),
462424
}
463425

@@ -1627,7 +1589,7 @@ func (ra *RegistrationAuthorityImpl) checkNewOrderLimits(ctx context.Context, na
16271589
// Deprecated: Use UpdateRegistrationContact or UpdateRegistrationKey instead.
16281590
func (ra *RegistrationAuthorityImpl) UpdateRegistration(ctx context.Context, req *rapb.UpdateRegistrationRequest) (*corepb.Registration, error) {
16291591
// Error if the request is nil, there is no account key or IP address
1630-
if req.Base == nil || len(req.Base.Key) == 0 || len(req.Base.InitialIP) == 0 || req.Base.Id == 0 {
1592+
if req.Base == nil || len(req.Base.Key) == 0 || req.Base.Id == 0 {
16311593
return nil, errIncompleteGRPCRequest
16321594
}
16331595

@@ -1741,7 +1703,6 @@ func mergeUpdate(base *corepb.Registration, update *corepb.Registration) (*corep
17411703
Contact: base.Contact,
17421704
ContactsPresent: base.ContactsPresent,
17431705
Agreement: base.Agreement,
1744-
InitialIP: base.InitialIP,
17451706
CreatedAt: base.CreatedAt,
17461707
Status: base.Status,
17471708
}

0 commit comments

Comments
 (0)