diff --git a/cdk/lambdas/rssFetcher/index.ts b/cdk/lambdas/rssFetcher/index.ts index c509de336..89a02b7ea 100644 --- a/cdk/lambdas/rssFetcher/index.ts +++ b/cdk/lambdas/rssFetcher/index.ts @@ -188,6 +188,9 @@ exports.handler = async function () { const client = new Client({ connectionString: DATABASE_URL, + // RDS rejects unencrypted connections (rds.force_ssl). The certificate is + // verified against the RDS CA bundle loaded via NODE_EXTRA_CA_CERTS. + ssl: true, }); await client.connect(); diff --git a/cdk/lambdas/voteReconcile/index.ts b/cdk/lambdas/voteReconcile/index.ts index 9991a08dc..0be01ec1d 100644 --- a/cdk/lambdas/voteReconcile/index.ts +++ b/cdk/lambdas/voteReconcile/index.ts @@ -58,6 +58,9 @@ exports.handler = async function () { const client = new Client({ connectionString: DATABASE_URL, + // RDS rejects unencrypted connections (rds.force_ssl). The certificate is + // verified against the RDS CA bundle loaded via NODE_EXTRA_CA_CERTS. + ssl: true, }); await client.connect(); diff --git a/cdk/lib/cron-stack.ts b/cdk/lib/cron-stack.ts index 66d051701..2593d6c7d 100644 --- a/cdk/lib/cron-stack.ts +++ b/cdk/lib/cron-stack.ts @@ -40,6 +40,12 @@ export class CronStack extends cdk.Stack { lambdaRole.addToPolicy(policy); + // Node 20+ Lambda runtimes no longer trust the Amazon RDS CAs by default, + // so the lambdas that connect to RDS over TLS load the bundled CA file. + const rdsCaEnvironment = { + NODE_EXTRA_CA_CERTS: "/var/runtime/ca-cert.pem", + }; + // RSS Feed Fetcher Lambda const rssFetcherFn = new NodejsFunction(this, "RSSFetcherLambda", { timeout: cdk.Duration.seconds(300), // 5 minutes for processing multiple feeds @@ -50,6 +56,7 @@ export class CronStack extends cdk.Stack { "/../lambdas/rssFetcher/package-lock.json", ), role: lambdaRole, + environment: rdsCaEnvironment, bundling: { nodeModules: ["@aws-sdk/client-ssm", "pg", "rss-parser"], }, @@ -72,6 +79,7 @@ export class CronStack extends cdk.Stack { "/../lambdas/voteReconcile/package-lock.json", ), role: lambdaRole, + environment: rdsCaEnvironment, bundling: { nodeModules: ["@aws-sdk/client-ssm", "pg"], }, diff --git a/cdk/lib/storage-stack.ts b/cdk/lib/storage-stack.ts index 9b1af584a..05143660f 100644 --- a/cdk/lib/storage-stack.ts +++ b/cdk/lib/storage-stack.ts @@ -162,7 +162,8 @@ export class StorageStack extends cdk.Stack { // connections must therefore carry `sslmode=require` in DATABASE_URL. const parameterGroup = new rds.ParameterGroup(this, "db-parameter-group", { engine: rds.DatabaseInstanceEngine.postgres({ version: pgVersion }), - description: "Codú Postgres 15 — force_ssl pinned on", + // ASCII only: RDS rejects a description with non-ASCII characters. + description: "Codu Postgres 15 - force_ssl pinned on", parameters: { "rds.force_ssl": "1", }, @@ -174,6 +175,9 @@ export class StorageStack extends cdk.Stack { databaseName: dbName, engine: rds.DatabaseInstanceEngine.postgres({ version: pgVersion }), parameterGroup, + // The instance was created under rds-ca-2019, whose server certificate + // expired in August 2024, so no client could verify the connection. + caCertificate: rds.CaCertificate.RDS_CA_RSA2048_G1, credentials: rds.Credentials.fromPassword( dbUsername, cdk.SecretValue.ssmSecure("/env/db/password", "1"),