-
Notifications
You must be signed in to change notification settings - Fork 23
450 lines (409 loc) · 17.5 KB
/
Copy pathtest.yaml
File metadata and controls
450 lines (409 loc) · 17.5 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
name: Test GatewayD
on:
push:
branches:
- main
tags:
- v*
paths-ignore:
- "README.md"
- "LICENSE"
- "CONTRIBUTING.md"
- "CODE_OF_CONDUCT.md"
- ".gitignore"
- ".gitattributes"
pull_request:
paths-ignore:
- "README.md"
- "LICENSE"
- "CONTRIBUTING.md"
- "CODE_OF_CONDUCT.md"
- ".gitignore"
- ".gitattributes"
jobs:
test:
name: Test GatewayD
runs-on: ubuntu-latest
# Timeout after 10 minutes, to avoid hanging tests
timeout-minutes: 10
services:
postgres:
image: postgres
env:
POSTGRES_HOST: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres2:
image: postgres
env:
POSTGRES_HOST: postgres2
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5433:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout 🛎️
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install Go 🧑💻
uses: actions/setup-go@v5
with:
go-version: "1.25"
- name: Lint code with golangci-lint 🚨
uses: golangci/golangci-lint-action@v6
with:
version: "latest"
install-mode: "goinstall"
- name: Lint Bash script with shellcheck 🚨
uses: ludeeus/action-shellcheck@master
- name: Lint Dockerfile with hadolint 🚨
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
- name: Run Go tests 🔬
run: go test -tags embed_plugin_template -p 1 -cover -covermode atomic -coverprofile=profile.cov -v ./...
env:
GITHUB_AUTH_TOKEN: ${{ secrets.INTEGRATION }}
- name: Report coverage to coveralls 📈
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: profile.cov
ignore: "api/v1/*,usagereport/*"
test-plugin:
name: "Test Plugin: ${{ matrix.plugin }}"
runs-on: ubuntu-latest
needs: test
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
plugin: [cache, auth, js, sql-ids-ips]
services:
postgres:
image: postgres
env:
POSTGRES_HOST: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout 🛎️
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install Go 🧑💻
uses: actions/setup-go@v5
with:
go-version: "1.25"
- name: Build GatewayD 🏗️
run: make build-dev
- name: Install PSQL 🧑💻
run: |
sudo apt-get update
sudo apt-get install --yes --no-install-recommends postgresql-client redis-tools
# ---------- cache plugin ----------
- name: Checkout cache plugin 🛎️
if: matrix.plugin == 'cache'
uses: actions/checkout@v6
with:
repository: gatewayd-io/gatewayd-plugin-cache
path: gatewayd-plugin-cache
- name: Build and configure cache plugin 🏗️
if: matrix.plugin == 'cache'
run: |
cd gatewayd-plugin-cache && make build-dev && cd ..
export SHA256SUM=$(sha256sum gatewayd-plugin-cache/gatewayd-plugin-cache | awk '{print $1}')
cat <<EOF > gatewayd_plugins.yaml
metricsMergerPeriod: 1s
healthCheckPeriod: 1s
reloadOnCrash: true
timeout: 30s
plugins:
- name: gatewayd-plugin-cache
enabled: True
url: github.com/gatewayd-io/gatewayd-plugin-cache
localPath: ./gatewayd-plugin-cache/gatewayd-plugin-cache
args: ["--log-level", "debug"]
env:
- MAGIC_COOKIE_KEY=GATEWAYD_PLUGIN
- MAGIC_COOKIE_VALUE=5712b87aa5d7e9f9e9ab643e6603181c5b796015cb1c09d6f5ada882bf2a1872
- REDIS_URL=redis://localhost:6379/0
- EXPIRY=1h
- DEFAULT_DB_NAME=postgres
- METRICS_ENABLED=True
- METRICS_UNIX_DOMAIN_SOCKET=/tmp/gatewayd-plugin-cache.sock
- METRICS_PATH=/metrics
- API_GRPC_ADDRESS=localhost:19090
- PERIODIC_INVALIDATOR_ENABLED=False
- EXIT_ON_STARTUP_ERROR=False
- CACHE_CHANNEL_BUFFER_SIZE=100
checksum: ${SHA256SUM}
EOF
- name: Run GatewayD with cache plugin 🚀
if: matrix.plugin == 'cache'
run: ./gatewayd run -c testdata/gatewayd_tls.yaml &
- name: Test cache plugin 🧪
if: matrix.plugin == 'cache'
run: |
sleep 2
redis-cli FLUSHALL
psql ${PGURL} -c "CREATE TABLE cache_test (id serial PRIMARY KEY, name varchar(255));" | grep CREATE || exit 1
psql ${PGURL} -c "INSERT INTO cache_test (name) VALUES ('cached_value');" | grep INSERT || exit 1
psql ${PGURL} -c "SELECT * FROM cache_test;" | grep cached_value || exit 1
# Second identical SELECT should succeed (served from cache or DB)
psql ${PGURL} -c "SELECT * FROM cache_test;" | grep cached_value || exit 1
# Write should invalidate cache
psql ${PGURL} -c "INSERT INTO cache_test (name) VALUES ('new_value');" | grep INSERT || exit 1
psql ${PGURL} -c "SELECT * FROM cache_test;" | grep new_value || exit 1
psql ${PGURL} -c "DROP TABLE cache_test;" | grep DROP || exit 1
env:
PGURL: postgres://postgres:postgres@localhost:15432/postgres?sslmode=disable
- name: Test cache plugin over TLS 🧪
if: matrix.plugin == 'cache'
run: |
redis-cli FLUSHALL
psql ${PGURL_TLS} -c "CREATE TABLE cache_tls_test (id serial PRIMARY KEY, name varchar(255));" | grep CREATE || exit 1
psql ${PGURL_TLS} -c "INSERT INTO cache_tls_test (name) VALUES ('tls_cached');" | grep INSERT || exit 1
psql ${PGURL_TLS} -c "SELECT * FROM cache_tls_test;" | grep tls_cached || exit 1
psql ${PGURL_TLS} -c "SELECT * FROM cache_tls_test;" | grep tls_cached || exit 1
psql ${PGURL_TLS} -c "DROP TABLE cache_tls_test;" | grep DROP || exit 1
env:
PGURL_TLS: postgres://postgres:postgres@localhost:15432/postgres?sslmode=require
# ---------- auth plugin ----------
- name: Checkout auth plugin 🛎️
if: matrix.plugin == 'auth'
uses: actions/checkout@v6
with:
repository: gatewayd-io/gatewayd-plugin-auth
path: gatewayd-plugin-auth
- name: Build and configure auth plugin 🏗️
if: matrix.plugin == 'auth'
run: |
cd gatewayd-plugin-auth && make build-dev && cd ..
export SHA256SUM=$(sha256sum gatewayd-plugin-auth/gatewayd-plugin-auth | awk '{print $1}')
cat <<EOF > gatewayd_plugins.yaml
metricsMergerPeriod: 1s
healthCheckPeriod: 1s
reloadOnCrash: true
timeout: 30s
plugins:
- name: gatewayd-plugin-auth
enabled: True
url: github.com/gatewayd-io/gatewayd-plugin-auth
localPath: ./gatewayd-plugin-auth/gatewayd-plugin-auth
args: ["--log-level", "debug"]
env:
- MAGIC_COOKIE_KEY=GATEWAYD_PLUGIN
- MAGIC_COOKIE_VALUE=5712b87aa5d7e9f9e9ab643e6603181c5b796015cb1c09d6f5ada882bf2a1872
- AUTH_TYPE=cleartext
- CREDENTIALS_FILE=testdata/plugins/auth/credentials.yaml
- SERVER_VERSION=17.4
- AUTHORIZATION_ENABLED=true
- CASBIN_MODEL_PATH=testdata/plugins/auth/model.conf
- CASBIN_POLICY_PATH=testdata/plugins/auth/policy.csv
checksum: ${SHA256SUM}
EOF
- name: Run GatewayD with auth plugin 🚀
if: matrix.plugin == 'auth'
run: ./gatewayd run -c testdata/gatewayd_auth.yaml &
- name: Test auth plugin - valid credentials 🧪
if: matrix.plugin == 'auth'
run: |
sleep 3
psql "postgres://testuser:testpass@localhost:15432/postgres?sslmode=disable&connect_timeout=5" -c "SELECT 1 AS auth_ok;" | grep auth_ok || exit 1
- name: Test auth plugin - invalid credentials 🧪
if: matrix.plugin == 'auth'
run: |
# Connection with wrong password must fail
if psql "postgres://testuser:wrongpass@localhost:15432/postgres?sslmode=disable&connect_timeout=5" -c "SELECT 1;" 2>/dev/null; then
echo "ERROR: Connection with wrong password should have failed"
exit 1
fi
echo "OK: Invalid credentials correctly rejected"
- name: Test auth plugin - authorization 🧪
if: matrix.plugin == 'auth'
run: |
ADMIN_URL="postgres://testuser:testpass@localhost:15432/postgres?sslmode=disable&connect_timeout=5"
READONLY_URL="postgres://readonly:readpass@localhost:15432/postgres?sslmode=disable&connect_timeout=5"
# Admin user (testuser) can do everything
psql "${ADMIN_URL}" -c "CREATE TABLE auth_test (id serial PRIMARY KEY, name varchar(255));" | grep CREATE || exit 1
psql "${ADMIN_URL}" -c "INSERT INTO auth_test (name) VALUES ('admin_write');" | grep INSERT || exit 1
psql "${ADMIN_URL}" -c "SELECT * FROM auth_test;" | grep admin_write || exit 1
# Readonly user can SELECT
psql "${READONLY_URL}" -c "SELECT * FROM auth_test;" | grep admin_write || exit 1
# Readonly user cannot INSERT (should fail)
if psql "${READONLY_URL}" -c "INSERT INTO auth_test (name) VALUES ('should_fail');" 2>/dev/null; then
echo "ERROR: Readonly user should not be able to INSERT"
exit 1
fi
echo "OK: Authorization enforcement working"
# Cleanup
psql "${ADMIN_URL}" -c "DROP TABLE auth_test;" | grep DROP || exit 1
# ---------- js plugin ----------
- name: Checkout js plugin 🛎️
if: matrix.plugin == 'js'
uses: actions/checkout@v6
with:
repository: gatewayd-io/gatewayd-plugin-js
path: gatewayd-plugin-js
- name: Build and configure js plugin 🏗️
if: matrix.plugin == 'js'
run: |
cd gatewayd-plugin-js && make build-dev && cd ..
export SHA256SUM=$(sha256sum gatewayd-plugin-js/gatewayd-plugin-js | awk '{print $1}')
cat <<EOF > gatewayd_plugins.yaml
metricsMergerPeriod: 1s
healthCheckPeriod: 1s
reloadOnCrash: true
timeout: 30s
plugins:
- name: gatewayd-plugin-js
enabled: True
url: github.com/gatewayd-io/gatewayd-plugin-js
localPath: ./gatewayd-plugin-js/gatewayd-plugin-js
args: ["--log-level", "debug"]
env:
- MAGIC_COOKIE_KEY=GATEWAYD_PLUGIN
- MAGIC_COOKIE_VALUE=5712b87aa5d7e9f9e9ab643e6603181c5b796015cb1c09d6f5ada882bf2a1872
- SCRIPT_PATH=testdata/plugins/js/test_hooks.js
checksum: ${SHA256SUM}
EOF
- name: Run GatewayD with js plugin 🚀
if: matrix.plugin == 'js'
run: ./gatewayd run -c testdata/gatewayd_tls.yaml &
- name: Test js plugin 🧪
if: matrix.plugin == 'js'
run: |
sleep 2
# JS hook intercepts and logs queries while passing them through
psql ${PGURL} -c "CREATE TABLE js_test (id serial PRIMARY KEY, name varchar(255));" | grep CREATE || exit 1
psql ${PGURL} -c "INSERT INTO js_test (name) VALUES ('js_hook_test');" | grep INSERT || exit 1
psql ${PGURL} -c "SELECT * FROM js_test;" | grep js_hook_test || exit 1
psql ${PGURL} -c "UPDATE js_test SET name = 'updated' WHERE id = 1;" | grep UPDATE || exit 1
psql ${PGURL} -c "SELECT * FROM js_test;" | grep updated || exit 1
psql ${PGURL} -c "DROP TABLE js_test;" | grep DROP || exit 1
env:
PGURL: postgres://postgres:postgres@localhost:15432/postgres?sslmode=disable
- name: Test js plugin over TLS 🧪
if: matrix.plugin == 'js'
run: |
psql ${PGURL_TLS} -c "CREATE TABLE js_tls_test (id serial PRIMARY KEY, val int);" | grep CREATE || exit 1
psql ${PGURL_TLS} -c "INSERT INTO js_tls_test (val) VALUES (42);" | grep INSERT || exit 1
psql ${PGURL_TLS} -c "SELECT * FROM js_tls_test;" | grep 42 || exit 1
psql ${PGURL_TLS} -c "DROP TABLE js_tls_test;" | grep DROP || exit 1
env:
PGURL_TLS: postgres://postgres:postgres@localhost:15432/postgres?sslmode=require
# ---------- sql-ids-ips plugin ----------
- name: Checkout sql-ids-ips plugin 🛎️
if: matrix.plugin == 'sql-ids-ips'
uses: actions/checkout@v6
with:
repository: gatewayd-io/gatewayd-plugin-sql-ids-ips
path: gatewayd-plugin-sql-ids-ips
- name: Start mock prediction API 🤖
if: matrix.plugin == 'sql-ids-ips'
run: python3 testdata/plugins/mock_sqli_api.py 8000 &
- name: Build and configure sql-ids-ips plugin 🏗️
if: matrix.plugin == 'sql-ids-ips'
run: |
cd gatewayd-plugin-sql-ids-ips && make build-dev && cd ..
export SHA256SUM=$(sha256sum gatewayd-plugin-sql-ids-ips/gatewayd-plugin-sql-ids-ips | awk '{print $1}')
cat <<EOF > gatewayd_plugins.yaml
metricsMergerPeriod: 1s
healthCheckPeriod: 1s
reloadOnCrash: true
timeout: 30s
plugins:
- name: gatewayd-plugin-sql-ids-ips
enabled: True
url: github.com/gatewayd-io/gatewayd-plugin-sql-ids-ips
localPath: ./gatewayd-plugin-sql-ids-ips/gatewayd-plugin-sql-ids-ips
args: ["--log-level", "debug"]
env:
- MAGIC_COOKIE_KEY=GATEWAYD_PLUGIN
- MAGIC_COOKIE_VALUE=5712b87aa5d7e9f9e9ab643e6603181c5b796015cb1c09d6f5ada882bf2a1872
- PREDICTION_API_ADDRESS=http://localhost:8000
- THRESHOLD=0.8
- ENABLE_LIBINJECTION=True
- LIBINJECTION_PERMISSIVE_MODE=True
- RESPONSE_TYPE=error
- ERROR_MESSAGE=SQL injection detected
- ERROR_DETAIL=Back off, you are not welcome here.
- ERROR_SEVERITY=EXCEPTION
- ERROR_NUMBER=42000
- METRICS_ENABLED=True
- METRICS_UNIX_DOMAIN_SOCKET=/tmp/gatewayd-plugin-sql-ids-ips.sock
- METRICS_PATH=/metrics
checksum: ${SHA256SUM}
EOF
- name: Run GatewayD with sql-ids-ips plugin 🚀
if: matrix.plugin == 'sql-ids-ips'
run: ./gatewayd run -c testdata/gatewayd_tls.yaml &
- name: Test sql-ids-ips plugin - legitimate queries 🧪
if: matrix.plugin == 'sql-ids-ips'
run: |
sleep 2
psql ${PGURL} -c "CREATE TABLE sqli_test (id serial PRIMARY KEY, name varchar(255));" | grep CREATE || exit 1
psql ${PGURL} -c "INSERT INTO sqli_test (name) VALUES ('safe_value');" | grep INSERT || exit 1
psql ${PGURL} -c "SELECT * FROM sqli_test WHERE id = 1;" | grep safe_value || exit 1
psql ${PGURL} -c "UPDATE sqli_test SET name = 'still_safe' WHERE id = 1;" | grep UPDATE || exit 1
psql ${PGURL} -c "SELECT * FROM sqli_test;" | grep still_safe || exit 1
env:
PGURL: postgres://postgres:postgres@localhost:15432/postgres?sslmode=disable
- name: Test sql-ids-ips plugin - injection blocked 🧪
if: matrix.plugin == 'sql-ids-ips'
run: |
# OR 1=1 injection should be blocked
if psql ${PGURL} -c "SELECT * FROM sqli_test WHERE id = 1 OR 1=1;" 2>/dev/null; then
echo "ERROR: OR 1=1 injection should have been blocked"
exit 1
fi
echo "OK: OR 1=1 injection blocked"
# UNION SELECT injection should be blocked
if psql ${PGURL} -c "SELECT * FROM sqli_test UNION SELECT 1, version();" 2>/dev/null; then
echo "ERROR: UNION SELECT injection should have been blocked"
exit 1
fi
echo "OK: UNION SELECT injection blocked"
# Stacked query injection should be blocked
if psql ${PGURL} -c "SELECT * FROM sqli_test; DROP TABLE sqli_test;" 2>/dev/null; then
echo "ERROR: Stacked query injection should have been blocked"
exit 1
fi
echo "OK: Stacked query injection blocked"
env:
PGURL: postgres://postgres:postgres@localhost:15432/postgres?sslmode=disable
- name: Test sql-ids-ips plugin - cleanup 🧪
if: matrix.plugin == 'sql-ids-ips'
run: |
psql ${PGURL} -c "DROP TABLE IF EXISTS sqli_test;" | grep DROP || exit 1
env:
PGURL: postgres://postgres:postgres@localhost:15432/postgres?sslmode=disable