I am using Airflow version 1.8.2 and set up couple of Dags.Everything running as expected .I have admin user created for airflow web server access.But for other teams to monitor their job we can't provide this admin user So I tried to create a different user from the UI '/admin/user/'.
But only the following fields are available .No options to provide roles or password etc.
Does anyone faced the same issue or I am doing some wrong thing .How to create role based users So that I can tag some specific dags to those teams
Thanks
As of Airflow 1.10, there is an airflow create_user
CLI: https://airflow.apache.org/cli.html#create_user.
It supports roles and passwords:
airflow create_user [-h] [-r ROLE] [-u USERNAME] [-e EMAIL] [-f FIRSTNAME]
[-l LASTNAME] [-p PASSWORD] [--use_random_password]
The user models in Airflow are currently simplistic and (as of at least 1.9.0) there is no way via the UI to set passwords.
The approach I use is the following python script:
#!/usr/bin/env python
import argparse
import getpass
import sys
def create_user(opts):
from airflow.contrib.auth.backends.password_auth import PasswordUser
from airflow import models, settings
u = PasswordUser(models.User())
u.username = opts['username']
u.email = opts['email']
u.password = opts['password']
s = settings.Session()
s.add(u)
s.commit()
s.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('email')
parser.add_argument('username', nargs='?', help="Defaults to local part of email")
args = parser.parse_args()
if not args.username:
# Default username is the local part of the email address
args.username = args.email[:args.email.index('@')]
args.password = getpass.getpass(prompt="Enter new user password: ")
confirm = getpass.getpass(prompt="Confirm: ")
if args.password != confirm:
sys.stderr.write("Passwords don't match\n")
sys.exit(1)
create_user(vars(args))
This versoin doesn't support changing passwords as we haven't needed it yet
来源:https://stackoverflow.com/questions/48072563/airflow-user-creation