This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 676
Tweak AS registration check and AS component HTTP clients #1785
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
88c381e
Tweak AS registration check
neilalexander 2e70ef4
Check appservice usernames using correct function
neilalexander d606eec
Update sytest-whitelist
neilalexander 9cf65c5
Use gomatrixserverlib.Client since that allows us to disable TLS vali…
neilalexander d327bac
Add appservice-specific client and ability to control TLS validation …
neilalexander 0d95e06
Set timeout on appservice client
neilalexander e7bdd06
Review comments
neilalexander 05ec2e6
Merge branch 'master' into neilalexander/asreg
neilalexander ff04a96
Remove dead code
neilalexander 2db487c
Enforce LoginTypeApplicationService after all
neilalexander f7ab99a
Check correct auth type field
neilalexander 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 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 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 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 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 |
---|---|---|
|
@@ -46,6 +46,7 @@ import ( | |
"github.com/matrix-org/gomatrixserverlib/tokens" | ||
"github.com/matrix-org/util" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/sirupsen/logrus" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
|
@@ -496,11 +497,20 @@ func Register( | |
r.Username = strconv.FormatInt(id, 10) | ||
} | ||
|
||
// Is this an appservice registration? It will be if the access | ||
// token is supplied | ||
accessToken, accessTokenErr := auth.ExtractAccessToken(req) | ||
|
||
// Squash username to all lowercase letters | ||
r.Username = strings.ToLower(r.Username) | ||
|
||
if resErr = validateUsername(r.Username); resErr != nil { | ||
return *resErr | ||
if r.Auth.Type == authtypes.LoginTypeApplicationService || accessTokenErr == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer it if we only look at the access token if the login type is set to AS? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out that this isn't always the case. It's another one of those "spec is vague" things but Synapse also treats all calls to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided with @Half-Shot to instead enforce |
||
if resErr = validateApplicationServiceUsername(r.Username); resErr != nil { | ||
return *resErr | ||
} | ||
} else { | ||
if resErr = validateUsername(r.Username); resErr != nil { | ||
return *resErr | ||
} | ||
} | ||
if resErr = validatePassword(r.Password); resErr != nil { | ||
return *resErr | ||
|
@@ -513,7 +523,7 @@ func Register( | |
"session_id": r.Auth.Session, | ||
}).Info("Processing registration request") | ||
|
||
return handleRegistrationFlow(req, r, sessionID, cfg, userAPI) | ||
return handleRegistrationFlow(req, r, sessionID, cfg, userAPI, accessToken, accessTokenErr) | ||
} | ||
|
||
func handleGuestRegistration( | ||
|
@@ -579,6 +589,8 @@ func handleRegistrationFlow( | |
sessionID string, | ||
cfg *config.ClientAPI, | ||
userAPI userapi.UserInternalAPI, | ||
accessToken string, | ||
accessTokenErr error, | ||
) util.JSONResponse { | ||
// TODO: Shared secret registration (create new user scripts) | ||
// TODO: Enable registration config flag | ||
|
@@ -588,12 +600,12 @@ func handleRegistrationFlow( | |
// TODO: Handle mapping registrationRequest parameters into session parameters | ||
|
||
// TODO: email / msisdn auth types. | ||
accessToken, accessTokenErr := auth.ExtractAccessToken(req) | ||
|
||
// Appservices are special and are not affected by disabled | ||
// registration or user exclusivity. | ||
if r.Auth.Type == authtypes.LoginTypeApplicationService || | ||
(r.Auth.Type == "" && accessTokenErr == nil) { | ||
// registration or user exclusivity. We'll go onto the appservice | ||
// registration flow if a valid access token was provided or if | ||
// the login type specifically requests it. | ||
if r.Auth.Type == authtypes.LoginTypeApplicationService || accessTokenErr == nil { | ||
return handleApplicationServiceRegistration( | ||
accessToken, accessTokenErr, req, r, cfg, userAPI, | ||
) | ||
|
@@ -679,6 +691,8 @@ func handleApplicationServiceRegistration( | |
cfg *config.ClientAPI, | ||
userAPI userapi.UserInternalAPI, | ||
) util.JSONResponse { | ||
logrus.Warnf("APPSERVICE Is appservice registration %q", r.Username) | ||
neilalexander marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Check if we previously had issues extracting the access token from the | ||
// request. | ||
if tokenErr != nil { | ||
|
This file contains 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 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 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 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 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
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.
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.
Why are we using this client instead of a normal one? GMSL.Client is for federation traffic only I thought? ASes do not get sent signed traffic.
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.
gomatrixserverlib.Client
is for normal requests (like what the media API uses to fetch media),gomatrixserverlib.FederationClient
is for signed requests.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's the difference between GMSL.Client and net/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.
Not much, mostly just that
gomatrixserverlib.Client
has all of the correct wiring already to give it a timeout and/or disable TLS validation without needing to reinvent the wheel again in the AS code.