Flask-AppBuilder (FAB) security integration component within Apache Airflow core, providing authentication, authorization, and security management features
npx @tessl/cli install tessl/pypi-apache-airflow-fab-security@2.8.0Flask-AppBuilder (FAB) security integration component within Apache Airflow core, providing authentication, authorization, and security management features. This component implements comprehensive security infrastructure including user management, role-based access control, permission management, and multiple authentication backends.
pip install apache-airflow)from airflow.www.fab_security.sqla.manager import SecurityManager
from airflow.www.fab_security.sqla.models import User, Role, Permission, Action, ResourceCommon view imports:
from airflow.www.fab_security.views import (
CustomUserDBModelView,
CustomRoleModelView,
ActionModelView,
ResourceModelView
)from airflow.www.fab_security.sqla.manager import SecurityManager
from airflow.www.fab_security.sqla.models import User, Role
from flask_appbuilder import AppBuilder
# Initialize security manager
app_builder = AppBuilder(app)
security_manager = SecurityManager(app_builder)
# Create a new user
user = security_manager.add_user(
username="john_doe",
first_name="John",
last_name="Doe",
email="john@example.com",
role=security_manager.find_role("User"),
password="secure_password"
)
# Create a role
admin_role = security_manager.add_role("CustomAdmin")
# Create permissions
permission = security_manager.create_permission("can_read", "Users")
security_manager.add_permission_to_role(admin_role, permission)
# Authenticate user
authenticated_user = security_manager.auth_user_db("john_doe", "secure_password")The FAB security component follows a layered architecture:
This design enables flexible security configuration while maintaining compatibility with Flask-AppBuilder's security model and Airflow's specific requirements.
Core security management functionality including user authentication, authorization checks, permission validation, and session management. Provides the foundation for all security operations.
class BaseSecurityManager:
def auth_user_db(self, username: str, password: str) -> User | None: ...
def auth_user_ldap(self, username: str, password: str) -> User | None: ...
def auth_user_oauth(self, userinfo: dict) -> User | None: ...
def auth_user_oid(self, email: str) -> User | None: ...
def auth_user_remote_user(self, username: str) -> User | None: ...
def reset_password(self, userid: int, password: str) -> bool: ...
def update_user_auth_stat(self, user: User, success: bool = True) -> None: ...Comprehensive user lifecycle management including creation, updates, deletion, and user queries. Handles user authentication statistics and profile management.
def add_user(self, username: str, first_name: str, last_name: str, email: str, role: Role | list[Role], password: str = "") -> User | None: ...
def update_user(self, user: User) -> bool: ...
def find_user(self, username: str = None, email: str = None) -> User | None: ...
def get_user_by_id(self, pk: int) -> User: ...
def get_all_users(self) -> list[User]: ...
def count_users(self) -> int: ...Role-based access control with granular permission management. Supports creating roles, assigning permissions, and managing access control for resources and actions.
def add_role(self, name: str) -> Role | None: ...
def find_role(self, name: str) -> Role | None: ...
def create_permission(self, action_name: str, resource_name: str) -> Permission | None: ...
def add_permission_to_role(self, role: Role, permission: Permission) -> None: ...
def remove_permission_from_role(self, role: Role, permission: Permission) -> None: ...Role and Permission Management
SQLAlchemy models representing the security schema including users, roles, permissions, actions, resources, and their relationships. Provides the data layer for security operations.
class User(Model):
id: int
username: str
email: str
first_name: str
last_name: str
password: str
active: bool
last_login: datetime
login_count: int
fail_login_count: int
roles: list[Role]
created_on: datetime
changed_on: datetime
created_by_fk: int
changed_by_fk: intFlask-AppBuilder view classes for web interface integration, providing customized security views that integrate with Airflow's permission model and web interface.
class CustomUserDBModelView(MultiResourceUserMixin, UserDBModelView): ...
class CustomRoleModelView(RoleModelView): ...
class ActionModelView(PermissionModelView): ...
class ResourceModelView(ViewMenuModelView): ...Multiple authentication backend support including database, LDAP, OAuth, OpenID, and remote user authentication with configurable options and provider-specific implementations.
def auth_user_db(self, username: str, password: str) -> User | None: ...
def auth_user_ldap(self, username: str, password: str) -> User | None: ...
def auth_user_oauth(self, userinfo: dict) -> User | None: ...
def auth_user_oid(self, email: str) -> User | None: ...
def auth_user_remote_user(self, username: str) -> User | None: ...The component supports multiple authentication types:
from flask_appbuilder.const import (
AUTH_DB,
AUTH_LDAP,
AUTH_OAUTH,
AUTH_OID,
AUTH_REMOTE_USER
)Key configuration properties for security behavior:
auth_type: Authentication backend typeauth_role_admin: Administrator role nameauth_role_public: Public/anonymous role nameauth_user_registration: Enable user self-registrationauth_roles_mapping: Map external roles to internal rolesauth_username_ci: Case-insensitive username matchingThe component provides comprehensive error handling with logging and graceful degradation for authentication failures, database errors, and configuration issues.