YAML file-based lightweight Auth Manager for Apache Airflow 3.x
Project description
airflow-file-auth-manager
A lightweight YAML file-based Auth Manager for Apache Airflow 3.x
Overview
airflow-file-auth-manager provides simple file-based authentication for Apache Airflow 3.x without requiring LDAP or external authentication services. Perfect for small teams of 1-3 people who need basic authentication with role-based access control.
Key Features
- Secure Password Storage: bcrypt hashing with configurable work factor
- Three-Tier Role System: Admin, Editor, and Viewer roles
- JWT Token Authentication: Stateless session management
- YAML-Based Configuration: Simple, human-readable user management
- CLI Tools: Command-line interface for user administration
- Modern Login UI: Clean, responsive login page
Installation
From PyPI
pip install airflow-file-auth-manager
From Source
git clone https://github.com/choo121600/airflow-file-auth-manager.git
cd airflow-file-auth-manager
pip install -e .
Quick Start
1. Create Users File
# Initialize with an admin user
python -m airflow_file_auth_manager.cli init \
-f /path/to/users.yaml \
-e admin@example.com
# Add additional users
python -m airflow_file_auth_manager.cli add-user \
-f /path/to/users.yaml \
-u developer \
-r editor \
-e dev@example.com
2. Configure Airflow
Add to your airflow.cfg:
[core]
auth_manager = airflow_file_auth_manager.FileAuthManager
[file_auth_manager]
users_file = /path/to/users.yaml
Or use environment variables:
export AIRFLOW__CORE__AUTH_MANAGER=airflow_file_auth_manager.FileAuthManager
export AIRFLOW_FILE_AUTH_USERS_FILE=/path/to/users.yaml
3. Start Airflow
airflow standalone
# or
astro dev start
Role-Based Access Control
| Role | Description |
|---|---|
| Admin | Full access including Connection, Variable, Pool, and Configuration management |
| Editor | DAG execution and management, read access to all resources |
| Viewer | Read-only access to all resources |
Permission Matrix
| Resource | Viewer | Editor | Admin |
|---|---|---|---|
| DAGs (view) | ✅ | ✅ | ✅ |
| DAGs (trigger/manage) | ❌ | ✅ | ✅ |
| Connections (view) | ✅ | ✅ | ✅ |
| Connections (modify) | ❌ | ❌ | ✅ |
| Variables (view) | ✅ | ✅ | ✅ |
| Variables (modify) | ❌ | ❌ | ✅ |
| Pools (view) | ✅ | ✅ | ✅ |
| Pools (modify) | ❌ | ❌ | ✅ |
| Configuration | ✅ (read) | ✅ (read) | ✅ |
Users File Format
version: "1.0"
users:
- username: admin
password_hash: "$2b$12$..." # bcrypt hash
role: admin
email: admin@example.com
first_name: Admin
last_name: User
active: true
- username: developer
password_hash: "$2b$12$..."
role: editor
email: dev@example.com
active: true
- username: analyst
password_hash: "$2b$12$..."
role: viewer
email: analyst@example.com
active: true
CLI Reference
Initialize Users File
python -m airflow_file_auth_manager.cli init \
-f users.yaml \
[-p password] \
[-e email] \
[--force]
Add User
python -m airflow_file_auth_manager.cli add-user \
-f users.yaml \
-u username \
-r admin|editor|viewer \
[-p password] \
[-e email] \
[--firstname "First"] \
[--lastname "Last"]
Update User
python -m airflow_file_auth_manager.cli update-user \
-f users.yaml \
-u username \
[-p] # Prompt for new password
[-r role] \
[-e email] \
[--active true|false]
Delete User
python -m airflow_file_auth_manager.cli delete-user \
-f users.yaml \
-u username \
[-y] # Skip confirmation
List Users
python -m airflow_file_auth_manager.cli list-users -f users.yaml
Generate Password Hash
python -m airflow_file_auth_manager.cli hash-password [-p password]
API Authentication
Obtain Token
curl -X POST http://localhost:8080/auth/file/token \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "your_password"}'
Response:
{
"access_token": "eyJ...",
"token_type": "Bearer",
"expires_in": 36000
}
Use Token
curl http://localhost:8080/api/v1/dags \
-H "Authorization: Bearer eyJ..."
Configuration Options
airflow.cfg
[file_auth_manager]
# Path to users YAML file
users_file = /opt/airflow/users.yaml
[api_auth]
# JWT token expiration in seconds (default: 36000 = 10 hours)
jwt_expiration_seconds = 36000
Environment Variables
| Variable | Description |
|---|---|
AIRFLOW_FILE_AUTH_USERS_FILE |
Path to users YAML file |
AIRFLOW__FILE_AUTH_MANAGER__USERS_FILE |
Alternative config path |
Password Policy
Passwords must meet the following requirements:
| Requirement | Description |
|---|---|
| Minimum length | 8 characters |
| Maximum length | 128 characters |
| Uppercase | At least 1 uppercase letter (A-Z) |
| Lowercase | At least 1 lowercase letter (a-z) |
| Digit | At least 1 number (0-9) |
| Special character | At least 1 special character (`!@#$%^&*(),.?":{} |
Example valid passwords:
MyP@ssw0rdAdmin123!Secure#Pass99
Security Considerations
- Protect the users file: Set appropriate permissions (
chmod 600 users.yaml) - Use strong passwords: All passwords are validated against the policy above
- Secure file location: Store outside web-accessible directories
- Regular rotation: Periodically update passwords
- HTTPS: Always use HTTPS in production for secure cookie transmission
Development
Setup
git clone https://github.com/yeonguk/airflow-file-auth-manager.git
cd airflow-file-auth-manager
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
Run Tests
pytest tests/ -v
Run Tests with Coverage
pytest tests/ -v --cov=airflow_file_auth_manager --cov-report=html
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Apache Airflow 3.x │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ FileAuthManager │◄───│ BaseAuthManager │ │
│ └────────┬────────┘ └─────────────────┘ │
│ │ │
│ ┌────────▼────────┐ ┌─────────────────┐ │
│ │ UserStore │◄───│ users.yaml │ │
│ └────────┬────────┘ └─────────────────┘ │
│ │ │
│ ┌────────▼────────┐ ┌─────────────────┐ │
│ │ FileAuthPolicy │ │ FastAPI App │ │
│ │ (RBAC rules) │ │ (login/logout) │ │
│ └─────────────────┘ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Comparison with Other Auth Managers
| Feature | File Auth | Simple Auth | FAB Auth | LDAP Auth |
|---|---|---|---|---|
| External Dependencies | None | None | Database | LDAP Server |
| Password Storage | bcrypt | Plain text | Database | LDAP |
| Role System | 3 roles | 4 roles | Flexible | Group-based |
| User Management | YAML + CLI | Config | Web UI | LDAP Admin |
| Production Ready | Yes | No | Yes | Yes |
| Best For | Small teams | Development | Medium teams | Enterprise |
Troubleshooting
Common Issues
"Users file not found"
- Ensure the file path is correct and accessible
- Check file permissions
"Invalid username or password"
- Verify the password hash was generated correctly
- Check if the user is marked as
active: true
"Module not found: airflow"
- The CLI works without Airflow for basic operations
- Install Airflow for full functionality
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Acknowledgments
- Apache Airflow - The workflow orchestration platform
- airflow-ldap-auth-manager - Inspiration for the architecture
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file airflow_file_auth_manager-0.1.8.tar.gz.
File metadata
- Download URL: airflow_file_auth_manager-0.1.8.tar.gz
- Upload date:
- Size: 23.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ca4b2e424c1f169ae515b6052cd1204299618962eb9149bc855b121f8646984
|
|
| MD5 |
053ce3b93c127e9f01187d6ffda5bc69
|
|
| BLAKE2b-256 |
331c8fdb42a33feee14e25791e01973dcd7f87f433e3b3ec79bd4ca288568584
|
File details
Details for the file airflow_file_auth_manager-0.1.8-py3-none-any.whl.
File metadata
- Download URL: airflow_file_auth_manager-0.1.8-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c15bc74af6220eeb05a04a48bcc04caf8db59091a156189726fdce03f5ea8e8a
|
|
| MD5 |
abb54808e8e44fe47ffa829913795f16
|
|
| BLAKE2b-256 |
3493558be6ca2e36da2bc419f8ec6fe9e1fe09d06f6665d2fd53c12916c909c2
|