Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 3f0ff53

Browse files
authored
Remove deprecated /_matrix/client/*/admin endpoints (#8785)
These are now only available via `/_synapse/admin/v1`.
1 parent 2b110dd commit 3f0ff53

File tree

16 files changed

+176
-68
lines changed

16 files changed

+176
-68
lines changed

UPGRADE.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ shown below:
105105
106106
return {"localpart": localpart}
107107
108+
Removal historical Synapse Admin API
109+
------------------------------------
110+
111+
Historically, the Synapse Admin API has been accessible under:
112+
113+
* ``/_matrix/client/api/v1/admin``
114+
* ``/_matrix/client/unstable/admin``
115+
* ``/_matrix/client/r0/admin``
116+
* ``/_synapse/admin/v1``
117+
118+
The endpoints with ``/_matrix/client/*`` prefixes have been removed as of v1.24.0.
119+
The Admin API is now only accessible under:
120+
121+
* ``/_synapse/admin/v1``
122+
123+
The only exception is the `/admin/whois` endpoint, which is
124+
`also available via the client-server API <https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid>`_.
125+
126+
The deprecation of the old endpoints was announced with Synapse 1.20.0 (released
127+
on 2020-09-22) and makes it easier for homeserver admins to lock down external
128+
access to the Admin API endpoints.
129+
108130
Upgrading to v1.23.0
109131
====================
110132

changelog.d/8785.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove old `/_matrix/client/*/admin` endpoints which was deprecated since Synapse 1.20.0.

docs/admin_api/user_admin_api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ The api is::
176176

177177
GET /_synapse/admin/v1/whois/<user_id>
178178

179+
and::
180+
181+
GET /_matrix/client/r0/admin/whois/<userId>
182+
183+
See also: `Client Server API Whois
184+
<https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid>`_
185+
179186
To use it, you will need to authenticate by providing an ``access_token`` for a
180187
server admin: see `README.rst <README.rst>`_.
181188

synapse/_scripts/register_new_matrix_user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def request_registration(
3737
exit=sys.exit,
3838
):
3939

40-
url = "%s/_matrix/client/r0/admin/register" % (server_location,)
40+
url = "%s/_synapse/admin/v1/register" % (server_location,)
4141

4242
# Get the nonce
4343
r = requests.get(url, verify=False)

synapse/rest/admin/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121
from synapse.api.errors import Codes, NotFoundError, SynapseError
2222
from synapse.http.server import JsonResource
2323
from synapse.http.servlet import RestServlet, parse_json_object_from_request
24-
from synapse.rest.admin._base import (
25-
admin_patterns,
26-
assert_requester_is_admin,
27-
historical_admin_path_patterns,
28-
)
24+
from synapse.rest.admin._base import admin_patterns, assert_requester_is_admin
2925
from synapse.rest.admin.devices import (
3026
DeleteDevicesRestServlet,
3127
DeviceRestServlet,
@@ -84,7 +80,7 @@ def on_GET(self, request):
8480

8581

8682
class PurgeHistoryRestServlet(RestServlet):
87-
PATTERNS = historical_admin_path_patterns(
83+
PATTERNS = admin_patterns(
8884
"/purge_history/(?P<room_id>[^/]*)(/(?P<event_id>[^/]+))?"
8985
)
9086

@@ -169,9 +165,7 @@ async def on_POST(self, request, room_id, event_id):
169165

170166

171167
class PurgeHistoryStatusRestServlet(RestServlet):
172-
PATTERNS = historical_admin_path_patterns(
173-
"/purge_history_status/(?P<purge_id>[^/]+)"
174-
)
168+
PATTERNS = admin_patterns("/purge_history_status/(?P<purge_id>[^/]+)")
175169

176170
def __init__(self, hs):
177171
"""

synapse/rest/admin/_base.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,6 @@
2222
from synapse.types import UserID
2323

2424

25-
def historical_admin_path_patterns(path_regex):
26-
"""Returns the list of patterns for an admin endpoint, including historical ones
27-
28-
This is a backwards-compatibility hack. Previously, the Admin API was exposed at
29-
various paths under /_matrix/client. This function returns a list of patterns
30-
matching those paths (as well as the new one), so that existing scripts which rely
31-
on the endpoints being available there are not broken.
32-
33-
Note that this should only be used for existing endpoints: new ones should just
34-
register for the /_synapse/admin path.
35-
"""
36-
return [
37-
re.compile(prefix + path_regex)
38-
for prefix in (
39-
"^/_synapse/admin/v1",
40-
"^/_matrix/client/api/v1/admin",
41-
"^/_matrix/client/unstable/admin",
42-
"^/_matrix/client/r0/admin",
43-
)
44-
]
45-
46-
4725
def admin_patterns(path_regex: str, version: str = "v1"):
4826
"""Returns the list of patterns for an admin endpoint
4927

synapse/rest/admin/groups.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
from synapse.api.errors import SynapseError
1818
from synapse.http.servlet import RestServlet
19-
from synapse.rest.admin._base import (
20-
assert_user_is_admin,
21-
historical_admin_path_patterns,
22-
)
19+
from synapse.rest.admin._base import admin_patterns, assert_user_is_admin
2320

2421
logger = logging.getLogger(__name__)
2522

@@ -28,7 +25,7 @@ class DeleteGroupAdminRestServlet(RestServlet):
2825
"""Allows deleting of local groups
2926
"""
3027

31-
PATTERNS = historical_admin_path_patterns("/delete_group/(?P<group_id>[^/]*)")
28+
PATTERNS = admin_patterns("/delete_group/(?P<group_id>[^/]*)")
3229

3330
def __init__(self, hs):
3431
self.group_server = hs.get_groups_server_handler()

synapse/rest/admin/media.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
admin_patterns,
2323
assert_requester_is_admin,
2424
assert_user_is_admin,
25-
historical_admin_path_patterns,
2625
)
2726

2827
logger = logging.getLogger(__name__)
@@ -34,10 +33,10 @@ class QuarantineMediaInRoom(RestServlet):
3433
"""
3534

3635
PATTERNS = (
37-
historical_admin_path_patterns("/room/(?P<room_id>[^/]+)/media/quarantine")
36+
admin_patterns("/room/(?P<room_id>[^/]+)/media/quarantine")
3837
+
3938
# This path kept around for legacy reasons
40-
historical_admin_path_patterns("/quarantine_media/(?P<room_id>[^/]+)")
39+
admin_patterns("/quarantine_media/(?P<room_id>[^/]+)")
4140
)
4241

4342
def __init__(self, hs):
@@ -63,9 +62,7 @@ class QuarantineMediaByUser(RestServlet):
6362
this server.
6463
"""
6564

66-
PATTERNS = historical_admin_path_patterns(
67-
"/user/(?P<user_id>[^/]+)/media/quarantine"
68-
)
65+
PATTERNS = admin_patterns("/user/(?P<user_id>[^/]+)/media/quarantine")
6966

7067
def __init__(self, hs):
7168
self.store = hs.get_datastore()
@@ -90,7 +87,7 @@ class QuarantineMediaByID(RestServlet):
9087
it via this server.
9188
"""
9289

93-
PATTERNS = historical_admin_path_patterns(
90+
PATTERNS = admin_patterns(
9491
"/media/quarantine/(?P<server_name>[^/]+)/(?P<media_id>[^/]+)"
9592
)
9693

@@ -116,7 +113,7 @@ class ListMediaInRoom(RestServlet):
116113
"""Lists all of the media in a given room.
117114
"""
118115

119-
PATTERNS = historical_admin_path_patterns("/room/(?P<room_id>[^/]+)/media")
116+
PATTERNS = admin_patterns("/room/(?P<room_id>[^/]+)/media")
120117

121118
def __init__(self, hs):
122119
self.store = hs.get_datastore()
@@ -134,7 +131,7 @@ async def on_GET(self, request, room_id):
134131

135132

136133
class PurgeMediaCacheRestServlet(RestServlet):
137-
PATTERNS = historical_admin_path_patterns("/purge_media_cache")
134+
PATTERNS = admin_patterns("/purge_media_cache")
138135

139136
def __init__(self, hs):
140137
self.media_repository = hs.get_media_repository()

synapse/rest/admin/rooms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
admin_patterns,
3030
assert_requester_is_admin,
3131
assert_user_is_admin,
32-
historical_admin_path_patterns,
3332
)
3433
from synapse.storage.databases.main.room import RoomSortOrder
3534
from synapse.types import RoomAlias, RoomID, UserID, create_requester
@@ -44,7 +43,7 @@ class ShutdownRoomRestServlet(RestServlet):
4443
joined to the new room.
4544
"""
4645

47-
PATTERNS = historical_admin_path_patterns("/shutdown_room/(?P<room_id>[^/]+)")
46+
PATTERNS = admin_patterns("/shutdown_room/(?P<room_id>[^/]+)")
4847

4948
def __init__(self, hs):
5049
self.hs = hs

synapse/rest/admin/users.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
admin_patterns,
3434
assert_requester_is_admin,
3535
assert_user_is_admin,
36-
historical_admin_path_patterns,
3736
)
37+
from synapse.rest.client.v2_alpha._base import client_patterns
3838
from synapse.types import JsonDict, UserID
3939

4040
if TYPE_CHECKING:
@@ -55,7 +55,7 @@
5555

5656

5757
class UsersRestServlet(RestServlet):
58-
PATTERNS = historical_admin_path_patterns("/users/(?P<user_id>[^/]*)$")
58+
PATTERNS = admin_patterns("/users/(?P<user_id>[^/]*)$")
5959

6060
def __init__(self, hs):
6161
self.hs = hs
@@ -338,7 +338,7 @@ class UserRegisterServlet(RestServlet):
338338
nonce to the time it was generated, in int seconds.
339339
"""
340340

341-
PATTERNS = historical_admin_path_patterns("/register")
341+
PATTERNS = admin_patterns("/register")
342342
NONCE_TIMEOUT = 60
343343

344344
def __init__(self, hs):
@@ -461,7 +461,14 @@ async def on_POST(self, request):
461461

462462

463463
class WhoisRestServlet(RestServlet):
464-
PATTERNS = historical_admin_path_patterns("/whois/(?P<user_id>[^/]*)")
464+
path_regex = "/whois/(?P<user_id>[^/]*)$"
465+
PATTERNS = (
466+
admin_patterns(path_regex)
467+
+
468+
# URL for spec reason
469+
# https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-admin-whois-userid
470+
client_patterns("/admin" + path_regex, v1=True)
471+
)
465472

466473
def __init__(self, hs):
467474
self.hs = hs
@@ -485,7 +492,7 @@ async def on_GET(self, request, user_id):
485492

486493

487494
class DeactivateAccountRestServlet(RestServlet):
488-
PATTERNS = historical_admin_path_patterns("/deactivate/(?P<target_user_id>[^/]*)")
495+
PATTERNS = admin_patterns("/deactivate/(?P<target_user_id>[^/]*)")
489496

490497
def __init__(self, hs):
491498
self._deactivate_account_handler = hs.get_deactivate_account_handler()
@@ -516,7 +523,7 @@ async def on_POST(self, request, target_user_id):
516523

517524

518525
class AccountValidityRenewServlet(RestServlet):
519-
PATTERNS = historical_admin_path_patterns("/account_validity/validity$")
526+
PATTERNS = admin_patterns("/account_validity/validity$")
520527

521528
def __init__(self, hs):
522529
"""
@@ -559,9 +566,7 @@ class ResetPasswordRestServlet(RestServlet):
559566
200 OK with empty object if success otherwise an error.
560567
"""
561568

562-
PATTERNS = historical_admin_path_patterns(
563-
"/reset_password/(?P<target_user_id>[^/]*)"
564-
)
569+
PATTERNS = admin_patterns("/reset_password/(?P<target_user_id>[^/]*)")
565570

566571
def __init__(self, hs):
567572
self.store = hs.get_datastore()
@@ -603,7 +608,7 @@ class SearchUsersRestServlet(RestServlet):
603608
200 OK with json object {list[dict[str, Any]], count} or empty object.
604609
"""
605610

606-
PATTERNS = historical_admin_path_patterns("/search_users/(?P<target_user_id>[^/]*)")
611+
PATTERNS = admin_patterns("/search_users/(?P<target_user_id>[^/]*)")
607612

608613
def __init__(self, hs):
609614
self.hs = hs

0 commit comments

Comments
 (0)