Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Implement ssl configuration for postgres

Hakan Shehuf074495f5fbd
diff --git a/apps/server/src/data/database.ts b/apps/server/src/data/database.ts
index e443d601..20ab5ab7 100644
--- a/apps/server/src/data/database.ts
+++ b/apps/server/src/data/database.ts
@@ -12,10 +12,17 @@ import pg from 'pg';
import { databaseMigrations } from '@/data/migrations';
import { DatabaseSchema } from '@/data/schema';
import { configuration } from '@/lib/configuration';
+import { createLogger } from '@/lib/logger';
+
+const logger = createLogger('database');
const dialect = new PostgresDialect({
pool: new pg.Pool({
connectionString: configuration.postgres.url,
+ ssl:
+ Object.keys(configuration.postgres.ssl).length > 0
+ ? configuration.postgres.ssl
+ : undefined,
}),
});
@@ -33,7 +40,18 @@ export const migrate = async () => {
},
});
- await migrator.migrateToLatest();
+ const result = await migrator.migrateToLatest();
+ if (result.error) {
+ logger.error(`Migration failed, ${result.error}`);
+ }
+
+ if (result.results && result.results.length > 0) {
+ for (const r of result.results) {
+ logger.info(
+ `Migration result: ${r.direction} - ${r.migrationName} - ${r.status} `
+ );
+ }
+ }
};
export const hasInsertChanges = (result: InsertResult[]): boolean => {
diff --git a/apps/server/src/lib/configuration.ts b/apps/server/src/lib/configuration.ts
index 1e5f99d7..ab698edb 100644
--- a/apps/server/src/lib/configuration.ts
+++ b/apps/server/src/lib/configuration.ts
@@ -29,6 +29,12 @@ export interface UserConfiguration {
export interface PostgresConfiguration {
url: string;
+ ssl: {
+ rejectUnauthorized?: boolean;
+ ca?: string;
+ key?: string;
+ cert?: string;
+ };
}
export interface RedisConfiguration {
@@ -111,6 +117,15 @@ export const configuration: Configuration = {
},
postgres: {
url: getRequiredEnv('POSTGRES_URL'),
+ ssl: {
+ rejectUnauthorized:
+ getOptionalEnv('POSTGRES_SSL_REJECT_UNAUTHORIZED') === undefined
+ ? undefined
+ : getOptionalEnv('POSTGRES_SSL_REJECT_UNAUTHORIZED') === 'true',
+ ca: getOptionalEnv('POSTGRES_SSL_CA'),
+ key: getOptionalEnv('POSTGRES_SSL_KEY'),
+ cert: getOptionalEnv('POSTGRES_SSL_CERT'),
+ },
},
redis: {
url: getRequiredEnv('REDIS_URL'),
diff --git a/docker-compose.yaml b/docker-compose.yaml
index c360d958..475b5408 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -85,6 +85,12 @@ services:
# The server expects a PostgreSQL database with the pgvector extension installed.
POSTGRES_URL: 'postgres://colanode_user:strongpassword@postgres:5432/colanode_db'
+ # Optional variables for SSL connection to the database
+ POSTGRES_SSL_REJECT_UNAUTHORIZED: 'false'
+ POSTGRES_SSL_CA: ''
+ POSTGRES_SSL_KEY: ''
+ POSTGRES_SSL_CERT: ''
+
# ───────────────────────────────────────────────────────────────
# Redis Configuration
# ───────────────────────────────────────────────────────────────