Skip to content

Commit fea7cb0

Browse files
authored
fix: removes deprecated config option for strict https and updates bootstrap to use supported option (#1)
1 parent 2c6466b commit fea7cb0

5 files changed

Lines changed: 15 additions & 3 deletions

File tree

apps/opencase/src/infrastructure/config/Config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export interface AppConfig {
3939
smtpHost?: string;
4040
smtpPort?: string;
4141
smtpFrom?: string;
42+
43+
// Keycloak realm SSL enforcement ('none' for HTTP dev, 'external' for production HTTPS)
44+
keycloakRealmSslRequired: 'none' | 'external' | 'all';
4245
}
4346

4447
export function loadConfig(): AppConfig {
@@ -78,6 +81,8 @@ export function loadConfig(): AppConfig {
7881
smtpHost: process.env.SMTP_HOST ?? (isProduction ? undefined : 'mailpit'),
7982
smtpPort: process.env.SMTP_PORT ?? '1025',
8083
smtpFrom: process.env.SMTP_FROM ?? 'noreply@opencase.local',
84+
85+
keycloakRealmSslRequired: (process.env.KEYCLOAK_SSL_REQUIRED ?? (isProduction ? 'external' : 'none')) as 'none' | 'external' | 'all',
8186
};
8287
}
8388

apps/opencase/src/infrastructure/keycloak/KeycloakAdminClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export class KeycloakAdminClient {
7575
logger.info({ realm }, 'Configured realm settings (resetPassword, loginWithEmail, SMTP, CASE scopes)')
7676
}
7777

78+
async setRealmSslRequired (realm: string, sslRequired: string): Promise<void> {
79+
await this.requestJson('PUT', `/admin/realms/${encodeURIComponent(realm)}`, { sslRequired })
80+
logger.info({ realm, sslRequired }, 'Set realm sslRequired')
81+
}
82+
7883
async ensureClient (client: {
7984
clientId: string
8085
publicClient: boolean

apps/opencase/src/wiring/container.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ export async function buildContainer(): Promise<Container> {
339339
try {
340340
await keycloakAdmin.ensureRealmExists()
341341
await keycloakTenantProvisioner.bootstrapSystemAdmin()
342+
await keycloakAdmin.setRealmSslRequired(config.keycloakRealm, config.keycloakRealmSslRequired)
343+
await keycloakAdmin.setRealmSslRequired(config.keycloakAdminRealm, config.keycloakRealmSslRequired)
342344
keycloakReady = true
343345
logger.info('Keycloak bootstrap completed successfully')
344346
} catch (error: any) {

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ services:
3737
# Hostname configuration - tell Keycloak its external URL
3838
- KC_HOSTNAME=${OPENCASE_HOSTNAME:-localhost}
3939
- KC_HOSTNAME_STRICT=false
40-
- KC_HOSTNAME_STRICT_HTTPS=${KC_HOSTNAME_STRICT_HTTPS:-false}
4140
# Proxy settings for running behind Traefik
4241
- KC_PROXY_HEADERS=xforwarded
4342
- KC_HTTP_RELATIVE_PATH=/
@@ -124,6 +123,7 @@ services:
124123
- SMTP_HOST=${SMTP_HOST:-mailpit}
125124
- SMTP_PORT=${SMTP_PORT:-1025}
126125
- SMTP_FROM=noreply@${OPENCASE_HOSTNAME:-opencase.local}
126+
- KEYCLOAK_SSL_REQUIRED=${KEYCLOAK_SSL_REQUIRED:-none}
127127
restart: on-failure
128128
volumes:
129129
- ./apps/opencase/data:/app/data

docs/env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
TRAEFIK_CONFIG=traefik/traefik-https.yml
1717
TRAEFIK_PORTS_WEB=443:443
1818
TRAEFIK_PORTS_ALT=80:80
19-
KC_HOSTNAME_STRICT_HTTPS=true
19+
KEYCLOAK_SSL_REQUIRED=external
2020
OPENCASE_SCHEME=https
2121
OPENCASE_PORT_SUFFIX=
2222

2323
# --- HTTP (local development) — plain HTTP on :3000, dashboard on :8080 ---
2424
# TRAEFIK_CONFIG=traefik/traefik-http.yml
2525
# TRAEFIK_PORTS_WEB=3000:3000
2626
# TRAEFIK_PORTS_ALT=8080:8080
27-
# KC_HOSTNAME_STRICT_HTTPS=false
27+
# KEYCLOAK_SSL_REQUIRED=none
2828
# OPENCASE_SCHEME=http
2929
# OPENCASE_PORT_SUFFIX=:3000
3030

0 commit comments

Comments
 (0)