From 8cb239abcbbc2543a91af8b061a8404364d546ef Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 13 Dec 2019 10:42:43 +0530 Subject: [PATCH] Rename some internal environment variables that could conflict with Kubernetes. Fixes #4999. --- docs/en_US/release_notes_4_17.rst | 1 + runtime/Server.cpp | 4 ++-- web/pgAdmin4.py | 18 +++++++++--------- web/pgadmin/__init__.py | 14 ++++++-------- web/regression/feature_utils/app_starter.py | 2 +- web/regression/runtests.py | 2 +- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/docs/en_US/release_notes_4_17.rst b/docs/en_US/release_notes_4_17.rst index aff6af1b8..38d18156b 100644 --- a/docs/en_US/release_notes_4_17.rst +++ b/docs/en_US/release_notes_4_17.rst @@ -19,4 +19,5 @@ Bug fixes | `Issue #4506 `_ - Fix an issue where clicking on an empty textbox like fill factor or comments, considers it as change and enabled the save button. | `Issue #4943 `_ - Added more information to the 'Database connected/disconnected' message. +| `Issue #4999 `_ - Rename some internal environment variables that could conflict with Kubernetes. | `Issue #5004 `_ - Fix vulnerability issues reported by 'yarn audit'. Replace the deprecated uglifyjs-webpack-plugin with a terser-webpack-plugin. \ No newline at end of file diff --git a/runtime/Server.cpp b/runtime/Server.cpp index 60ddc7e5b..76ee95d6b 100644 --- a/runtime/Server.cpp +++ b/runtime/Server.cpp @@ -341,8 +341,8 @@ void Server::run() // Set the port number and key, and force SERVER_MODE off. Logger::GetLogger()->Log("Set the port number, key and force SERVER_MODE off"); - PyRun_SimpleString(QString("PGADMIN_PORT = %1").arg(m_port).toLatin1()); - PyRun_SimpleString(QString("PGADMIN_KEY = '%1'").arg(m_key).toLatin1()); + PyRun_SimpleString(QString("PGADMIN_INT_PORT = %1").arg(m_port).toLatin1()); + PyRun_SimpleString(QString("PGADMIN_INT_KEY = '%1'").arg(m_key).toLatin1()); PyRun_SimpleString(QString("SERVER_MODE = False").toLatin1()); // Run the app! diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index 4668458f0..71eaed5e1 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -129,15 +129,15 @@ if config.DEBUG: # runtime if we're running in desktop mode, otherwise we'll just use the # Flask default. PGADMIN_RUNTIME = False -if 'PGADMIN_PORT' in globals(): +if 'PGADMIN_INT_PORT' in globals(): app.logger.debug( 'Running under the desktop runtime, port: %s', - globals()['PGADMIN_PORT'] + globals()['PGADMIN_INT_PORT'] ) - server_port = int(globals()['PGADMIN_PORT']) + server_port = int(globals()['PGADMIN_INT_PORT']) PGADMIN_RUNTIME = True -elif 'PGADMIN_PORT' in os.environ: - port = os.environ['PGADMIN_PORT'] +elif 'PGADMIN_INT_PORT' in os.environ: + port = os.environ['PGADMIN_INT_PORT'] app.logger.debug( 'Not running under the desktop runtime, port: %s', port @@ -154,11 +154,11 @@ else: app.PGADMIN_RUNTIME = PGADMIN_RUNTIME # Set the key if appropriate -if 'PGADMIN_KEY' in globals(): - app.PGADMIN_KEY = globals()['PGADMIN_KEY'] - app.logger.debug("Desktop security key: %s" % app.PGADMIN_KEY) +if 'PGADMIN_INT_KEY' in globals(): + app.PGADMIN_INT_KEY = globals()['PGADMIN_INT_KEY'] + app.logger.debug("Desktop security key: %s" % app.PGADMIN_INT_KEY) else: - app.PGADMIN_KEY = '' + app.PGADMIN_INT_KEY = '' # Output a startup message if we're not under the runtime and startup. # If we're under WSGI, we don't need to worry about this diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py index 293054f28..f60ddf374 100644 --- a/web/pgadmin/__init__.py +++ b/web/pgadmin/__init__.py @@ -620,13 +620,11 @@ def create_app(app_name=None): # Check the auth key is valid, if it's set, and we're not in server # mode, and it's not a help file request. - if not config.SERVER_MODE and app.PGADMIN_KEY != '': - if ( - ('key' not in request.args or - request.args['key'] != app.PGADMIN_KEY) and - request.cookies.get('PGADMIN_KEY') != app.PGADMIN_KEY and - request.endpoint != 'help.static' - ): + if not config.SERVER_MODE and app.PGADMIN_INT_KEY != '': + if (('key' not in request.args or + request.args['key'] != app.PGADMIN_INT_KEY) and + request.cookies.get('PGADMIN_INT_KEY') != + app.PGADMIN_INT_KEY and request.endpoint != 'help.static'): abort(401) if not config.SERVER_MODE and not current_user.is_authenticated: @@ -659,7 +657,7 @@ def create_app(app_name=None): if config.COOKIE_DEFAULT_DOMAIN and \ config.COOKIE_DEFAULT_DOMAIN != 'localhost': domain['domain'] = config.COOKIE_DEFAULT_DOMAIN - response.set_cookie('PGADMIN_KEY', value=request.args['key'], + response.set_cookie('PGADMIN_INT_KEY', value=request.args['key'], path=config.COOKIE_DEFAULT_PATH, **domain) diff --git a/web/regression/feature_utils/app_starter.py b/web/regression/feature_utils/app_starter.py index 7597cde94..6d1340fae 100644 --- a/web/regression/feature_utils/app_starter.py +++ b/web/regression/feature_utils/app_starter.py @@ -28,7 +28,7 @@ class AppStarter: """ This function start the subprocess to start pgAdmin app """ random_server_port = str(random.randint(10000, 65535)) env = { - "PGADMIN_PORT": random_server_port, + "PGADMIN_INT_PORT": random_server_port, "SQLITE_PATH": str(self.app_config.TEST_SQLITE_PATH) } env.update(os.environ) diff --git a/web/regression/runtests.py b/web/regression/runtests.py index 8c52753f3..f80eb5c7a 100644 --- a/web/regression/runtests.py +++ b/web/regression/runtests.py @@ -106,7 +106,7 @@ config.CONSOLE_LOG_LEVEL = WARNING # Create the app app = create_app() -app.PGADMIN_KEY = '' +app.PGADMIN_INT_KEY = '' app.config.update({'SESSION_COOKIE_DOMAIN': None}) driver = None app_starter = None