Commit c807e9f
committed
Enable TLS automatically for Amazon RDS endpoints
A connection to an *.rds.amazonaws.com address now verifies against Amazon's
RDS root bundle, embedded here, unless the DSN asked for something else.
Three Block repositories had already written this: strata's pkg/mysqlrds,
vitess's go/vt/topo/mysqltopo, and spirit's pkg/dbconn each carry a copy of the
bundle, a hostname regexp, and a RegisterTLSConfig call. They agree on what
should happen and disagree on the details — two of the three regexps require
the leading dot in `.rds.amazonaws.com` and one does not, one pins a TLS
minimum version and two take the Go default, one checks the result of
AppendCertsFromPEM and two discard it, and strata's bundle is three
ca-west-1 roots newer than the other two. Every consumer of the driver has to
get all of that right independently, and getting it wrong by omission produces
an unencrypted connection rather than an error.
The driver is where this belongs: it is the only layer that sees every
connection, and the address is all the input it needs.
Design:
- The hook is one line in Config.normalize, so it covers both entry points
(ParseDSN and NewConnector) and everything downstream of them. All the
logic is in rds.go, a file upstream does not have.
- It fires only when neither cfg.TLS nor cfg.TLSConfig is set, so anything
the DSN specifies wins — including tls=false, which is the documented
opt-out. normalize then fills in ServerName as it does for any other
config, making this identity verification and not just encryption.
- The regexp requires the leading dot. Without it `notrds.amazonaws.com`
matches; that fails safely (verification against RDS roots fails rather
than trusting the wrong CA) but a confusing handshake error is still worse
than not matching.
- MinVersion is TLS 1.2 rather than the Go default, so a future change to
that default cannot quietly weaken an RDS connection.
- The bundle is the newest of the three (strata's, which has ca-west-1), and
covers the aws partition only — which is why the regexp does not match the
China or GovCloud endpoint forms. RDSTLSConfig() is exported for anything
that needs the trust store under a different name.
Tests cover the endpoint patterns including the near-misses, the precedence of
each way a DSN can specify TLS, the independence of the per-connection configs
(normalize writes ServerName into them), and the bundle itself — a truncated
PEM would otherwise parse into an empty pool and fail every RDS connection at
handshake time, a long way from the mistake.
Full suite passes against MySQL 8.0.44, race enabled.1 parent a3178f8 commit c807e9f
5 files changed
Lines changed: 3377 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | | - | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
25 | 32 | | |
26 | 33 | | |
27 | 34 | | |
| |||
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
82 | 90 | | |
83 | 91 | | |
84 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
234 | 239 | | |
235 | 240 | | |
236 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
0 commit comments