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

Implement is_authorized() in auth manager #33213

Merged
merged 27 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b34afaa
Implement `is_authorized` in auth manager
vincbeck Aug 15, 2023
954c78f
Use dataclass for `is_all_authorized`
vincbeck Aug 15, 2023
2a35538
Update `_resource_name_for_dag`
vincbeck Aug 15, 2023
f6e0f82
Simplify authorization
vincbeck Aug 15, 2023
4125166
Merge branch 'main' into vincbeck/is_authorized
vincbeck Aug 15, 2023
1586272
Fix static checks
vincbeck Aug 16, 2023
7ae2ddf
Merge branch 'main' into vincbeck/is_authorized
vincbeck Aug 24, 2023
fc738f3
Merge branch 'main' into vincbeck/is_authorized
vincbeck Aug 25, 2023
8f1da42
Move `_get_root_dag_id` to FAB auth manager
vincbeck Aug 25, 2023
3b0b8b8
Rename `ResourceAction` to `ResourceMethod`
vincbeck Aug 25, 2023
1106dc9
Create an enum `ResourceType`
vincbeck Aug 25, 2023
aafb4ee
Merge branch 'main' into vincbeck/is_authorized
vincbeck Aug 29, 2023
2caf0f0
Merge branch 'main' into vincbeck/is_authorized
vincbeck Aug 31, 2023
f1144c6
Merge branch 'main' into vincbeck/is_authorized
vincbeck Sep 1, 2023
5a75ca4
Merge branch 'main' into vincbeck/is_authorized
vincbeck Sep 5, 2023
971af1a
Create individual `is_authorized_` APIs instead of one
vincbeck Sep 6, 2023
78b5ecb
Merge branch 'main' into vincbeck/is_authorized
vincbeck Sep 7, 2023
0461edb
Apply suggestion by @uranusjr
vincbeck Sep 7, 2023
d143a94
Add back `can_read_dag` in security manager. Will do that in separate PR
vincbeck Sep 7, 2023
10fc281
Cleanup
vincbeck Sep 7, 2023
5901a0d
Use select()
vincbeck Sep 8, 2023
f1d7060
Merge branch 'main' into vincbeck/is_authorized
vincbeck Sep 8, 2023
0606f3b
Merge branch 'main' into vincbeck/is_authorized
vincbeck Sep 11, 2023
2212bec
Remove `cast`
vincbeck Sep 12, 2023
7e56ba5
Merge branch 'main' into vincbeck/is_authorized
vincbeck Sep 14, 2023
6794540
Fix tests
vincbeck Sep 14, 2023
fa84c41
Merge branch 'main' into vincbeck/is_authorized
vincbeck Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 113 additions & 1 deletion airflow/auth/managers/base_auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from __future__ import annotations

from abc import abstractmethod
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Literal

from airflow.exceptions import AirflowException
from airflow.utils.log.logging_mixin import LoggingMixin
Expand All @@ -27,9 +27,16 @@
from flask import Flask

from airflow.auth.managers.models.base_user import BaseUser
from airflow.auth.managers.models.resource_details import (
ConnectionDetails,
DagAccessEntity,
DagDetails,
)
from airflow.cli.cli_config import CLICommand
from airflow.www.security_manager import AirflowSecurityManagerV2

ResourceMethod = Literal["GET", "POST", "PUT", "DELETE"]


class BaseAuthManager(LoggingMixin):
"""
Expand Down Expand Up @@ -70,6 +77,111 @@ def get_user_id(self) -> str:
def is_logged_in(self) -> bool:
"""Return whether the user is logged in."""

@abstractmethod
def is_authorized_configuration(
self,
*,
method: ResourceMethod,
user: BaseUser | None = None,
) -> bool:
"""
Return whether the user is authorized to perform a given action on configuration.

:param method: the method to perform
:param user: the user to perform the action on. If not provided (or None), it uses the current user
"""

@abstractmethod
def is_authorized_cluster_activity(
self,
*,
method: ResourceMethod,
user: BaseUser | None = None,
) -> bool:
"""
Return whether the user is authorized to perform a given action on the cluster activity.

:param method: the method to perform
:param user: the user to perform the action on. If not provided (or None), it uses the current user
"""

@abstractmethod
def is_authorized_connection(
self,
*,
method: ResourceMethod,
connection_details: ConnectionDetails | None = None,
user: BaseUser | None = None,
) -> bool:
"""
Return whether the user is authorized to perform a given action on a connection.

:param method: the method to perform
:param connection_details: optional details about the connection
:param user: the user to perform the action on. If not provided (or None), it uses the current user
"""

@abstractmethod
def is_authorized_dag(
self,
*,
method: ResourceMethod,
dag_access_entity: DagAccessEntity | None = None,
dag_details: DagDetails | None = None,
user: BaseUser | None = None,
) -> bool:
"""
Return whether the user is authorized to perform a given action on a DAG.

:param method: the method to perform
:param dag_access_entity: the kind of DAG information the authorization request is about.
If not provided, the authorization request is about the DAG itself
:param dag_details: optional details about the DAG
:param user: the user to perform the action on. If not provided (or None), it uses the current user
"""

@abstractmethod
def is_authorized_dataset(
self,
*,
method: ResourceMethod,
user: BaseUser | None = None,
) -> bool:
"""
Return whether the user is authorized to perform a given action on a dataset.

:param method: the method to perform
:param user: the user to perform the action on. If not provided (or None), it uses the current user
"""

@abstractmethod
def is_authorized_variable(
self,
*,
method: ResourceMethod,
user: BaseUser | None = None,
) -> bool:
"""
Return whether the user is authorized to perform a given action on a variable.

:param method: the method to perform
:param user: the user to perform the action on. If not provided (or None), it uses the current user
"""

@abstractmethod
def is_authorized_website(
self,
*,
user: BaseUser | None = None,
) -> bool:
"""
Return whether the user is authorized to access the read-only state of the installation.

This includes the homepage, the list of installed plugins, the list of providers and list of triggers.

:param user: the user to perform the action on. If not provided (or None), it uses the current user
"""

@abstractmethod
def get_url_login(self, **kwargs) -> str:
"""Return the login page url."""
Expand Down
Loading