This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Don't load the media repo when configured to use an external media repo #5754
Merged
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
108bc6c
disable media repo if it's disabled and not an option
hawkowl 997fd94
changelog
hawkowl bbffae3
config sync
hawkowl 4f2caf1
config sync
hawkowl c463960
config sync
hawkowl 081e102
reorder config too
hawkowl cd70e82
reorder config too
hawkowl 3ff9935
fix
hawkowl 85f5cbd
fix
hawkowl 1763a73
Merge remote-tracking branch 'origin/develop' into hawkowl/disable-me…
hawkowl f528371
fix worker mode just exploding
hawkowl c7561c2
unmove this about
hawkowl f695e0b
Update and rename 5754.misc to 5754.feature
hawkowl 22c1d80
Merge remote-tracking branch 'origin/develop' into hawkowl/disable-me…
hawkowl fe5d337
fix
hawkowl 5f6b687
cleanup config
hawkowl 7eeed4b
fix import
hawkowl 74232f5
lol oops
hawkowl 7c2149f
reduce diff
hawkowl 3a23f6a
doc
hawkowl afb31e9
Update docs/sample_config.yaml
hawkowl 4a0380b
fix
hawkowl 94ec373
Merge remote-tracking branch 'origin/develop' into hawkowl/disable-me…
hawkowl 80d6c48
review cleanups
hawkowl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Synapse will no longer serve any media repo admin endpoints when `enable_media_repo` is set to False in the configuration. If a media repo worker is used, the admin APIs relating to the media repo will be served from it instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ | |||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||
# See the License for the specific language governing permissions and | ||||||||
# limitations under the License. | ||||||||
|
||||||||
import os | ||||||||
from collections import namedtuple | ||||||||
|
||||||||
|
@@ -87,6 +88,18 @@ def parse_thumbnail_requirements(thumbnail_sizes): | |||||||
|
||||||||
class ContentRepositoryConfig(Config): | ||||||||
def read_config(self, config, **kwargs): | ||||||||
|
||||||||
# Only enable the media repo if either the media repo is enabled or the | ||||||||
# current worker app is the media repo. | ||||||||
if ( | ||||||||
self.enable_media_repo is False | ||||||||
and config.worker_app != "synapse.app.media_repository" | ||||||||
): | ||||||||
self.can_load_media_repo = False | ||||||||
return | ||||||||
else: | ||||||||
self.can_load_media_repo = True | ||||||||
|
||||||||
self.max_upload_size = self.parse_size(config.get("max_upload_size", "10M")) | ||||||||
self.max_image_pixels = self.parse_size(config.get("max_image_pixels", "32M")) | ||||||||
self.max_spider_size = self.parse_size(config.get("max_spider_size", "10M")) | ||||||||
|
@@ -202,6 +215,12 @@ def generate_config_section(self, data_dir_path, **kwargs): | |||||||
|
||||||||
return ( | ||||||||
r""" | ||||||||
hawkowl marked this conversation as resolved.
Show resolved
Hide resolved
hawkowl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
## Media Store ## | ||||||||
|
||||||||
# Enable the media store service inside Synapse. | ||||||||
|
# Enable the media store service inside Synapse. | |
# Enable the media store service in the Synapse master. Uncomment the following if you are using a separate | |
# media store worker. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
# enable_media_repo: False | |
#enable_media_repo: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
|
||
import synapse | ||
from synapse.api.constants import Membership, UserTypes | ||
from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError | ||
from synapse.api.errors import Codes, NotFoundError, SynapseError | ||
from synapse.http.server import JsonResource | ||
from synapse.http.servlet import ( | ||
RestServlet, | ||
|
@@ -36,36 +36,23 @@ | |
parse_json_object_from_request, | ||
parse_string, | ||
) | ||
from synapse.rest.admin._base import assert_requester_is_admin, assert_user_is_admin | ||
from synapse.rest.admin._base import ( | ||
assert_requester_is_admin, | ||
assert_user_is_admin, | ||
historical_admin_path_patterns, | ||
) | ||
from synapse.rest.admin.media import ( | ||
ListMediaInRoom, | ||
PurgeMediaCacheRestServlet, | ||
QuarantineMediaInRoom, | ||
) | ||
from synapse.rest.admin.server_notice_servlet import SendServerNoticeServlet | ||
from synapse.types import UserID, create_requester | ||
from synapse.util.versionstring import get_version_string | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def historical_admin_path_patterns(path_regex): | ||
richvdh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Returns the list of patterns for an admin endpoint, including historical ones | ||
|
||
This is a backwards-compatibility hack. Previously, the Admin API was exposed at | ||
various paths under /_matrix/client. This function returns a list of patterns | ||
matching those paths (as well as the new one), so that existing scripts which rely | ||
on the endpoints being available there are not broken. | ||
|
||
Note that this should only be used for existing endpoints: new ones should just | ||
register for the /_synapse/admin path. | ||
""" | ||
return list( | ||
re.compile(prefix + path_regex) | ||
for prefix in ( | ||
"^/_synapse/admin/v1", | ||
"^/_matrix/client/api/v1/admin", | ||
"^/_matrix/client/unstable/admin", | ||
"^/_matrix/client/r0/admin", | ||
) | ||
) | ||
|
||
|
||
class UsersRestServlet(RestServlet): | ||
PATTERNS = historical_admin_path_patterns("/users/(?P<user_id>[^/]*)") | ||
|
||
|
@@ -255,25 +242,6 @@ def on_GET(self, request, user_id): | |
return (200, ret) | ||
|
||
|
||
class PurgeMediaCacheRestServlet(RestServlet): | ||
PATTERNS = historical_admin_path_patterns("/purge_media_cache") | ||
|
||
def __init__(self, hs): | ||
self.media_repository = hs.get_media_repository() | ||
self.auth = hs.get_auth() | ||
|
||
@defer.inlineCallbacks | ||
def on_POST(self, request): | ||
yield assert_requester_is_admin(self.auth, request) | ||
|
||
before_ts = parse_integer(request, "before_ts", required=True) | ||
logger.info("before_ts: %r", before_ts) | ||
|
||
ret = yield self.media_repository.delete_old_remote_media(before_ts) | ||
|
||
return (200, ret) | ||
|
||
|
||
class PurgeHistoryRestServlet(RestServlet): | ||
PATTERNS = historical_admin_path_patterns( | ||
"/purge_history/(?P<room_id>[^/]*)(/(?P<event_id>[^/]+))?" | ||
|
@@ -542,50 +510,6 @@ def on_POST(self, request, room_id): | |
) | ||
|
||
|
||
class QuarantineMediaInRoom(RestServlet): | ||
"""Quarantines all media in a room so that no one can download it via | ||
this server. | ||
""" | ||
|
||
PATTERNS = historical_admin_path_patterns("/quarantine_media/(?P<room_id>[^/]+)") | ||
|
||
def __init__(self, hs): | ||
self.store = hs.get_datastore() | ||
self.auth = hs.get_auth() | ||
|
||
@defer.inlineCallbacks | ||
def on_POST(self, request, room_id): | ||
requester = yield self.auth.get_user_by_req(request) | ||
yield assert_user_is_admin(self.auth, requester.user) | ||
|
||
num_quarantined = yield self.store.quarantine_media_ids_in_room( | ||
room_id, requester.user.to_string() | ||
) | ||
|
||
return (200, {"num_quarantined": num_quarantined}) | ||
|
||
|
||
class ListMediaInRoom(RestServlet): | ||
"""Lists all of the media in a given room. | ||
""" | ||
|
||
PATTERNS = historical_admin_path_patterns("/room/(?P<room_id>[^/]+)/media") | ||
|
||
def __init__(self, hs): | ||
self.store = hs.get_datastore() | ||
|
||
@defer.inlineCallbacks | ||
def on_GET(self, request, room_id): | ||
requester = yield self.auth.get_user_by_req(request) | ||
is_admin = yield self.auth.is_server_admin(requester.user) | ||
if not is_admin: | ||
raise AuthError(403, "You are not a server admin") | ||
|
||
local_mxcs, remote_mxcs = yield self.store.get_media_mxcs_in_room(room_id) | ||
|
||
return (200, {"local": local_mxcs, "remote": remote_mxcs}) | ||
|
||
|
||
class ResetPasswordRestServlet(RestServlet): | ||
"""Post request to allow an administrator reset password for a user. | ||
This needs user to have administrator access in Synapse. | ||
|
@@ -822,10 +746,18 @@ def register_servlets(hs, http_server): | |
VersionServlet(hs).register(http_server) | ||
|
||
|
||
def register_servlets_for_media_repo(hs, http_server): | ||
|
||
""" | ||
Media repo specific APIs. | ||
""" | ||
PurgeMediaCacheRestServlet(hs).register(http_server) | ||
QuarantineMediaInRoom(hs).register(http_server) | ||
ListMediaInRoom(hs).register(http_server) | ||
|
||
|
||
def register_servlets_for_client_rest_resource(hs, http_server): | ||
"""Register only the servlets which need to be exposed on /_matrix/client/xxx""" | ||
WhoisRestServlet(hs).register(http_server) | ||
PurgeMediaCacheRestServlet(hs).register(http_server) | ||
PurgeHistoryStatusRestServlet(hs).register(http_server) | ||
DeactivateAccountRestServlet(hs).register(http_server) | ||
PurgeHistoryRestServlet(hs).register(http_server) | ||
|
@@ -834,10 +766,13 @@ def register_servlets_for_client_rest_resource(hs, http_server): | |
GetUsersPaginatedRestServlet(hs).register(http_server) | ||
SearchUsersRestServlet(hs).register(http_server) | ||
ShutdownRoomRestServlet(hs).register(http_server) | ||
QuarantineMediaInRoom(hs).register(http_server) | ||
ListMediaInRoom(hs).register(http_server) | ||
UserRegisterServlet(hs).register(http_server) | ||
DeleteGroupAdminRestServlet(hs).register(http_server) | ||
AccountValidityRenewServlet(hs).register(http_server) | ||
|
||
# Load the media repo ones if we're using them. | ||
if hs.config.can_load_media_repo: | ||
register_servlets_for_media_repo(hs, http_server) | ||
|
||
# don't add more things here: new servlets should only be exposed on | ||
# /_synapse/admin so should not go here. Instead register them in AdminRestResource. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.