vouch / vouch-proxy

an SSO and OAuth / OIDC login solution for Nginx using the auth_request module
MIT License
2.92k stars 327 forks source link

Using vouch with http basic authentication #501

Closed iercan closed 2 years ago

iercan commented 2 years ago

Hi. I'm trying to configure vouch proxy with auth_basic module. But because of 401 redirection, I'm ending up infinite redirection. I've tried satisfy all but didn't work. #390 is also opened about this without any solution. I'd be happy if anyone share a workaround for this.

iercan commented 2 years ago

I've managed to do that by adding a dummy proxy server and configured basic_auth on that server. Here is how my config look like. Hope it helps someone else.

upstream myserver {
    server localhost:8888;
    keepalive 16;
}

upstream dummy {
    server localhost:9999;
    keepalive 16;
}

server {
    listen 80;
    server_name myserver.mydomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name myserver.mydomain.com;
    ssl_certificate /etc/letsencrypt/live/myserver.mydomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/myserver.mydomain.com/privkey.pem;

    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

###
# Add vouch configuration here. I removed it for simplicity    
###

    location / {
        proxy_pass http://dummy/;
        proxy_set_header  X-Forwarded-Proto $scheme;    
        proxy_read_timeout 3600;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Vouch-User $auth_resp_x_vouch_user;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
 }

##dummy server configuration
server {
    listen 9999 default_server;
    server_name _;

    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;

    location / {
        proxy_pass http://myserver/;
        proxy_set_header  X-Forwarded-Proto $scheme;
        proxy_read_timeout 3600;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Vouch-User $auth_resp_x_vouch_user;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Connection "";

    }

 }
bnfinet commented 2 years ago

@iercan thanks for sharing this solution! Much appreciated.