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

Add role handlers and endpoints for REST API #3980

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

vladfreeze
Copy link
Contributor

@vladfreeze vladfreeze commented Jul 15, 2022

I needed to dynamically add/edit roles and permissions of groups and therefore created an endpoint which allows the admins to create, edit or delete roles using JupyterHub's REST API.

It can be accessed by using the api url with the /roles/rolename path and supports the GET, POST, PUT and DELETE requests.

@manics
Copy link
Member

manics commented Jul 15, 2022

Relevant issue: #3858

@vladfreeze
Copy link
Contributor Author

After further testing I noticed that the roles added using the api are deleted when restarting the hub. Is this behaviour intended? It seems that only the default roles show up after restarting.

@minrk
Copy link
Member

minrk commented Jul 16, 2022

As the issue @manics links mentioned, it is intended now, but not intended to stay that way. We have to be extremely careful with the runtime creation of permissions. In particular, it's critical to be able to distinguish changes at runtime (should be preserved across restart) from changes in config (old values should be clobbered - only current behavior).

Specific case: if a role is present in the db now, but not in config, it's certain that it has been deleted from config, and should be deleted from the db. That's indistinguishable from a runtime-created role right now, but we have to be able to tell the difference to make the right decision.

@eeeeeeeason
Copy link

eeeeeeeason commented Nov 13, 2023

After further testing I noticed that the roles added using the api are deleted when restarting the hub. Is this behaviour intended? It seems that only the default roles show up after restarting.

Please tell me how to solve this problem in the end. I am also doing dynamic permission control and need persistent role management.thanks alot

I have commented out the initialization code related to this role for the time being, and will add more if there are any questions later.
app.py -> init_role_creation ->

# for role in self.db.query(orm.Role).filter(
#     orm.Role.name.notin_(init_role_names)
# ):
#     self.log.warning(f"Deleting role {role.name}")
#     self.db.delete(role)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants