Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ratelimits: Implement batched Spends and Refunds #7143

Merged
merged 16 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/boulder-wfe2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,18 @@ func main() {
pendingAuthorizationLifetime := time.Duration(c.WFE.PendingAuthorizationLifetimeDays) * 24 * time.Hour

var limiter *ratelimits.Limiter
var txnBuilder *ratelimits.TransactionBuilder
var limiterRedis *bredis.Ring
if c.WFE.Limiter.Defaults != "" {
// Setup rate limiting.
limiterRedis, err = bredis.NewRingFromConfig(*c.WFE.Limiter.Redis, stats, logger)
cmd.FailOnError(err, "Failed to create Redis ring")

source := ratelimits.NewRedisSource(limiterRedis.Ring, clk, stats)
limiter, err = ratelimits.NewLimiter(clk, source, c.WFE.Limiter.Defaults, c.WFE.Limiter.Overrides, stats)
limiter, err = ratelimits.NewLimiter(clk, source, stats)
cmd.FailOnError(err, "Failed to create rate limiter")
txnBuilder, err = ratelimits.NewTransactionBuilder(c.WFE.Limiter.Defaults, c.WFE.Limiter.Overrides)
cmd.FailOnError(err, "Failed to create rate limits transaction builder")
}

var accountGetter wfe2.AccountGetter
Expand Down Expand Up @@ -380,6 +383,7 @@ func main() {
npKey,
accountGetter,
limiter,
txnBuilder,
)
cmd.FailOnError(err, "Unable to create WFE")

Expand Down
23 changes: 1 addition & 22 deletions ra/ra.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/jmhodges/clock"
"github.com/prometheus/client_golang/prometheus"
"github.com/weppos/publicsuffix-go/publicsuffix"
"golang.org/x/crypto/ocsp"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -1375,26 +1374,6 @@ func (ra *RegistrationAuthorityImpl) getSCTs(ctx context.Context, cert []byte, e
return scts, nil
}

// domainsForRateLimiting transforms a list of FQDNs into a list of eTLD+1's
// for the purpose of rate limiting. It also de-duplicates the output
// domains. Exact public suffix matches are included.
func domainsForRateLimiting(names []string) []string {
var domains []string
for _, name := range names {
domain, err := publicsuffix.Domain(name)
if err != nil {
// The only possible errors are:
// (1) publicsuffix.Domain is giving garbage values
// (2) the public suffix is the domain itself
// We assume 2 and include the original name in the result.
domains = append(domains, name)
} else {
domains = append(domains, domain)
}
}
return core.UniqueLowerNames(domains)
}

// enforceNameCounts uses the provided count RPC to find a count of certificates
// for each of the names. If the count for any of the names exceeds the limit
// for the given registration then the names out of policy are returned to be
Expand Down Expand Up @@ -1465,7 +1444,7 @@ func (ra *RegistrationAuthorityImpl) checkCertificatesPerNameLimit(ctx context.C
return nil
}

tldNames := domainsForRateLimiting(names)
tldNames := ratelimits.DomainsForRateLimiting(names)
namesOutOfLimit, earliest, err := ra.enforceNameCounts(ctx, tldNames, limit, regID)
if err != nil {
return fmt.Errorf("checking certificates per name limit for %q: %s",
Expand Down
20 changes: 0 additions & 20 deletions ra/ra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,26 +1114,6 @@ func TestAuthzFailedRateLimitingNewOrder(t *testing.T) {
testcase()
}

func TestDomainsForRateLimiting(t *testing.T) {
domains := domainsForRateLimiting([]string{})
test.AssertEquals(t, len(domains), 0)

domains = domainsForRateLimiting([]string{"www.example.com", "example.com"})
test.AssertDeepEquals(t, domains, []string{"example.com"})

domains = domainsForRateLimiting([]string{"www.example.com", "example.com", "www.example.co.uk"})
test.AssertDeepEquals(t, domains, []string{"example.co.uk", "example.com"})

domains = domainsForRateLimiting([]string{"www.example.com", "example.com", "www.example.co.uk", "co.uk"})
test.AssertDeepEquals(t, domains, []string{"co.uk", "example.co.uk", "example.com"})

domains = domainsForRateLimiting([]string{"foo.bar.baz.www.example.com", "baz.example.com"})
test.AssertDeepEquals(t, domains, []string{"example.com"})

domains = domainsForRateLimiting([]string{"github.io", "foo.github.io", "bar.github.io"})
test.AssertDeepEquals(t, domains, []string{"bar.github.io", "foo.github.io", "github.io"})
}

type mockSAWithNameCounts struct {
mocks.StorageAuthority
nameCounts *sapb.CountByNames
Expand Down
Loading