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

Make the role assigned to anonymous users customizable #14042

Merged
merged 2 commits into from
Feb 4, 2021

Conversation

jhtimmins
Copy link
Contributor

Fixes the issue wherein regardless of what role anonymous users are assigned (via the AUTH_ROLE_PUBLIC env var), they can't see any DAGs.

Current behavior causes:
Anonymous users are handled as a special case by Airflow's DAG-related security methods (.has_access() and .get_accessible_dags()). Rather than checking the AUTH_ROLE_PUBLIC value to check for role permissions, the methods reject access to view or edit any DAGs.

Changes in this PR:
Rather than hardcoding permission rules inside the security methods, this change checks the AUTH_ROLE_PUBLIC value and gives anonymous users all permissions linked to the designated role.

This places security in the hands of the Airflow users. If the value is set to Admin, anonymous users will have full admin functionality.

This also changes how the Public role is created. Currently, the Public role is created automatically by Flask App Builder. This PR explicitly declares Public as a default role with no permissions in security.py. This change makes it easier to test.

closes: #13340

@boring-cyborg boring-cyborg bot added the area:webserver Webserver related Issues label Feb 3, 2021
@jhtimmins jhtimmins changed the title Allow anon users to have arbitrary roles. Make the role assigned to anonymous users customizable Feb 3, 2021
@jhtimmins
Copy link
Contributor Author

@AmarEL @ashb @kaxil If y'all wouldn't mind taking a look at this.

@AmarEL
Copy link
Contributor

AmarEL commented Feb 3, 2021

Looks perfect, I did some similar tests here and this should work

user = mock.MagicMock()
user.is_anonymous = True
self.app.config['AUTH_ROLE_PUBLIC'] = 'Public'
assert self.app.appbuilder.sm.get_user_roles(user) == [self.app.appbuilder.sm.find_role("Public")]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert self.app.appbuilder.sm.get_user_roles(user) == [self.app.appbuilder.sm.find_role("Public")]
assert self.app.appbuilder.sm.get_user_roles(user) == [self.app.appbuilder.sm.get_public_role()]

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Feb 3, 2021
@github-actions
Copy link

github-actions bot commented Feb 3, 2021

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest master or amend the last commit of the PR, and push it with --force-with-lease.

@jhtimmins jhtimmins force-pushed the test-allow-non-public-anon-user branch from 236ea97 to 80112c3 Compare February 3, 2021 21:11
@jhtimmins
Copy link
Contributor Author

@ashb @kaxil Made the suggested updates

@kaxil kaxil merged commit 78aa921 into apache:master Feb 4, 2021
@kaxil kaxil deleted the test-allow-non-public-anon-user branch February 4, 2021 00:48
@kaxil kaxil added this to the Airflow 2.0.1 milestone Feb 4, 2021
kaxil pushed a commit that referenced this pull request Feb 4, 2021
Fixes the issue wherein regardless of what role anonymous users are assigned (via the `AUTH_ROLE_PUBLIC` env var), they can't see any DAGs.

Current behavior causes:
Anonymous users are handled as a special case by Airflow's DAG-related security methods (`.has_access()` and `.get_accessible_dags()`). Rather than checking the `AUTH_ROLE_PUBLIC` value to check for role permissions, the methods reject access to view or edit any DAGs.

Changes in this PR:
Rather than hardcoding permission rules inside the security methods, this change checks the `AUTH_ROLE_PUBLIC` value and gives anonymous users all permissions linked to the designated role.

**This places security in the hands of the Airflow users. If the value is set to `Admin`, anonymous users will have full admin functionality.**

This also changes how the `Public` role is created. Currently, the `Public` role is created automatically by Flask App Builder. This PR explicitly declares `Public` as a default role with no permissions in `security.py`. This change makes it easier to test.

closes: #13340
(cherry picked from commit 78aa921)
kaxil pushed a commit that referenced this pull request Feb 4, 2021
Fixes the issue wherein regardless of what role anonymous users are assigned (via the `AUTH_ROLE_PUBLIC` env var), they can't see any DAGs.

Current behavior causes:
Anonymous users are handled as a special case by Airflow's DAG-related security methods (`.has_access()` and `.get_accessible_dags()`). Rather than checking the `AUTH_ROLE_PUBLIC` value to check for role permissions, the methods reject access to view or edit any DAGs.

Changes in this PR:
Rather than hardcoding permission rules inside the security methods, this change checks the `AUTH_ROLE_PUBLIC` value and gives anonymous users all permissions linked to the designated role.

**This places security in the hands of the Airflow users. If the value is set to `Admin`, anonymous users will have full admin functionality.**

This also changes how the `Public` role is created. Currently, the `Public` role is created automatically by Flask App Builder. This PR explicitly declares `Public` as a default role with no permissions in `security.py`. This change makes it easier to test.

closes: #13340
(cherry picked from commit 78aa921)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:webserver Webserver related Issues okay to merge It's ok to merge this PR as it does not require more tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Anonymous users aren't able to view DAGs even with Admin Role
4 participants