Nginx 结合Python Ldap认证用于Kibana权限登陆

参考及依赖

https://github.com/nginxinc/nginx-ldap-auth
http://nginx.org/
nginx-1.14.2
http_auth_request_module
nginx-ldap-auth
python2.7
python-ldap

Nginx支持ldap

  1. 部署nginx,注意需要http_auth_request_module支持
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --with-http_auth_request_module
make
make install
/usr/local/nginx/sbin/nginx
  1. 配置nginx,注意ldap配置
    cat /usr/local/nginx/conf/nginx.conf

    
    user                  nobody nobody;
    worker_processes auto;
    #worker_cpu_affinity auto;
    worker_rlimit_nofile 65535;

error_log logs/error.log;
pid logs/nginx.pid;

events {
use epoll;
#reuse_port on; #used in tengine and linux kernel >= 3.9
accept_mutex off; #used in nginx
worker_connections 65535;
}

http {
include mime.types;
default_type application/octet-stream;
server_tokens off;

log_format      main        ‘$remote_addr - $remote_user [$time_local] "$request" ‘
                            ‘$status $request_time $body_bytes_sent "$http_referer" ‘
                            ‘"$http_user_agent" "$http_x_forwarded_for"|body: $request_body‘;

sendfile                    on;
tcp_nopush                  on;
tcp_nodelay                 on;
keepalive_timeout           60;

gzip                        on;
gzip_vary                   on;
gzip_comp_level             5;
gzip_buffers                16 4k;
gzip_min_length             1000;
gzip_proxied                any;
gzip_disable                "msie6";
gzip_types                  text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;

open_file_cache max=1000    inactive=20s;
open_file_cache_valid       30s;
open_file_cache_min_uses    2;
open_file_cache_errors      on;

client_max_body_size        50m;

#缓存可以减少ldap验证频率,不然每个页面都需要ldap验证一次
#你不在乎的话,不要缓存也是没有任何问题的
proxy_cache_path cache/ keys_zone=auth_cache:10m;

#kibanan
upstream kibana_server {
server 10.2.8.44:5601;
}

server {
listen 5601;
server_name localhost;
access_log logs/kibanan_access.log main;
error_log logs/kibanan_error.log debug;

#后端程序,也就是kubernetes-dashboard
location / {
    auth_request /auth-proxy;

    #nginx接收到nginx-ldap-auth-daemon.py返回的401和403都会重新跳转到登录页面
    error_page 401 403 =200 /login;

    proxy_pass http://kibana_server;
}

#登录页面,由backend-sample-app.py提供,跑在同一台机器的8082端口(默认不是8082端口)
location /login {
    proxy_pass http://127.0.0.1:9000/login;
    proxy_set_header X-Target $request_uri;
}

location = /auth-proxy {
    internal;
    proxy_pass http://127.0.0.1:8888;     #nginx-ldap-auth-daemon.py运行端口
    #缓存设置
    proxy_cache auth_cache;
    proxy_cache_key "$http_authorization$cookie_nginxauth";
    proxy_cache_valid 200 403 10m;

    proxy_pass_request_body off;
    proxy_set_header Content-Length "";

    #最最重要的ldap配置,请务必按照贵公司的ldap配置如下四项,我在这一步卡了好久,就是ldap配置不对
    #这些配置都会通过http头部传递给nginx-ldap-auth-daemon.py脚本
    proxy_set_header X-Ldap-URL      "ldap://10.2.150.11:389";
    proxy_set_header X-Ldap-BaseDN   "ou=People,dc=yiche,dc=org";
    proxy_set_header X-Ldap-BindDN   "cn=OPITUser,ou=OuterUser,dc=che,dc=org";
    proxy_set_header X-Ldap-BindPass "[email protected]";
    proxy_set_header X-Ldap-Template "(uid=%(username)s)";

    proxy_set_header X-CookieName "nginxauth";
    proxy_set_header Cookie nginxauth=$cookie_nginxauth;
}

}
}


> ### Python Ldap认证

wget https://github.com/nginxinc/nginx-ldap-auth/archive/0.0.4.tar.gz
tar zxvf 0.0.4.tar.gz
python nginx-ldap-auth-daemon.py &


> ### 后端登陆跳转页面

默认页面只能测试,这里需要大概改下才能使用
vim backend-sample-app.py
python backend-sample-app.py &
backend-sample-app.py其中html=``````修改后如下

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8"/>
<title>login</title>
</head>
<style>
*{margin:0;padding:0;}
.login{
width:400px;
height:220px;
margin:0 auto;
position:absolute;
left:35%;
top:25%;
}
.login_title{
color: #000000;
font: bold 14px/37px Arial,Helvetica,sans-serif;
height: 37px;
padding-left: 35px;
text-align: left;
}

.login_cont {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #B8B7B7;
height: 152px;
padding-top: 30px;
}
.form_table {
float: left;
margin-top: 10px;
table-layout: fixed;
width: 100%;
}
.form_table th {
color: #333333;
font-weight: bold;
padding: 5px 8px 5px 0;
text-align: right;
white-space: nowrap;
}
.form_table td {
color: #717171;
line-height: 200%;
padding: 6px 0 5px 10px;
text-align: left;
}
.login_cont input.submit {
background-position: 0 -37px;
height: 29px;
margin: 10px 14px 0 0;
width: 38px;
}
</style>
<body>
<div class="login">
<div class="login_cont">
<form action=‘/login‘ method=‘post‘>
<table class="form_table">
<col width="60px" />
<col />
<p align="center"> 欢迎登陆kibana管理平台</p>
<p align="center"> 请使用邮箱账户密码登陆</p>
<tr>
<th>用户名:</th><td><input class="normal" type="text" name="username" alt="请填写用户名" /><th>@zhidaoauto.com</th></td>
</tr>
<tr>
<th>密???码:</th><td><input class="normal" type="password" name="password" alt="请填写密码" /></td>
</tr>
<tr>
<th></th><td><input class="submit" type="submit" value="登录" /><input class="submit" type="reset" value="取消" /></td>
</tr>
</table>
<input type="hidden" name="target" value="TARGET">
</form>
</div>
</div>
</body>
</html>



> ### 登陆测试
http://10.2.8.24:5601/
![](http://i2.51cto.com/images/blog/201812/24/2ec96017895b0be37676ff980fd50f5a.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

原文地址:http://blog.51cto.com/jerrymin/2334757

时间: 2024-07-30 04:59:17

Nginx 结合Python Ldap认证用于Kibana权限登陆的相关文章

Gitlab加入LDAP认证

如果企业大大小小系统较多,每个系统都给用户单独配置一账户.这样各个系统的账户信息都要单独记忆,比较繁琐,而且账户信息易忘.所以加入集成 LDAP 统一认证,域控管理.这里对Gitlab应用系统结合LDAP认证,前提是企业内部已搭建好AD域服务. Gitlab配置LDAPGitlab已安装好,安装的CE版本.Gitlab配置LDAP服务要在配置文件中修改,无法像Jenkins加入LDAP那样安装一LDAP插件,然后配置LDAP信息即可.Gitlab中需在默认的配置文件/etc/gitlab/git

关于python基础认证(用于爬虫)

转自http://www.voidspace.org.uk/python/articles/authentication.shtml 先转来,由于是python2的版本之后会翻译文章以及移植到python3 Introduction This tutorial aims to explain and illustrate what basic authentication is, and how to deal with it from Python. You can download the

python 连接使用LDAP认证的hive

主要使用pyhive包. 使用linux中的普通账号,venv环境.python版本 3.6.4. ldap认证需要sasl包,在安装sasl包的时候因为机器中没有g++编译器,导致无法安装.因为我使用的普通账号,没法给服务器安装g++编译器,解决的方案是在另一台机器中安装sasl,将安装完成后生成的.so动态链接库文件及py文件直接拷贝到合适目录即可使用. 以下是连接hive的示例代码: #!/bin/python # -*- coding: utf-8 -*- import sys,pyhi

搭建harbor仓库、LDAP认证

ldap: 192.168.199.177 c5game.com 宿主机:192.168.199.224 测试客户机:192.168.199.223 安装docker.docker-compose 访问查看最新版本https://github.com/goharbor/harbor/releases并下载harbor-offline-installer-vxxx.tgz [[email protected] ~]# cd /opt/ [[email protected]-registry opt

关于AD域在通过LDAP认证登录时密码修改后还可使用旧密码正常登录问题解决方法

最近一直在做一个LDAP的管理认证登录平台,但是发现在Active Directory中修改用户账号密码后,LDAP认证还可以正常通过认证,并登录系统,这是什么原因了? 在查看相关资料后发现,系Active Directory原因造成:那么应该如何解决这个问题了,可以通过修改旧密码的生命周期时间可以解决此问题: 具体原因: ?域用户成功更改密码使用 NTLM 后,旧密码仍然可用于网络访问用户可定义的时间段.此行为允许帐户,如服务帐户,登录到多台计算机来访问网络,而密码更改会传播. ?密码的扩展寿

SVN使用LDAP认证

完成了openldap的配置之后,为了更进一步的进行用户统一身份认证,所以需要配置SVN使用openldap进行认证,这样的话只需要维护ldap中的用户数据,然后在SVN上进行服务授权即可完成SVN的用户权限分配.同样的,这个配置也适合于其他的软件,比如vsftpd,ssh,openvpn等,下面开始配置SVN使用ldap认证. 1.安装sasl SASL全称Simple Authentication and Security Layer,是一种用来扩充C/S模式验证能力的机制. SASL是一个

Windows 2008 使用Linux LDAP认证

公司出于数据安全需要, 把linux服务器放到了子网里面, 但是linux查看文档不是太方便. 然后领导说折腾一台windows专门用来查看文档. 网上找了下 pGina 可以用于windows的LDAP认证. 因为AD不在那个子网中, 出于安装考虑, 只有使用linux的LDAP认证了. 直接起一台windows 2008虚拟机. 在里面安装好 pGina. 打开软件. 1: 把LDAP 相关选项勾上. 因为要操作组所以把 Gateway也勾上了.然后再点击配置 2: 这里直接更改ldap的地

zabbix使用LDAP认证

为统一管理内部系统的账户,想让zabbix使用LDAP认证方式.原来zabbix有和SSO系统进行整合.当想更好管理zabbix的权限,所以想直接和LDAP整合,反正SSO账户信息也是从LDAP得到的. 公司LDAP使用的是windows的Exchange.首先需要在AD域内创建一个账户. Admin.LDAPuser和zabbix这三个账户,是为zabbix创建的三个账户. 接下来,就可以在zabbix上设置认证方式 1.在配置之前,首先需要安装php-ldap Module,否则会报找不到该

jenkins 使用LDAP认证

jenkins使用LDAP认证配置如下图所示: 用管理员账户登录jenkins,点击系统管理 ==> Configure Global Security 注意:我没有配置User search base和Group search base,这样ldap用户登录时,会对ldap 服务器上所有组所有用户进行匹配查询,如果指定了某一个组或某一个用户,那么其他组其他用户就算在ldap服务器上存在,也无法通过认证.LDAP只是做认证的,jenkins的的权限需要在授权策略中配置. 另外,我使用的是ldap