Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Airflow basic auth - cannot login with created user

Tags:

flask

airflow

I have similar situation as mentioned here Airflow basic auth - cannot create user

So, I create user like this:

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 = '[email protected]'
user._set_password = 'set_the_password'.encode('utf8')
session = settings.Session()
session.add(user)
session.commit()
session.close()

And user is created. Kinda. If I exit from python shell and launch it again I can see the user doing

session.query(PasswordUser).all()

or

session.query(models.User).all()

But when I try to login I get "Incorrect login details". I checked all the logs I could grab from airflow and got nothing. Just a request one-liner. Also, I checked postgres db I use. And table "users" is empty for some reason. Though if I delete this table, user creation fails, so I don't even understand in which place this user is saved.

like image 541
Dmitriy Uvarenkov Avatar asked Sep 17 '25 01:09

Dmitriy Uvarenkov


2 Answers

I just had the exact same thing happen... and I just used the correct URI string like so...

import airflow
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
user = PasswordUser(models.User())
user.username = 'user'
user.email = '[email protected]'
user.password = 'password'

# the secret sauce is right here
from sqlalchemy import create_engine
engine = create_engine("postgresql://airflow:airflow@postgres:5432/airflow")

session = settings.Session(bind=engine)
session.add(user)
session.commit()
session.close()
exit()

You can also use either PyCharm Pro or pgadmin to connect to the db directly.

Now I've just gotta solve the problem with it still not prompting me to login despite changing the config file.

like image 178
Matt Camp Avatar answered Sep 22 '25 16:09

Matt Camp


So I found out that when I run airflow from console, it uses different db than when it is run at webserver. I used this https://github.com/puckel/docker-airflow as the boilerplate to setup my instance in docker. So, if I insert needed script in some dag task and run it from webserver, it fills my postgres db all right and I can then login with a created user. Why the heck different db is used in console - I still don't know, which is different question.

like image 28
Dmitriy Uvarenkov Avatar answered Sep 22 '25 16:09

Dmitriy Uvarenkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!