Skip to content

Support for SSL connections with PostgreSQL #1773

Open

Description

@mkochco

Checked for duplicates

Yes - I've already checked

Alternatives considered

Yes - and alternatives don't suffice

Related problems

I'm trying to deploy Aerie to K8S (AWS EKS) and use Aurora Serverless as the databsae. I've got the pods running but It looks like by default PostgreSQL connections do not use SSL. Which is required by default in RDS.

For example the use of pg.Pool in aerie-action does not provide an option to pass in the ssl: true. Is this consistent across all Aerie services? :sadtrombones:

    import type { Pool } from "pg";
    import pg from "pg";
    import { configuration } from "./config";
    import logger from "./utils/logger";

    const { AERIE_DB, AERIE_DB_HOST, AERIE_DB_PORT, ACTION_DB_USER, ACTION_DB_PASSWORD } = configuration();

    export class ActionsDbManager {
      private static pool: Pool;

      static getDb(): Pool {
        // singleton DB pool, shared by the process
        // saved as a static to prevent accidental re-initialization
        if (ActionsDbManager.pool) return ActionsDbManager.pool;

        try {
          logger.info(`Creating PG pool`);
          ActionsDbManager.pool = new pg.Pool({
            host: AERIE_DB_HOST,
            port: parseInt(AERIE_DB_PORT, 5432),
            database: AERIE_DB,
            user: ACTION_DB_USER,
            password: ACTION_DB_PASSWORD,
            max: 3,
            min: 3,
          });
          return ActionsDbManager.pool;
        } catch (error) {
          logger.error(error);
          throw error;
        }
      }
    }

Describe the feature request

Please make the use of SSL in Postgres configurable. This will open up options for it's use typical cloud based deployments in which postgres is managed externally to Aerie itself.

Activity

  1. added
    feature
    on Jan 13, 2026
  2. nikhilred2619 commented on Nov 7, 2026

    @nikhilred2619

    Hi @mkochco , I'd be interested in contributing to this issue. I can investigate PostgreSQL connection handling across the affected services and propose configurable TLS support with backward compatibility and regression tests. Is this available for an external contribution, and is there a preferred configuration approach?

  3. mkochco commented on Nov 7, 2026

    @mkochco
    Author

    @nikhilred2619 - the original post under-scoped the changes required. Here's what I think is involved with enabling SSL/TLS to Postgres in plandev.

    Goal

    Add one set of environment variables that all services use to turn on TLS for Postgres, with a choice of whether to verify the server certificate. When
    the variables are unset, behaviour stays exactly as it is today, so existing docker-compose deployments are unaffected.

    Proposed configuration

    Variable Values Default
    PLANDEV_DB_SSL_MODE disable, require, verify-ca, verify-full unset (current behaviour)
    PLANDEV_DB_SSL_ROOT_CERT Path to a PEM CA bundle, e.g. the AWS RDS global bundle unset
    • require: the connection is encrypted, but the server certificate is not verified.
    • verify-ca: the connection is encrypted and the certificate chain is checked against PLANDEV_DB_SSL_ROOT_CERT.
    • verify-full: same as verify-ca, plus the hostname is checked. This is the recommended setting for production.
    • A service should fail at startup if verify-* is set but PLANDEV_DB_SSL_ROOT_CERT is missing or unreadable.

    The mode names match libpq and pgjdbc, so they mean the same thing in every service.

    Java services (pgjdbc via HikariCP)

    These files create a HikariConfig with PGSimpleDataSource:

    • merlin-server/src/main/java/gov/nasa/ammos/plandev/merlin/server/AerieAppDriver.java
    • merlin-worker/src/main/java/gov/nasa/ammos/plandev/merlin/worker/MerlinWorkerAppDriver.java
    • scheduler-server/src/main/java/gov/nasa/ammos/plandev/scheduler/server/SchedulerAppDriver.java
    • scheduler-worker/src/main/java/gov/nasa/ammos/plandev/scheduler/worker/SchedulerWorkerAppDriver.java
    • workspace-server/src/main/java/gov/nasa/ammos/plandev/workspace/server/WorkspaceAppDriver.java

    Changes:

    1. Add sslMode and sslRootCert fields to the three PostgresStore records (merlin-server, scheduler-server, workspace-server, each under
      .../server/config/PostgresStore.java). The two workers import their server module's record, so they pick the fields up for free. Populate them from the
      environment in each loadConfiguration().

    2. In each driver, set the extra data source properties only when the values are present:

      postgresStore.sslMode().ifPresent(mode -> hikariConfig.addDataSourceProperty("sslMode", mode));
      postgresStore.sslRootCert().ifPresent(cert -> hikariConfig.addDataSourceProperty("sslRootCert", cert));

      pgjdbc reads PEM bundles directly, so you don't need to convert the bundle to a JKS truststore.

    3. Optional: move the duplicated Hikari setup into a small shared helper so the five drivers can't drift apart.

    Node services (node-postgres)

    These files create a pg.Pool:

    • action-server/src/db.ts
    • action-server/src/threads/worker.ts
    • sequencing-server/src/db.ts

    node-postgres doesn't use sslmode and takes an ssl object instead, so add a shared helper that converts the env vars (the action server would read
    them through configuration() in action-server/src/config.ts, the sequencing server through getEnv() in sequencing-server/src/env.ts):

    function pgSslConfig(): PoolConfig["ssl"] {
      switch (PLANDEV_DB_SSL_MODE) {
        case undefined:
        case "disable":
          return false;
        case "require":
          return { rejectUnauthorized: false };
        case "verify-ca":
          return {
            ca: fs.readFileSync(PLANDEV_DB_SSL_ROOT_CERT!, "utf8"),
            rejectUnauthorized: true,
            checkServerIdentity: () => undefined, // skip hostname check
          };
        case "verify-full":
          return {
            ca: fs.readFileSync(PLANDEV_DB_SSL_ROOT_CERT!, "utf8"),
            rejectUnauthorized: true,
          };
      }
    }

    Each pool then gets ssl: pgSslConfig().

    Hasura

    Hasura connects using PLANDEV_DATABASE_URL and HASURA_GRAPHQL_METADATA_DATABASE_URL. Both are libpq-style URLs, so TLS should work by adding query
    parameters (the compose file already appends ?options=... to PLANDEV_DATABASE_URL, so the SSL parameters go on with &):

    postgres://user:pass@host:5432/plandev?options=...&sslmode=verify-full&sslrootcert=/certs/global-bundle.pem
    

    This most likely needs documentation and deployment manifest changes rather than code changes, but it should be tested with Hasura OSS. If Hasura OSS
    doesn't honour sslrootcert in the URL, Hasura would need its ssl_configuration metadata block, which may be limited to Hasura Cloud/EE.
    deployment/plandev_db_migration.py runs migrations through the Hasura CLI, so it inherits whatever Hasura is configured with.

    Out of this repo

    plandev-gateway also connects to Postgres directly and will need the same Node change.

    Docs and deployment

    • Add the two variables to deployment/Environment.md
    • Add commented-out examples to docker-compose.yml, deployment/docker-compose.yml and deployment/kubernetes/*, including mounting the CA bundle
      (a ConfigMap or Secret in Kubernetes)
    • Note that on RDS/Aurora, the server side is controlled by rds.force_ssl in the cluster parameter group

    Testing

    • Existing tests pass unchanged with the variables unset
    • For a manual or CI check, run Postgres with ssl=on and a self-signed CA. Confirm each mode connects, and that verify-full fails when the
      hostname doesn't match
    • On a live connection, SELECT ssl FROM pg_stat_ssl WHERE pid = pg_backend_pid(); returns t when TLS is in use
  4. nikhilred2619 commented on Nov 7, 2026

    @nikhilred2619

    Hi Mark (@mkochco),

    Thank you for the detailed breakdown. This is very helpful.

    I'd be happy to work on the implementation following the proposed configuration and compatibility requirements.

    Given the changes across Java services, Node services, Hasura, and deployment configuration, would you prefer the work to be submitted as a series of focused PRs or as a single implementation?

    If this issue is available for me to take on, I can start with the shared TLS configuration and service-level changes, followed by the deployment updates and regression tests.

    Thanks again for outlining the scope!

  5. mkochco commented on Nov 7, 2026

    @mkochco
    Author

    Hi @nikhilred2619, I'm not the code owner in this case. I would guess a single PR to avoid inconsistencies in runtime, or having blocking PRs.

    @dandelany could you weigh in on preferred process here? @nikhilred2619 has offered to implement this against the plan above. Is a single PR against develop fine, or would you prefer it split (Java drivers, Node services, docs/deployment)? Any objection to the PLANDEV_DB_SSL_MODE / PLANDEV_DB_SSL_ROOT_CERT naming?

  6. dandelany commented on Nov 13, 2026

    @dandelany
    Collaborator

    Hi @nikhilred2619 and @mkochco - apologies for slow responses, we're a small team & have been busy with review & testing activities around our latest release. A few thoughts:

    • Overall I agree with @mkochco 's outlined approach above, including the variable names. We'd welcome a good, well-tested PR from @nikhilred2619 for this feature.
    • One PR for most of this work is fine - although the changes to plandev-gateway and plandev-docs will need to be separate PRs since they are in other repos.
    • The implementation should be opt-in as described and prioritize backwards-compatibility for existing users.
    • For easiest review it should also minimize any architectural changes and stay as limited in scope as possible. Eg. above you mention adding a shared helper for action-server and sequencing-server - I'm not sure we have a good package for sharing code between them today, so it may be simpler to just add the same function in both places.
    • Separately - we currently have some CI issues with tests & code scanning not running correctly on fork PRs. I will work on resolving that issue on Monday, but just FYI tests may not initially pass on the PR.
  7. nikhilred2619 commented on Nov 30, 2026

    @nikhilred2619

    Hi @mkochco and @dandelany,

    Sorry for the delay, and thank you for your guidance and patience.

    I've completed the PostgreSQL TLS implementation, including regression testing, live certificate verification, and deployment documentation.

    I've submitted the three PRs as suggested:

    Please let me know if any adjustments are needed. I'm happy to address your feedback.

    Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions