-
Notifications
You must be signed in to change notification settings - Fork 5
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
Improve permission handling #86
Conversation
On second thought, leaving as a draft until #85 gets merged, so I can add docs on this. |
from goosebit.updater.manager import UpdateManager, get_update_manager | ||
|
||
router = APIRouter(prefix="/{dev_id}") | ||
|
||
|
||
@router.get( | ||
"", | ||
dependencies=[Security(validate_user_permissions, scopes=[Permissions.HOME.READ])], | ||
dependencies=[Security(validate_user_permissions, scopes=["home.read"])], |
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.
Bit sad to switch from a "type-safe" approach to free form strings that can have typos. But ok for me.
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.
Yeah it's not my favorite either, but I think this makes more sense for allowing plugins.
I could try to make this more type safe, maybe by having the nav register permissions, then checking if all user permissions match a valid pattern, but that could be a problem with plugins.
73d83b7
to
e40b640
Compare
|
18a5dd5
to
58a436d
Compare
58a436d
to
18f4ae2
Compare
18f4ae2
to
5252258
Compare
5252258
to
53784d4
Compare
53784d4
to
928f7ad
Compare
Use strings for permissions as they are more extensible than enums. Less granular permissions are also available, `*` is all permissions, `software` or `software.*` gives access to all software endpoints, and `software.read` gives access to read-only software information. `*.read` can also be used to give read access to all endpoints.
Prevent users from writing when they don't have the correct permissions.
Using the `!` prefix will deny permissions for a route, and takes precedence over allowing permissions. If you wanted to allow reading but deny software access, you could use `["*.read", "!software"]`.
Update pytest-asyncio because it was unable to find the event loop for new tests, see pytest-dev/pytest-asyncio#862
9f80896
to
b690ec1
Compare
Improve permissions handling with string parsing.
Rules are as follows -
*
- Matches all at all levels.!
- Prefix, inverts the permission, and takes priority.foo
- The name of a permission, justfoo
on its own grants all sub permissions for that value.foo.*
- Same asfoo
.foo.bar
- Grantsbar
permissions forfoo
endpoint.For example, if an endpoint requires
foo.bar.baz
, valid user permissions are*
foo
foo.*
foo.bar
foo.bar.*
foo.bar.baz
User permissions that will always be invalid are the inverted versions of this, so
!*
!foo
!foo.*
!foo.bar
!foo.bar.*
!foo.bar.baz