From 922880af3b52990e6dd20982485a80e56b4bcfea Mon Sep 17 00:00:00 2001 From: Sheikh Date: Mon, 25 Sep 2023 18:23:40 +0800 Subject: [PATCH 1/9] Allow hiding python version. Signed-off-by: Sheikh --- synapse/config/server.py | 1 + synapse/rest/admin/__init__.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/synapse/config/server.py b/synapse/config/server.py index 72d30da30082..b74bb1eb8334 100644 --- a/synapse/config/server.py +++ b/synapse/config/server.py @@ -293,6 +293,7 @@ class ServerConfig(Config): def read_config(self, config: JsonDict, **kwargs: Any) -> None: self.server_name = config["server_name"] self.server_context = config.get("server_context", None) + self.hide_python_version = config.get("hide_python_version", False) try: parse_and_validate_server_name(self.server_name) diff --git a/synapse/rest/admin/__init__.py b/synapse/rest/admin/__init__.py index 7d0b4b55a0df..bd2d1ab4d5c8 100644 --- a/synapse/rest/admin/__init__.py +++ b/synapse/rest/admin/__init__.py @@ -109,7 +109,11 @@ class VersionServlet(RestServlet): def __init__(self, hs: "HomeServer"): self.res = { "server_version": SYNAPSE_VERSION, - "python_version": platform.python_version(), + "python_version": ( + platform.python_version() + if not hs.config.server.hide_python_version + else "UNKNOWN" + ), } def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: From 0e0742c9265715b1017dba673d28d214066724b5 Mon Sep 17 00:00:00 2001 From: Sheikh Date: Mon, 25 Sep 2023 18:57:37 +0800 Subject: [PATCH 2/9] add doc Signed-off-by: Sheikh --- docs/usage/configuration/config_documentation.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/usage/configuration/config_documentation.md b/docs/usage/configuration/config_documentation.md index 54315a417ec1..9cafaeb78e6c 100644 --- a/docs/usage/configuration/config_documentation.md +++ b/docs/usage/configuration/config_documentation.md @@ -694,6 +694,19 @@ This setting has the following sub-options: * `password_reset`: Subject to use when sending a password reset email. Defaults to "[%(server_name)s] Password reset" * `email_validation`: Subject to use when sending a verification email to assert an address's ownership. Defaults to "[%(server_name)s] Validate your email" +--- +### `hide_python_version` + +This option controls whether or not the current Python version of the homeserver is displayed [here](../../admin_api/version_api.md). + +The default is False, which means that the homeserver will display the Python version. + +**Note:** This option does not affect the Python-related information exposed by [Metrics](#Metrics). + +Example configuration: +```yaml +hide_python_version: True +``` Example configuration: From 136f644773f7cf09522f70b309f9bbb517ffd846 Mon Sep 17 00:00:00 2001 From: MomentQYC <62551256+MomentQYC@users.noreply.github.com> Date: Mon, 25 Sep 2023 19:10:21 +0800 Subject: [PATCH 3/9] Create changelog --- changelog.d/16380.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/16380.feature diff --git a/changelog.d/16380.feature b/changelog.d/16380.feature new file mode 100644 index 000000000000..f8fb9b32dfb3 --- /dev/null +++ b/changelog.d/16380.feature @@ -0,0 +1 @@ +Allow hiding Python version information. From 57037f1090d6d76bdbd0899780f3b0e912049e00 Mon Sep 17 00:00:00 2001 From: Sheikh Date: Sat, 30 Sep 2023 02:24:02 +0800 Subject: [PATCH 4/9] change Signed-off-by: Sheikh --- changelog.d/16380.feature | 1 - changelog.d/16380.removal | 1 + docs/usage/configuration/config_documentation.md | 13 ------------- synapse/config/server.py | 1 - synapse/rest/admin/__init__.py | 8 +------- 5 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 changelog.d/16380.feature create mode 100644 changelog.d/16380.removal diff --git a/changelog.d/16380.feature b/changelog.d/16380.feature deleted file mode 100644 index f8fb9b32dfb3..000000000000 --- a/changelog.d/16380.feature +++ /dev/null @@ -1 +0,0 @@ -Allow hiding Python version information. diff --git a/changelog.d/16380.removal b/changelog.d/16380.removal new file mode 100644 index 000000000000..6e9372134ddd --- /dev/null +++ b/changelog.d/16380.removal @@ -0,0 +1 @@ +Remove Python version from `/_synapse/admin/v1/server_version`. \ No newline at end of file diff --git a/docs/usage/configuration/config_documentation.md b/docs/usage/configuration/config_documentation.md index a92b55d1b51c..502cd9f8236d 100644 --- a/docs/usage/configuration/config_documentation.md +++ b/docs/usage/configuration/config_documentation.md @@ -694,19 +694,6 @@ This setting has the following sub-options: * `password_reset`: Subject to use when sending a password reset email. Defaults to "[%(server_name)s] Password reset" * `email_validation`: Subject to use when sending a verification email to assert an address's ownership. Defaults to "[%(server_name)s] Validate your email" ---- -### `hide_python_version` - -This option controls whether or not the current Python version of the homeserver is displayed [here](../../admin_api/version_api.md). - -The default is False, which means that the homeserver will display the Python version. - -**Note:** This option does not affect the Python-related information exposed by [Metrics](#Metrics). - -Example configuration: -```yaml -hide_python_version: True -``` Example configuration: diff --git a/synapse/config/server.py b/synapse/config/server.py index b74bb1eb8334..72d30da30082 100644 --- a/synapse/config/server.py +++ b/synapse/config/server.py @@ -293,7 +293,6 @@ class ServerConfig(Config): def read_config(self, config: JsonDict, **kwargs: Any) -> None: self.server_name = config["server_name"] self.server_context = config.get("server_context", None) - self.hide_python_version = config.get("hide_python_version", False) try: parse_and_validate_server_name(self.server_name) diff --git a/synapse/rest/admin/__init__.py b/synapse/rest/admin/__init__.py index bd2d1ab4d5c8..fc901e62ac5c 100644 --- a/synapse/rest/admin/__init__.py +++ b/synapse/rest/admin/__init__.py @@ -16,7 +16,6 @@ # limitations under the License. import logging -import platform from http import HTTPStatus from typing import TYPE_CHECKING, Optional, Tuple @@ -108,12 +107,7 @@ class VersionServlet(RestServlet): def __init__(self, hs: "HomeServer"): self.res = { - "server_version": SYNAPSE_VERSION, - "python_version": ( - platform.python_version() - if not hs.config.server.hide_python_version - else "UNKNOWN" - ), + "server_version": SYNAPSE_VERSION } def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: From b8b8604480f6cd52cc2ce4ddbb12e8466507c175 Mon Sep 17 00:00:00 2001 From: MomentQYC <62551256+MomentQYC@users.noreply.github.com> Date: Sat, 30 Sep 2023 03:35:03 +0800 Subject: [PATCH 5/9] fix test --- tests/rest/admin/test_admin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rest/admin/test_admin.py b/tests/rest/admin/test_admin.py index 695e84357ad2..90a05141dcbd 100644 --- a/tests/rest/admin/test_admin.py +++ b/tests/rest/admin/test_admin.py @@ -43,7 +43,7 @@ def test_version_string(self) -> None: self.assertEqual(200, channel.code, msg=channel.json_body) self.assertEqual( - {"server_version", "python_version"}, set(channel.json_body.keys()) + {"server_version"}, set(channel.json_body.keys()) ) From b277fc5f99423d9fd3c862e3583bf2d52895bab8 Mon Sep 17 00:00:00 2001 From: MomentQYC <62551256+MomentQYC@users.noreply.github.com> Date: Sat, 30 Sep 2023 03:35:45 +0800 Subject: [PATCH 6/9] style --- synapse/rest/admin/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/synapse/rest/admin/__init__.py b/synapse/rest/admin/__init__.py index fc901e62ac5c..e42dade2463b 100644 --- a/synapse/rest/admin/__init__.py +++ b/synapse/rest/admin/__init__.py @@ -106,9 +106,7 @@ class VersionServlet(RestServlet): PATTERNS = admin_patterns("/server_version$") def __init__(self, hs: "HomeServer"): - self.res = { - "server_version": SYNAPSE_VERSION - } + self.res = {"server_version": SYNAPSE_VERSION} def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: return HTTPStatus.OK, self.res From 4a405b39f8cf8df57053a42b305099cc6173f834 Mon Sep 17 00:00:00 2001 From: MomentQYC <62551256+MomentQYC@users.noreply.github.com> Date: Sat, 30 Sep 2023 03:42:05 +0800 Subject: [PATCH 7/9] test style --- tests/rest/admin/test_admin.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/rest/admin/test_admin.py b/tests/rest/admin/test_admin.py index 90a05141dcbd..359d131b37fa 100644 --- a/tests/rest/admin/test_admin.py +++ b/tests/rest/admin/test_admin.py @@ -42,9 +42,7 @@ def test_version_string(self) -> None: channel = self.make_request("GET", self.url, shorthand=False) self.assertEqual(200, channel.code, msg=channel.json_body) - self.assertEqual( - {"server_version"}, set(channel.json_body.keys()) - ) + self.assertEqual({"server_version"}, set(channel.json_body.keys())) class QuarantineMediaTestCase(unittest.HomeserverTestCase): From 7f17cdb7d207e331a2b6c0b7d58637acfd39ba88 Mon Sep 17 00:00:00 2001 From: MomentQYC <62551256+MomentQYC@users.noreply.github.com> Date: Sat, 30 Sep 2023 03:51:14 +0800 Subject: [PATCH 8/9] Update doc --- docs/admin_api/version_api.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/admin_api/version_api.md b/docs/admin_api/version_api.md index 27977de0d379..cd076035a109 100644 --- a/docs/admin_api/version_api.md +++ b/docs/admin_api/version_api.md @@ -1,7 +1,7 @@ # Version API -This API returns the running Synapse version and the Python version -on which Synapse is being run. This is useful when a Synapse instance +This API returns the running Synapse version. +This is useful when a Synapse instance is behind a proxy that does not forward the 'Server' header (which also contains Synapse version information). @@ -15,7 +15,6 @@ It returns a JSON body like the following: ```json { - "server_version": "0.99.2rc1 (b=develop, abcdef123)", - "python_version": "3.7.8" + "server_version": "0.99.2rc1 (b=develop, abcdef123)" } ``` From 2bf90e0c2680f231015fd431e039b6c7402e96a0 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 2 Oct 2023 08:39:29 -0400 Subject: [PATCH 9/9] Note the change in the documentation. --- docs/admin_api/version_api.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/admin_api/version_api.md b/docs/admin_api/version_api.md index cd076035a109..bdc37d9119a9 100644 --- a/docs/admin_api/version_api.md +++ b/docs/admin_api/version_api.md @@ -18,3 +18,6 @@ It returns a JSON body like the following: "server_version": "0.99.2rc1 (b=develop, abcdef123)" } ``` + +*Changed in Synapse 1.94.0:* The `python_version` key was removed from the +response body.