Skip to content

AWS CDK: route backend CouchDB traffic inside the VPC instead of via the public ALB - #2529

Merged
PeterBaker0 merged 4 commits into
FAIMS:mainfrom
PeterBaker0:feat/aws-cdk-route-backend-couchdb-traffic-inside-the
Nov 25, 2026
Merged

PeterBaker0 merged 4 commits into
FAIMS:mainfrom
PeterBaker0:feat/aws-cdk-route-backend-couchdb-traffic-inside-the

Conversation

@PeterBaker0

Copy link
Copy Markdown
Contributor

Description

Backend Conductor, spatial-worker, capacity-manager, and TTL-cleanup tasks were using COUCHDB_INTERNAL_URL equal to the public ALB HTTPS URL. Every admin-credentialed Couch call left the VPC, resolved public DNS, and came back through the internet-facing ALB.

This change gives Couch a stable VPC hostname via a Route 53 private hosted zone, points COUCHDB_INTERNAL_URL at http://couchdb.internal.<baseDomain>:5984, keeps COUCHDB_PUBLIC_URL as the public HTTPS URL devices already get via base_url, restricts instance ingress to 5984 from the ALB and Conductor task security groups, and stops the unauthenticated / fallback page from rendering the internal hostname.

Proposed Changes

  • Private hosted zone internal.<baseDomain> associated with the stack VPC, plus A record couchdb.internal.<baseDomain> → Couch EC2 private IP (EC2CouchDB).
  • buildConductorRuntimeEnv takes a distinct couchDBInternalUrl (no fallback to the public URL). Spatial worker, capacity manager, and TTL cleanup still receive conductor.environment with no second Couch URL overlay.
  • Couch SG: TCP 5984 from the ALB SG and from conductor.serviceSecurityGroup. 0.0.0.0/0 TCP 443 removed in the same change as the internal-URL split. AmazonSSMManagedInstanceCore kept for scripts/ssmCouchTunnel.sh.
  • Fallback GET / renders config.couchdbPublicUrl as the clickable URL, and a publicFacingDatabaseReport copy of databaseValidityReport that redacts the internal URL/hostname from server_msg, database_errors, and validate_error. verifyCouchDBConnection still records the real internal URL for logs/CLI. stampListingCouchUrl is unchanged (dataDb.base_url still from couchdbPublicUrl).
  • Operator docs: do not set AWS COUCHDB_INTERNAL_URL to https://db.<domain>:443. env-from-cdk-stack now emits the VPC hostname; laptop access uses ssmCouchTunnel.sh.

How to Test

Automated (merge gate):

pnpm --filter=@faims3/infra-aws-cdk test
pnpm --filter=@faims3/api test

The fallback test in api/test/healthApp.test.ts calls verifyCouchDBConnection() (real payload includes couchdb.internal.* in server_msg) and asserts GET / HTML does not.

Named manual checks before a production deploy:

  • From a Conductor task: COUCHDB_INTERNAL_URL is http://couchdb.internal.<baseDomain>:5984, that name resolves to the instance private IP, and curl of that URL returns 200 or 401 (not a TCP failure).
  • Confirm 443-from-anywhere is gone and ./scripts/ssmCouchTunnel.sh still works.

Additional Information

Cause of the 1c1be2034 443 revert

dab0866d9 closed unused inbound 443 on the Couch instance SG. 1c1be2034 restored 0.0.0.0/0 TCP 443 “due to connectivity issues.”

Code path: COUCHDB_INTERNAL_URL was still assigned from input.couchDBEndpoint (the public https://<couch-domain>:443 URL). Backend Nano/Pouch/JWT-key/migrate/worker traffic therefore left the VPC, resolved the public hostname, and returned through the internet-facing ALB — or, if operators used the instance public IP, hit instance:443 directly. Closing instance 443 while that was still the configured internal endpoint broke Conductor connectivity.

This PR does not remove 443 while internal URL equals public URL. 443 is removed only together with pointing COUCHDB_INTERNAL_URL at the VPC HTTP :5984 hostname, plus an explicit 5984 rule from the Conductor task SG.

Checklist

  • I have confirmed all commits have been signed.
  • I have added JSDoc style comments to any new functions or classes.
  • I have added tests for new code if appropriate
  • Relevant documentation such as READMEs, guides, and class comments are updated.

…the public ALB

Signed-off-by: Peter Baker <peter.baker122@csiro.au>
Signed-off-by: Peter Baker <peter.baker122@csiro.au>
…ting it after the fafct

Signed-off-by: Peter Baker <peter.baker122@csiro.au>
Signed-off-by: Peter Baker <peter.baker122@csiro.au>

@PeterBaker0 PeterBaker0 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy now

@PeterBaker0
PeterBaker0 marked this pull request as ready for review November 25, 2026 01:17

@stevecassidy stevecassidy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok.

@PeterBaker0
PeterBaker0 merged commit 3ff6c41 into FAIMS:main Nov 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants