Airflow添加用户登录

 

通常我们部署airflow调度系统的时候,默认是直接以admin用户登录进来的,而且不需要输入账号密码

如果业务要求必须通过不同的用户登录进来,可以采用以下的方法给airflow添加用户

在 airflow.cfg 文件中 [webserver] 下添加如下配置

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

在这里提醒一下,authenticate这个配置项在配置文件里面很多地方都有,非常容易配错了,如果配置错了,很容易掉坑里

个人建议先在配置文件找到[webserver],然后直接添加内容,然后保存退出

接下来通过命令行添加用户,我这里的airflow是部署在容器里面的,先进入airflow所在的容器,如果部署在服务器上就直接在服务器里执行

以下是添加用户的命令

python

import airflow
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser

user = PasswordUser(models.User())
user.username = ‘usertest1‘
user.email = ‘[email protected]‘
user.password = ‘usertest1‘
user.superuser = 1 //赋予管理员权限,如果是普通用户就不需要这个

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

考虑到现在新的airflow版本用的是python3,在执行语句

from airflow.contrib.auth.backends.password_auth import PasswordUser

的时候会报错,大概也是是没有对应的包,可以通过    pip install  包名    来下载对应的依赖包。

下面是具体例子

[email protected]:/usr/local/airflow# python
Python 3.7.5 (default, Nov 15 2019, 02:58:08)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import airflow
/usr/local/lib/python3.7/site-packages/airflow/configuration.py:226: FutureWarning: The task_runner setting in [core] has the old default value of ‘BashTaskRunner‘. This value has been changed to ‘StandardTaskRunner‘ in the running config, but please update your config before Apache Airflow 2.0.
  FutureWarning
/usr/local/lib/python3.7/site-packages/airflow/configuration.py:606: DeprecationWarning: Specifying both AIRFLOW_HOME environment variable and airflow_home in the config file is deprecated. Please use only the AIRFLOW_HOME environment variable and remove the config file entry.
  warnings.warn(msg, category=DeprecationWarning)
/usr/local/lib/python3.7/site-packages/airflow/utils/sqlalchemy.py:40: DeprecationWarning: get: Accessing configuration method ‘get‘ directly from the configuration module is deprecated. Please access the configuration from the ‘configuration.conf‘ object via ‘conf.get‘
  tz = conf.get("core", "default_timezone")
/usr/local/lib/python3.7/site-packages/airflow/utils/timezone.py:30: DeprecationWarning: get: Accessing configuration method ‘get‘ directly from the configuration module is deprecated. Please access the configuration from the ‘configuration.conf‘ object via ‘conf.get‘
  tz = conf.get("core", "default_timezone")
/usr/local/lib/python3.7/site-packages/airflow/config_templates/airflow_local_settings.py:65: DeprecationWarning: The elasticsearch_host option in [elasticsearch] has been renamed to host - the old setting has been used, but please update your config.
  ELASTICSEARCH_HOST = conf.get(‘elasticsearch‘, ‘HOST‘)
/usr/local/lib/python3.7/site-packages/airflow/config_templates/airflow_local_settings.py:67: DeprecationWarning: The elasticsearch_log_id_template option in [elasticsearch] has been renamed to log_id_template - the old setting has been used, but please update your config.
  ELASTICSEARCH_LOG_ID_TEMPLATE = conf.get(‘elasticsearch‘, ‘LOG_ID_TEMPLATE‘)
/usr/local/lib/python3.7/site-packages/airflow/config_templates/airflow_local_settings.py:69: DeprecationWarning: The elasticsearch_end_of_log_mark option in [elasticsearch] has been renamed to end_of_log_mark - the old setting has been used, but please update your config.
  ELASTICSEARCH_END_OF_LOG_MARK = conf.get(‘elasticsearch‘, ‘END_OF_LOG_MARK‘)
[2020-04-08 17:41:17,838] {settings.py:252} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=21338
>>> from airflow import models, settings
>>> from airflow.contrib.auth.backends.password_auth import PasswordUser
>>> user = PasswordUser(models.User())
>>> user.username = ‘usertest‘
>>> user.email = ‘[email protected]‘
>>> user.password = ‘usertest‘
>>> session = settings.Session()
>>> session.add(user)
>>> session.commit()
>>> user = PasswordUser(models.User())
>>> user.username = ‘usertest1‘
>>> user.email = ‘[email protected]‘
>>> user.password = ‘usertest1‘
>>> session = settings.Session()
>>> session.add(user)
>>> session.commit()
>>> session.close()
>>> exit()

然后重启一下web,进入浏览器

点击右上角的退出

这个时候就可以通过用户名密码登录了!!

原文地址:https://www.cnblogs.com/braveym/p/12661735.html

时间: 2024-08-03 02:20:23

Airflow添加用户登录的相关文章

使用jquery为个人博客园首页公告栏添加用户登录与注销

未登录前,注销的字体颜色为黑色,登录后,登录的字体为蓝色. 1.在公告栏添加布局显示代码 <!--显示登录 Begin--> <!-- 隐藏调用html代码--> <div class="hide"> <!--------------------------用户登陆前后显示-------------------------------> <div class="login_message " style=&quo

在Oracle中添加用户登录名称

第一步,打开Oracle客户端单击 “帮助”-->"支持信息"-->”TNS名“,加入红色部分.页面如下: 第二步,再次打开Oracle客户端时,就会显示数据库了,只需选择要登录的数据库,输入密码就可以了. 总结:这是一个很小的问题,是我第一次用Oracle时的问题,现在想起来了,就随手记一下.

(三)学习MVC之密码加密及用户登录

1.密码加密采用SHA256 算法,此类的唯一实现是 SHA256Managed.在Common/Text.cs里添加Sha256方法: public static string Sha256(string plainText) { SHA256Managed _sha256 = new SHA256Managed(); byte[] _cipherText = _sha256.ComputeHash(Encoding.Default.GetBytes(plainText)); return C

13 Servlet——session案例2:用户登录主页显示用户名和注销登录

案例说明 我们使用原本 第11节的代码进行改进,添加用户登录到主页后显示自己名字的功能和添加注销登录的功能. 思路设计 主页获取用户名设计 在LoginServlet中,我们在判断用户账号密码正确后,跳转主页之前,创建session并将用户对象添加到session中,在主页获取session中的对象即可. 同样地,在3天免登陆的情况下,在cookieServlet中跳转主页之前,创建session并将用户对象添加到session中,在主页获取session中的对象即可. 注销设计 添加一个表单,

centos 6.x 7.x 批量添加用户 开启sudo 权限 并设置密匙登录

需求背景: 局域网内全公司有50余台Linux服务器,现在有两个运维人员,之前都是使用root账号登录来管理服务器,现在想在每台服务器添加各自的账号,开启sudo权限,并设置密钥登录(密钥提前准备好了). 需求分析: 功能其实很简单,但是如果逐一登录服务器去配置,一台服务器5分钟,50台我已经不敢想象了--,所以想办法弄得简单些. 搭建简单ftp服务器: 本机利用IIS建立一个ftp服务器,把shell脚本,和管理员公钥放进去,注意允许ftp通过防火墙(详细步骤略)5分钟内可以完成本步骤:浏览器

把discuzX 的用户登录信息添加到纯静态页面

把discuzX 的用户登录信息添加到纯静态页面 转:http://cq6.com/forum.php?mod=viewthread&tid=86560&extra=page%3D1&page=1 分享&收藏 花了几个小时的间,终于把discuzX 的用户登录信息加到纯静态页面了:演示地址:http://cq6.com/bm/ 源码:1. zx.php (存放在网站根目录) <?php require './source/class/class_core.php';

1.5.2 添加一个用户lidao指定uid为888 禁止用户登录系统 不创建家目录

添加一个用户lidao指定uid为888 禁止用户登录系统 不创建家目录 #添加一个傀儡用户lidao 并指定这个用户的uid为888 [[email protected]~]# #添加一个用户lidao指定uid为888 禁止用户登录系统 不创建家目录 [[email protected]~]# useradd -u 888 -s /sbin/nologin -M lidao888 [[email protected]~]# id lidao888 uid=888(lidao888)gid=8

linux下添加新用户,切换用户登录

如何在linux下添加用户?以及成功退出用户登录?以及切换用户登录? 步骤如下: 命令行输入 adduser 用户名(如:lanp) 回车,(注意:此处linux不会显示任何信息出来); 接着输入 passwd 用户名 回车: 提示你输入新的密码,以及密码输入后的确认密码:(注意,在你输入密码时,linux是不会显示的) 出现身份验证令牌已经成功更新,表示用户以及创建成功: 退出用户登录,直接 logout 回车即可; root切换到普通用户,用命令su 用户名(su即switch user切换

动态添加数据源,根据用户登录切换数据库.编程式Spring事务.

使用Spring数据源路由,现在好像没有直接添加数据源的方法,无奈之下只能用反射. 用户登录成功时,在Spring Security UserDetailService.loadUserByUsername 里面添加用户数据源 /** * 加入用户数据源 */ routingDataSource.addDataSource(userid); /** * 根据用户创建数据源 */ public void addDataSource(String userid) { if (StringUtils.