-
-
Notifications
You must be signed in to change notification settings - Fork 675
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
Tweak AS registration check and AS component HTTP clients #1785
Changes from 6 commits
88c381e
2e70ef4
d606eec
9cf65c5
d327bac
0d95e06
e7bdd06
05ec2e6
ff04a96
2db487c
f7ab99a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
|
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.