Skip to content

Conversation

@vandonr-amz
Copy link
Contributor

@vandonr-amz vandonr-amz commented Aug 29, 2023

ℹ️ the diff is big because I re-unified the various FAB security managers in one class. See #33901 (comment)


There is currently a weird situation with the security managers, where the AirflowSecurityManager, which is supposed to be the more generic construct, inherits from FabAirflowSecurityManagerOverride, supposed to be the more specific one. Because of this, FabAirflowSecurityManagerOverride doesn't bear well its name, because it cannot override anything from AirflowSecurityManager since it sits lower on the inheritance tree.

This was done initially to be able to extend functionalities of the Security Manager, while retaining an existing feature which was that users could plug their own security manager inheriting from AirflowSecurityManager (so we couldn't squeeze the FAB one in between because that'd be a breaking change).

The solution I used here is to have an empty shell stay where the AirflowSecurityManager was, just to maintain back-compatibility. That one inherits from FAB Security Manager, which can now sit below the actual AirflowSecurityManager.

This means that users can only override the FAB security manager and not other auth provider's SM but that's ok because this feature is pretty much rendered obsolete by AIP-56. See #33690 (comment)

Joining some class diagrams to help understanding.
Arrows read as "is inherited/implemented by".

current situation:
image

after:
image

I had to make the ApplessAirflowSecurityManager inherit from the "FAB" one instead of the generic airflow SM because it had some dependencies there. It's not ideal, and not what we want in a final state, but for now we just want a state that closer to it.
We'll sort that dependency later on.

Copy link
Contributor

@vincbeck vincbeck left a comment

Choose a reason for hiding this comment

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

The whole goal of this change was not to make FabAirflowSecurityManagerOverride inherit from AirflowSecurityManager?

Oh now I might understand why you made inherited Db and Oauth module from AirflowSecurityManager. I guess you wanted a more vertical hierarchy. The idea of modules I introduced in FabAirflowSecurityManagerOverride was to avoid to build a big monster class very hard to maintain, so I split it in multiple modules. To me, making these modules inherited from AirflowSecurityManager does not really make sense.

I would:

  • Remove dependency between the modules and AirflowSecurityManager
  • Add dependency between FabAirflowSecurityManagerOverride and AirflowSecurityManager

WDYT?

@vincbeck vincbeck added the AIP-56 Extensible user management label Aug 30, 2023
@vandonr-amz
Copy link
Contributor Author

The idea of modules I introduced in FabAirflowSecurityManagerOverride was to avoid to build a big monster class very hard to maintain, so I split it in multiple modules.

BTW, I'm wondering if this isn't causing more harm than good.
A big file is not necessarily hard to maintain, and I'd argue it's actually harder to maintain code that's spread over 3 different files.
Inheritance also comes with extra features that we don't want here. For instance, defining the same method/property/field in 2 files would result in one overriding the other rather than an error.

@vincbeck
Copy link
Contributor

The idea of modules I introduced in FabAirflowSecurityManagerOverride was to avoid to build a big monster class very hard to maintain, so I split it in multiple modules.

BTW, I'm wondering if this isn't causing more harm than good. A big file is not necessarily hard to maintain, and I'd argue it's actually harder to maintain code that's spread over 3 different files. Inheritance also comes with extra features that we don't want here. For instance, defining the same method/property/field in 2 files would result in one overriding the other rather than an error.

If you think this is better without these modules, let's go then

if TYPE_CHECKING:
from airflow.api_connexion.types import APIResponse, UpdateMask
from airflow.www.security import AirflowSecurityManager
from airflow.www.security_manager import AirflowSecurityManagerV2
Copy link
Contributor

Choose a reason for hiding this comment

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

Since on the long term we will deprecate AirflowSecurityManager in favor of AirflowSecurityManagerV2 I am wondering if AirflowSecurityManagerV2 is a good name since this name will stay. Should we keep the name AirflowSecurityManager? It can confusing but we can assume this is only temporary? Or should we come up with another name? SimplifiedAirflowSecurityManager? I dont like it either xD.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

temporary things still stay around for a pretty long time to give users time to migrate...
Idk, I'm open to suggestions, but we can always rename it once we remove the old one.

@potiuk
Copy link
Member

potiuk commented Sep 4, 2023

I need to twist my head around it :). Will take a look tomorrow .

@vincbeck
Copy link
Contributor

vincbeck commented Sep 5, 2023

We should double check it resolves: #34107

@kaxil kaxil added this to the Airflow 2.7.2 milestone Sep 8, 2023
@vincbeck vincbeck merged commit d3ce442 into apache:main Sep 11, 2023
@vincbeck vincbeck deleted the vandonr/fab branch September 11, 2023 17:27
from airflow.www.fab_security.sqla.manager import SecurityManager
from airflow.www.utils import CustomSQLAInterface

EXISTING_ROLES = {
Copy link
Member

@pankajastro pankajastro Sep 20, 2023

Choose a reason for hiding this comment

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

@vandonr-amz @vincbeck are we considering removing EXISTING_ROLES from here a breaking change or I'm missing something here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would that be a breaking change? In which case user code would use this constant? The only use case I can think of is, if the user provide its own security manager and inside this security manager, they use this constant. But if we want to avoid such things ... every change will be breaking change and doing any change in security managers will be almost impossible.

Or maybe you had something else in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Why would that be a breaking change

yes, it breaking change because I import this constant from airflow.www.security import EXISTING_ROLES in my security manager and after this changes my code will break.

But if we want to avoid such things ... every change will be breaking change and doing

from airflow.www.security import * import path was very important for the implementing custom security manager and I feel it would be natural for many people to import EXISTING_ROLES if they need this rather than redefine so removing this suddenly is not good and may impact other users. I understand that maintaining backward compatibility for constant type this is painful but still, I would like to keep this maybe we can remove it when we decide to remove airflow.www.security.py

Copy link
Contributor

Choose a reason for hiding this comment

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

I see ... I'll try to think about a solution. We might have to keep whatever is static (constants, variables, functions) in these files then ... Which I really dont like ... But it seems we do not have much choice if we want to be backward compatible with users bringing their own security managers. I wish this feature did not exist xD.

But anyway, thanks for the feedback. I'll probably create a PR to fix that and will tag you on it.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @vincbeck

@ephraimbuddy ephraimbuddy added the type:bug-fix Changelog: Bug Fixes label Oct 3, 2023
@ephraimbuddy ephraimbuddy added changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) and removed type:bug-fix Changelog: Bug Fixes labels Oct 4, 2023
ashb added a commit that referenced this pull request Dec 16, 2024
In #33901 this was moved to a new file and mistakenly changed to
flask_session.

It's not clear to me why this didn't cause errors, but it was highlighted in
my editor as an invalid type 🤷
ashb added a commit that referenced this pull request Dec 16, 2024
…44962)

In #33901 this was moved to a new file and mistakenly changed to
flask_session.

It's not clear to me why this didn't cause errors, but it was highlighted in
my editor as an invalid type 🤷
got686-yandex pushed a commit to got686-yandex/airflow that referenced this pull request Jan 30, 2025
…pache#44962)

In apache#33901 this was moved to a new file and mistakenly changed to
flask_session.

It's not clear to me why this didn't cause errors, but it was highlighted in
my editor as an invalid type 🤷
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-56 Extensible user management area:webserver Webserver related Issues changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants