TeslaGov / ngx-http-auth-jwt-module

Secure your NGINX locations with JWT
MIT License
308 stars 118 forks source link

Compiling with nginx 1.23 or newer statically fails #119

Closed Limest0n3 closed 6 months ago

Limest0n3 commented 6 months ago

Compiling statically with nginx version 1.23 or greater fails because of missing/renamed headers???

../ngx-http-auth-jwt-module-2.0.3/src/ngx_http_auth_jwt_module.c:657:58: error: 'ngx_http_headers_in_t' has no member named 'cookies'; did you mean 'cookie'? 90.38 657 | if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &jwt_location, &jwtCookieVal) != NGX_DECLINED) 90.38 | ^~~ 90.38 | cookie 90.38 ../ngx-http-auth-jwt-module-2.0.3/src/ngx_http_auth_jwt_module.c:657:67: error: passing argument 2 of 'ngx_http_parse_multi_header_lines' from incompatible pointer type [-Werror=incompatible-pointer-types] 90.38 657 | if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &jwt_location, &jwtCookieVal) != NGX_DECLINED) 90.38 | ^~~~~ 90.38 | | 90.38 | ngx_str_t 90.38 In file included from ../ngx-http-auth-jwt-module-2.0.3/src/ngx_http_auth_jwt_module.c:12: 90.38 src/http/ngx_http.h:107:22: note: expected 'ngx_table_elt_t ' {aka 'struct ngx_table_elt_s '} but argument is of type 'ngx_str_t ' 90.38 107 | ngx_table_elt_t headers, ngx_str_t name, ngx_str_t value); 90.38 | ~~~^~~~~ 90.38 ../ngx-http-auth-jwt-module-2.0.3/src/ngx_http_auth_jwt_module.c:657:9: error: too few arguments to function 'ngx_http_parse_multi_header_lines' 90.38 657 | if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &jwt_location, &jwtCookieVal) != NGX_DECLINED) 90.38 | ^~~~~~~~~ 90.38 In file included from ../ngx-http-auth-jwt-module-2.0.3/src/ngx_http_auth_jwt_module.c:12: 90.38 src/http/ngx_http.h:106:18: note: declared here 90.38 106 | ngx_table_elt_t ngx_http_parse_multi_header_lines(ngx_http_request_t *r, 90.38 | ^~~~~~~~~ 90.39 cc1: all warnings being treated as errors 90.39 make[1]: Leaving directory '/src/nginx-1.23.1' 90.39 make[1]: [objs/Makefile:1364: objs/addon/src/ngx_http_auth_jwt_module.o] Error 1 90.39 make: [Makefile:10: build] Error 2

It all works with version 1.22.1 and lower.

Command used for configuring, fail happens in make process. ./configure --add-module=../ngx-http-auth-jwt-module-2.0.3 --prefix=. --with-cc-opt='-static' --with-ld-opt='-static'

JoshMcCullough commented 6 months ago

See: https://github.com/TeslaGov/ngx-http-auth-jwt-module/issues/99

JoshMcCullough commented 6 months ago

We don't publish module binaries for 1.23.x because it's not listed on NGINX's download page as a mainline/stable/legacy version.

If you need to use this version of NGINX, you can build the module by running this from the repo root:

NGINX_VERSION=1.23.1 ./scripts.sh rebuild_module rebuild_test_runner test cp_bin

You should see all tests pass and you should have a bin dir with the module binaries inside. I just tried this and it seems to work fine.

JoshMcCullough commented 6 months ago

Here is the binary if it's easier for you...

ngx_http_auth_jwt_module_2.0.3_nginx_1.23.1.zip

Limest0n3 commented 6 months ago

We don't publish module binaries for 1.23.x because it's not listed on NGINX's download page as a mainline/stable/legacy version.

If you need to use this version of NGINX, you can build the module by running this from the repo root:

NGINX_VERSION=1.23.1 ./scripts.sh rebuild_module rebuild_test_runner test cp_bin

You should see all tests pass and you should have a bin dir with the module binaries inside. I just tried this and it seems to work fine.

Hi! Thanks for the reply.

I don't need to use 1.23.1 specifically but I would like to use the latest or stable (at this moment) nginx version compiled with ngx-http-auth-jwt module and I would like to compile the nginx statically so I don't have to mess around with dynamic libraries and can just execute the binary.

It all works with versions 1.22.1 and lower.

I tried running the script and the binaries updated but still can't compile statically. Is it possible with newer nginx versions or am I just dumb and didn't get what you meant. :)

Limest0n3 commented 6 months ago

As I understand the script compiles a dynamic module aka .so file.

Limest0n3 commented 6 months ago

Ok, seems like I got it working. Took a closer look to the Dockerfile that builds the module I noticed this section.

NGINX 1.23.0+ changes cookies to use a linked list, and renames cookies to cookie if [ "${MAJ}" -gt 1 ] || [ "${MAJ}" -eq 1 -a "${MIN}" -ge 23 ]; then BUILD_FLAGS="${BUILD_FLAGS} --with-cc-opt='-DNGX_LINKED_LIST_COOKIES=1'" fi

So when compiling with version 1.23.0 and newer, you have to add -DNGX_LINKED_LIST_COOKIES=1 as additional parameter.

The configure command now looks like this.

./configure --add-module=../ngx-http-auth-jwt-module-2.0.3 --prefix=. --with-cc-opt='-DNGX_LINKED_LIST_COOKIES=1 -static' --with-ld-opt='-static'

JoshMcCullough commented 6 months ago

So when compiling with version 1.23.0 and newer, you have to add -DNGX_LINKED_LIST_COOKIES=1 as additional parameter.

Yes! Glad you figured it out.