Giter VIP home page Giter VIP logo

nginx-ntlm-module's Introduction

nginx-ntlm-module

The NTLM module allows proxying requests with NTLM Authentication. The upstream connection is bound to the client connection once the client sends a request with the "Authorization" header field value starting with "Negotiate" or "NTLM". Further client requests will be proxied through the same upstream connection, keeping the authentication context.

How to use

Syntax: ntlm [connections];
Default: ntlm 100;
Context: upstream

upstream http_backend {
    server 127.0.0.1:8080;

    ntlm;
}

server {
    ...

    location /http/ {
        proxy_pass http://http_backend;
        # next 2 settings are required for the keepalive to work properly
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}

The connections parameter sets the maximum number of connections to the upstream servers that are preserved in the cache.

Syntax: ntlm_timeout timeout;
Default: ntlm_timeout 60s;
Context: upstream

Sets the timeout during which an idle connection to an upstream server will stay open.

Build

Follow the instructions from Building nginx from Sources and add the following line to the configure command

./configure \
    --add-module=../nginx-ntlm-module

To build this as dynamic module run this command

./configure \
    --add-dynamic-module=../nginx-ntlm-module

Tests

In order to run the tests you need nodejs and perl installed on your system

# install the backend packages
npm install -C t/backend

# instal the test framework
cpan Test::Nginx

# set the path to your nginx location
export PATH=/opt/local/nginx/sbin:$PATH

prove -r t

Acknowledgments

  • This module is using most of the code from the original nginx keepalive module.
  • DO NOT USE THIS IN PRODUCTION. Nginx Plus has support for NTLM.

Authors

TODO

  • Add tests
  • Add support for multiple workers
  • Drop the upstream connection when the client connection drops.
  • Add travis ci

nginx-ntlm-module's People

Contributors

gabihodoroaga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nginx-ntlm-module's Issues

Some segfaults

Hi,

I'm having some segfaults here. nginx version: nginx/1.20.1
Please help me to get some debug info for you.

Not able to increase timeout of ntlm

upstream backend_ntlm { server backend.com:443; ntlm_timeout 240s; ntlm; }

I am trying this but ntlm is expiring in 60s which is its default timeout.

Doesn't work with nginx 1.16/1.18

Hi,

I am not able to install it either on nginx 1.16 nor 1.18.

 nginx-1.16.1]# ./configure     --add-dynamic-module=../nginx-ntlm-module/
checking for OS
 + Linux 4.9.27-14.31.amzn1.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for EPOLLEXCLUSIVE ... not found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for prctl(PR_SET_KEEPCAPS) ... found
checking for capabilities ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for sched_setaffinity() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for SO_BINDANY ... not found
checking for IP_TRANSPARENT ... found
checking for IP_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... not found
checking for IP_RECVDSTADDR ... not found
checking for IP_SENDSRCADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
configuring additional dynamic modules
adding module in ../nginx-ntlm-module/
 + ngx_http_upstream_ntlm_module was configured
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
upstream http_backend {
    server 127.0.0.1:8080;
    ntlm;
}

server {
    listen 5001;
    location / {
        proxy_pass http://http_backend;
        # next 2 settings are required for the keepalive to work properly
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}


/etc/init.d/nginx start
Starting nginx: nginx: [emerg] unknown directive "ntlm" in /etc/nginx/conf.d/default.conf:3

What do I wrong?

Working, but using Auth Login Pop-Up - Can I not forward credentials?

Hey there,

Thanks for the great software! I'm hitting one limitation though. It seems that when I make the initial request, it asks for credentials via pop-up. After this it seems to save them for a time, but I'd prefer it just uses the Windows Auth credentials. Is this possible or is this normal behavior?

Here is my nginx config:

server {
    listen       80;
    listen  [::]:80;
    server_name  domain.com;

        location / {
            ##CORS
            proxy_hide_header Access-Control-Allow-Origin;
            add_header Access-Control-Allow-Origin http://domain.com;
            ##CORS
            ##API
            proxy_pass_header Access-Control-Allow-Methods;
            proxy_hide_header Access-Control-Allow-Headers;
            add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type';
            add_header Access-Control-Allow-Credentials true;
            ##API
            ##NTLM
            proxy_set_header Cookie $http_cookie;
            add_header 'Access-Control-Expose-Headers' 'Authorization' always;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            #NTLM
            proxy_pass http://http_backend;
        }
}

Dockerfile Request

I'm wondering if you could supply a Dockerfile to help get this up and running easily?

Also, on a side note, I'm trying to build a proxy that will enable me to bypass CORS and still utilize NTML, this looks like my only option (free). This should work for my scenario though correct?

Thanks!

Not Working

Have tested and not work...
only log line is: ntlm auth header found

Verify NTLM working and pass username to app?

First of all, thank you @gabihodoroaga for your work with this module.

This may be a stupid question, but how do I know that this module is working? I don't see any headers referencing Authorization or the like and I was not prompted for any credentials. Perhaps I am not fully understanding NTLM in this context. I successfully started a docker container following the alpine/static instructions and am able to be proxied to a test JS web app running locally like so:

    upstream backend {
        # js app running locally
        server 172.30.88.113:3000;
        ntlm;
    }

    server {
        listen          80;
        server_name     _;

        root      /etc/nginx/html;
        index     index.html;

        location / {
            proxy_pass http://backend;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
        }
    }

Is there a way to pass the username from NTLM to the JS app running locally? Like in a request header or something?

Happy to provide any more logs/information.
Thanks!

Seems conflicts with `balancer_by_lua_file` directive

Hi,
My nginx.conf is:

    upstream backsource {
        server 127.0.0.1;
        ntlm 100;
        balancer_by_lua_file /home/work/waf/lua/balancer.lua;
    }

openresty report a error: nginx: [warn] load balancing method redefined in /.../nginx.conf
It seems that the directive ntlm conflicts with balancer_by_lua_file.

Nginx not responding and use 100% cpu

Hi @gabihodoroaga

thank you for this very nice module it works very well! ๐Ÿ‘

But after a couple of hours the Nginx Server is not responding for requests anymore and has 100% CPU usage.
Do you have any idea how to analyze this?

Systeminfo:

  • Debian GNU/Linux 10 (buster)
  • nginx/1.14.2

Nginx error.log:
2021/05/30 01:11:37 [error] 29161#29161: MEMSTORE:05: my procslot not found! I don't know what to do!
ker process is shutting down: /build/nginx-Cjs4TR/nginx-1.14.2/debian/modules/nchan/src/store/memory/memstore.c:1616: nchan_store_exit_worker: Assertion `0' failed.
2021/05/30 01:11:37 [alert] 555#555: worker process 29161 exited on signal 6
double free or corruption (!prev)
2021/05/31 15:40:16 [alert] 1549#1549: worker process 1551 exited on signal 6
free(): invalid pointer
2021/05/31 15:42:22 [alert] 1549#1549: worker process 1557 exited on signal 6
2021/05/31 15:42:22 [alert] 1549#1549: worker process 1550 exited on signal 11
double free or corruption (!prev)
2021/05/31 15:43:26 [alert] 1549#1549: worker process 1561 exited on signal 6
double free or corruption (!prev)
2021/05/31 15:44:30 [alert] 1549#1549: worker process 1562 exited on signal 6
double free or corruption (!prev)
2021/05/31 15:46:10 [alert] 1549#1549: worker process 1563 exited on signal 6
double free or corruption (!prev)
2021/05/31 15:47:14 [alert] 1549#1549: worker process 1564 exited on signal 6
double free or corruption (!prev)
2021/05/31 15:48:22 [alert] 1549#1549: worker process 1566 exited on signal 6
double free or corruption (!prev)
2021/05/31 15:49:34 [alert] 1549#1549: worker process 1567 exited on signal 6
double free or corruption (!prev)
2021/05/31 15:50:36 [alert] 1549#1549: worker process 1568 exited on signal 6
double free or corruption (!prev)
2021/05/31 15:51:09 [alert] 1549#1549: worker process 1569 exited on signal 6
2021/05/31 15:58:45 [alert] 1549#1549: worker process 1560 exited on signal 9
2021/05/31 15:58:45 [alert] 1549#1549: worker process 1570 exited on signal 9

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.