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

New, Dynamic user registration role #1410

Merged
merged 3 commits into from
Jun 23, 2020

Conversation

szczeles
Copy link
Contributor

This PR brings dynamic user role on registration based on OAuth userinfo.

The current approach sets static AUTH_USER_REGISTRATION_ROLE for all users if self-registration is enabled. In our case, with OAuth authentication on GSuite domain (with FAB being auth engine for Airflow), we'd like to set team members as Admins and every other employee as read-only user ("Viewer").

This PR implements method that is used in Grafana (docs), it uses JMESPath to resolve the role from userinfo retrieved from OAuth. It's quite flexible, as some OAuth providers return only username (like Google does), but others, like Okta, can return groups, so they can be utilized by the dynamic expression.

If needed, I'm more than happy to extend the docs by adding more examples of JMESPath.

Copy link
Owner

@dpgaspar dpgaspar left a comment

Choose a reason for hiding this comment

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

Nice feature, dependencies are not correct (let's make it an extra) or document that the use of jmepath needs an extra package.
Also would be great if you could add some documentation with a couple of examples

requirements.txt Outdated
@@ -22,6 +22,7 @@ flask==1.1.1
idna==2.9 # via email-validator
itsdangerous==1.1.0 # via flask
jinja2==2.10.1 # via flask, flask-babel
jmespath==0.9.5
Copy link
Owner

Choose a reason for hiding this comment

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

If it's not on setup.py it can't be here, this file is auto generated by pip-compile. We could add it to requirements-dev.txt if we decide it's not a root dependency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I think it's not a root dependency. Added to extras.

@@ -347,6 +348,10 @@ def auth_user_registration(self):
def auth_user_registration_role(self):
return self.appbuilder.get_app.config["AUTH_USER_REGISTRATION_ROLE"]

@property
def auth_user_registration_role_jmespath(self):
Copy link
Owner

Choose a reason for hiding this comment

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

nit: I'm starting to add type annotations, at least on every new PR.

def auth_user_registration_role_jmespath(self) -> str:

@szczeles szczeles requested a review from dpgaspar June 22, 2020 12:12
@szczeles
Copy link
Contributor Author

@dpgaspar Thanks for the review! I've moved the dependency to setup's extras and added a few lines of documentation with examples

@dpgaspar dpgaspar merged commit 670f7f2 into dpgaspar:master Jun 23, 2020
@szczeles szczeles deleted the dynamic_user_registration_role branch July 7, 2021 06:39
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.

2 participants