Skip to content

The open alternative to Salesforce, designed for AI.

feat: allow self signed certificates with postgres connections (#5143)

Quentin G806666d90956
diff --git a/packages/twenty-docs/docs/start/self-hosting/self-hosting.mdx b/packages/twenty-docs/docs/start/self-hosting/self-hosting.mdx
index 9bbacd045f8..5efa3dc0e3e 100644
--- a/packages/twenty-docs/docs/start/self-hosting/self-hosting.mdx
+++ b/packages/twenty-docs/docs/start/self-hosting/self-hosting.mdx
@@ -34,6 +34,7 @@ import TabItem from '@theme/TabItem';
<OptionTable options={[
['PG_DATABASE_URL', 'postgres://user:pw@localhost:5432/default?connection_limit=1', 'Database connection'],
+ ['PG_SSL_ALLOW_SELF_SIGNED', 'false', 'Allow self signed certificates'],
['REDIS_HOST', '127.0.0.1', 'Redis connection host'],
['REDIS_PORT', '6379', 'Redis connection port'],
['FRONT_BASE_URL', 'http://localhost:3001', 'Url to the hosted frontend'],
diff --git a/packages/twenty-server/.env.example b/packages/twenty-server/.env.example
index dd36a7c8ba5..9f0973e1047 100644
--- a/packages/twenty-server/.env.example
+++ b/packages/twenty-server/.env.example
@@ -71,3 +71,4 @@ SIGN_IN_PREFILLED=true
# API_RATE_LIMITING_LIMIT=
# MUTATION_MAXIMUM_RECORD_AFFECTED=100
# CHROME_EXTENSION_REDIRECT_URL=https://bggmipldbceihilonnbpgoeclgbkblkp.chromiumapp.org
+# PG_SSL_ALLOW_SELF_SIGNED=true
diff --git a/packages/twenty-server/src/database/typeorm/core/core.datasource.ts b/packages/twenty-server/src/database/typeorm/core/core.datasource.ts
index 64f3e2394a9..db0768432c9 100644
--- a/packages/twenty-server/src/database/typeorm/core/core.datasource.ts
+++ b/packages/twenty-server/src/database/typeorm/core/core.datasource.ts
@@ -14,6 +14,12 @@ export const typeORMCoreModuleOptions: TypeOrmModuleOptions = {
migrationsRun: false,
migrationsTableName: '_typeorm_migrations',
migrations: ['dist/src/database/typeorm/core/migrations/*{.ts,.js}'],
+ ssl:
+ process.env.PG_SSL_ALLOW_SELF_SIGNED === 'true'
+ ? {
+ rejectUnauthorized: false,
+ }
+ : undefined,
};
export const connectionSource = new DataSource(
typeORMCoreModuleOptions as DataSourceOptions,
diff --git a/packages/twenty-server/src/database/typeorm/metadata/metadata.datasource.ts b/packages/twenty-server/src/database/typeorm/metadata/metadata.datasource.ts
index 7fbe5e599dd..89bc837d99d 100644
--- a/packages/twenty-server/src/database/typeorm/metadata/metadata.datasource.ts
+++ b/packages/twenty-server/src/database/typeorm/metadata/metadata.datasource.ts
@@ -14,6 +14,12 @@ export const typeORMMetadataModuleOptions: TypeOrmModuleOptions = {
migrationsRun: false,
migrationsTableName: '_typeorm_migrations',
migrations: ['dist/src/database/typeorm/metadata/migrations/*{.ts,.js}'],
+ ssl:
+ process.env.PG_SSL_ALLOW_SELF_SIGNED === 'true'
+ ? {
+ rejectUnauthorized: false,
+ }
+ : undefined,
};
export const connectionSource = new DataSource(
typeORMMetadataModuleOptions as DataSourceOptions,
diff --git a/packages/twenty-server/src/database/typeorm/typeorm.service.ts b/packages/twenty-server/src/database/typeorm/typeorm.service.ts
index cc542d60ba1..c9a05a12a66 100644
--- a/packages/twenty-server/src/database/typeorm/typeorm.service.ts
+++ b/packages/twenty-server/src/database/typeorm/typeorm.service.ts
@@ -33,6 +33,11 @@ export class TypeORMService implements OnModuleInit, OnModuleDestroy {
BillingSubscription,
BillingSubscriptionItem,
],
+ ssl: environmentService.get('PG_SSL_ALLOW_SELF_SIGNED')
+ ? {
+ rejectUnauthorized: false,
+ }
+ : undefined,
});
}
diff --git a/packages/twenty-server/src/engine/integrations/environment/environment-variables.ts b/packages/twenty-server/src/engine/integrations/environment/environment-variables.ts
index 7553c4ff0cc..6aec43e78a0 100644
--- a/packages/twenty-server/src/engine/integrations/environment/environment-variables.ts
+++ b/packages/twenty-server/src/engine/integrations/environment/environment-variables.ts
@@ -103,6 +103,11 @@ export class EnvironmentVariables {
})
PG_DATABASE_URL: string;
+ @CastToBoolean()
+ @IsBoolean()
+ @IsOptional()
+ PG_SSL_ALLOW_SELF_SIGNED = false;
+
// Frontend URL
@IsUrl({ require_tld: false })
FRONT_BASE_URL: string;