Skip to content

Commit b4e483d

Browse files
authored
Add gRPC MaxConnectionAge config. (letsencrypt#5311)
This allows servers to tell clients to go away after some period of time, which triggers the clients to re-resolve DNS. Per grpc/grpc#12295, this is the preferred way to do this. Related: letsencrypt#5307.
1 parent 066ed34 commit b4e483d

File tree

12 files changed

+29
-3
lines changed

12 files changed

+29
-3
lines changed

cmd/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ type GRPCServerConfig struct {
269269
// (SANs). The server will reject clients that do not present a certificate
270270
// with a SAN present on the `ClientNames` list.
271271
ClientNames []string `json:"clientNames"`
272+
// MaxConnectionAge specifies how long a connection may live before the server sends a GoAway to the
273+
// client. Because gRPC connections re-resolve DNS after a connection close,
274+
// this controls how long it takes before a client learns about changes to its
275+
// backends.
276+
// https://pkg.go.dev/google.golang.org/grpc/keepalive#ServerParameters
277+
MaxConnectionAge ConfigDuration
272278
}
273279

274280
// PortConfig specifies what ports the VA should call to on the remote

grpc/server.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"errors"
66
"net"
77

8-
"github.com/grpc-ecosystem/go-grpc-prometheus"
8+
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
99
"github.com/jmhodges/clock"
1010
"github.com/letsencrypt/boulder/cmd"
1111
bcreds "github.com/letsencrypt/boulder/grpc/creds"
1212
"github.com/prometheus/client_golang/prometheus"
1313
"google.golang.org/grpc"
14+
"google.golang.org/grpc/keepalive"
1415
)
1516

1617
// CodedError is a alias required to appease go vet
@@ -42,10 +43,17 @@ func NewServer(c *cmd.GRPCServerConfig, tlsConfig *tls.Config, metrics serverMet
4243
}
4344

4445
si := newServerInterceptor(metrics, clk)
45-
return grpc.NewServer(
46+
options := []grpc.ServerOption{
4647
grpc.Creds(creds),
4748
grpc.UnaryInterceptor(si.intercept),
48-
), l, nil
49+
}
50+
if c.MaxConnectionAge.Duration > 0 {
51+
options = append(options,
52+
grpc.KeepaliveParams(keepalive.ServerParameters{
53+
MaxConnectionAge: c.MaxConnectionAge.Duration,
54+
}))
55+
}
56+
return grpc.NewServer(options...), l, nil
4957
}
5058

5159
// serverMetrics is a struct type used to return a few registered metrics from

test/config-next/akamai-purger.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"grpc": {
1616
"address": ":9099",
17+
"maxConnectionAge": "30s",
1718
"clientNames": [
1819
"health-checker.boulder",
1920
"ra.boulder"

test/config-next/ca-a.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
},
99
"hostnamePolicyFile": "test/hostname-policy.yaml",
1010
"grpcCA": {
11+
"maxConnectionAge": "30s",
1112
"address": ":9093",
1213
"clientNames": [
1314
"health-checker.boulder",
1415
"ra.boulder"
1516
]
1617
},
1718
"grpcOCSPGenerator": {
19+
"maxConnectionAge": "30s",
1820
"address": ":9096",
1921
"clientNames": [
2022
"health-checker.boulder",

test/config-next/ca-b.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
},
99
"hostnamePolicyFile": "test/hostname-policy.yaml",
1010
"grpcCA": {
11+
"maxConnectionAge": "30s",
1112
"address": ":9093",
1213
"clientNames": [
1314
"health-checker.boulder",
1415
"ra.boulder"
1516
]
1617
},
1718
"grpcOCSPGenerator": {
19+
"maxConnectionAge": "30s",
1820
"address": ":9096",
1921
"clientNames": [
2022
"health-checker.boulder",

test/config-next/nonce.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
},
99
"debugAddr": ":8111",
1010
"grpc": {
11+
"maxConnectionAge": "30s",
1112
"address": ":9101",
1213
"clientNames": [
1314
"health-checker.boulder",

test/config-next/publisher.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"blockProfileRate": 1000000000,
55
"debugAddr": ":8009",
66
"grpc": {
7+
"maxConnectionAge": "30s",
78
"address": ":9091",
89
"clientNames": [
910
"health-checker.boulder",

test/config-next/ra.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"timeout": "15s"
4343
},
4444
"grpc": {
45+
"maxConnectionAge": "30s",
4546
"address": ":9094",
4647
"clientNames": [
4748
"admin-revoker.boulder",

test/config-next/sa.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"keyFile": "test/grpc-creds/sa.boulder/key.pem"
1313
},
1414
"grpc": {
15+
"maxConnectionAge": "30s",
1516
"address": ":9095",
1617
"clientNames": [
1718
"admin-revoker.boulder",

test/config-next/va-remote-a.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"keyFile": "test/grpc-creds/va.boulder/key.pem"
2020
},
2121
"grpc": {
22+
"maxConnectionAge": "30s",
2223
"address": ":9097",
2324
"clientNames": [
2425
"health-checker.boulder",

0 commit comments

Comments
 (0)