LoginSignup
5
6

More than 5 years have passed since last update.

Airflowにユーザー認証機能を作成する

Posted at

airflowにはデフォルトのwebserverの設定だと認証機能がONになっていない。
運用的に外部からのアクセスはないとはいえ、つけておきたい!
っていう人もいると思うのでその方法。
というか基本はドキュメントに書いてあるのでこちらを見ればすべて出来る。
https://pythonhosted.org/airflow/security.html

LDAPとかGHEとかあるけど今回は一番basicなemail,pass

事前準備

まずは認証を使用する際にはflask_bcryptが必要なので、インストール

pip install flask_bcrypt

後は標準で入っているもので対応できるはず

airflow.cfgの変更

authenticateは最初はFalseになっているのでコメントアウトするなりTrueにする。

authenticate = True
auth_backend = airflow.contrib.auth.backends.password_auth

ユーザーの作成

ユーザーの作成にはコマンドラインから行う。

pythonコマンドでコンソール開いて下記のユーザー情報変更してEnterでユーザー作成完了

import airflow
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
user = PasswordUser(models.User())
user.username = '[任意のユーザー名]'
user.email = '[任意のEmailアドレス]'
user.password = '[任意のパスワード]'
session = settings.Session()
session.add(user)
session.commit()
session.close()
exit()

これでwebserverを再起動すれば下記画面になるはず

スクリーンショット.png

最後に

権限周りの設定はどうやらできないっぽい??

5
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6