Skip to content

Commit cac9498

Browse files
Update the RDS root CA list
The current root is expiring in a few months, so we need to migrate to a new one. We'll be copying similar code to perf, but we can start with making sure it works with triagebot. I've checked that the new CA file contains the old certificate, so this should keep working with our current database (i.e. doesn't need to be synchronized deployment wise with anything).
1 parent b0bbe70 commit cac9498

File tree

3 files changed

+139
-12
lines changed

3 files changed

+139
-12
lines changed

Cargo.lock

Lines changed: 113 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ chrono = { version = "0.4", features = ["serde"] }
3232
tokio-postgres = { version = "0.7.2", features = ["with-chrono-0_4", "with-serde_json-1", "with-uuid-0_8"] }
3333
postgres-native-tls = "0.5.0"
3434
native-tls = "0.2"
35+
x509-cert = { version = "0.2.5", features = ["pem"] }
3536
serde_path_to_error = "0.1.2"
3637
octocrab = "0.30.1"
3738
comrak = { version = "0.8.2", default-features = false }

src/db.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pub mod jobs;
1212
pub mod notifications;
1313
pub mod rustc_commits;
1414

15-
const CERT_URL: &str = "https://s3.amazonaws.com/rds-downloads/rds-ca-2019-root.pem";
15+
const CERT_URL: &str = "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem";
1616

1717
lazy_static::lazy_static! {
18-
static ref CERTIFICATE_PEM: Vec<u8> = {
18+
static ref CERTIFICATE_PEMS: Vec<u8> = {
1919
let client = reqwest::blocking::Client::new();
2020
let resp = client
2121
.get(CERT_URL)
@@ -94,12 +94,11 @@ impl ClientPool {
9494
async fn make_client() -> anyhow::Result<tokio_postgres::Client> {
9595
let db_url = std::env::var("DATABASE_URL").expect("needs DATABASE_URL");
9696
if db_url.contains("rds.amazonaws.com") {
97-
let cert = &CERTIFICATE_PEM[..];
98-
let cert = Certificate::from_pem(&cert).context("made certificate")?;
99-
let connector = TlsConnector::builder()
100-
.add_root_certificate(cert)
101-
.build()
102-
.context("built TlsConnector")?;
97+
let mut builder = TlsConnector::builder();
98+
for cert in make_certificates() {
99+
builder.add_root_certificate(cert);
100+
}
101+
let connector = builder.build().context("built TlsConnector")?;
103102
let connector = MakeTlsConnector::new(connector);
104103

105104
let (db_client, connection) = match tokio_postgres::connect(&db_url, connector).await {
@@ -134,6 +133,24 @@ async fn make_client() -> anyhow::Result<tokio_postgres::Client> {
134133
}
135134
}
136135

136+
fn make_certificates() -> Vec<Certificate> {
137+
use x509_cert::der::pem::LineEnding;
138+
use x509_cert::der::EncodePem;
139+
140+
let certs = x509_cert::Certificate::load_pem_chain(&CERTIFICATE_PEMS[..]).unwrap();
141+
certs
142+
.into_iter()
143+
.map(|cert| Certificate::from_pem(cert.to_pem(LineEnding::LF).unwrap().as_bytes()).unwrap())
144+
.collect()
145+
}
146+
147+
// Makes sure we successfully parse the RDS certificates and load them into native-tls compatible
148+
// format.
149+
#[test]
150+
fn cert() {
151+
make_certificates();
152+
}
153+
137154
pub async fn run_migrations(client: &DbClient) -> anyhow::Result<()> {
138155
client
139156
.execute(

0 commit comments

Comments
 (0)