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 ...
随机推荐
- NserviceBus:消息Message、Command、Event(2)
NServiceBus.IMessage 用于定义消息.NServiceBus.ICommand 用于定义命令.NServiceBus.IEvent 用于定义事件. ICommand 命令 用于点对点 ...
- C++ 使用openssl库实现 DES 加密——CBC模式 && RSA加密——公加私解——私加公解
之前工作上需要用C++把软件生成的用户序列号用des加密cbc的模式,加密后为二进制,转化为十六进制,然后提供给java写的授权码管理平台. java平台会根据用户序列号,生成一个授权码,授权码是用r ...
- jQuery-动画点击淡化消失
<!DOCTYPE html> <html> <head> <title> new document </title> <meta c ...
- armv8 memory system
在armv8中,由于processor的预取,流水线, 以及多线程并行的执行方式,而且armv8-a中,使用的是一种weakly-ordered memory model, 不保证program or ...
- Python全栈-异常处理
一.异常 1.异常的定义 异常是错误发生的信号,程序一旦出错就会抛出错误信息,如果不及时处理就会程序就会随之停止运行 异常有三部分组成: 1)异常类型 2)异常追踪 3)异常的值 2.异常的分类 1) ...
- JOptionPane
2018-10-30 14:44:43 开始写 作者:tjk123456 来源:CSDN 原文链接 建议阅读官方资料:https://docs.oracle.com/javase/7/docs/api ...
- 20155228 2016-2017-2 《Java程序设计》第8周学习总结
20155228 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 NIO与NIO2 NIO使用频道来衔接数据节点,在处理数据时,NIO可以让你设定缓冲区容量, ...
- CSS布局实战
1. ul li中上图下字,图片.文字居中. <ul> <li> <img src="dash.png" style="display:bl ...
- flask用宏渲染表单模板时,表单提交后,如果form.validate_on_submit()返回的是false的可能原因
flask用宏渲染表单模板时,表单提交后,提交的内容符合DataRequired()校验, 但是form.validate_on_submit()返回的是False, 原因可能是表单模板中的<f ...
- Linux基础命令---文本格式转换expand,unexpand
expand 将文件中的tab转换成空格,结果送到标准输出.如果没有指定文件,那么从标准输入读取. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.F ...