Correct way to pass headers to a Flask/WSGI app? #705
-
Please tell me, what configuration is recommended to pass headers set by mod-auth-openidc to a proxied Flask/WSGI application? I'm using docker image httpd:2.4-buster, installed libapache2-mod-auth-openidc at version 2.3.10 from the Debian package repo. I have SSL turned on and am using a valid (not self-signed) server cert, if that matters. I set my httpd-ssl.conf for proxying requests for a sub-location (not /), a REST API app built on Flask/WSGI; that's where I need the user name. I turned on debug by adding
But I could not observe any OIDC-set headers arriving at the proxied python app. Much searching lead me to the following workaround, which accesses environment variable
Is there a smarter way to configure apache and the openidc module? I guess what I'm really asking, if I'm not missing something really obvious, why different treatment? I.e., why is the environment variable REMOTE_USER accessible via Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
setting the headers in proxied requests is the default behaviour, there should be no need to configure something for that; perhaps you've turned it off somehow? (e.g. using OIDCPassClaimsAs) |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for answering so soon! I did not set config option OIDCPassClaimsAs. To debug, I added an endpoint at my Flask app to dump out all request headers. That endpoint showed headers like Accept, Cookie, X-Forwarded-For and so on; but no OIDC_* claims as headers. I am running the docker container locally, the browser locally also, so there's no network appliance/firewall in the path. I suspect I'm doing something wrong, which is why I posted, but I just don't see it yet. Update: here's the relevant portion of my httpd-ssl.conf file. The apache server has a single-page app and proxies REST requests to the python app. User browsers send secure (https) requests; the apache httpd server sends the data/JSON requests to the back-end app insecurely (http). Maybe having two
With this configuration in place, the Flask app receives the headers X-Forwarded-User and X-Remote-User as expected. |
Beta Was this translation helpful? Give feedback.
-
Here's a posting written so I can accept it as the answer. A flask/WSGI app (proxied or hosted) by Apache HTTPD version 2.4 receives no OIDC request headers because they contain underscore. To receive headers set by mod-auth-openidc, I changed the default OIDC header prefix to have no underscores via the following configuration line in a httpd.conf (or httpd-ssl.conf, etc.):
With this in place, the headers set by mod-auth-openidc arrive at my python/flask/wsgi app. |
Beta Was this translation helpful? Give feedback.
Here's a posting written so I can accept it as the answer.
A flask/WSGI app (proxied or hosted) by Apache HTTPD version 2.4 receives no OIDC request headers because they contain underscore. To receive headers set by mod-auth-openidc, I changed the default OIDC header prefix to have no underscores via the following configuration line in a httpd.conf (or httpd-ssl.conf, etc.):
With this in place, the headers set by mod-auth-openidc arrive at my python/flask/wsgi app.