Repository navigation
Expand file tree
/
Copy pathcompose.yaml
More file actions
157 lines (151 loc) · 4.78 KB
/
Copy pathcompose.yaml
File metadata and controls
157 lines (151 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# End-to-end / staging stack: Caddy (TLS) → app → Postgres, plus an optional mock
# OIDC IdP (docs/04 §4). The app applies migrations itself on startup, so there's
# no separate migrate step. This is NOT the daily loop — develop locally with
# `make run` + `make web-dev` (see README). Bring the IdP up with `--profile idp`.
#
# Secrets fail closed: POSTGRES_PASSWORD and SESSION_SECRET must be set (in a
# .env file next to this one, or the environment) or `compose up` aborts.
#
# Hardening applied to every service: no-new-privileges, all Linux capabilities
# dropped (only the few each image genuinely needs are added back), and read-only
# root filesystems with tmpfs for the paths that must be writable.
#
# Two networks isolate the datastore: `edge` carries Caddy↔app (and matches
# TRUSTED_PROXIES); `backend` is internal-only (no egress) and carries app↔db.
services:
postgres:
image: docker.io/library/postgres:17
environment:
POSTGRES_USER: wolke
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD (e.g. in .env)}
POSTGRES_DB: wolke
volumes:
- pgdata:/var/lib/postgresql/data
networks:
- backend
restart: unless-stopped
security_opt:
- no-new-privileges:true
# The entrypoint starts as root to init the data dir, then drops to the
# postgres user — so it needs exactly these caps and nothing more.
cap_drop:
- ALL
cap_add:
- CHOWN
- DAC_OVERRIDE
- FOWNER
- SETGID
- SETUID
read_only: true
tmpfs:
- /tmp
- /var/run/postgresql
healthcheck:
test: ["CMD-SHELL", "pg_isready -U wolke -d wolke"]
interval: 5s
timeout: 3s
retries: 10
app:
build:
context: .
environment:
# Public HTTPS URL (TLS terminates at Caddy). Drives Secure cookies and,
# in Phase 1, OIDC redirect_uri — even though the app serves plain HTTP here.
PUBLIC_URL: https://localhost
HTTP_ADDR: ":8080"
DATABASE_URL: postgres://wolke:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD (e.g. in .env)}@postgres:5432/wolke?sslmode=disable
SESSION_SECRET: ${SESSION_SECRET:?set SESSION_SECRET (openssl rand -base64 32)}
# Trust X-Forwarded-* only from the edge network (Caddy's subnet).
TRUSTED_PROXIES: 172.28.0.0/16
LOG_LEVEL: info
# OIDC is wired in Phase 1; point it at the mock IdP then:
# OIDC_ISSUER_URL: http://mock-oidc:8080/default
# The app applies migrations itself on startup (auto-migrate), so it only
# needs the database to be reachable.
depends_on:
postgres:
condition: service_healthy
networks:
- edge
- backend
# Not published to the host: only Caddy reaches the app.
expose:
- "8080"
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
read_only: true
tmpfs:
- /tmp
# The binary probes itself (distroless has no shell); gates on /readyz so
# Caddy waits for real readiness, not just process start.
healthcheck:
test: ["CMD", "/server", "healthcheck"]
interval: 15s
timeout: 5s
start_period: 10s
retries: 3
caddy:
image: docker.io/library/caddy:2
# Prod defaults to the privileged ports (Caddy is the only exposed surface).
# Rootless podman can't bind <1024: override e.g. CADDY_HTTPS_PORT=8443.
ports:
- "${CADDY_HTTP_PORT:-80}:80"
- "${CADDY_HTTPS_PORT:-443}:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro,z
- caddy_data:/data
- caddy_config:/config
depends_on:
app:
condition: service_healthy
networks:
- edge
restart: unless-stopped
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
# Needed to bind 80/443; harmless when overridden to high ports.
cap_add:
- NET_BIND_SERVICE
read_only: true
tmpfs:
- /tmp
# Provider-agnostic dev IdP (proves the OIDC client is not Keycloak-specific).
# Started only with `--profile idp`; wired up in Phase 1.
mock-oidc:
image: ghcr.io/navikt/mock-oauth2-server:2.1.10
profiles: ["idp"]
environment:
SERVER_PORT: "8080"
expose:
- "8080"
networks:
- backend
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
volumes:
pgdata:
caddy_data:
caddy_config:
networks:
# Caddy ↔ app. Its subnet is what the app trusts for X-Forwarded-* headers
# (TRUSTED_PROXIES above), so keep the two in sync.
edge:
ipam:
config:
- subnet: 172.28.0.0/16
# app ↔ Postgres (and the mock IdP). internal:true → no route to the internet,
# so the datastore is unreachable from outside the compose project.
backend:
internal: true
ipam:
config:
- subnet: 172.29.0.0/16