Skip to content

Commit c0f5700

Browse files
authored
CKM-5630 Support data team in debugging login report (#154)
1 parent 44d83b8 commit c0f5700

File tree

11 files changed

+90
-104
lines changed

11 files changed

+90
-104
lines changed

nginx.dockerfile

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,6 @@ RUN <<`
129129
useradd -g nginx nginx
130130
`
131131

132-
# RUN <<`
133-
# set -e
134-
# curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor > /usr/share/keyrings/nginx-archive-keyring.gpg
135-
# printf "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian `lsb_release -cs` nginx\n" > /etc/apt/sources.list.d/nginx.list
136-
# printf "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" > /etc/apt/preferences.d/99nginx
137-
# `
138-
139-
# RUN <<`
140-
# set -e
141-
# apt-get update
142-
# apt-get install -y nginx
143-
# `
144-
145132
COPY <<` /etc/nginx/nginx.conf
146133
daemon off;
147134
user nginx;

scripts

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ build_test() {
192192
--build-arg RUNNER_BASE_IMAGE=${runnerBaseImage} \
193193
--build-arg PORT=${port} \
194194
--build-arg SSL_PORT=${sslPort} \
195+
--build-arg platform="linux/amd64" \
195196
${dockerArgs}
196197
}
197198

@@ -219,34 +220,15 @@ test() {
219220
trap 'test_cleanup' 0
220221

221222
printf "${MAGENTA}Running tests...${NC}\n"
223+
printf "\n"
224+
printf "Executing tests with the following options:\n"
225+
printf " SSL Version: ${SSL_VERSION}\n"
226+
printf " LIBJWT Version: ${LIBJWT_VERSION}\n"
227+
printf " NGINX Version: ${NGINX_VERSION}\n"
228+
222229
docker compose \
223230
-p ${TEST_CONTAINER_NAME_PREFIX} \
224-
-f ${TEST_COMPOSE_FILE} up \
225-
--no-start
226-
227-
test_now
228-
}
229-
230-
test_now() {
231-
nginxContainerName="${TEST_CONTAINER_NAME_PREFIX}-nginx"
232-
runnerContainerName="${TEST_CONTAINER_NAME_PREFIX}-runner"
233-
234-
echo
235-
echo "Executing tests with the following options:"
236-
echo " SSL Version: ${SSL_VERSION}"
237-
echo " LIBJWT Version: ${LIBJWT_VERSION}"
238-
echo " NGINX Version: ${NGINX_VERSION}"
239-
240-
docker start ${nginxContainerName}
241-
242-
if [ "$(docker container inspect -f '{{.State.Running}}' ${nginxContainerName})" != "true" ]; then
243-
printf "${RED}Failed to start container \"${nginxContainerName}\". See logs below:\n"
244-
docker logs ${nginxContainerName}
245-
printf "${NC}\n"
246-
return 1
247-
fi
248-
249-
docker start -a ${runnerContainerName}
231+
-f ${TEST_COMPOSE_FILE} up
250232
}
251233

252234
test_cleanup() {
@@ -260,9 +242,16 @@ get_port() {
260242
endPort=$((startPort + 100))
261243

262244
for p in $(seq ${startPort} ${endPort}); do
263-
if ! ss -ln | grep -q ":${p} "; then
264-
echo ${p}
265-
break
245+
if [ "$(uname)" == "Darwin" ]; then
246+
if ! lsof -i -P | grep LISTEN | grep -q ":${p} "; then
247+
echo ${p}
248+
break
249+
fi
250+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
251+
if ! ss -ln | grep -q ":${p} "; then
252+
echo ${p}
253+
break
254+
fi
266255
fi
267256
done
268257
}

src/ngx_http_auth_jwt_module.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,11 @@ static char *merge_extract_var_claims(ngx_conf_t *cf, ngx_command_t *cmd, void *
350350

351351
static ngx_int_t get_jwt_var_claim(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data)
352352
{
353-
ngx_log_debug(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "getting jwt value for var index %l", *((ngx_uint_t *)data));
353+
ngx_uint_t *claim_idx = (ngx_uint_t *)data;
354354
auth_jwt_ctx_t *ctx = get_request_jwt_ctx(r);
355355

356+
ngx_log_debug(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "getting jwt var claim for var at index %l", *claim_idx);
357+
356358
if (ctx == NULL)
357359
{
358360
ngx_log_debug(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "no module context found while getting jwt value");
@@ -361,7 +363,6 @@ static ngx_int_t get_jwt_var_claim(ngx_http_request_t *r, ngx_http_variable_valu
361363
}
362364
else
363365
{
364-
ngx_uint_t *claim_idx = (ngx_uint_t *)data;
365366
ngx_str_t claim_value = ((ngx_str_t *)ctx->claim_values->elts)[*claim_idx];
366367

367368
v->valid = 1;

test/docker-compose-test.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
services:
1+
name: ngx-http-auth-jwt-test
22

3+
services:
34
nginx:
45
container_name: ${TEST_CONTAINER_NAME_PREFIX:?required}-nginx
56
build:
@@ -10,8 +11,14 @@ services:
1011
args:
1112
BASE_IMAGE: ${FULL_IMAGE_NAME}:${NGINX_VERSION:?required}
1213
platform: linux/amd64
14+
pull_policy: always
1315
logging:
1416
driver: ${LOG_DRIVER:-json-file}
17+
healthcheck:
18+
test: ["CMD", "curl", "-f", "http://nginx:${PORT:-8000}/ping"]
19+
interval: 30s
20+
timeout: 5s
21+
retries: 3
1522

1623
runner:
1724
container_name: ${TEST_CONTAINER_NAME_PREFIX:?required}-runner
@@ -21,5 +28,7 @@ services:
2128
platforms:
2229
- linux/amd64
2330
platform: linux/amd64
31+
pull_policy: always
2432
depends_on:
25-
- nginx
33+
nginx:
34+
condition: service_healthy

test/ec_key_256.pem

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

test/ec_key_384.pem

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

test/ec_key_521.pem

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

test/etc/nginx/conf.d/test.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
error_log /var/log/nginx/debug.log debug;
22
access_log /var/log/nginx/access.log;
33

4+
log_format extractTest 'Log extract test sub: $jwt_claim_sub';
5+
46
server {
57
listen %{PORT};
68
listen %{SSL_PORT} ssl;
@@ -15,6 +17,10 @@ server {
1517
auth_jwt_loginurl "https://example.com/login";
1618
auth_jwt_enabled off;
1719

20+
location /ping {
21+
return 200 "pong";
22+
}
23+
1824
location / {
1925
alias /usr/share/nginx/html/;
2026
try_files index.html =404;
@@ -418,6 +424,15 @@ vXjq39xtcIBRTO1c2zs=
418424
return 200 "sub: $jwt_claim_sub";
419425
}
420426

427+
location /unsecure/extract-claim/body/sub {
428+
auth_jwt_enabled off;
429+
auth_jwt_redirect off;
430+
auth_jwt_location HEADER=Authorization;
431+
auth_jwt_extract_var_claims sub;
432+
433+
return 200 "sub: $jwt_claim_sub";
434+
}
435+
421436
location /secure/extract-claim/body/multiple {
422437
auth_jwt_enabled on;
423438
auth_jwt_redirect off;
@@ -445,4 +460,16 @@ vXjq39xtcIBRTO1c2zs=
445460
auth_jwt_enabled on;
446461
auth_jwt_redirect on;
447462
}
463+
464+
location /log {
465+
auth_jwt_enabled on;
466+
auth_jwt_redirect off;
467+
auth_jwt_location HEADER=Authorization;
468+
auth_jwt_validate_sub on;
469+
auth_jwt_extract_var_claims sub;
470+
471+
access_log /var/log/nginx/test_access.log extractTest;
472+
473+
return 200 "Log extract test sub: $jwt_claim_sub";
474+
}
448475
}

test/rsa_key_2048.pem

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

test/test-nginx.dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ FROM ${BASE_IMAGE:?required}
44
ARG PORT
55
ARG SSL_PORT
66

7+
RUN <<`
8+
set -e
9+
apt-get update
10+
apt-get install -y curl
11+
apt-get clean
12+
`
13+
714
COPY etc/ /etc/
815

916
COPY <<` /usr/share/nginx/html/index.html

0 commit comments

Comments
 (0)