TeslaGov / ngx-http-auth-jwt-module

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

cookie and cookies in 1.24.0... #99

Closed TomaszWojtas closed 1 year ago

TomaszWojtas commented 1 year ago

Hi,

I keep receiving weird looking error:

image

Any ideas how to solve?

Best regards Tomasz

JoshMcCullough commented 1 year ago

Hello. Can you confirm which version of the module you're using, and how you obtained it (from the release or self-built)?

NGINX v1.23.0 changed "cookies" to "cookie", so you need to make sure you're using the latest code for the module.

TomaszWojtas commented 1 year ago

Hi! Thank you for instant reply. I am using latest release 2.0.1, but now I think I don't really understand how Dockers and those .so files work. I thought I just need to put them into folder with source, but now I see it doesn't work that way.

However - I am trying to compile nginx 1.24.0 from source using: ./configure --add-module=../ngx-http-auth-jwt-module \ --with-http_ssl_module \ --with-http_v2_module \ --with-ld-opt="-L/usr/local/opt/openssl/lib" \ --with-cc-opt="-I/usr/local/opt/openssl/include"

it fails on make

I am using plugin sources from: https://github.com/TeslaGov/ngx-http-auth-jwt-module/archive/refs/tags/2.0.1.tar.gz and nginx from: https://nginx.org/download/nginx-1.24.0.tar.gz

What I am doing wrong?

Thank you for any assistance :)

TomaszWojtas commented 1 year ago

@JoshMcCullough - any suggestions? :)

TW

JoshMcCullough commented 1 year ago

I don't think there's any need for you to compile the module from source, or for you to include the module in the ./configure line there. Are you compiling NGINX from source for some specific reason, vs. just using a binary release?

My suggestions:

  1. Get NGINX 1.24.0 working as you need it (without this module).
  2. "Install" this module's binary release from here: https://github.com/TeslaGov/ngx-http-auth-jwt-module/releases/download/2.0.1/ngx_http_auth_jwt_module_2.0.1_nginx_1.24.0.tgz

In your NGINX config, load the module -- this should be at the root level of the config (update the path as needed):

load_module /usr/lib64/nginx/modules/ngx_http_auth_jwt_module.so;

Then running nginx -t should hopefully work.

TomaszWojtas commented 1 year ago

@JoshMcCullough I followed your approach.

  1. I configured nginx 1.24.0 this way:

./configure --prefix=/var/www/html --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --with-pcre --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-http_ssl_module --with-http_image_filter_module=dynamic --modules-path=/etc/nginx/modules --with-http_v2_module --with-stream=dynamic --with-http_addition_module --with-http_mp4_module --with-http_ssl_module --with-ld-opt="-L/usr/local/opt/openssl/lib" --with-cc-opt="-I/usr/local/opt/openssl/include"

sudo make sudo make install

I added: load_module /usr/lib/nginx/modules/ngx_http_auth_jwt_module.so; to /etc/nginx/nginx.conf

But now I get: nginx: [emerg] module "/usr/lib/nginx/modules/ngx_http_auth_jwt_module.so" is not binary compatible in /etc/nginx/nginx.conf:6 nginx: configuration file /etc/nginx/nginx.conf test failed

JoshMcCullough commented 1 year ago

I assume, still, that there's a reason you're building NGINX from source. And if you need to do that then I think the problem is that you're missing the --with-compat option which needs to be passed to ./configure in order to enable dynamic modules. But I'm not sure, since we do not build NGINX from source, we just use the binaries / official NGINX Docker container. Here's an example

nginx-test.dockerfile

FROM nginx:1.24.0
RUN <<`
apt-get update
apt-get -y install libjansson4 libjwt0 wget
cd /etc/nginx
sed -ri '/pid\s+\/var\/run\/nginx\.pid;$/a load_module \/etc\/nginx\/ngx_http_auth_jwt_module\.so;' nginx.conf
wget https://github.com/TeslaGov/ngx-http-auth-jwt-module/releases/download/2.0.1/ngx_http_auth_jwt_module_2.0.1_nginx_1.24.0.tgz
tar -xzf ngx_http_auth_jwt_module_2.0.1_nginx_1.24.0.tgz
rm ngx_http_auth_jwt_module_2.0.1_nginx_1.24.0.tgz
`

And you can confirm that it works by building an image from this Dockerfile, and running a container (with bash as the entrypoint):

> docker buildx build -t nginx-test -f nginx-test.dockerfile .
> docker run --rm -it --entrypoint bash nginx-test
> nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
TomaszWojtas commented 1 year ago

I don't think there's any need for you to compile the module from source, or for you to include the module in the ./configure line there. Are you compiling NGINX from source for some specific reason, vs. just using a binary release?

Ok, now I get it. The reason I was compiling nginx from the source was that the latest version I could get by sudo apt-get install nginx was 1.18. However we can use prebuilt packages from: https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/ and update /etc/apt/sources.list.d/ to get the latest one. In that case plugin seems to be working! Thanks! ;)

@JoshMcCullough In fact there were no reason to do it from sources. I just didn't know I can use repositories directly from nginx. Thank you for your help!

TomaszWojtas commented 1 year ago

Solved!

JoshMcCullough commented 1 year ago

Glad to hear it!