Re: [pgAdmin][RM4768] Reverse proxy on non-standard port

Aditya Toshniwal <[email protected]>
Newsgroups gmane.comp.db.postgresql.pgadmin.devel
Message-ID <CAM9w-_nruTEO46N_g1j9mMyUVKSCA4U8gAzFAt9pszMJWuN2hQ@mail.gmail.com>
Hi Hackers,

Attached is the updated patch.
Changes are made to not to apply ProxyFix if it is not available. Plus,
requirements.txt is updated to Werkzeug>=0.15.0

Kindly review.

On Tue, Oct 1, 2019 at 2:07 PM Murtuza Zabuawala <
[email protected]> wrote:

> Hi,
>
> I forgot to change the virtualenv in another terminal Tab, I am getting
> error
>
> TypeError: __init__() got an unexpected keyword argument ‘x_for’
>
> with Flask 1.0.2.
>
> Regards,
> Murtuza
>
> On Tue, Oct 1, 2019 at 1:35 PM Murtuza Zabuawala <
> [email protected]> wrote:
>
>> Hi Aditya,
>>
>> Tested with below version and works fine.
>>
>> >>> flask.__version__
>> '1.0.2'
>> >>> werkzeug.__version__
>> '0.14.1'
>>
>>
>> --
>> Regards,
>> Murtuza Zabuawala
>> EnterpriseDB: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>>
>>
>> On Tue, Oct 1, 2019 at 12:04 PM Aditya Toshniwal <
>> [email protected]> wrote:
>>
>>> Hi Hackers,
>>>
>>> I have added a backward compatible code in cases werkzeug is older. This
>>> will never happen considering we use Flask 1.0.2.
>>> Attached is the precautionary patch.
>>>
>>> On Fri, Sep 27, 2019 at 1:29 PM Akshay Joshi <
>>> [email protected]> wrote:
>>>
>>>> Thanks, patch applied.
>>>>
>>>> On Fri, Sep 27, 2019 at 12:17 PM Aditya Toshniwal <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi Hackers,
>>>>>
>>>>> Attached is the patch to allow pgAdmin to run behind reverse proxy on
>>>>> a non standard port.
>>>>> The middleware -
>>>>> https://werkzeug.palletsprojects.com/en/0.15.x/middleware/proxy_fix/#werkzeug.middleware.proxy_fix.ProxyFix
>>>>> allows us to set the number of trusted ports (and few other params) behind
>>>>> the proxy. By default it is zero.
>>>>> With this patch, user can set these params using pgAdmin config.
>>>>> I have set the default value for port as 1, which will allow to run
>>>>> behind non-standard port.
>>>>>
>>>>> I have added the documentation under reverse proxy section.
>>>>>
>>>>> Kindly review.
>>>>>
>>>>> --
>>>>> Thanks and Regards,
>>>>> Aditya Toshniwal
>>>>> Sr. Software Engineer | EnterpriseDB India | Pune
>>>>> "Don't Complain about Heat, Plant a TREE"
>>>>>
>>>>
>>>>
>>>> --
>>>> *Thanks & Regards*
>>>> *Akshay Joshi*
>>>>
>>>> *Sr. Software Architect*
>>>> *EnterpriseDB Software India Private Limited*
>>>> *Mobile: +91 976-788-8246*
>>>>
>>>
>>>
>>> --
>>> Thanks and Regards,
>>> Aditya Toshniwal
>>> Sr. Software Engineer | EnterpriseDB India | Pune
>>> "Don't Complain about Heat, Plant a TREE"
>>>
>>

-- 
Thanks and Regards,
Aditya Toshniwal
Sr. Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"
RM4768.oldwerkzeug_V2.patch (application/octet-stream, 1.9 KB)
diff --git a/requirements.txt b/requirements.txt
index 5bd5d726..839e0fb9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -16,6 +16,7 @@
 ##############################################################################
 blinker==1.4
 Flask==1.0.2
+Werkzeug>=0.15.0
 Flask-Gravatar==0.5.0
 Flask-Login==0.4.1
 Flask-Mail==0.9.1
diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py
index 4bcfccc5..845ca52a 100644
--- a/web/pgAdmin4.py
+++ b/web/pgAdmin4.py
@@ -13,7 +13,6 @@ to start a web server."""
 
 import os
 import sys
-from werkzeug.middleware.proxy_fix import ProxyFix
 
 if sys.version_info[0] >= 3:
     import builtins
@@ -71,13 +70,17 @@ if not os.path.isfile(config.SQLITE_PATH):
 class ReverseProxied(object):
     def __init__(self, app):
         # https://werkzeug.palletsprojects.com/en/0.15.x/middleware/proxy_fix/#module-werkzeug.middleware.proxy_fix
-        self.app = ProxyFix(app,
-                            x_for=config.PROXY_X_FOR_COUNT,
-                            x_proto=config.PROXY_X_PROTO_COUNT,
-                            x_host=config.PROXY_X_HOST_COUNT,
-                            x_port=config.PROXY_X_PORT_COUNT,
-                            x_prefix=config.PROXY_X_PREFIX_COUNT
-                            )
+        try:
+            from werkzeug.middleware.proxy_fix import ProxyFix
+            self.app = ProxyFix(app,
+                                x_for=config.PROXY_X_FOR_COUNT,
+                                x_proto=config.PROXY_X_PROTO_COUNT,
+                                x_host=config.PROXY_X_HOST_COUNT,
+                                x_port=config.PROXY_X_PORT_COUNT,
+                                x_prefix=config.PROXY_X_PREFIX_COUNT
+                                )
+        except ImportError:
+            pass
 
     def __call__(self, environ, start_response):
         script_name = environ.get("HTTP_X_SCRIPT_NAME", "")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.