Skip to content

Commit 1b64971

Browse files
committed
chore: implements docker-compose.
1 parent 9b350e0 commit 1b64971

File tree

6 files changed

+174
-32
lines changed

6 files changed

+174
-32
lines changed

example/kong/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

example/kong/Makefile

Lines changed: 0 additions & 30 deletions
This file was deleted.

example/kong/POSTGRES_PASSWORD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kong

example/kong/config/kong.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# a very minimal declarative config file
2+
_format_version: "2.1"
3+
_transform: true

example/kong/docker-compose.yaml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Inspired in https://github.com/Kong/docker-kong
2+
version: '3.9'
3+
4+
x-kong-config:
5+
&kong-env
6+
KONG_DATABASE: postgres
7+
KONG_PG_DATABASE: ${KONG_PG_DATABASE:-kong}
8+
KONG_PG_HOST: db
9+
KONG_PG_USER: ${KONG_PG_USER:-kong}
10+
KONG_PG_PASSWORD_FILE: /run/secrets/kong_postgres_password
11+
12+
volumes:
13+
kong_data: {}
14+
kong_prefix_vol:
15+
driver_opts:
16+
type: tmpfs
17+
device: tmpfs
18+
kong_tmp_vol:
19+
driver_opts:
20+
type: tmpfs
21+
device: tmpfs
22+
23+
networks:
24+
kong-net:
25+
external: false
26+
27+
services:
28+
kong-migrations:
29+
image: "kong/incubator:gateway-wasmer-3.0.0.0"
30+
command: kong migrations bootstrap
31+
depends_on:
32+
- db
33+
environment:
34+
<<: *kong-env
35+
secrets:
36+
- kong_postgres_password
37+
networks:
38+
- kong-net
39+
restart: on-failure
40+
41+
kong-migrations-up:
42+
image: "kong/incubator:gateway-wasmer-3.0.0.0"
43+
command: kong migrations up && kong migrations finish
44+
depends_on:
45+
- db
46+
- kong-migrations
47+
environment:
48+
<<: *kong-env
49+
secrets:
50+
- kong_postgres_password
51+
networks:
52+
- kong-net
53+
restart: on-failure
54+
55+
kong:
56+
image: "kong/incubator:gateway-wasmer-3.0.0.0"
57+
user: "${KONG_USER:-kong}"
58+
environment:
59+
<<: *kong-env
60+
KONG_ADMIN_ACCESS_LOG: /dev/stdout
61+
KONG_ADMIN_ERROR_LOG: /dev/stderr
62+
KONG_PROXY_LISTEN: "${KONG_PROXY_LISTEN:-0.0.0.0:8000}"
63+
KONG_ADMIN_LISTEN: "${KONG_ADMIN_LISTEN:-0.0.0.0:8001}"
64+
KONG_PROXY_ACCESS_LOG: /dev/stdout
65+
KONG_PROXY_ERROR_LOG: /dev/stderr
66+
KONG_PREFIX: ${KONG_PREFIX:-/var/run/kong}
67+
KONG_DECLARATIVE_CONFIG: "/opt/kong/kong.yaml"
68+
KONG_WASM: "on"
69+
KONG_WASM_MODULES: "/wasm/main.wasm"
70+
secrets:
71+
- kong_postgres_password
72+
networks:
73+
- kong-net
74+
ports:
75+
# The following two environment variables default to an insecure value (0.0.0.0)
76+
# according to the CIS Security test.
77+
- "${KONG_INBOUND_PROXY_LISTEN:-0.0.0.0}:8000:8000/tcp"
78+
- "${KONG_INBOUND_SSL_PROXY_LISTEN:-0.0.0.0}:8443:8443/tcp"
79+
# Making them mandatory but undefined, like so would be backwards-breaking:
80+
# - "${KONG_INBOUND_PROXY_LISTEN?Missing inbound proxy host}:8000:8000/tcp"
81+
# - "${KONG_INBOUND_SSL_PROXY_LISTEN?Missing inbound proxy ssl host}:8443:8443/tcp"
82+
# Alternative is deactivating check 5.13 in the security bench, if we consider Kong's own config to be enough security here
83+
84+
- "127.0.0.1:8001:8001/tcp"
85+
- "127.0.0.1:8444:8444/tcp"
86+
healthcheck:
87+
test: [ "CMD", "kong", "health" ]
88+
interval: 10s
89+
timeout: 10s
90+
retries: 10
91+
restart: on-failure:5
92+
read_only: true
93+
volumes:
94+
- kong_prefix_vol:${KONG_PREFIX:-/var/run/kong}
95+
- kong_tmp_vol:/tmp
96+
- ./config:/opt/kong
97+
- ../../build:/wasm
98+
security_opt:
99+
- no-new-privileges
100+
depends_on:
101+
- httpbin
102+
103+
db:
104+
image: postgres:9.5
105+
environment:
106+
POSTGRES_DB: ${KONG_PG_DATABASE:-kong}
107+
POSTGRES_USER: ${KONG_PG_USER:-kong}
108+
POSTGRES_PASSWORD_FILE: /run/secrets/kong_postgres_password
109+
secrets:
110+
- kong_postgres_password
111+
healthcheck:
112+
test: [ "CMD", "pg_isready", "-U", "${KONG_PG_USER:-kong}" ]
113+
interval: 30s
114+
timeout: 30s
115+
retries: 3
116+
restart: on-failure
117+
stdin_open: true
118+
tty: true
119+
networks:
120+
- kong-net
121+
volumes:
122+
- kong_data:/var/lib/postgresql/data
123+
124+
httpbin:
125+
image: mccutchen/go-httpbin:v2.5.0
126+
environment:
127+
- MAX_BODY_SIZE=15728640 # 15 MiB
128+
ports:
129+
- 10080:8080
130+
networks:
131+
- kong-net
132+
133+
service-provisioner:
134+
image: clue/httpie
135+
volumes:
136+
- .:/run
137+
entrypoint: [ "/run/service-provisioner.sh" ]
138+
depends_on:
139+
- httpbin
140+
- kong
141+
networks:
142+
- kong-net
143+
144+
secrets:
145+
kong_postgres_password:
146+
file: ./POSTGRES_PASSWORD
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
UPSTREAM_HOST=${UPSTREAM_HOST:-httpbin}
4+
KONG_HOST=${KONG_HOST:-kong}
5+
KONG_HOSTPORT=${KONG_HOST}:8001
6+
7+
numRetries=0
8+
for numRetries in {1..5}; do
9+
sleep 10
10+
http ${KONG_HOSTPORT} && break
11+
echo "Retrying...";
12+
done
13+
14+
if [ numRetries == 5 ] exit 1; fi
15+
16+
http --ignore-stdin POST ${KONG_HOSTPORT}/services name="httpbin" host="${UPSTREAM_HOST}" path="/" port:=10080 protocol="http"
17+
18+
http --ignore-stdin POST ${KONG_HOSTPORT}/services/httpbin/routes name="httpbin" "paths[]=/" "paths[]=/anything" "paths[]=/uuid"
19+
20+
http --ignore-stdin POST ${KONG_HOSTPORT}/services/httpbin/plugins name="proxy-wasm" \
21+
"config[filters][0][name]=main" \
22+
"config[filters][0][config]={\"rules\":[\"Include @demo-conf\",\"Include @crs-setup-demo-conf\",\"SecDebugLogLevel 3\",\"Include @owasp_crs/*.conf\",\"SecRule REQUEST_URI \\\"@streq /uuid\\\" \\\"id:101,phase:1,t:lowercase,deny\\\" \\\nSecRule REQUEST_BODY \\\"@rx maliciouspayload\\\" \\\"id:102,phase:2,t:lowercase,deny\\\" \\\nSecRule RESPONSE_HEADERS::status \\\"@rx 406\\\" \\\"id:103,phase:3,t:lowercase,deny\\\" \\\nSecRule RESPONSE_BODY \\\"@contains responsebodycode\\\" \\\"id:104,phase:4,t:lowercase,deny\\\"\"]}"
23+
24+
http --ignore-stdin GET ${KONG_HOST}:8000/

0 commit comments

Comments
 (0)