Open sc-anssi opened 2 years ago
This is intended to be used with IIS on an internal network by setting windows authentication enabled and anonymous disabled.
Hi,
The documentation mentions Apache and Nginx but I've not seen any reference to IIS in /docs/security.rst. But I don't think the webserver acting as reverse proxy is responsible for the issue at hand. If you tcpdump the traffic between the reverse proxy and the Flask webserver you can see the header is indeed REMOTE_USER
, so the conversion of HTTP headers to environment variables by prefixing HTTP_
is done by Flask/Werkzeug I believe.
That's why I believe FAB should either read HTTP_REMOTE_USER
from request.environ or read Remote-User
from request.headers (the first option seems to be the easiest one as we don't have to worry about the case or the mix of dashes and underscores in headers)
What do you think ? Regards
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Feel free to reopen it if it's still relevant to you. Thank you
Hi, This issue is still relevant. @dpgaspar what do you think of the suggested fix ? Regards
I am attempting to run an authenticating reverse proxy in front of a FAB app, and I am faced with this exact issue. Passing REMOTE_USER
in the request headers from the proxy results to HTTP_REMOTE_USER
in the request.environ
object of the FAB web-server.
As suggested by @sc-anssi, a very simple change would enable authentication to be offloaded. We could check HTTP_REMOTE_USER
exists in request.environ
in addition to REMOTE_USER
(to preserve compatibility for anyone relying on REMOTE_USER
)?
Could this issue please be re-open @dpgaspar?
Environment
Flask-Appbuilder version: 3.4.1
pip freeze output:
Describe the expected results
When using FAB with
AUTH_TYPE = AUTH_REMOTE_USER
behind a reverse proxy which sets the request headerREMOTE_USER
, FAB should authenticate that user when trying to loginDescribe the actual results
Authentication fails with message
Invalid login. Please try again.
when clicking "login" link.Steps to reproduce
1) Setup the base skeleton app 2) Modify
config.py
to setAUTH_TYPE = AUTH_REMOTE_USER
3) Setup a reverse proxy in front of the app setting the request header REMOTE_USER to "Admin" (the following example is for Apache HTTPD):4) Restart reverse proxy and start the app 5) Try to login and fail with message
Invalid login. Please try again.
Potential lead
I believe CGI uses HTTP request headers as environment variable by prefixing them with
HTTP_
(https://www.ietf.org/rfc/rfc3875, section 4.1.18). However FAB readsREMOTE_USER
in flask_appbuilder/security/views.py.Patching the code as follow seems to fix the problem: