Skip to content

Unable to connect through SSL  #2178

Closed
Closed
@gpanainte

Description

@gpanainte

I'm using "pg": "^8.0.3" with nestjs and TypeOrm to connect to a PostgreSQL database hosted on Google Cloud.

I have the following configuration for the db connection.

TypeOrmCoreModule.forRootAsync({
      useFactory: (configService: AppConfigService) => ({
        type: 'postgres',
        host: configService.dbHost,
        port: configService.dbPort,
        username: configService.dbUser,
        password: configService.dbPassword,
        database: configService.dbName,
        schema: configService.dbSchema,
        entities: [`${__dirname}/**/*.entity{.ts,.js}`],
        autoLoadEntities: true,
        synchronize: configService.dbSync,
        ssl: {
          // rejectUnauthorized: false,
          ca: configService.dbServerCA,    // downloaded from  GCC
          cert: configService.dbClientCert, // downloaded from  GCC
          key: configService.dbClientKey,  // downloaded from  GCC
          enableTrace: true,
        },
      }),
      imports: [ConfigurationModule],
      inject: [AppConfigService],
    }),

When I start my application I receive the error following message:

Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: localhost. is not cert's CN: **********

What I've read/and tested is that I should use rejectUnauthorized: false, but doing this I give up on security features. Am I missing something with regards to configuration options, that should allow me to use SSL without rejectUnauthorized: false?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions