-
Notifications
You must be signed in to change notification settings - Fork 412
MSC2967: API scopes #2967
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
Merged
Merged
MSC2967: API scopes #2967
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a2e9656
API Scopes MSC
sandhose 544d75b
Proposed insufficient privilege response format
hughns d49f2d8
Remove realm as not required
hughns 23c7638
Clarifications + update on latest device management proposal
hughns b609c2b
Revised namespace structure + unstable prefixes
hughns f07b466
Revise prefix for device ID
hughns 1ce049e
Reference to MSC3861 + cleanup
hughns 5c57507
Add scope for guest access and tidy up
hughns 5afb697
No need for UIA scope
hughns 8ec2d7c
Update proposals/2967-api-scopes.md
hughns 8539ab2
Clarification about encoding of device ID within URN scope
hughns 0666b24
Merge branch 'matrix-org:main' into msc/sandhose/api-scopes
sandhose f65aef3
Rework MSC
sandhose 660946a
Update proposals/2967-api-scopes.md
sandhose 4dd433f
Reword as dbkr suggested
sandhose 79845f5
Reword how unstable subdivisions are used
sandhose 49550fe
Remove confusing sentence
sandhose 14b962c
Gather all the links at the bottom of the document
sandhose 58f2398
Tyding up, define exactly how device IDs are handled
sandhose e7531fa
Don't use a table for a single row
sandhose acc8e91
Typo
sandhose 1304203
Fix math rendering
sandhose 6623b96
Fix the math
sandhose 1ddd733
Minor rewording on device uniqueness
sandhose a33d1e3
Simplify wording around the ASCII range
sandhose 0800ea6
Typo
sandhose a7bb99c
Scope vs scope token is confusing
sandhose abbae1e
Reword how the device ID is requested
sandhose 082625d
Explain why we keep the device ID generation on the client
sandhose 089a789
MSCXXXX is a better placeholder
sandhose 858b7be
The scope MUST have a device ID
sandhose c9f8690
Clarify that device IDs are still unique per user
sandhose 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# MSC2967: API scope restriction | ||
|
||
When a user logs in with a Matrix client, it gives this client full access to their Matrix account. | ||
|
||
This introduces scopes to allow restricting client access to only part of the Matrix client API. | ||
|
||
## Proposal | ||
|
||
The [MSC2964](https://github.com/matrix-org/matrix-doc/pull/2964) introduces the usage of OAuth 2.0 to authenticate against a Matrix server. | ||
OAuth 2.0 grants have scopes associated to them and encourage to ask for user consent when a client asks for a new scope that was not granted before. | ||
|
||
This MSC does not attempt to define all the scopes necessary to cover the whole API, but lays out a base for that. | ||
|
||
### Format | ||
|
||
URN are widely used formats for OAuth 2.0 scopes. | ||
All scopes related to Matrix must therefore start with `urn:matrix:`. | ||
|
||
Calls to the Matrix client API, excluding calls that need UIA, must be restricted by scopes prefixed by `urn:matrix:api:`. | ||
Calls to endpoints that currently need User-Interactive Authentication (UIA) must be restricted by scopes prefixed by `urn:matrix:sudo:`. | ||
|
||
Protected resource can have both `read` and `write` operations. | ||
`write` access to a resource implies `read` access to it. | ||
Access to those operations are specified as the scope suffix, e.g. `urn:matrix:api:[resource]:read`. | ||
|
||
### Globs | ||
|
||
Scopes used by the Matrix client API support wildcard globs. | ||
`urn:matrix:api:*` gives full access to the API (excluding UIA). | ||
`urn:matrix:api:*:read` gives read-only access to the API. | ||
Access to the `urn:matrix:sudo:*` can be time-restricted and require user re-authentication for sensitive operations. | ||
hughns marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Top-level wildcards (`urn:matrix:*` or `*`) are not valid and must be rejected by the authentication server. | ||
Wildcards can only replace URN segments, e.g. `urn:matrix:a*` is invalid. | ||
|
||
### Exact scopes | ||
|
||
The exact scopes are intentionally not specified in this MSC. | ||
The glob mechanism allows to the existing behaviour during a transition period while allowing further MSCs that introduces those exact scopes. | ||
|
||
### Device handling | ||
|
||
With the pre-MSC2964 authentication mechanism, a `device_id` was associated with the access token. | ||
Since there are no such thing as a session in OAuth 2.0, this can be hardly mapped like this. | ||
|
||
`device_id` can be bound to a client session via a scope with this format: `urn:matrix:device:[device_id]`. | ||
If the client does not ask such a scope during the initial login, the authentication server must generate a new `device_id` and give it as a granted scope to the client. | ||
A client can adopt and rehydrate an existing client by asking for its scope on login. | ||
This also has a nice side-effect: if the device asked was never used by the client making the request, the authorization server will ask for explicit consent from the user. | ||
sandhose marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
The authentication server must only grant exactly one device scope for a token. | ||
Wildcards are not allowed under the `urn:matrix:device:` prefix. | ||
|
||
## Potential issues | ||
|
||
The Device ID handling involves some custom logic on the authorization server side. | ||
This means the Matrix server must be involved at some point in the authorization logic, which also involves implementation-specific code for each Matrix server implementation and OAuth 2.0 authentication server implementation. | ||
This is not a problem when the Matrix server acts as the authorization server. | ||
|
||
## Alternatives | ||
|
||
Scope format could also have an URL format, e.g. `https://matrix.org/api/*/read`. | ||
sandhose marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
The URL prefix could either be static (`https://matrix.org`) or dependant on the homeserver (`https://matrix.example.com`). | ||
In both cases, the URL could be confused with API endpoints and in the second case it would require discovery to know what scopes to ask. | ||
|
||
The actual prefix as well as the `:api:`, `:sudo:` and `:device:` URN parts are open to debate. | ||
|
||
## Security considerations | ||
|
||
TBD | ||
|
||
## Unstable prefix | ||
|
||
None relevant. |
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.
Uh oh!
There was an error while loading. Please reload this page.