-
-
Notifications
You must be signed in to change notification settings - Fork 643
Restrict WFE account cache to POST-as-GET requests #8852
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
Draft
aarongable
wants to merge
4
commits into
main
Choose a base branch
from
get-only-account-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,12 @@ import ( | |
| "github.com/letsencrypt/boulder/goodkey" | ||
| bgrpc "github.com/letsencrypt/boulder/grpc" | ||
| "github.com/letsencrypt/boulder/grpc/noncebalancer" | ||
| "github.com/letsencrypt/boulder/metrics" | ||
| "github.com/letsencrypt/boulder/nonce" | ||
| noncepb "github.com/letsencrypt/boulder/nonce/proto" | ||
| sapb "github.com/letsencrypt/boulder/sa/proto" | ||
| "github.com/letsencrypt/boulder/test" | ||
| inmemnonce "github.com/letsencrypt/boulder/test/inmem/nonce" | ||
| "github.com/letsencrypt/boulder/web" | ||
| ) | ||
|
|
||
|
|
@@ -1175,7 +1178,7 @@ func TestLookupJWK(t *testing.T) { | |
| in := tc.JWS.Signatures[0].Header | ||
| inputLogEvent := newRequestEvent() | ||
|
|
||
| gotJWK, gotAcct, gotErr := wfe.lookupJWK(in, context.Background(), tc.Request, inputLogEvent) | ||
| gotJWK, gotAcct, gotErr := wfe.lookupJWK(t.Context(), in, tc.Request, wfe.accountCache, inputLogEvent) | ||
| if tc.WantErrDetail == "" { | ||
| if gotErr != nil { | ||
| t.Fatalf("lookupJWK(%#v) = %#v, want nil", in, gotErr) | ||
|
|
@@ -1392,7 +1395,7 @@ func TestValidPOSTForAccount(t *testing.T) { | |
| wfe.stats.joseErrorCount.Reset() | ||
| inputLogEvent := newRequestEvent() | ||
|
|
||
| gotPayload, gotJWS, gotAcct, gotErr := wfe.validPOSTForAccount(tc.Request, context.Background(), inputLogEvent) | ||
| gotPayload, gotJWS, gotAcct, gotErr := wfe.validPOSTForAccount(t.Context(), tc.Request, inputLogEvent) | ||
| if tc.WantErrDetail == "" { | ||
| if gotErr != nil { | ||
| t.Fatalf("validPOSTForAccount(%#v) = %#v, want nil", tc.Request, gotErr) | ||
|
|
@@ -1420,8 +1423,103 @@ func TestValidPOSTForAccount(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| type staticRegistrationGetter struct { | ||
| sapb.StorageAuthorityReadOnlyClient | ||
| registration *corepb.Registration | ||
| calls int | ||
| } | ||
|
|
||
| func (getter *staticRegistrationGetter) GetRegistration( | ||
| _ context.Context, | ||
| in *sapb.RegistrationID, | ||
| _ ...grpc.CallOption, | ||
| ) (*corepb.Registration, error) { | ||
| getter.calls++ | ||
| if in.Id == getter.registration.Id { | ||
| return getter.registration, nil | ||
| } | ||
| return nil, berrors.NotFound | ||
| } | ||
|
|
||
| type rejectingRegistrationGetter struct { | ||
| sapb.StorageAuthorityReadOnlyClient | ||
| t *testing.T | ||
| } | ||
|
|
||
| func (getter rejectingRegistrationGetter) GetRegistration( | ||
| _ context.Context, | ||
| _ *sapb.RegistrationID, | ||
| _ ...grpc.CallOption, | ||
| ) (*corepb.Registration, error) { | ||
| getter.t.Fatal("validPOSTForCurrentAccount used cached account getter") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and below in the test function names I think you mean |
||
| return nil, nil | ||
| } | ||
|
|
||
| func registrationForAuthTest(key []byte, status core.AcmeStatus) *corepb.Registration { | ||
| return &corepb.Registration{ | ||
| Id: 1, | ||
| Key: key, | ||
| Agreement: agreementURL, | ||
| Status: string(status), | ||
| } | ||
| } | ||
|
|
||
| func setupAuthOnlyWFE( | ||
| t *testing.T, | ||
| freshAccount *corepb.Registration, | ||
| ) (WebFrontEndImpl, requestSigner, *staticRegistrationGetter) { | ||
| t.Helper() | ||
|
|
||
| rncKey := []byte("b8c758dd85e113ea340ce0b3a99f389d40a308548af94d1730a7692c1874f1f") | ||
| noncePrefix := nonce.DerivePrefix("192.168.1.1:8080", rncKey) | ||
| nonceService, err := nonce.NewNonceService(metrics.NoopRegisterer, 100, noncePrefix) | ||
| test.AssertNotError(t, err, "making nonceService") | ||
|
|
||
| inmemNonceService := &inmemnonce.NonceService{Impl: nonceService} | ||
| freshGetter := &staticRegistrationGetter{registration: freshAccount} | ||
| wfe := WebFrontEndImpl{ | ||
| sa: freshGetter, | ||
| rnc: inmemNonceService, | ||
| rncKey: rncKey, | ||
| accountCache: rejectingRegistrationGetter{t: t}, | ||
| stats: initStats(metrics.NoopRegisterer), | ||
| } | ||
|
|
||
| return wfe, requestSigner{t, inmemNonceService.AsSource()}, freshGetter | ||
| } | ||
|
|
||
| func TestValidPOSTForCurrentAccountRejectsCachedDeactivatedAccount(t *testing.T) { | ||
| wfe, signer, freshGetter := setupAuthOnlyWFE( | ||
| t, | ||
| registrationForAuthTest([]byte(test1KeyPublicJSON), core.StatusDeactivated), | ||
| ) | ||
|
|
||
| _, _, body := signer.byKeyID(1, nil, "http://localhost/test", "{}") | ||
| request := makePostRequestWithPath("test", body) | ||
|
|
||
| _, _, _, err := wfe.validPOSTForAccount(ctx, request, newRequestEvent()) | ||
| test.AssertErrorIs(t, err, berrors.Unauthorized) | ||
| test.AssertContains(t, err.Error(), `Account is not valid, has status "deactivated"`) | ||
| test.AssertEquals(t, freshGetter.calls, 1) | ||
| } | ||
|
|
||
| func TestValidPOSTForCurrentAccountRejectsCachedPreRolloverKey(t *testing.T) { | ||
| wfe, signer, freshGetter := setupAuthOnlyWFE( | ||
| t, | ||
| registrationForAuthTest([]byte(test2KeyPublicJSON), core.StatusValid), | ||
| ) | ||
|
|
||
| _, _, body := signer.byKeyID(1, nil, "http://localhost/test", "{}") | ||
| request := makePostRequestWithPath("test", body) | ||
|
|
||
| _, _, _, err := wfe.validPOSTForAccount(ctx, request, newRequestEvent()) | ||
| test.AssertErrorIs(t, err, berrors.Malformed) | ||
| test.AssertContains(t, err.Error(), "JWS verification error") | ||
| test.AssertEquals(t, freshGetter.calls, 1) | ||
| } | ||
|
|
||
| // TestValidPOSTAsGETForAccount tests POST-as-GET processing. Because | ||
| // wfe.validPOSTAsGETForAccount calls `wfe.validPOSTForAccount` to do all | ||
| // wfe.validPOSTAsGETForAccount uses the configured account getter for all | ||
| // processing except the empty body test we do not duplicate the | ||
| // `TestValidPOSTForAccount` testcases here. | ||
| func TestValidPOSTAsGETForAccount(t *testing.T) { | ||
|
|
@@ -1459,7 +1557,7 @@ func TestValidPOSTAsGETForAccount(t *testing.T) { | |
| for _, tc := range testCases { | ||
| t.Run(tc.Name, func(t *testing.T) { | ||
| ev := newRequestEvent() | ||
| _, gotErr := wfe.validPOSTAsGETForAccount(tc.Request, context.Background(), ev) | ||
| _, gotErr := wfe.validPOSTAsGETForAccount(t.Context(), tc.Request, ev) | ||
| if tc.WantErrDetail == "" { | ||
| if gotErr != nil { | ||
| t.Fatalf("validPOSTAsGETForAccount(%#v) = %#v, want nil", tc.Request, gotErr) | ||
|
|
@@ -1497,7 +1595,7 @@ func (sa mockSADifferentStoredKey) GetRegistration(_ context.Context, _ *sapb.Re | |
| func TestValidPOSTForAccountSwappedKey(t *testing.T) { | ||
| wfe, _, signer := setupWFE(t) | ||
| wfe.sa = &mockSADifferentStoredKey{} | ||
| wfe.accountGetter = wfe.sa | ||
| wfe.accountCache = wfe.sa | ||
| event := newRequestEvent() | ||
|
|
||
| payload := `{"resource":"ima-payload"}` | ||
|
|
@@ -1508,7 +1606,7 @@ func TestValidPOSTForAccountSwappedKey(t *testing.T) { | |
| // Ensure that ValidPOSTForAccount produces an error since the | ||
| // mockSADifferentStoredKey will return a different key than the one we used to | ||
| // sign the request | ||
| _, _, _, err := wfe.validPOSTForAccount(request, ctx, event) | ||
| _, _, _, err := wfe.validPOSTForAccount(ctx, request, event) | ||
| test.AssertError(t, err, "No error returned for request signed by wrong key") | ||
| test.AssertErrorIs(t, err, berrors.Malformed) | ||
| test.AssertContains(t, err.Error(), "JWS verification error") | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I'm reading this wrong, but I think the requests this comment describes mostly don't reach this function. Specifically authz and challenge polling are both handled by functions that call
validPOSTForAccount(). From the stats I looked at a couple weeks ago I believe this change will decrease the cache hit rate from ~60% to ~14, if not worse due to a lack of warming.