-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WFE: Correct Error Handling for Nonce Redemption RPCs with Unknown Pr…
…efixes (#7004) Fix an issue related to the custom gRPC Picker implementation introduced in #6618. When a nonce contained a prefix not associated with a known backend, the Picker would continuously rebuild, re-resolve DNS, and eventually throw a 500 "Server Error" at RPC timeout. The Picker now promptly returns a 400 "Bad Nonce" error as expected, in response the requesting client should retry their request with a fresh nonce. Additionally: - WFE unit tests use derived nonces when `"BOULDER_CONFIG_DIR" == "test/config-next"`. - `Balancer.Build()` in "noncebalancer" forces a rebuild until non-zero backends are available. This matches the [balancer/roundrobin](https://github.com/grpc/grpc-go/blob/d524b409462c601ef3f05a7e1fba19755a337c77/balancer/roundrobin/roundrobin.go#L49-L53) implementation. - Nonces with no matching backend increment "jose_errors" with label `"type": "JWSInvalidNonce"` and "nonce_no_backend_found". - Nonces of incorrect length are now rejected at the WFE and increment "jose_errors" with label `"type": "JWSMalformedNonce"` instead of `"type": "JWSInvalidNonce"`. - Nonces not encoded as base64url are now rejected at the WFE and increment "jose_errors" with label `"type": "JWSMalformedNonce"` instead of `"type": "JWSInvalidNonce"`. Fixes #6969 Part of #6974
- Loading branch information
1 parent
4da9853
commit b141fa7
Showing
9 changed files
with
366 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/jmhodges/clock" | ||
|
||
"github.com/letsencrypt/boulder/cmd" | ||
bgrpc "github.com/letsencrypt/boulder/grpc" | ||
nb "github.com/letsencrypt/boulder/grpc/noncebalancer" | ||
"github.com/letsencrypt/boulder/metrics" | ||
"github.com/letsencrypt/boulder/nonce" | ||
noncepb "github.com/letsencrypt/boulder/nonce/proto" | ||
"github.com/letsencrypt/boulder/test" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
type Config struct { | ||
NotWFE struct { | ||
TLS cmd.TLSConfig | ||
GetNonceService *cmd.GRPCClientConfig | ||
RedeemNonceService *cmd.GRPCClientConfig | ||
NoncePrefixKey cmd.PasswordConfig | ||
} | ||
} | ||
|
||
func TestNonceBalancer_NoBackendMatchingPrefix(t *testing.T) { | ||
t.Parallel() | ||
|
||
if !strings.Contains(os.Getenv("BOULDER_CONFIG_DIR"), "test/config-next") { | ||
t.Skip("Derived nonce prefixes are only configured in config-next") | ||
} | ||
|
||
// We're going to use a minimal nonce service client called "notwfe" which | ||
// masquerades as a wfe for the purpose of redeeming nonces. | ||
|
||
// Load the test config. | ||
var c Config | ||
err := cmd.ReadConfigFile("test/integration/testdata/nonce-client.json", &c) | ||
test.AssertNotError(t, err, "Could not read config file") | ||
|
||
tlsConfig, err := c.NotWFE.TLS.Load(metrics.NoopRegisterer) | ||
test.AssertNotError(t, err, "Could not load TLS config") | ||
|
||
rncKey, err := c.NotWFE.NoncePrefixKey.Pass() | ||
test.AssertNotError(t, err, "Failed to load noncePrefixKey") | ||
|
||
clk := clock.New() | ||
|
||
redeemNonceConn, err := bgrpc.ClientSetup(c.NotWFE.RedeemNonceService, tlsConfig, metrics.NoopRegisterer, clk) | ||
test.AssertNotError(t, err, "Failed to load credentials and create gRPC connection to redeem nonce service") | ||
rnc := nonce.NewRedeemer(redeemNonceConn) | ||
|
||
// Attempt to redeem a nonce with a prefix that doesn't match any backends. | ||
ctx := context.WithValue(context.Background(), nonce.PrefixCtxKey{}, "12345678") | ||
ctx = context.WithValue(ctx, nonce.HMACKeyCtxKey{}, rncKey) | ||
_, err = rnc.Redeem(ctx, &noncepb.NonceMessage{Nonce: "0123456789"}) | ||
|
||
// We expect to get a specific gRPC status error with code NotFound. | ||
gotRPCStatus, ok := status.FromError(err) | ||
test.Assert(t, ok, "Failed to convert error to status") | ||
test.AssertEquals(t, gotRPCStatus, nb.ErrNoBackendsMatchPrefix) | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"notwfe": { | ||
"tls": { | ||
"caCertFile": "test/grpc-creds/minica.pem", | ||
"certFile": "test/grpc-creds/wfe.boulder/cert.pem", | ||
"keyFile": "test/grpc-creds/wfe.boulder/key.pem" | ||
}, | ||
"getNonceService": { | ||
"dnsAuthority": "consul.service.consul", | ||
"srvLookup": { | ||
"service": "nonce", | ||
"domain": "service.consul" | ||
}, | ||
"timeout": "15s", | ||
"noWaitForReady": true, | ||
"hostOverride": "nonce.boulder" | ||
}, | ||
"redeemNonceService": { | ||
"dnsAuthority": "consul.service.consul", | ||
"srvLookups": [ | ||
{ | ||
"service": "nonce1", | ||
"domain": "service.consul" | ||
}, | ||
{ | ||
"service": "nonce2", | ||
"domain": "service.consul" | ||
} | ||
], | ||
"srvResolver": "nonce-srv", | ||
"timeout": "15s", | ||
"noWaitForReady": true, | ||
"hostOverride": "nonce.boulder" | ||
}, | ||
"noncePrefixKey": { | ||
"passwordFile": "test/secrets/nonce_prefix_key" | ||
} | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.