From 4c54c639e5c5e0d9ce5ee9423b7f5dc651bf64e0 Mon Sep 17 00:00:00 2001 From: Do Siki Date: Thu, 10 Sep 2026 10:32:04 +0200 Subject: [PATCH] fix(docker): authenticate the dev app's MongoDB URI (MITHOME-98) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docker-compose.dev.yml's mongodb service sets MONGO_INITDB_ROOT_USERNAME/ PASSWORD, which makes the official mongo image enable --auth — but the app service's MONGODB_URI was unauthenticated (mongodb://mongodb:27017/mozdit). Same bug class as MITHOME-32 (staging/production), but that ticket covers docker-compose.staging.yml /docker-compose.prod.yml specifically, not this dev file — hence the separate MITHOME-98. Why /api/health never caught it: that route is a pure liveness check and never touches MongoDB. Only an endpoint that actually performs a DB operation exercises the bug. Verified live (docker compose -f docker-compose.dev.yml up --build): - Reproduced the failure first: inside the running app container, a plain `mongodb://mongodb:27017/mozdit` connection's findOne() throws "Command find requires authentication" — confirms the hypothesis that the app fails only on a real query, not at startup. - With the fix in place: POST /api/contact returns 200 with a submissionId, and the document is actually present in contact_submissions (checked via mongosh) — a real, previously- broken write path now works end to end. - npm test: 58/58 passed (unaffected, as expected for a docker-compose/doc-only change). Also fixed the same stale unauthenticated example in DOCKER.md. Co-Authored-By: Claude Sonnet 5 --- DOCKER.md | 2 +- docker-compose.dev.yml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/DOCKER.md b/DOCKER.md index 2230f6c..4a833a0 100755 --- a/DOCKER.md +++ b/DOCKER.md @@ -56,7 +56,7 @@ mongosh "mongodb://admin:password123@localhost:27017/mozdit" ### 3. Alkalmazásból Az alkalmazás automatikusan csatlakozik: ``` -MONGODB_URI=mongodb://mongodb:27017/mozdit +MONGODB_URI=mongodb://admin:password123@mongodb:27017/mozdit?authSource=admin ``` ## 🛠️ Fejlesztési Parancsok diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 86960a8..01a074b 100755 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -12,7 +12,11 @@ services: - "127.0.0.1:8080:3000" environment: - NODE_ENV=development - - MONGODB_URI=mongodb://mongodb:27017/mozdit + # WHY authSource=admin: the mongodb service below only creates a root + # user (via MONGO_INITDB_ROOT_USERNAME/PASSWORD), which forces --auth + # on the mongod process — an unauthenticated URI fails every query + # with "Command find requires authentication" (MITHOME-98). + - MONGODB_URI=mongodb://admin:password123@mongodb:27017/mozdit?authSource=admin - MONGODB_DB=mozdit - NEXT_PUBLIC_SITE_URL=http://localhost:8080 - NEXT_PUBLIC_COMPANY_NAME=mozdIT Bt.