From c58ca34b2cc195abbecedb367dee29b03f7c7bfe Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Sun, 5 Apr 2026 17:32:36 +0200 Subject: [PATCH] fix: route all public traffic through Traefik at localhost:80 Logto ENDPOINT now points at Traefik (http://localhost) instead of directly at port 3001. All services share the same base URL, eliminating OIDC issuer mismatches and crypto.subtle secure context issues. - Remove :3001 from all public-facing Logto URLs - Add cameleer3-server-ui to Traefik at /server/ with prefix strip - Dashboard link uses /server/ path instead of port 8082 - Bootstrap Host headers match Logto ENDPOINT (no port) - Redirect URIs simplified (Traefik handles port 80) Co-Authored-By: Claude Opus 4.6 (1M context) --- docker-compose.yml | 17 ++++++++++++----- docker/logto-bootstrap.sh | 14 +++++++------- ui/src/components/Layout.tsx | 2 +- ui/src/config.ts | 2 +- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index ac9c384..45630a9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: entrypoint: ["sh", "-c", "npm run cli db seed -- --swe && npm start"] environment: DB_URL: postgres://${POSTGRES_USER:-cameleer}:${POSTGRES_PASSWORD:-cameleer_dev}@postgres:5432/logto - ENDPOINT: http://${PUBLIC_HOST:-localhost}:3001 + ENDPOINT: http://${PUBLIC_HOST:-localhost} ADMIN_ENDPOINT: http://${PUBLIC_HOST:-localhost}:3002 TRUST_PROXY_HEADER: 1 healthcheck: @@ -67,7 +67,7 @@ services: environment: LOGTO_ENDPOINT: http://logto:3001 LOGTO_ADMIN_ENDPOINT: http://logto:3002 - LOGTO_PUBLIC_ENDPOINT: http://${PUBLIC_HOST:-localhost}:3001 + LOGTO_PUBLIC_ENDPOINT: http://${PUBLIC_HOST:-localhost} PUBLIC_HOST: ${PUBLIC_HOST:-localhost} PG_HOST: postgres PG_USER: ${POSTGRES_USER:-cameleer} @@ -104,8 +104,8 @@ services: SPRING_DATASOURCE_USERNAME: ${POSTGRES_USER:-cameleer} SPRING_DATASOURCE_PASSWORD: ${POSTGRES_PASSWORD:-cameleer_dev} LOGTO_ENDPOINT: ${LOGTO_ENDPOINT:-http://logto:3001} - LOGTO_PUBLIC_ENDPOINT: http://${PUBLIC_HOST:-localhost}:3001 - LOGTO_ISSUER_URI: http://${PUBLIC_HOST:-localhost}:3001/oidc + LOGTO_PUBLIC_ENDPOINT: http://${PUBLIC_HOST:-localhost} + LOGTO_ISSUER_URI: http://${PUBLIC_HOST:-localhost}/oidc LOGTO_JWK_SET_URI: ${LOGTO_ENDPOINT:-http://logto:3001}/oidc/jwks LOGTO_M2M_CLIENT_ID: ${LOGTO_M2M_CLIENT_ID:-} LOGTO_M2M_CLIENT_SECRET: ${LOGTO_M2M_CLIENT_SECRET:-} @@ -139,7 +139,7 @@ services: CAMELEER_AUTH_TOKEN: ${CAMELEER_AUTH_TOKEN:-default-bootstrap-token} CAMELEER_JWT_SECRET: ${CAMELEER_JWT_SECRET:-cameleer-dev-jwt-secret-change-in-production} CAMELEER_TENANT_ID: ${CAMELEER_TENANT_SLUG:-default} - CAMELEER_OIDC_ISSUER_URI: http://${PUBLIC_HOST:-localhost}:3001/oidc + CAMELEER_OIDC_ISSUER_URI: http://${PUBLIC_HOST:-localhost}/oidc CAMELEER_OIDC_AUDIENCE: ${CAMELEER_OIDC_AUDIENCE:-https://api.cameleer.local} healthcheck: test: ["CMD-SHELL", "curl -sf http://localhost:8081/api/v1/health || exit 1"] @@ -168,6 +168,13 @@ services: condition: service_healthy environment: CAMELEER_API_URL: http://cameleer3-server:8081 + labels: + - traefik.enable=true + - traefik.http.routers.server-ui.rule=PathPrefix(`/server`) + - traefik.http.routers.server-ui.service=server-ui + - traefik.http.routers.server-ui.middlewares=server-ui-strip + - traefik.http.middlewares.server-ui-strip.stripprefix.prefixes=/server + - traefik.http.services.server-ui.loadbalancer.server.port=80 networks: - cameleer diff --git a/docker/logto-bootstrap.sh b/docker/logto-bootstrap.sh index 9e99101..231dcad 100644 --- a/docker/logto-bootstrap.sh +++ b/docker/logto-bootstrap.sh @@ -42,8 +42,8 @@ SERVER_UI_PASS="${SERVER_UI_PASS:-admin}" # Redirect URIs (derived from PUBLIC_HOST) HOST="${PUBLIC_HOST:-localhost}" -SPA_REDIRECT_URIS="[\"http://${HOST}/callback\",\"http://${HOST}:8080/callback\",\"http://${HOST}:5173/callback\"]" -SPA_POST_LOGOUT_URIS="[\"http://${HOST}/login\",\"http://${HOST}:8080/login\",\"http://${HOST}:5173/login\"]" +SPA_REDIRECT_URIS="[\"http://${HOST}/callback\",\"http://${HOST}:5173/callback\"]" +SPA_POST_LOGOUT_URIS="[\"http://${HOST}/login\",\"http://${HOST}:5173/login\"]" TRAD_REDIRECT_URIS="[\"http://${HOST}:8081/oidc/callback\"]" TRAD_POST_LOGOUT_URIS="[\"http://${HOST}:8081\"]" @@ -104,7 +104,7 @@ get_admin_token() { get_default_token() { curl -s -X POST "${LOGTO_ENDPOINT}/oidc/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ - -H "Host: ${HOST}:3001" \ + -H "Host: ${HOST}" \ -d "grant_type=client_credentials&client_id=${1}&client_secret=${2}&resource=${MGMT_API_RESOURCE}&scope=all" } @@ -116,18 +116,18 @@ log "Got Management API token." # --- Helper: Logto API calls --- api_get() { - curl -s -H "Authorization: Bearer $TOKEN" -H "Host: ${HOST}:3001" "${LOGTO_ENDPOINT}${1}" 2>/dev/null || echo "[]" + curl -s -H "Authorization: Bearer $TOKEN" -H "Host: ${HOST}" "${LOGTO_ENDPOINT}${1}" 2>/dev/null || echo "[]" } api_post() { - curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "Host: ${HOST}:3001" \ + curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "Host: ${HOST}" \ -d "$2" "${LOGTO_ENDPOINT}${1}" 2>/dev/null || true } api_put() { - curl -s -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "Host: ${HOST}:3001" \ + curl -s -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -H "Host: ${HOST}" \ -d "$2" "${LOGTO_ENDPOINT}${1}" 2>/dev/null || true } api_delete() { - curl -s -X DELETE -H "Authorization: Bearer $TOKEN" -H "Host: ${HOST}:3001" "${LOGTO_ENDPOINT}${1}" 2>/dev/null || true + curl -s -X DELETE -H "Authorization: Bearer $TOKEN" -H "Host: ${HOST}" "${LOGTO_ENDPOINT}${1}" 2>/dev/null || true } # ============================================================ diff --git a/ui/src/components/Layout.tsx b/ui/src/components/Layout.tsx index 355bd70..a21ccd0 100644 --- a/ui/src/components/Layout.tsx +++ b/ui/src/components/Layout.tsx @@ -162,7 +162,7 @@ export function Layout() { } label="View Dashboard" - onClick={() => window.open(`http://${window.location.hostname}:8082`, '_blank', 'noopener')} + onClick={() => window.open('/server/', '_blank', 'noopener')} /> {/* User info + logout */} diff --git a/ui/src/config.ts b/ui/src/config.ts index cb876f2..fb32c44 100644 --- a/ui/src/config.ts +++ b/ui/src/config.ts @@ -22,7 +22,7 @@ export async function fetchConfig(): Promise { // Fallback to env vars (Vite dev mode) cached = { - logtoEndpoint: import.meta.env.VITE_LOGTO_ENDPOINT || `http://${window.location.hostname}:3001`, + logtoEndpoint: import.meta.env.VITE_LOGTO_ENDPOINT || `http://${window.location.hostname}`, logtoClientId: import.meta.env.VITE_LOGTO_CLIENT_ID || '', logtoResource: import.meta.env.VITE_LOGTO_RESOURCE || '', scopes: [