@sssb/cdk 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/sssb-app.js +22 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sssb/cdk",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,11 +26,11 @@
26
26
  "peerDependencies": {
27
27
  "aws-cdk-lib": "^2.274.0",
28
28
  "constructs": "^10.8.1",
29
- "@sssb/tools": "0.9.1"
29
+ "@sssb/tools": "0.10.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "aws-cdk-lib": "^2.274.0",
33
33
  "constructs": "^10.8.1",
34
- "@sssb/tools": "0.9.1"
34
+ "@sssb/tools": "0.10.0"
35
35
  }
36
36
  }
package/src/sssb-app.js CHANGED
@@ -50,6 +50,13 @@ export function toolsVersionProblem(tools, own = OWN_VERSION) {
50
50
 
51
51
  const TRANSPORTS = /** @type {const} */ (['pg', 'data-api'])
52
52
 
53
+ /**
54
+ * The Amazon CA bundle in the Lambda Node.js runtime (AWS Lambda's guide, "Using AWS Lambda with Amazon RDS": from
55
+ * Node.js 20 the runtime keeps the Amazon CA certificates, RDS's among them, in this file and no longer loads them).
56
+ * Both Lambdas are zip functions on that runtime (NODEJS_22_X), not container images, which need not have the file.
57
+ */
58
+ const LAMBDA_CA_BUNDLE = '/var/runtime/ca-cert.pem'
59
+
53
60
  /**
54
61
  * The migrator entry, a published subpath of `@sssb/kit` (its `exports` map), resolved through that map from the
55
62
  * app; and the framework's migration registry, which is not published, so it is named by its path inside the
@@ -520,6 +527,14 @@ export class SssbApp extends Construct {
520
527
  })
521
528
  : undefined
522
529
 
530
+ // How both Lambdas protect their `pg` connection (the kit's `databaseSsl`): TLS that checks the certificate
531
+ // chains to Amazon RDS's roots and names the cluster endpoint. Those roots are in the Amazon CA bundle every
532
+ // Lambda Node.js runtime from 20 on carries at /var/runtime/ca-cert.pem (and loads no longer by default), so the
533
+ // adapter trusts that file for this one connection. Not a parameter: Aurora always offers TLS, so there is no
534
+ // deployment of this construct that should turn it off. On `data-api` neither applies: the SDK speaks HTTPS.
535
+ /** @type {Record<string, string>} */
536
+ const pgTlsEnv = { DATABASE_SSL_MODE: 'verify-full', DATABASE_SSL_ROOT_CERT: LAMBDA_CA_BUNDLE }
537
+
523
538
  // The database half of each Lambda's environment (the framework's real adapters read it at boot).
524
539
  // data-api builds no DATABASE_URL at all: the credential stays in Secrets Manager, where the Data
525
540
  // API reads it, so the `db-credential-not-in-env` concern does not arise on that path.
@@ -533,6 +548,7 @@ export class SssbApp extends Construct {
533
548
  }
534
549
  : {
535
550
  DATABASE_TRANSPORT: 'pg',
551
+ ...pgTlsEnv,
536
552
  // DRAFT: built via CFN dynamic references so the server
537
553
  // can actually boot; revisit with the shared secrets constructs at cutover
538
554
  // (env-var exposure vs runtime secret fetch).
@@ -625,7 +641,12 @@ export class SssbApp extends Construct {
625
641
  // which the synthesized secret does not carry (only the cluster's secret attachment would add it, at deploy).
626
642
  environment: dataApi
627
643
  ? databaseEnv
628
- : { DATABASE_TRANSPORT: 'pg', DB_SECRET_ARN: secret.secretArn, DATABASE_NAME: databaseName },
644
+ : {
645
+ DATABASE_TRANSPORT: 'pg',
646
+ ...pgTlsEnv,
647
+ DB_SECRET_ARN: secret.secretArn,
648
+ DATABASE_NAME: databaseName,
649
+ },
629
650
  bundling: {
630
651
  format: aws_lambda_nodejs.OutputFormat.ESM,
631
652
  // An ESM bundle has no `require`, and esbuild's stand-in for the CommonJS packages it inlines (`pg`,