Skip to content
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

Open
wants to merge 80 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
ba542fe
mas: added /auth_issuer endpoint
mdnight Dec 21, 2024
2c47959
mas: added username_available endpoint
mdnight Dec 22, 2024
e1dfe62
mas: rename msc2965 to msc3861
mdnight Dec 22, 2024
150be58
mas: added localpart_external_ids table
mdnight Dec 24, 2024
63a199c
mas: first successful attempt of login with via mas
mdnight Dec 29, 2024
9d9841d
mas: added "admin's replacement without uia" endpoint
mdnight Dec 30, 2024
4f406e2
minor goimports fix
mdnight Dec 30, 2024
b950703
mas: return correct http code
mdnight Dec 30, 2024
9ebcebe
another goimports fix
mdnight Dec 30, 2024
be8d490
mas: implemented PUT /admin/v2/users/{userID} endpoint
mdnight Dec 30, 2024
524f65c
mas: add AccountTypeOIDCService
mdnight Dec 30, 2024
ff63e7f
mas: modify PUT /profile/{userID}/displayname endpoint
mdnight Dec 30, 2024
bf310d5
drop primary key constraint from userapi_devices.access_token
mdnight Dec 31, 2024
f4ff426
mas: refactor admin user device handler
mdnight Jan 1, 2025
803cce8
mas: added admin's delete devices endpoint
mdnight Jan 1, 2025
7ffb2c1
mas: minor fixes in cross_signing_keys_table files
mdnight Jan 5, 2025
c06e0aa
refactor logger calls
mdnight Jan 5, 2025
48f3cd3
mas: added /admin/v1/deactivate/{userID} endpoint
mdnight Jan 5, 2025
9b064b1
minor refactoring
mdnight Jan 5, 2025
cc7deb2
mas: added support of msc3861 to /keys/device_signing/upload endpoint
mdnight Jan 5, 2025
5cffc2c
mas: fix displayname handling
mdnight Jan 6, 2025
811a504
mas: handle 3pids from mas
mdnight Jan 6, 2025
17576cc
mas: acced msc3861 config example to the dendrite-sample.yaml
mdnight Jan 7, 2025
e943ba5
mas: fail if conflicts in config occur
mdnight Jan 7, 2025
7eec60e
mas: reorganise endpoints
mdnight Jan 7, 2025
fb15db7
unit tests fix
mdnight Jan 8, 2025
b44a79c
Bump golang version
mdnight Jan 8, 2025
7311d3e
more fixes
mdnight Jan 8, 2025
0990676
linter fixes
mdnight Jan 9, 2025
1afe2b9
fix cross_signing_keys_table
mdnight Jan 9, 2025
244021d
deleted test cases TestDevices/sqlite/dupe_token
mdnight Jan 9, 2025
78457f3
++
mdnight Jan 9, 2025
80ee52e
fix syncapi tests
mdnight Jan 9, 2025
930daa1
mas: move org.matrix.cross_signing_reset const from logintypes.go to …
mdnight Jan 10, 2025
0be9b3c
syncapi_test.go fix
mdnight Jan 10, 2025
4cde3ba
mas: add missing migration for adding x-signing updatable_without_uia…
mdnight Jan 10, 2025
5ea033d
mas: remove enabled field from msc3861 config + remove some incorrect…
mdnight Jan 10, 2025
5fd654f
Add TestMakeServiceAdminAPI
mdnight Jan 10, 2025
5914661
mas: add TestVerifyUserFromRequest
mdnight Jan 15, 2025
90e3de3
mas: TestAdminCheckUsernameAvailable
mdnight Jan 15, 2025
59f73b1
mas: TestAdminUserDeviceRetrieveCreate
mdnight Jan 15, 2025
f1de5aa
mas: TestAdminUserDeviceDelete
mdnight Jan 15, 2025
0db7647
mas: TestAdminUserDevicesDelete
mdnight Jan 15, 2025
4193b7b
mas: TestAdminDeactivateAccount
mdnight Jan 15, 2025
e8902da
mas: TestAdminRetrieveAccount
mdnight Jan 15, 2025
5dd8568
mas: TestAdminCreateOrModifyAccount
mdnight Jan 15, 2025
418c584
mas: TestAdminAllowCrossSigningReplacementWithoutUIA
mdnight Jan 15, 2025
3619a6d
mas: refactoring
mdnight Jan 15, 2025
64f308b
mas: add missing server_name field to sqlite migration
mdnight Jan 17, 2025
6833e99
Merge branch 'main' of github.com:element-hq/dendrite into msc3861
mdnight Jan 17, 2025
b44f899
mas: cross signing fixes after merge
mdnight Jan 17, 2025
021431c
mas: fix key_crosssigning_test.go
mdnight Jan 17, 2025
641f5b5
mas: todo comment
mdnight Jan 17, 2025
7d076a9
Merge branch 'main' into msc3861
mdnight Jan 20, 2025
17b7677
fix typo in api.QueryAccessTokenAPI
mdnight Jan 22, 2025
8a05a66
code review fixes
mdnight Jan 23, 2025
ea875b3
Merge branch 'msc3861' of github.com:mdnight/dendrite into msc3861
mdnight Jan 23, 2025
bf31c44
more fixes
mdnight Jan 23, 2025
a185027
cr fixes
mdnight Jan 23, 2025
b5f34df
fix test
mdnight Jan 23, 2025
4534456
mas: store crossSigngingKeysReplacement period in sessionsDict struct…
mdnight Jan 24, 2025
0b4cf3b
mas: revert cross_signing_keys.updatable_without_uia_before_ms field …
mdnight Jan 25, 2025
27f7a5e
mas: fix tests
mdnight Jan 25, 2025
c1ad175
more test fixes
mdnight Jan 25, 2025
b8ea41b
tests for sessionsDict.crossSigningKeysReplacement
mdnight Jan 25, 2025
ba919d7
Merge branch 'main' into msc3861
mdnight Jan 29, 2025
6a741b2
Merge branch 'main' into msc3861
mdnight Jan 30, 2025
9ab9a8d
Merge branch 'main' into msc3861
mdnight Feb 3, 2025
8d39801
Merge branch 'main' into msc3861
mdnight Feb 4, 2025
0924e99
Merge branch 'main' into msc3861
mdnight Feb 4, 2025
8df6442
msd3861: added license headers for the new files
mdnight Feb 5, 2025
3eb4c7e
msc3861: cr fixes
mdnight Feb 12, 2025
f91cc64
msc3861: cr fixes
mdnight Feb 12, 2025
fd52c7e
msc3861: cr
mdnight Feb 12, 2025
ff2ba03
msc3861: ++
mdnight Feb 12, 2025
c490bad
msc3861: delete QueryMasterKeys function and related as it's redundan…
mdnight Feb 12, 2025
1b8a659
msc3861: tests
mdnight Feb 12, 2025
b74b52d
remove deprecated linters from golangci-lint
mdnight Feb 12, 2025
950555a
goimports
mdnight Feb 12, 2025
20b3917
msc3861: validate access_token uniqueness manually
mdnight Mar 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mas: added username_available endpoint
mdnight committed Dec 22, 2024
commit 2c47959600fd3df21f122023c7757e3048af8999
21 changes: 21 additions & 0 deletions clientapi/routing/admin.go
Original file line number Diff line number Diff line change
@@ -496,6 +496,27 @@ func AdminDownloadState(req *http.Request, device *api.Device, rsAPI roomserverA
}
}

func AdminCheckUsernameAvailable(
req *http.Request,
userAPI userapi.ClientUserAPI,
cfg *config.ClientAPI,
) util.JSONResponse {
username := req.URL.Query().Get("username")
if username == "" {
return util.MessageResponse(http.StatusBadRequest, "Query parameter 'username' is missing or empty")
}
rq := userapi.QueryAccountAvailabilityRequest{Localpart: username, ServerName: cfg.Matrix.ServerName}
rs := userapi.QueryAccountAvailabilityResponse{}
if err := userAPI.QueryAccountAvailability(req.Context(), &rq, &rs); err != nil {
return util.ErrorResponse(err)
}

return util.JSONResponse{
Code: http.StatusOK,
JSON: map[string]bool{"available": rs.Available},
}
}

// GetEventReports returns reported events for a given user/room.
func GetEventReports(
req *http.Request,
7 changes: 6 additions & 1 deletion clientapi/routing/routing.go
Original file line number Diff line number Diff line change
@@ -334,7 +334,12 @@ func Setup(
return util.JSONResponse{Code: http.StatusOK, JSON: map[string]string{
"issuer": m.Issuer,
}}
}))
})).Methods(http.MethodGet)

synapseAdminRouter.Handle("/admin/v1/username_available",
httputil.MakeServiceAdminAPI("admin_username_available", m.AdminToken, func(r *http.Request) util.JSONResponse {
return AdminCheckUsernameAvailable(r, userAPI, cfg)
})).Methods(http.MethodGet)
}

if mscCfg.Enabled("msc2753") {
32 changes: 32 additions & 0 deletions internal/httputil/httpapi.go
Original file line number Diff line number Diff line change
@@ -136,6 +136,38 @@ func MakeAdminAPI(
})
}

// MakeServiceAdminAPI is a wrapper around MakeAuthAPI which enforces that the request can only be
// completed by a trusted service e.g. Matrix Auth Service.
func MakeServiceAdminAPI(
metricsName, serviceToken string,
f func(*http.Request) util.JSONResponse,
) http.Handler {
h := func(req *http.Request) util.JSONResponse {
logger := util.GetLogger(req.Context())
token, err := auth.ExtractAccessToken(req)

if err != nil {
logger.Debugf("ExtractAccessToken %s -> HTTP %d", req.RemoteAddr, http.StatusUnauthorized)
return util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: spec.MissingToken(err.Error()),
}
}
if token != serviceToken {
logger.Debugf("Invalid service token '%s'", token)
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if it is invalid (maybe just a typo in the token at the end or such), better don't log it.

Suggested change
logger.Debugf("Invalid service token '%s'", token)
logger.Debugf("Invalid service token")

Copy link
Author

Choose a reason for hiding this comment

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

You’re right. I should have removed the variable from the message. I forgot to change it after debugging.

return util.JSONResponse{
Code: http.StatusForbidden,
JSON: spec.UnknownToken(token),
}
}
// add the service addr to the logger
logger = logger.WithField("service_useragent", req.UserAgent())
req = req.WithContext(util.ContextWithLogger(req.Context(), logger))
return f(req)
}
return MakeExternalAPI(metricsName, h)
}

// MakeExternalAPI turns a util.JSONRequestHandler function into an http.Handler.
// This is used for APIs that are called from the internet.
func MakeExternalAPI(metricsName string, f func(*http.Request) util.JSONResponse) http.Handler {
2 changes: 1 addition & 1 deletion setup/mscs/mscs.go
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ func EnableMSC(cfg *config.Dendrite, cm *sqlutil.Connections, routers httputil.R
return msc2836.Enable(cfg, cm, routers, monolith.RoomserverAPI, monolith.FederationAPI, monolith.UserAPI, monolith.KeyRing)
case "msc2444": // enabled inside federationapi
case "msc2753": // enabled inside clientapi
case "msc2965": // enabled inside clientapi
case "msc2965": // enabled inside clientapi
default:
logrus.Warnf("EnableMSC: unknown MSC '%s', this MSC is either not supported or is natively supported by Dendrite", msc)
}