-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Implement login and logout in AWS auth manager #35488
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
fab6e97
Implement AWS auth manager
vincbeck 2f638af
Mark test as db test
vincbeck 1e572ee
Merge branch 'main' into vincbeck/aws_auth_manager
vincbeck 240401f
Add tests
vincbeck 7b7431d
Merge branch 'main' into vincbeck/aws_auth_manager
vincbeck b0cce0f
Merge branch 'main' into vincbeck/aws_auth_manager
vincbeck 107eda2
Pass only appbuilder to auth manager
vincbeck 8f5aaf1
Make `AwsSecurityManagerOverride` inherit from `AirflowSecurityManage…
vincbeck cc69de5
Fix tests
vincbeck 601504d
Fix tests
vincbeck a6b5636
Fix tests
vincbeck 7b2f08f
Fix tests
vincbeck 6dee0a6
Fix tests
vincbeck 80caf15
Move config to its own section
vincbeck 1c02157
Merge branch 'main' into vincbeck/aws_auth_manager
vincbeck 1115d56
Merge branch 'main' into vincbeck/aws_auth_manager
vincbeck 3fc1f68
Add flag to use the AWS auth manager
vincbeck 57a22bf
Move `get_user_name` to `base_auth_manager`
vincbeck 60c6cd0
Address other feedbacks
vincbeck 407a0e0
Update airflow/providers/amazon/provider.yaml
vincbeck d9ca41c
Update airflow/providers/amazon/provider.yaml
vincbeck e553a6b
Rename `use_experimental` config to `enable`
vincbeck b8d8340
Specify `python3-saml` as additional-extra
vincbeck 19a6a48
Add message when `python3-saml` is not installed
vincbeck 83b92d8
Merge branch 'main' into vincbeck/aws_auth_manager
vincbeck 6a21cc7
Add logout_callback endpoint
vincbeck b3eb860
Move import
vincbeck 28b053e
Skip test if module is not installed
vincbeck 190b9be
Remove `abstractmethod` from `get_user_name`
vincbeck 476221d
Fix test
vincbeck dd16f5a
Define the extra at the Airflow level
vincbeck 105b8c3
Fix static checks
vincbeck 3285b36
Fix tests
vincbeck 8d1d365
Add "saml" word to spellcheck dictionary
vincbeck b11fbe9
nit
vincbeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. |
143 changes: 143 additions & 0 deletions
143
airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| from __future__ import annotations | ||
|
|
||
| from functools import cached_property | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from flask import session, url_for | ||
|
|
||
| from airflow.configuration import conf | ||
| from airflow.exceptions import AirflowOptionalProviderFeatureException | ||
| from airflow.providers.amazon.aws.auth_manager.constants import ( | ||
| CONF_ENABLE_KEY, | ||
| CONF_SECTION_NAME, | ||
| ) | ||
| from airflow.providers.amazon.aws.auth_manager.security_manager.aws_security_manager_override import ( | ||
| AwsSecurityManagerOverride, | ||
| ) | ||
|
|
||
| try: | ||
| from airflow.auth.managers.base_auth_manager import BaseAuthManager, ResourceMethod | ||
| except ImportError: | ||
| raise AirflowOptionalProviderFeatureException( | ||
| "Failed to import BaseUser. This feature is only available in Airflow versions >= 2.8.0" | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from airflow.auth.managers.models.base_user import BaseUser | ||
| from airflow.auth.managers.models.resource_details import ( | ||
| AccessView, | ||
| ConfigurationDetails, | ||
| ConnectionDetails, | ||
| DagAccessEntity, | ||
| DagDetails, | ||
| DatasetDetails, | ||
| PoolDetails, | ||
| VariableDetails, | ||
| ) | ||
| from airflow.providers.amazon.aws.auth_manager.user import AwsAuthManagerUser | ||
| from airflow.www.extensions.init_appbuilder import AirflowAppBuilder | ||
|
|
||
|
|
||
| class AwsAuthManager(BaseAuthManager): | ||
| """ | ||
| AWS auth manager. | ||
|
|
||
| Leverages AWS services such as Amazon Identity Center and Amazon Verified Permissions to perform | ||
| authentication and authorization in Airflow. | ||
|
|
||
| :param appbuilder: the flask app builder | ||
| """ | ||
|
|
||
| def __init__(self, appbuilder: AirflowAppBuilder) -> None: | ||
| super().__init__(appbuilder) | ||
| enable = conf.getboolean(CONF_SECTION_NAME, CONF_ENABLE_KEY) | ||
| if not enable: | ||
| raise NotImplementedError( | ||
| "The AWS auth manager is currently being built. It is not finalized. It is not intended to be used yet." | ||
| ) | ||
|
|
||
| def get_user(self) -> AwsAuthManagerUser | None: | ||
| return session["aws_user"] if self.is_logged_in() else None | ||
o-nikolas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def is_logged_in(self) -> bool: | ||
| return "aws_user" in session | ||
|
|
||
| def is_authorized_configuration( | ||
| self, | ||
| *, | ||
| method: ResourceMethod, | ||
| details: ConfigurationDetails | None = None, | ||
| user: BaseUser | None = None, | ||
| ) -> bool: | ||
| return self.is_logged_in() | ||
|
||
|
|
||
| def is_authorized_cluster_activity(self, *, method: ResourceMethod, user: BaseUser | None = None) -> bool: | ||
| return self.is_logged_in() | ||
|
|
||
| def is_authorized_connection( | ||
| self, | ||
| *, | ||
| method: ResourceMethod, | ||
| details: ConnectionDetails | None = None, | ||
| user: BaseUser | None = None, | ||
| ) -> bool: | ||
| return self.is_logged_in() | ||
|
|
||
| def is_authorized_dag( | ||
| self, | ||
| *, | ||
| method: ResourceMethod, | ||
| access_entity: DagAccessEntity | None = None, | ||
| details: DagDetails | None = None, | ||
| user: BaseUser | None = None, | ||
| ) -> bool: | ||
| return self.is_logged_in() | ||
|
|
||
| def is_authorized_dataset( | ||
| self, *, method: ResourceMethod, details: DatasetDetails | None = None, user: BaseUser | None = None | ||
| ) -> bool: | ||
| return self.is_logged_in() | ||
|
|
||
| def is_authorized_pool( | ||
| self, *, method: ResourceMethod, details: PoolDetails | None = None, user: BaseUser | None = None | ||
| ) -> bool: | ||
| return self.is_logged_in() | ||
|
|
||
| def is_authorized_variable( | ||
| self, *, method: ResourceMethod, details: VariableDetails | None = None, user: BaseUser | None = None | ||
| ) -> bool: | ||
| return self.is_logged_in() | ||
|
|
||
| def is_authorized_view( | ||
| self, | ||
| *, | ||
| access_view: AccessView, | ||
| user: BaseUser | None = None, | ||
| ) -> bool: | ||
| return self.is_logged_in() | ||
|
|
||
| def get_url_login(self, **kwargs) -> str: | ||
| return url_for("AwsAuthManagerAuthenticationViews.login") | ||
|
|
||
| def get_url_logout(self) -> str: | ||
| return url_for("AwsAuthManagerAuthenticationViews.logout") | ||
|
|
||
| @cached_property | ||
| def security_manager(self) -> AwsSecurityManagerOverride: | ||
| return AwsSecurityManagerOverride(self.appbuilder) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # Configuration keys | ||
| from __future__ import annotations | ||
|
|
||
| CONF_SECTION_NAME = "aws_auth_manager" | ||
| CONF_SAML_METADATA_URL_KEY = "saml_metadata_url" | ||
| CONF_ENABLE_KEY = "enable" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@vincbeck This looks like a breaking change since
get_name()method was just defined in the BaseUser class. WDYT?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.
No because the auth manager interface is not public interface YET. It will become in the near future but work in auth manager is still in progress. It is not documented anywhere how to build an auth manager or even how to use it so I assume nobody uses it