Skip to content

Enforce new orders per acct per window rate limit.#3501

Merged
rolandshoemaker merged 6 commits into
masterfrom
cpu-v2-orders-per-window-rl
Mar 2, 2018
Merged

Enforce new orders per acct per window rate limit.#3501
rolandshoemaker merged 6 commits into
masterfrom
cpu-v2-orders-per-window-rl

Conversation

@cpu

@cpu cpu commented Mar 1, 2018

Copy link
Copy Markdown
Contributor

Previously we introduced the concept of a "pending orders per account
ID" rate limit. After struggling with making an implementation of this
rate limit perform well we reevaluated the problem and decided a "new
orders per account per time window" rate limit would be a better fit for
ACMEv2 overall.

This commit introduces the new newOrdersPerAccount rate limit. The RA
now checks this before creating new pending orders in ra.NewOrder. It
does so after order reuse takes place ensuring the rate limit is only
applied in cases when a distinct new pending order row would be created.
To accomplish this a migration for a new orders field (created) and an
index over created and registrationID is added. It would be possible to
use the existing expires field for this like we've done in the past, but that
was primarily to avoid running a migration on a large table in prod. Since
we don't have that problem yet for V2 tables we can Do The Right Thing
and add a column.

For deployability the deprecated pendingOrdersPerAccount code & SA
gRPC bits are left around. A follow-up PR will be needed to remove
those (#3502).

Resolves #3410

Previously we introduced the concept of a "pending orders per account
ID" rate limit. After struggling with making an implementation of this
rate limit perform well we reevaluated the problem and decided a "new
orders per account per time window" rate limit would be a better fit for
ACMEv2 overall.

This commit introduces the new `newOrdersPerAccount` rate limit. The RA
now checks this before creating new pending orders in `ra.NewOrder`. It
does so _after_ order reuse takes place ensuring the rate limit is only
applied in cases when a distinct new pending order row would be created.

For deployability the deprecated `pendingOrdersPerAccount` code & SA
gRPC bits are left around. A follow-up PR will be needed to remove
those.
@cpu cpu self-assigned this Mar 1, 2018
@cpu cpu requested review from jsha and rolandshoemaker March 1, 2018 00:04
@cpu cpu requested a review from a team as a code owner March 1, 2018 00:04

@jsha jsha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great, thanks for the quick turnaround on this! On nit: I think the SA method should be called CountOrders rather than CountNewOrders.

@cpu

cpu commented Mar 1, 2018

Copy link
Copy Markdown
Contributor Author

I think the SA method should be called CountOrders rather than CountNewOrders.

@jsha agreed. Resolved in 582789c. Thanks!

jsha
jsha previously approved these changes Mar 1, 2018

@rolandshoemaker rolandshoemaker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small questions. Also currently there are no checks for order.Created in the various gRPC wrapper files, which is necessary for deployability but could we add a comment/open a issue that we will need to add those checks once the code has been deployed.

Comment thread ra/ra.go

// Check that the registration ID in question has rate limit space for another
// pending order
if err := ra.checkPendingOrderLimit(ctx, *req.RegistrationID); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not also kill off the checkPendingOrderLimit code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense. I think I was overly generous in what I left around for the deployability guidelines.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 000d0c9

Comment thread ra/ra.go
// order

// Check if there is rate limit space for a new order within the current window
if err := ra.checkNewOrdersPerAccountLimit(ctx, *order.RegistrationID); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is for an API that isn't yet prod but given if this doesn't work how we want (or has negative side effects) I kind of think this should be gated behind a feature... I could probably be convinced that isn't needed though.

@cpu cpu Mar 1, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this feedback and your feedback about killing off ra.checkPendingOrderLimit are hard to achieve together.

If I delete the ra.checkPendingOrderLimit impl in the RA (and the call from ra.NewOrder that is already deleted stays deleted), then the feature flag would make NewOrder limitless (minus the authz limits ofc) if disabled which seems more harmful overall.

I'm slightly inclined to not introduce the feature flag here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be done (i.e. if featureEnabled { limitA } else { limitB }) but your right it would require keeping the old code around. I'm fine going forward without it to be honest, I'm just hesitant that if we ever need to back it out we'll need to essentially revert and re-deploy, which is a pain.

That said... this code looks right enough to me, so I'm happy to just dive in head first 😄.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YOLO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just hesitant that if we ever need to back it out we'll need to essentially revert and re-deploy, which is a pain.

That's true, but the pain of doing so only in staging is relatively minor compared to a prod revert.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For rate limits, the limit.Enabled() flag acts as a good feature flag, since Enabled() will return false if there is not entry for that limit.

@cpu

cpu commented Mar 1, 2018

Copy link
Copy Markdown
Contributor Author

@jsha @rolandshoemaker Ready for more 🔍's

@rolandshoemaker

Copy link
Copy Markdown
Contributor

Ping on

currently there are no checks for order.Created in the various gRPC wrapper files, which is necessary for deployability but could we add a comment/open a issue that we will need to add those checks once the code has been deployed.

Otherwise looks fine.

@cpu

cpu commented Mar 1, 2018

Copy link
Copy Markdown
Contributor Author

currently there are no checks for order.Created in the various gRPC wrapper files,

Missed that feedback, thanks! Resolved in 5fa5f33

jsha
jsha previously approved these changes Mar 1, 2018
@rolandshoemaker rolandshoemaker merged commit f2d3ad6 into master Mar 2, 2018
@cpu cpu deleted the cpu-v2-orders-per-window-rl branch March 2, 2018 18:48
cpu pushed a commit that referenced this pull request Mar 6, 2018
#3501 made this code
deprecated. We've deployed 3501 to the staging environment and can now
pull out the old cruft.
rolandshoemaker pushed a commit that referenced this pull request Mar 6, 2018
#3501 made this code deprecated. We've deployed 3501 to the staging environment and can now pull out the old cruft.

Resolves #3502
beautifulentropy added a commit that referenced this pull request Aug 28, 2023
Remove PendingOrdersPerAccount, which was officially deprecated in #3501
(5 years ago).

Part of #5545
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants