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

E2E backups #4019

Merged
merged 47 commits into from
Oct 15, 2018
Merged

E2E backups #4019

merged 47 commits into from
Oct 15, 2018

Conversation

dbkr
Copy link
Member

@dbkr dbkr commented Oct 8, 2018

Supersedes #3757 and #2731

Note that most of this has already been reviewed when it was in 2731 (unsure if it would be easier or more confusing to merge this branch over to that one and re-open that PR).

This is MSC1687: https://github.com/uhoreg/matrix-doc/blob/e2e_backup/proposals/1219-storing-megolm-keys-serverside.md

Sytests: matrix-org/sytest#503

@dbkr dbkr requested a review from a team October 9, 2018 17:49
@dbkr dbkr mentioned this pull request Oct 9, 2018
@uhoreg
Copy link
Member

uhoreg commented Oct 10, 2018

I took a quick look at @dbkr's changes, and they look fine to me. It would be great to get a full review from a Synapse dev.

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just needs a little bit of sprucing up.

FTR: I've only really been reviewing the code, rather than trying to grok how E2E backups are meant to work as a whole.

For future reference, it'd also be good to avoid using @defer.inlineCallbacks in tests and instead use the test reactor infrastructure (which is also fairly nice). There are a number of advantages to this (Though personally the main one is that if you CTRL^C trial it sometimes completely wedges if using a real reactor)

return exception.error_dict()
else:
logger.error("Unknown exception type: %s", type(exception))
return {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears unused?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm, so it does

@@ -0,0 +1,283 @@
# -*- coding: utf-8 -*-
# Copyright 2017 New Vector Ltd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its 2018

room, or a given session.
See EndToEndRoomKeyStore.get_e2e_room_keys for full details.

Returns:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add Args section, giving types (and description if not obvious)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And the same for the other functions.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if e.code == 404:
raise SynapseError(404, "Version '%s' not found" % (version,))
else:
raise e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just use raise rather than raise e as you end up losing a bunch of stack traces

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good to know

if E2eRoomKeysHandler._should_replace_room_key(current_room_key, room_key):
yield self.store.set_e2e_room_key(
user_id, version, room_id, session_id, room_key
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not want to be in the lock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where by lock you mean try block? I don't think so as the try is just catching 404s from the get.

"""

if version:
raise SynapseError(405, "Cannot POST to a specific version")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please split this servlet into two: 1) which doesn't accept a version and only works for PUT and 2) which requires a version and only works with GET/DELETE.

This has the advantages of:

  1. Its easier to grasp the API shapes without having to read the code
  2. Don't have to re-implement all the validations/error handling

It does somewhat look like we've forgotten to check that we're actually given a version in GET/DELETE handlers for example

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if e.code == 404:
e.errcode = Codes.NOT_FOUND
e.msg = "No backup found"
raise e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make a new error rather than rewriting the existing one please? Otherwise we may end up with bizarre hybrid exceptions :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I'm not even sure we want to bother rewriting anything here. If we do, we should probably do the same for the DELETE handler.

In fact, for consistency sake we should probably make the exceptions returned by the handler on unknown version be consistent, rather than the exception being specific to each REST endpoint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes :)

# See the License for the specific language governing permissions and
# limitations under the License.

import simplejson as json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use just import json nowadays

session_id(str): the session whose room_key we're setting
room_key(dict): the room_key being set
Raises:
StoreError if stuff goes wrong, probably
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think its worth having this comment :)

@@ -0,0 +1,361 @@
# -*- coding: utf-8 -*-
# Copyright 2017 New Vector Ltd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@erikjohnston erikjohnston assigned dbkr and unassigned erikjohnston Oct 12, 2018
Copy link
Member Author

@dbkr dbkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully all addressed now - ptal

return exception.error_dict()
else:
logger.error("Unknown exception type: %s", type(exception))
return {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm, so it does

room, or a given session.
See EndToEndRoomKeyStore.get_e2e_room_keys for full details.

Returns:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if e.code == 404:
raise SynapseError(404, "Version '%s' not found" % (version,))
else:
raise e
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good to know

if E2eRoomKeysHandler._should_replace_room_key(current_room_key, room_key):
yield self.store.set_e2e_room_key(
user_id, version, room_id, session_id, room_key
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where by lock you mean try block? I don't think so as the try is just catching 404s from the get.

# purely for legibility.

if room_key['is_verified'] and not current_room_key['is_verified']:
pass
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm, agreed

"""

results = yield self.store.get_e2e_room_keys_version_info(user_id, version)
defer.returnValue(results)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm, I see what you mean

"""

if version:
raise SynapseError(405, "Cannot POST to a specific version")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if e.code == 404:
e.errcode = Codes.NOT_FOUND
e.msg = "No backup found"
raise e
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes :)

@dbkr dbkr assigned erikjohnston and unassigned dbkr Oct 12, 2018
Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this goes live we should probably move this functionality into a worker, as it sounds like this API is going to get hit a lot

@erikjohnston erikjohnston assigned dbkr and unassigned erikjohnston Oct 15, 2018
@dbkr dbkr merged commit 03c1103 into develop Oct 15, 2018
@richvdh
Copy link
Member

richvdh commented Oct 17, 2018

@dbkr please please please can we squash-merge things like this in future?

michaelkaye added a commit that referenced this pull request Oct 22, 2018
**Warning**: This release removes the example email notification templates from
`res/templates` (they are now internal to the python package). This should only
affect you if you (a) deploy your Synapse instance from a git checkout or a
github snapshot URL, and (b) have email notifications enabled.

If you have email notifications enabled, you should ensure that
`email.template_dir` is either configured to point at a directory where you
have installed customised templates, or leave it unset to use the default
templates.

The configuration parser will try to detect the situation where
`email.template_dir` is incorrectly set to `res/templates` and do the right
thing, but will warn about this.

Features
--------

- Ship the example email templates as part of the package ([\#4052](#4052))
- Add support for end-to-end key backup (MSC1687) ([\#4019](#4019))

Bugfixes
--------

- Fix bug which made get_missing_events return too few events ([\#4045](#4045))
- Fix bug in event persistence logic which caused 'NoneType is not iterable' ([\#3995](#3995))
- Fix exception in background metrics collection ([\#3996](#3996))
- Fix exception handling in fetching remote profiles ([\#3997](#3997))
- Fix handling of rejected threepid invites ([\#3999](#3999))
- Workers now start on Python 3. ([\#4027](#4027))
- Synapse now starts on Python 3.7. ([\#4033](#4033))

Internal Changes
----------------

- Log exceptions in looping calls ([\#4008](#4008))
- Optimisation for serving federation requests ([\#4017](#4017))
- Add metric to count number of non-empty sync responses ([\#4022](#4022))
@DMRobertson DMRobertson deleted the dbkr/e2e_backups branch June 28, 2022 11:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants