I have a Django application that sits behind Nginx, which requires the user to authenticate via a government CAC (Smartcard). The CAC ID is read by Nginx and passed to Django, which maps that ID to a Django User and logs in that user. That part works fine.
However, if the user removes his/her CAC from the card reader, the application still moves merrily along, allowing the user to continue to load pages from that domain.
How can I force Nginx to verify the CAC certificate on each page load so that once the CAC is removed, Django can log the user out and force them to re-authenticate?
Nginx config:
server {
listen 443 ssl;
server_name my-server;
ssl_certificate ssl/server.crt;
ssl_certificate_key ssl/server.key;
ssl_verify_client on;
ssl_verify_depth 2;
ssl_client_certificate /etc/ssl/certs/dod-root-certs.pem;
location /static/ {
alias /etc/nginx/static/;
expires 30d;
}
location / {
proxy_pass http://localhost:8000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Protocol ssl;
proxy_set_header X-SSL-User-DN $ssl_client_s_dn;
proxy_set_header X-SSL-Authenticated $ssl_client_verify;
proxy_connect_timeout 60;
proxy_read_timeout 60;
}
}