diff --git a/.env.example b/.env.example index baaa456..02407cf 100644 --- a/.env.example +++ b/.env.example @@ -46,4 +46,6 @@ CONTACT_EMAIL=sales@such.software # UI API_BASE_URL=http://api:8000 +# Private API address for the admin panel; nginx refuses /api/admin publicly. +ADMIN_API_BASE_URL=http://api:8000 SITE_URL=https://example.com diff --git a/README.md b/README.md index cbba5ad..eb1eff9 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,9 @@ Start from `.env.example` and adjust for your host. For non-Docker deployments y - `API_BASE_URL` for the UI: - If using a reverse proxy that routes `/api/` to the API on the same origin, set `API_BASE_URL=https://example.com` - If not using a reverse proxy, set `API_BASE_URL=http://127.0.0.1:8000` (see the notes in step 6) +- `ADMIN_API_BASE_URL` for the UI's admin panel, set to the API's private address + (for example `http://127.0.0.1:8000`). It falls back to `API_BASE_URL`; keep `/api/admin` + off your public reverse proxy. If you need a new `API_KEY_ENCRYPTION_KEY` value: @@ -375,6 +378,18 @@ From the admin panel you can: All endpoints require the `X-Admin-Key` header set to your `ADMIN_API_KEY`. +These endpoints return merchant API keys and webhook secrets, so the bundled nginx +refuses `/api/admin` with a 404. The admin panel calls them from the UI server over +the compose network (`ADMIN_API_BASE_URL`, default `http://api:8000`). To call them +yourself, do it from inside that network. This example reads the key from the API +container's environment, so it never appears on a command line: + +``` +docker compose exec api python -c 'import os, urllib.request as u; print(u.urlopen(u.Request("http://127.0.0.1:8000/api/admin/users", headers={"X-Admin-Key": os.environ["ADMIN_API_KEY"]})).read().decode())' +``` + +If you run your own reverse proxy, refuse `/api/admin` there as well. + ``` POST /api/admin/auth/verify — verify admin key GET /api/admin/users — list all merchants diff --git a/docker-compose.yml b/docker-compose.yml index 9a3903a..c364059 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -193,6 +193,7 @@ services: NEXT_PUBLIC_SITE_NAME: ${SITE_NAME:-XMR Checkout} environment: API_BASE_URL: ${API_BASE_URL:-http://nginx} + ADMIN_API_BASE_URL: ${ADMIN_API_BASE_URL:-http://api:8000} NEXT_PUBLIC_SITE_URL: ${SITE_URL:-http://localhost} NEXT_PUBLIC_DONATIONS_ENABLED: ${DONATIONS_ENABLED:-false} NEXT_PUBLIC_TURNSTILE_SITE_KEY: ${TURNSTILE_SITE_KEY:-} diff --git a/nginx/conf.d/default.conf b/nginx/conf.d/default.conf index 1516914..89199cd 100644 --- a/nginx/conf.d/default.conf +++ b/nginx/conf.d/default.conf @@ -26,6 +26,15 @@ server { return 308 $scheme://$host$uri$is_args$args; } + # The admin API returns every merchant's API key and webhook secret. Only the + # UI's server actions call it, over the compose network (ADMIN_API_BASE_URL), + # so the public edge refuses it. ^~ keeps any later regex location from + # claiming these paths, and nginx matches the normalized URI, so encoded or + # dot-segment spellings land here too. + location ^~ /api/admin { + return 404; + } + location /api/ { set $api_upstream "api"; # No URI suffix: nginx preserves the complete /api/v1/... request path. diff --git a/ui/app/(app)/admin/actions.ts b/ui/app/(app)/admin/actions.ts index f8dfbd6..670a678 100644 --- a/ui/app/(app)/admin/actions.ts +++ b/ui/app/(app)/admin/actions.ts @@ -4,7 +4,10 @@ import { cookies } from "next/headers"; import { redirect } from "next/navigation"; import { revalidatePath } from "next/cache"; -const apiBaseUrl = process.env.API_BASE_URL ?? "http://localhost:8000"; +// The public nginx edge refuses /api/admin, so admin calls go straight to the +// API service. Compose sets ADMIN_API_BASE_URL to http://api:8000. +const apiBaseUrl = + process.env.ADMIN_API_BASE_URL ?? process.env.API_BASE_URL ?? "http://localhost:8000"; const ADMIN_COOKIE = "xmrcheckout_admin_key";