feat!(auth): Consider ordering of scopes for auth#429
Conversation
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
🤖 This preview updates automatically when you update the PR. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d42adaa. Configure here.
| // Allowed: | ||
| // auth_context: (empty vec) | ||
| // object: org.123 | ||
| #[test] | ||
| fn test_assert_authorized_empty_scope_allows_any_request() -> Result<(), AuthError> { |
There was a problem hiding this comment.
This is weird, but consistent with what we want semantically.
It could be used to grant access to the whole usecase.
There was a problem hiding this comment.
currently you can do this with a token for org.*/proj.*
There was a problem hiding this comment.
In theory we don't enforce the scope to be of the form org.*/proj.*.
matt-codecov
left a comment
There was a problem hiding this comment.
iirc i actually made scopes unordered on purpose in an attempt to preserve the service-agnostic design of the token. it is less awkward for other services to ignore objectstore-specific scopes if the token doesn't encode those objectstore scopes as the root of a hierarchy
scope order/hierarchy is now up to the application to interpret. for objectstore, the interpretation is:
- the
os:usecasescope is required and its value must match the first part of an object's scope - every subsequent part of the object's scope must be present in the token's scopes
- any token scope that isn't present in the object's scope is ignored
- wildcards must be explicit;
org.123does not implyorg.123/proj.*
i guess i never updated the PR description or notion doc (whoops! sorry) but the tests show the expected behavior:
objectstore/objectstore-server/src/auth/context.rs
Lines 350 to 413 in af57fd8
#\3 above is a bit awkward. consider this possibly counterintuitive example:
// Allowed:
// auth_context: org.123 / proj.456
// object: org.123because there is no project component in the object scope, any project component in the token scope is ignored. it behaves this way for two reasons:
- this is how objectstore can ignore scopes specific to other services
- something like debug symbols may be uploaded at org scope yet still be accessible to multiple projects that need to read them to symbolicate errors
that said, i admit it is weird.
all this said: do you still want to move forward with this change? i'm not necessarily opposed. sentry does need a real service-agnostic auth scheme, but if i pick that effort up again it will be on another team.

This changes the format for the
scopesfield in our JWTs to be aVec, andAuthContextto take ordering into account when validating auth.Previously,
scopeswas amap, which meant that order didn't matter.I think this is the way this was intended to work in the first place.
From #199:
This is a breaking change as the serialization format for our JWTs changes.
We will need to update our client libraries in all services.
Luckily we're still not enforcing auth, so we can easily make the breaking change now.