airflow.providers.fab.auth_manager.security_manager.override¶
Attributes¶
Classes¶
This security manager overrides the default AirflowSecurityManager security manager. |
Module Contents¶
- airflow.providers.fab.auth_manager.security_manager.override.MAX_NUM_DATABASE_USER_SESSIONS = 50000[source]¶
- class airflow.providers.fab.auth_manager.security_manager.override.FabAirflowSecurityManagerOverride(appbuilder)[source]¶
Bases:
airflow.providers.fab.www.security_manager.AirflowSecurityManagerV2
This security manager overrides the default AirflowSecurityManager security manager.
This security manager is used only if the auth manager FabAuthManager is used. It defines everything in the security manager that is needed for the FabAuthManager to work. Any operation specific to the AirflowSecurityManager should be defined here instead of AirflowSecurityManager.
- Parameters:
appbuilder – The appbuilder.
- oauth_remotes: dict[str, Any][source]¶
Initialized (remote_app) providers dict {‘provider_name’, OBJ }
- reset_password(userid, password)[source]¶
Change/Reset a user’s password for auth db.
Password will be hashed and saved.
- create_admin_standalone()[source]¶
Create an Admin user with a random password so that users can access airflow.
- get_all_permissions()[source]¶
Return all permissions as a set of tuples with the action and resource names.
- create_dag_specific_permissions()[source]¶
Add permissions to all DAGs.
Creates ‘can_read’, ‘can_edit’, and ‘can_delete’ permissions for all DAGs, along with any access_control permissions provided in them.
This does iterate through ALL the DAGs, which can be slow. See sync_perm_for_dag if you only need to sync a single DAG.
- sync_perm_for_dag(dag_id, access_control=None)[source]¶
Sync permissions for given dag id.
The dag id surely exists in our dag bag as only / refresh button or DagBag will call this function.
- Parameters:
dag_id (str) – the ID of the DAG whose permissions should be updated
access_control (collections.abc.Mapping[str, collections.abc.Mapping[str, collections.abc.Collection[str]] | collections.abc.Collection[str]] | None) – a dict where each key is a role name and each value can be: - a set() of DAGs resource action names (e.g. {‘can_read’}) - or a dict where each key is a resource name (‘DAGs’ or ‘DAG Runs’) and each value is a set() of action names (e.g., {‘DAG Runs’: {‘can_create’}, ‘DAGs’: {‘can_read’}})
- Returns:
- Return type:
None
- add_permissions_view(base_action_names, resource_name)[source]¶
Add an action on a resource to the backend.
- Parameters:
base_action_names –
- list of permissions from view (all exposed methods):
’can_add’,’can_edit’ etc…
resource_name – name of the resource to add
Add menu_access to resource on permission_resource.
- Parameters:
resource_name – The resource name
- sync_roles()[source]¶
Initialize default and custom roles with related permissions.
Init the default role(Admin, Viewer, User, Op, public) with related permissions.
Init the custom role(dag-user) with related permissions.
- create_perm_vm_for_all_dag()[source]¶
Create perm-vm if not exist and insert into FAB security model for all-dags.
- update_admin_permission()[source]¶
Add missing permissions to the table for admin.
Admin should get all the permissions, except the dag permissions because Admin already has Dags permission. Add the missing ones to the table for admin.
- delete_role(role_name)[source]¶
Delete the given Role.
- Parameters:
role_name (str) – the name of a role in the ab_role table
- get_roles_from_keys(role_keys)[source]¶
Construct a list of FAB role objects, from a list of keys.
NOTE: - keys are things like: “LDAP group DNs” or “OAUTH group names” - we use AUTH_ROLES_MAPPING to map from keys, to FAB role names
- add_user(username, first_name, last_name, email, role, password='', hashed_password='')[source]¶
Create a user.
- add_register_user(username, first_name, last_name, email, password='', hashed_password='')[source]¶
Add a registration request for the user.
:rtype : RegisterUser
- del_register_user(register_user)[source]¶
Delete registration object from database.
- Parameters:
register_user – RegisterUser object to delete
- update_user_auth_stat(user, success=True)[source]¶
Update user authentication stats.
This is done upon successful/unsuccessful authentication attempts.
- Parameters:
user – The identified (but possibly not successfully authenticated) user model
success – Defaults to true, if true increments login_count, updates last_login, and resets fail_login_count to 0, if false increments fail_login_count on user model.
- create_action(name)[source]¶
Add an action to the backend, model action.
- Parameters:
name – name of the action: ‘can_add’,’can_edit’ etc…
- delete_action(name)[source]¶
Delete a permission action.
- Parameters:
name (str) – Name of action to delete (e.g. can_read).
- get_resource(name)[source]¶
Return a resource record by name, if it exists.
- Parameters:
name (str) – Name of resource
- create_resource(name)[source]¶
Create a resource with the given name.
- Parameters:
name – The name of the resource to create created.
- get_permission(action_name, resource_name)[source]¶
Get a permission made with the given action->resource pair, if the permission already exists.
- get_resource_permissions(resource)[source]¶
Retrieve permission pairs associated with a specific resource object.
- Parameters:
resource (airflow.providers.fab.auth_manager.models.Resource) – Object representing a single resource.
- create_permission(action_name, resource_name)[source]¶
Add a permission on a resource to the backend.
- Parameters:
action_name – name of the action to add: ‘can_add’,’can_edit’ etc…
resource_name – name of the resource to add
- delete_permission(action_name, resource_name)[source]¶
Delete the permission linking an action->resource pair.
Doesn’t delete the underlying action or resource.
- add_permission_to_role(role, permission)[source]¶
Add an existing permission pair to a role.
- Parameters:
role (airflow.providers.fab.auth_manager.models.Role) – The role about to get a new permission.
permission (airflow.providers.fab.auth_manager.models.Permission | None) – The permission pair to add to a role.
- remove_permission_from_role(role, permission)[source]¶
Remove a permission pair from a role.
- Parameters:
role (airflow.providers.fab.auth_manager.models.Role) – User role containing permissions.
permission (airflow.providers.fab.auth_manager.models.Permission) – Object representing resource-> action pair
- static get_user_roles(user=None)[source]¶
Get all the roles associated with the user.
- Parameters:
user – the ab_user in FAB model.
- Returns:
a list of roles associated with the user.
- auth_user_ldap(username, password)[source]¶
Authenticate user with LDAP.
NOTE: this depends on python-ldap module.
- Parameters:
username – the username
password – the password
- check_password(username, password)[source]¶
Check if the password is correct for the username.
- Parameters:
username – the username
password – the password
- auth_user_db(username, password)[source]¶
Authenticate user, auth db style.
- Parameters:
username – The username or registered email address
password – The password, will be tested against hashed password on db