-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSC3861: MAS support #3493
base: main
Are you sure you want to change the base?
MSC3861: MAS support #3493
Conversation
i.e. /_synapse/admin/v1/users/{userID}/_allow_cross_signing_replacement_without_uia
If access token expires the client(i.e. element) expects a specific response with http code 401 and spec.UnknownToken
MAS requires this endpoint to fetch the data for the account management page
Extended logic of the endpoint in order to make it compatible with MAS
this change is based mostly on changes made in synapse https://github.com/element-hq/synapse/blob/develop/synapse/rest/client/keys.py#L392
Since MSC3861 is conflicting with standard reg/login flows, we require to disable them before running the server
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3493 +/- ##
==========================================
- Coverage 49.44% 49.44% -0.01%
==========================================
Files 524 533 +9
Lines 59799 60996 +1197
==========================================
+ Hits 29569 30159 +590
- Misses 26750 27251 +501
- Partials 3480 3586 +106
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
From what I've seen so far (and tested), this is awesome! Thanks a lot for this!
The requested changes are only minor, still need to go through 34 changed files 🙃
@@ -817,7 +819,7 @@ func checkAndCompleteFlow( | |||
return util.JSONResponse{ | |||
Code: http.StatusUnauthorized, | |||
JSON: newUserInteractiveResponse(sessionID, | |||
cfg.Derived.Registration.Flows, cfg.Derived.Registration.Params), | |||
cfg.Derived.Registration.Flows, cfg.Derived.Registration.Params, ""), |
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.
We should add a default message instead of returning nothing, I think.
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.
We need the message field only once, when we want to show this: To reset your end-to-end encryption cross-signing identity, you first need to approve it at ${URL} and then try again.
For other cases, we simply ignore the empty field and do not return it in the response.
type userInteractiveResponse struct {
Flows []authtypes.Flow `json:"flows"`
...
Msg string `json:"msg,omitempty"` <--- this
}
Also, I can't find msg
in the spec 🤷
userapi/api/api.go
Outdated
@@ -129,6 +132,7 @@ type QuerySearchProfilesAPI interface { | |||
QuerySearchProfiles(ctx context.Context, req *QuerySearchProfilesRequest, res *QuerySearchProfilesResponse) error | |||
} | |||
|
|||
// FIXME: typo in Acccess |
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.
🙃 Ooops.
userapi/api/api.go
Outdated
Localpart string | ||
ExternalID string | ||
AuthProvider string | ||
CreatedTs int64 |
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.
CreatedTs int64 | |
CreatedTS int64 |
clientapi/routing/routing.go
Outdated
})).Methods(http.MethodPost) | ||
} else { | ||
// If msc3861 is enabled, these endpoints are either redundant or replaced by Matrix Auth Service (MAS) | ||
// Once we migrate to MAS completely, these edndpoints should be removed |
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.
// Once we migrate to MAS completely, these edndpoints should be removed | |
// Once we migrate to MAS completely, these endpoints should be removed |
syncapi/syncapi_test.go
Outdated
@@ -119,6 +120,20 @@ func (s *syncUserAPI) PerformLastSeenUpdate(ctx context.Context, req *userapi.Pe | |||
return nil | |||
} | |||
|
|||
type userVerifier struct { | |||
m map[string]struct { |
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.
What is m
? (more descriptive field name please, something like accessTokenToDeviceAndResponse
, maybe?)
@@ -0,0 +1,23 @@ | |||
package deltas |
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.
As mentioned OOB, we probably don't need this migration and can instead use
dendrite/clientapi/routing/register.go
Lines 57 to 69 in f4506a0
// sessionsDict keeps track of completed auth stages for each session. | |
// It shouldn't be passed by value because it contains a mutex. | |
type sessionsDict struct { | |
sync.RWMutex | |
sessions map[string][]authtypes.LoginType | |
sessionCompletedResult map[string]registerResponse | |
params map[string]registerRequest | |
timer map[string]*time.Timer | |
// deleteSessionToDeviceID protects requests to DELETE /devices/{deviceID} from being abused. | |
// If a UIA session is started by trying to delete device1, and then UIA is completed by deleting device2, | |
// the delete request will fail for device2 since the UIA was initiated by trying to delete device1. | |
deleteSessionToDeviceID map[string]string | |
} |
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.
Not sure I have a clear understanding of how this structure might apply to our case. I need to reflect on it a bit. 🤔
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.
Done. Added a new map to the structure for managing this kind of session and covered new methods with tests. Also deleted xsigning_updatable_without_uia_before_ms
column from the database and reverted all related logic
@@ -116,6 +116,7 @@ func (s *accountsStatements) InsertAccount( | |||
localpart string, serverName spec.ServerName, | |||
hash, appserviceID string, accountType api.AccountType, | |||
) (*api.Account, error) { | |||
// TODO: can we replace "UnixNano() / 1M" with "UnixMilli()"? |
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.
Yes we can! :)
As a followup PR, use spec.AsTimestamp(time.Now())
which does the same, and update AsTimestamp
in gomatrixserverlib to use UnixMilli()
.
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.
created a pull requests for gomatrixserverlib 🙂 matrix-org/gomatrixserverlib#447
setup/config/config_mscs.go
Outdated
// 'msc2444': Peeking over federation - https://github.com/matrix-org/matrix-doc/pull/2444 | ||
// 'msc2753': Peeking via /sync - https://github.com/matrix-org/matrix-doc/pull/2753 | ||
// 'msc2836': Threading - https://github.com/matrix-org/matrix-doc/pull/2836 | ||
MSCs []string `yaml:"mscs"` | ||
|
||
// MSC3861 contains config related to the experimental feature MSC3861. It takes effect only if 'msc3861' is included in 'MSCs' array |
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.
// MSC3861 contains config related to the experimental feature MSC3861. It takes effect only if 'msc3861' is included in 'MSCs' array | |
// MSC3861 contains config related to the experimental feature MSC3861. | |
// It takes effect only if 'msc3861' is included in 'MSCs' array. |
setup/config/config_clientapi.go
Outdated
c.RecaptchaApiJsUrl = "https://www.google.com/recaptcha/api.js" | ||
|
||
if c.MSCs.MSC3861Enabled() { | ||
if c.RecaptchaEnabled || !c.RegistrationDisabled { |
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.
Maybe just me, but I prefer reading the "not" path first.
if c.RecaptchaEnabled || !c.RegistrationDisabled { | |
if !c.RegistrationDisabled || c.RecaptchaEnabled { |
For a different PR: We should only have either Enabled
or Disabled
in our config. Otherwise stuff like this might become confusing.
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.
I don't have any preferences regarding the "not" path, but I agree that registration should go first. 😄
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.
Didn't want to request changes again, just wanted to add a few more comments..
const deleteUserExternalIDSQL = "" + | ||
"SELECT localpart, external_id, auth_provider, created_ts FROM userapi_localpart_external_ids WHERE external_id = $1 AND auth_provider = $2" |
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.
This doesn't look like a DELETE
. (same for SQLite)
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.
🤦
serverName spec.ServerName, | ||
cfg *config.MSC3861, | ||
allowGuest bool, | ||
httpClient *http.Client, |
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.
httpClient
should probably be a fclient.Client
, see https://github.com/matrix-org/gomatrixserverlib/blob/0a1b2bafb5cf72727787359d39653493b3318398/fclient/client.go#L44-L50
And it should be an error if it is not set, we shouldn't use http.DefaultClient
.
…and related logic
@S7evinK the PR is ready for review again. I believe I have addressed all the comments. Please have another look when you have a moment. 🙏 |
Pull Request Checklist
Signed-off-by:
Roman Isaev <[email protected]>