Skip to content

ADR 0003: Semantics of OAuth scopes - #27153

Open
NobodysNightmare wants to merge 3 commits into
devfrom
adr-0003-oauth-scope-semantics
Open

NobodysNightmare wants to merge 3 commits into
devfrom
adr-0003-oauth-scope-semantics

Conversation

@NobodysNightmare

@NobodysNightmare NobodysNightmare commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Suggesting a new ADR covering a topic we had some fun debate over in todays Dev Open Door.

Tickets

If you need to track time for work on this ADR, I suggest https://community.openproject.org/wp/SI-248. It's a pretty good catcher for the topic at hand.

Status of this ADR

I've done a first round of writing this together and have a fuming head now. If you are reading this, it's either because you scanned the PR list yourself or because I invited you to a first round of feedback.

AI disclosure

None/Assisted:

The majority of the ADR was human-written. Before submitting it for first human review, I used an LLM to find logical mistakes and contradictions. I hope that led to the ADR being less biased than writing it alone 🤷

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Caution

The provided work package version does not match the core version

Details:

Please make sure that:

  • The work package version OR your pull request target branch is correct


## Decision Outcome

Chosen option: "C: Combined scopes for resource actions, and resource location, but separate scopes for allowed API protocol",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Especially after LLM input the goods/bads would also rationalize choosing option A. It's definitely simpler to build for us and maintain for IDP admins in many regards. (In retrospect I'd say I was more biased against this solution than I realized myself)

However, we definitely limit expressiveness here. If we say it must be possible to have different resource access per resource + location pair in a single token, this would disqualify A. Otherwise it could be the better choice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I kind of stay with my argument for now, that simplicity and extensibility beats the wider expressiveness.

Do we need to hand out a single(!) token, that allows for action A in workspace 1 and action B in workspace 2? For my interpretation those use cases should be divided into two separate concerns, aka two separate tokens in the end. One for action A in workspace 1 and another for action B in workspace 2.

@klaustopher klaustopher Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also note, that we already sort of do a separation per API protocol. When looking at the different classes that inherit from Token, the difference between an iCal Token, an RSS token and an API Token is only really the different area where they can be used. So going with approach C would be able to absorb this into the regular token imho.

With that in mind. Maybe the scope as in "what is this token allowed to access" and the access point as in "how can it be accessed (api, mcp, rss, ical, ...)" should be 2 seperate concepts?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With that in mind. Maybe the scope as in "what is this token allowed to access" and the access point as in "how can it be accessed (api, mcp, rss, ical, ...)" should be 2 seperate concepts?

That would support the solutions A and C, which put this into their own scope, correct? Or do you want to suggest that a different concept means this shouldn't be decided in the scope-section of a token?

To drive your initial idea further:

the difference between an iCal Token, an RSS token and an API Token is only really the different area where they can be used

If we now said that op:api:rss etc would be their own scopes, this could allow admins/developers to:

  • Add OAuth applications to OpenProject that only allow obtaining RSS/iCal tokens
    • think of a calendar web service or app that wants to obtain calendars from OpenProject
  • Configure their third-party IDP to hand out RSS or iCal tokens

While I don't see immediate use cases for this, it also doesn't sound absurd to me to support them.

On the other hand, if I am mis-reading you and you indeed wanted to decouple this from the scopes concept: This would mean that admins would lose their ability to use scopes to decide which APIs are accessible. This would at least be a feature loss for third party IDPs. It's effectively as bad as option D.

In other words: I am not sure whether I understood your message correctly, but I answered for two interpretations of it above :D

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, the IDP argument is a good one. My thought was that the token object has an additional column like access_method, but putting it in the scope helps IDPs, that would also be fine.

So that my token "All Meeetings in Project A via MCP,APIv3" has the scopes ["op:mcp", "op:apiv3", "op:meetings:project:1234"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would Sebastian's argument about performance and scope complexity explosion also be a reason to not choose option A?
We should definitely include performance and complexity in the evaluation criteria for each option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My first instinct would be that A would be the least complex and most performant(ly implementable) solution.

If I remember @tisba 's argumentation from the initial IRL conversation correctly, he was even a fan of solution A.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Currently, AFAIK, we do permission checks in the database. Depending on how creative we will get with limiting access to resources in tokens, it might get messy if additional constraints are provided. It's at least something we should keep in mind.

One of my arguments was that you typically want to keep the cardinality of scopes in check (token size being one argument). That's why you typically see scopes used to specify "what you can do" and not "what you can do to what" (separate scopes and resource authorization). I'm not sure what good alternatives are in our case, but we could so something like Resource-specific authorization claims in tokens, or track resource specific permissions entirely elsewhere.

@judithroth judithroth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @NobodysNightmare
Thanks for writing all this down, I think this moves us a huge step forward!
I added my thoughts mostly in comments, but here are some more 🙂

  1. I think we should add performance and complexity as criteria for evaluating each solution (I also mentioned this in a comment, but since that adds to a long discussion already, I don't want it to be lost).

  2. I haven't thought of this so far and I am not sure we completely need to specify it, just make sure we have a possible solution: How would we handle the /api/v3/users/me endpoint? We probably don't want to give permissions to view all users just so a user can access his own data. Should this be included in op:api:api_v3 by default?

  3. I kind of find it weird to discuss this level of detail for things we want to build in the future (e.g. how the new API scopes will work), where we don't even have a date for yet in an ADR. It carries the risk of being wrong in the future if it gets implemented differently.


## Decision Outcome

Chosen option: "C: Combined scopes for resource actions, and resource location, but separate scopes for allowed API protocol",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would Sebastian's argument about performance and scope complexity explosion also be a reason to not choose option A?
We should definitely include performance and complexity in the evaluation criteria for each option.

Additionally the new naming scheme common to most of the options is being adopted for new token scopes (see "More information" at the bottom).
The existing API scopes remain as legacy scopes until the new scoping scheme has been implemented and documented **and** we are able
to make a breaking change to the public API, i.e. during a major release. Until then, the existing legacy scopes act equivalent to their
`op:api:<name>` counterpart as well as `op:resource` being present in the scope. **The behaviour for mixing legacy scopes and new scopes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Until then, the existing legacy scopes act equivalent to their op:api:<name> counterpart as well as op:resource being present in the scope.

I am not sure I understand this. So, the existing api_v3 scope grants access to the whole APIv3 at the moment. Now I understand you as "if a token holds the scopes api_v3 + an op:ressource scope, e.g. for documents, it should not grant access to the full APIv3, but only to the endpoints which are allowed the op:ressource scope (e.g. documents)".

❗ Doesn't this contradict the existing behaviour of the api_v3 scope and would already be the breaking change you want to have only with a major release of OpenProject?

So, shouldn't we instead write:
"Until then, the existing legacy scopes (e.g. api_v3) can not be used together with the the new op:ressource scopes in the same token, because they would nullify the resource token"?

One more thing to keep in mind: JwtOidc#valid_scope? only checks for api_v3 and never saves the token's scopes to env, because we agreed that JWT is out of scope for this first implementation step that the documents need. So if there was - for what ever reason - a JWT token holding api_v3 and op:ressource:documents:edit it would still get access to the whole API, which would contradict the behaviour of an OAuth token with the exact same scopes. I'd strongly prefer to stay consistent there and then make the switch to the new behaviour when we introduce the new API scopes which you describe at the end of this document.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"if a token holds the scopes api_v3 + an op:ressource scope, e.g. for documents, it should not grant access to the full APIv3, but only to the endpoints which are allowed the op:ressource scope (e.g. documents)"

Where do you read/understand the bold section of that quote?

The ADR right now writes

The behaviour for mixing legacy scopes and new scopes is undefined, but it's suggested that we raise an API error in this case.

That should be explicitly the case you mention. In other words: Mixing api_v3 with any op:resource:anything scope does not make lots of sense and indicates that an error was made. api_v3 "classically" grants access to the whole API, while op:resource:anything would give access to the "anything" resource.

So if there was - for what ever reason - a JWT token holding api_v3 and op:ressource:documents:edit it would still get access to the whole API, which would contradict the behaviour of an OAuth token with the exact same scopes. I'd strongly prefer to stay consistent

I don't quite understand this. The only way to stay consistent across the behaviour of JWTs and Doorkeeper tokens with the same scopes would be to implement the new scoping features for both at the same time. Something that you didn't want to do, because of capacity constraints.

I'd also prefer if we stayed consistent here, and I hope to quickly implement the missing code for JWTs afterwards, but I am not sure what your suggestion for improvement is.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where do you read/understand the bold section of that quote?

In the sentence quoted at the beginning of my comment:

Until then, the existing legacy scopes act equivalent to their op:api: counterpart as well as op:resource being present in the scope.

If api_v3 should behave equivalent to op:api:api_v3 and you describe that op:api:api_v3 should be used together with something like op:ressource:documents:write to only give the token access to the documents endpoints on APIv3 (and nothing else on APIv3), it would mean the existing behaviour of api_v3 needed to change. Because at the moment it gives access to the entirety of APIv3 and I think we should keep that behavior. So I fully agree on not allowing to combine those two scopes 👍

So after your answer I think we mean and want the same, just the wording in the sentence: "Until then, the existing legacy scopes act equivalent to their op:api: counterpart as well as op:resource being present in the scope." is wrong or can be understood in a wrong way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we mean and want the same, just the wording [...] can be understood in a wrong way

Yes, this is what happened apparently. How about this:

Until then, the existing legacy scopes act equivalent to a scope of op:api:<name> op:resource, where <name> is the name of the legacy scope. In other words they grant access to any resource, just as they did before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please remove the part of the sentence about that the legacy scopes should act equivalent to a scope of op:api:<name>, because they don't and shouldn't! The behaviour of the new ones as described in other places in this ADR will be different from what the old ones did, e.g. not granting access to any ressources (while the legacy ones always grant access to all resources):

API scopes will replace the existing legacy scopes. They grant access to OpenProject via specific protocols, but contrary to the existing legacy scopes do not grant access to any resources themselves. Resource access has to be granted separately using at least one resource scope.

So how about:

"Until then, the existing legacy scopes grant access to any resource, just as they did before."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe this is clearer. I wanted to be extra clear, that why I wrote down how they should behave, but the fact that my writing and your reading fail to align indicates that this was not successful.

I'll change it as you suggested, but as a late attempt of explaining what I tried to write down:

legacy scopes should act equivalent to a scope of op:api:<name>

This is not what I wrote in my suggestion above. I wrote

legacy scopes act equivalent to a scope of op:api:<name> op:resource

And a scope of (both!) op:api:<name> and op:resource acts exactly as the old scopes did. I.e. I tried to clarify that the old scopes carry an implicit op:resource with them. Pushing changes with the next update.

A trailing wildcard also satisfies additional trailing parts, so `op:example:*` would satisfy access that requires `op:example:a`,
but also `op:example:a:b:c:d`.

A trailing `:*` can be omitted. This requires that all current and future uses of trailing scope parts are always more restrictive

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to support two ways to write wildcards at the end? Wouldn't it be easier for us to just define that wildcards at the end have to be omitted or have to be there?

* `op:api:mcp`
* `op:api:bcf_v2_1`

TODO: are version numbers for things like BCF and SCIM relevant?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What are pros and cons of that?

Pro for having the version numbers in:

  • Forcing people to decide which API version they are using (so not allowing mixed access with the same token on default)
  • In the future, with more and more third parties using OpenProject's APIs and we probably have to the answer questions like "can we already remove api_v2?", would it be good to be able to look at the tokens and see which apps still use old APIs or maybe which parts of old APIs are still used? Or are there enough other ways to get this data?

Cons for having the version numbers in:

  • higher complexity

@NobodysNightmare NobodysNightmare Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've now removed this TODO and went for op:api:<whatever-it-was-before> mostly to reduce the number of additional decisions we introduce in this ADR.


Resource scopes grant access to a class of resources. Their kind is `resource`, followed by a part naming the resource class in
singular and another part naming the action performed on the resource. The most typical actions are `read` and `write`, however
certain resources might define and document additional actions. Unless documented otherwise for a resource, `write` includes `read`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does write also include create on default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So the tricky part is: I don't really want to think too deeply on this yet. I think this part is already more detailed than I wanted it to be. The "action" is what you can do with it and we'll be able to decide what actions will mean hopefully.

On the other hand the first action is immediately defined, so we have to start. If we call it edit, that kinda implies that it will be different from create (at least to me). In my head write would be anything that's not read-only access: create, edit, delete.

```

All dimensions of token access are carried in an extra kind of scope, no two dimensions are conflated in the same kind.
A scope can use wildcards to allow any value in the omitted part(s). A trailing wildcard includes further parts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be good to mention that different kinds of scope all need to match (logical AND) and scopes of the same kind are combined (logical OR).
It's somehow implied in the examples, but given that we record decisions with that, it would be better to explicitly mention it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's interesting. While we both have the same mental model about what the scopes effectively do, I'd have said that all of the scopes are logically ORed together.

The thing is that we have two dimensions that need to come together. The api dimension and the resource dimension. If any of the two is missing, the "area" is zero.

Does that make sense? Maybe this picture helps explain my thought on it:

scope-dimensions

The purple scope is the outlier: It only specifies an API scope, so it's a one dimensional object in two dimensional space: It has no area.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, wow, it's really fascinating to see how different mental models work 👀 And I'm glad we're on the same page what the outcome should be and just differ in how we would want it written down 🙂

While we both have the same mental model about what the scopes effectively do, I'd have said that all of the scopes are logically ORed together.

Well... no 😅
How about this example:
A token capable of reading and writing work packages and meetings in the APIv3 and MCP API
op:api:api_v3 op:api:mcp op:resource:work_packages:write op:resource:meetings:write

That translates to
"All API endpoints that belong to either work_packages write endpoints OR to meetings write endpoints AND are either in the APIv3 OR in the MCP API"

Or, in other words "(work packages write OR meetings write) AND (APIv3 OR MCP)

So it's not sufficient that the endpoint is just a work packages write or meetings write or endpoint, it also has to be in the right API.

So, to sum it up, I would prefer to have a very clear, explicit description of how those scope combinations should work so that there are no misunderstandings possible. But if you strongly feel that the description you have so far is enough, I can accept that as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd avoid the mention of an AND, because this might not be how other scopes work.

Practical view: sudo mode

Let's quickly assume we bring Klaus' concept of a sudo mode for admins to tokens as well.

Quick recap what that would do: An admin classically had all permissions anywhere, because they are an admin, independent from their roles. Instead we could say that an admin has to follow the permissions their roles grant them by default. If they want to do more than that, they are capable of explicitly giving themselves "sudo mode". Let's imagine this would be done through a scope op:sudo:project:42. When this scope is present, the admin can still do anything they are allowed to do with their other scopes, but additionally they have unrestricted access to project 42.

Would this scope be added to the other scopes via AND or via OR in your mental model? (serious question, I don't want to assume)

Theoretical view: scopes only add, they never take

Maybe I can also explain one rule that I have in mind (and that I believe to read this way in the OAuth RFC) w.r.t. scopes that (I believe) also contradicts the idea of including an AND: Scopes should always allow you to do more than not having the scope. Adding a scope should never remove from your (scope of) access.

If there were any scopes that would be added via AND, this would imply that it's possible to reduce the amount of access the token grants by adding a scope.

You can see that this is true under the current model: op:api:foo op:resource:bar grants more access than op:api:foo and it also grants more access than op:resource:bar.

I am open to write the desired behaviour down in other words. I just don't think that the AND logic properly captures the idea of how I believe scopes should work.

@NobodysNightmare
NobodysNightmare force-pushed the adr-0003-oauth-scope-semantics branch from 48d01cb to 6aaaf71 Compare November 24, 2026 14:58

@judithroth judithroth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I read through it again. Thanks for all the adaptions so far 🙂

Additionally the new naming scheme common to most of the options is being adopted for new token scopes (see "More information" at the bottom).
The existing API scopes remain as legacy scopes until the new scoping scheme has been implemented and documented **and** we are able
to make a breaking change to the public API, i.e. during a major release. Until then, the existing legacy scopes act equivalent to their
`op:api:<name>` counterpart as well as `op:resource` being present in the scope. **The behaviour for mixing legacy scopes and new scopes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please remove the part of the sentence about that the legacy scopes should act equivalent to a scope of op:api:<name>, because they don't and shouldn't! The behaviour of the new ones as described in other places in this ADR will be different from what the old ones did, e.g. not granting access to any ressources (while the legacy ones always grant access to all resources):

API scopes will replace the existing legacy scopes. They grant access to OpenProject via specific protocols, but contrary to the existing legacy scopes do not grant access to any resources themselves. Resource access has to be granted separately using at least one resource scope.

So how about:

"Until then, the existing legacy scopes grant access to any resource, just as they did before."

```

All dimensions of token access are carried in an extra kind of scope, no two dimensions are conflated in the same kind.
A scope can use wildcards to allow any value in the omitted part(s). A trailing wildcard includes further parts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, wow, it's really fascinating to see how different mental models work 👀 And I'm glad we're on the same page what the outcome should be and just differ in how we would want it written down 🙂

While we both have the same mental model about what the scopes effectively do, I'd have said that all of the scopes are logically ORed together.

Well... no 😅
How about this example:
A token capable of reading and writing work packages and meetings in the APIv3 and MCP API
op:api:api_v3 op:api:mcp op:resource:work_packages:write op:resource:meetings:write

That translates to
"All API endpoints that belong to either work_packages write endpoints OR to meetings write endpoints AND are either in the APIv3 OR in the MCP API"

Or, in other words "(work packages write OR meetings write) AND (APIv3 OR MCP)

So it's not sufficient that the endpoint is just a work packages write or meetings write or endpoint, it also has to be in the right API.

So, to sum it up, I would prefer to have a very clear, explicit description of how those scope combinations should work so that there are no misunderstandings possible. But if you strongly feel that the description you have so far is enough, I can accept that as well.

A wildcard is not allowed in the first and second part of a scope. So neither `op`, nor `op:*`, nor `*` are valid scopes.
Rationale: If a wildcard was allowed in either of these, it would hurt forward compatibility, because we can't yet know what other kinds of
scopes could even mean. And the `op` in the first part literally means "OpenProject", so there is no other first part we'd ever want
to accept.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

singular and another part naming the action performed on the resource. The most typical actions are `read` and `write`, however
certain resources might define and document additional actions. Unless documented otherwise for a resource, `write` includes `read`.
Implementation and decision on implementation details for generic resource scopes is still pending.
plural and another part naming the action performed on the resource. Decisions on implementation details and naming for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants