Airflow basic auth - cannot create user

亡梦爱人 提交于 2020-01-02 05:20:13

问题


I'm running airflow v 1.9.0. I am trying to get some form of authentication working but have so far failed to get github auth and password auth working. The password auth feels like it should be pretty straight forward and I'm hoping someone can point me in the right direction. My airflow.cfg has the following

[webserver]
authenticate = True
auth_backend = airflow.contrib.auth.backends.password_auth

Following the instructions here https://airflow.incubator.apache.org/security.html#password I've logged into my airflow web server and run the following interactive python to try to create a user which gives me an error

airflow@airflow-web-66fbccc84c-vmqbp:~$ python3
Python 3.6.4 (default, Feb 15 2018, 13:07:07)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import airflow
>>> from airflow import models, settings
>>> from airflow.contrib.auth.backends.password_auth import PasswordUser
>>> user = PasswordUser(models.User())
>>> user.username = 'admin'
>>> user.password = 'airflowWTF'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    File "/usr/local/lib/python3.6/site-packages/sqlalchemy/ext/hybrid.py", line 873, in __set__
        raise AttributeError("can't set attribute")
        AttributeError: can't set attribute

Going through the web UI to create a user I just get an exception. Here is the end of the exception. https://www.dropbox.com/s/7cxwi6hdde61wnb/Screenshot%202018-02-21%2013.52.16.png?dl=0

Any tips appreciated.
Thanks!


回答1:


You need to use <1.2.0 version of sqlalchemy ('sqlalchemy>=1.1.15, <1.2.0',) or use "_password".

Changing version of sqlalchemy is better.




回答2:


As mentioned here, using the _set_password method worked for me when I had the same error:

import airflow
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
user = PasswordUser(models.User())
user.username = 'new_user_name'
user.email = 'new_user_email@example.com'
user._set_password = 'set_the_password'.encode('utf8')
session = settings.Session()
session.add(user)
session.commit()
session.close()


来源:https://stackoverflow.com/questions/48917131/airflow-basic-auth-cannot-create-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!