博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx 结合Python Ldap认证用于Kibana权限登陆
阅读量:7048 次
发布时间:2019-06-28

本文共 4335 字,大约阅读时间需要 14 分钟。

参考及依赖

https://github.com/nginxinc/nginx-ldap-authhttp://nginx.org/nginx-1.14.2http_auth_request_modulenginx-ldap-authpython2.7python-ldap

Nginx支持ldap

  1. 部署nginx,注意需要http_auth_request_module支持
wget http://nginx.org/download/nginx-1.14.2.tar.gztar zxvf nginx-1.14.2.tar.gzcd nginx-1.14.2./configure --with-http_auth_request_modulemakemake 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;#kibananupstream 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 "opit@minminmsn";        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.gztar zxvf 0.0.4.tar.gzpython nginx-ldap-auth-daemon.py &

后端登陆跳转页面

默认页面只能测试,这里需要大概改下才能使用

vim backend-sample-app.py
python backend-sample-app.py &
backend-sample-app.py其中html=修改后如下

login

登陆测试

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

转载于:https://blog.51cto.com/jerrymin/2334757

你可能感兴趣的文章
ansible简介与应用【转】
查看>>
man-pages项目包含文档的说明
查看>>
[LeetCode] Find K-th Smallest Pair Distance 找第K小的数对儿距离
查看>>
Cacti snmp监控磁盘IO之bytes read/written和reads/writes
查看>>
小程序节点查询
查看>>
C# 单元测试
查看>>
【阿里聚安全·安全周刊】互联网时代人类还有被遗忘的权利吗 | Android与中兴...
查看>>
业务配置开发平台qMISPlat 2.0 产品介绍
查看>>
org.dom4j.DocumentException:对实体 "virtual_card_id" 的引用必须以 ';' 分隔符结尾
查看>>
【ASP.NET MVC系列】浅谈ASP.NET 页面之间传值的几种方式
查看>>
linux内核剖析(七)Linux进程间通信的几种方式总结
查看>>
180510.最近踩过和听过的sql的坑
查看>>
api 25 PopupWindow会占据整个屏幕
查看>>
Target runtime Apache Tomcat v6.0 is not defined.错误解决方法
查看>>
Android GreenDao操作外部DB数据库文件
查看>>
spring 邮件服务
查看>>
饿了么多活利器:实时双向复制工具(DRC)
查看>>
SpringBoot各类扩展点详解
查看>>
NancyFx-打造小型 WebAPI 與 Microservice 的輕巧利器
查看>>
为什么使用Reazor
查看>>