ldap集成nginx
nginx版本:1.10.2
nginx安装:
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_ssl_module --with-http_sub_module --with-http_auth_request_module --with-http_stub_status_module
make
make install
已安装nginx服务的话,通过 nginx -V 检查是否支持编译时是否添加 --with-http_auth_request_module,因为认证需要用到ngx_http_auth_request_module,如果不支持,需要重新编译添加(参考:https://anyof.me/articles/236)。
nginx的ldap认证需要通过nginx官方提供的服务去实现,首先需要把代码下载下来。
git clone https://github.com/nginxinc/nginx-ldap-auth
nginx-ldap-auth主要涉及的有两个脚本:
backend-sample-app.py:提供登录服务
nginx-ldap-auth-daemon.py:提供认证服务
脚本需要ldap模块支持: yum install python-ldap -y
backend-sample-app.py的登录界面会将密码明文显示,很不友好,将html内容替换成:
html="""
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8"/>
<title>登陆框</title>
</head>
<style>
*{margin:0;padding:0;}
.login{
width:334px;
height:220px;
margin:0 auto;
position:absolute;
left:40%;
top:40%;
}
.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: 82px;
}
</style>
<body>
<div class="login">
<div class="login_cont">
<form action='/login' method='post'>
<table class="form_table">
<col width="90px" />
<col />
<tr>
<th>用户名:</th><td><input class="normal" type="text" name="username" alt="请填写用户名" /></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>"""
接下来把两个脚本运行起来:
nohup python backend-sample-app.py > login.log 2>&1 &
nohup python nginx-ldap-auth-daemon.py --host 0.0.0.0 >auth.log 2>&1 &
脚本默认监听localhost,根据需要自行修改。
nginx ldap认证 配置
在需要认证的server里加入以下:
location / {
#auth_basic "Welcome to solr";
#auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
auth_request /auth-proxy;
error_page 401 403 =200 /login;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#需要认证的服务
proxy_pass http://dev-solr:8983;
}
location /login {
#登录服务
proxy_pass http://172.31.29.18:9000/login;
proxy_set_header X-Target $request_uri;
}
location = /auth-proxy {
internal;
#认证服务
proxy_pass http://172.31.29.18:8888;
proxy_cache_key "$http_authorization$cookie_nginxauth";
proxy_cache_valid 200 403 1m;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Ldap-URL "ldap://ldap.xxxx.net:389";
proxy_set_header X-Ldap-BaseDN "DC=ldap,DC=xxxx,DC=net";
#proxy_set_header X-Ldap-Template "(|(cn=xxxxx@xxxxx.com)(cn=xxxxx@xxxxxx.com))";
proxy_set_header X-Ldap-BindDN "cn=Manager,dc=ldap,dc=xxxxx,dc=net";
proxy_set_header X-Ldap-BindPass "xxxxxxx";
proxy_set_header X-CookieName "nginxauth";
proxy_set_header Cookie nginxauth=$cookie_nginxauth;
}
可以通过X-Ldap-Template配置ldap某个组的用户访问server:proxy_set_header X-Ldap-Template "(&(cn=%(username)s)(memberOf=cn=groupname,cn=Users,dc=ldap,dc=xxxxx,dc=com))";
但我这边配置后发现ldap 不支持 memberOf,需要手动开启。因为是一些内部服务,这边采用一个折中的方法,设置白名单方式限制访问。
缺陷:
不支持权限控制
管理账号明文显示,有风险(可以把账号配置在nginx-ldap-auth-daemon.py脚本里)
参考链接:https://sapser.github.io/devops/2016/07/22/nginx-ldap
ldap集成nginx的更多相关文章
- ldap集成bitbucket
confluence ldap配置跟jira ldap集成一样,请参考:https://www.cnblogs.com/imcati/p/9378668.html 需在 Global permissi ...
- ldap集成jenkins
jenkins版本:2.5.3,ldap插件:1.15 jenkins ldap支持需要安装ldap plugin,强烈建议插件安装版本为1.15及以上(支持ldap 配置测试) 安装插件: 系统管理 ...
- ldap集成confluence
confluence ldap配置跟jira ldap集成一样,请参考:https://www.cnblogs.com/imcati/p/9378668.html
- CAS与LDAP集成
参考文献: CAS集成ldap:https://wiki.jasig.org/display/CASUM/LDAP CAS集成restful api:https://wiki.jasig.org/di ...
- apache+svn+ldap集成
apache+svn搭建方式如下:http://www.cnblogs.com/uglyliu/p/6914056.html SVN和ldap集成,我用的方式只需要更改 /etc/http/conf. ...
- 【Web】Rest && 权限管理 && LDAP && OAuth && Nginx && Lua 等
最好的8个 Java RESTful 框架:http://www.importnew.com/17138.html 如何设计RESTful的API权限:https://segmentfault.com ...
- tomcat集群搭建集成nginx负载均衡
软件基础+版本: 1.3台centos7系统,其中都已经配置完成了jdk环境,jdk的版本为 [root@node03 bin]# java -version java version "1 ...
- ldap 集成harbor
harbor: 1.6 默认配置文件在harbor.cfg,我们可以先不添加配置,直接在harbor web界面进行配置(harbor 1.6 如果db 启动失败提示postgresql 数据目录已存 ...
- ldap集成grafana
grafana版本: 5.0.3 grafana通过k8s方式安装,所以需将配置文件挂载过去. cat grafana-configmap.yaml apiVersion: v1 kind: Conf ...
随机推荐
- XML反序列化遇到数字型节点值为空导致反序列化异常
实体类: [XmlRoot("stream")] public class _30320DuisiFukuanQueryResponseModel : ResponseModelB ...
- JS引擎的执行机制
深入理解JS引擎的执行机制 1.灵魂三问 : JS为什么是单线程的? 为什么需要异步? 单线程又是如何实现异步的呢? 2.JS中的event loop(1) 3.JS中的event loop(2) 4 ...
- C# 基于DocumentFormat.OpenXml的数据导出到Excel
using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.S ...
- C#7.0新特性(VS2017可用)
分享一下其实2016年12月就已经公布了的C#7.0的新特性吧,虽然很早就出来了,但咱这IDE不支持啊.. 不过在昨天的VS2017中已经完美可以支持使用了. E文好的,移步官方介绍地址:https: ...
- Django后台管理系统讲解及使用
大家在创建Django项目后,在根路由urls.py文件中,会看到一行代码 from django.contrib import admin urlpatterns = [ url(r'^admin/ ...
- oracle中实现md5加密
记得要实现md5加密,在oracle 11g 和 12c中是有不同的方式的,在12c中较为简单,记得直接有预定义的函数. 但是在11g中要实现就需要自己进行一些额外的处理,以下给出一个md5函数的实现 ...
- linux 监控脚本运行时间
虽然可以使用time命令,但是有时候会有写日志之类的需求. 使用如下脚本可以计算时间: #!/bin/bash sdate=`date +%s.%N` edate=`date +%s.%N` echo ...
- python deque
Deque objects support the following methods: append(x)¶ Add x to the right side of the deque. append ...
- NFS配置与安装
安装 1 环境描述: * 网络环境: NFS server: 192.168.102.47 NFS client: 192.1 ...
- JavaScript--函数、匿名函数和自执行函数详解
函数的声明及调用 1.函数的声明格式: function 函数名([参数1],[参数2],.....){ //函数体代码 [return 返回值 ...