LDAP [Phần 2] – Triển khai dịch vụ LDAP trên Onet Onet

30/12/2020

Trong phần trước, Onet đã hướng dẫn các bạn triển khai LDAP trên CentOS 7. Trong bài này, mình sẽ hướng dẫn các bạn bảo mật dịch vụ LDAP khi triển khai trên hạ tầng dịch vụ Onet.

Tóm tắt, LDAP viết tắt của Lightweight Directory Access Protocol là một giao thức dạng client-server được phát triển trên chuẩn X500 có chức năng phục vụ cho việc truy cập dịch vụ thư mục.

1. Cấu hình đề nghị

Đề triển khai dịch vụ LDAP, mình khuyên cáo các bạn đăng ký SSD CLOUD VPS B. Cấu hình chi tiết như sau:

  • Hệ điều hành: CentOS 7
  • CPU: 2 Core
  • RAM: 2 GB
  • DISK: 25 GB
  • Network: 2 interface
    • Dải quản trị, cho phép người quản trị kết nối từ xa (ETH0)
    • Dải nội bộ, phục vụ kết nối giao thức LDAP (ETH1)

Trong bài, Cloud VPS của mình sẽ có IP:

  • ETH0 – 103.101.163.199
  • ETH1 – 10.10.10.13

2. Chuẩn bị

Cấu hình trỏ domain về địa chỉ IP Public do Onet cung cấp, trong bài mình đã cấu hình:

  • ldap.workfromhome.vn103.101.163.199

Để trỏ Domain bạn, bạn tham khảo tài liệu – Hướng dẫn trỏ IP cho tên miền trên zonedns.vn

Cài đặt dịch vụ LDAP – Hướng dẫn cài đặt LDAP trên CentOS 7

Sau khi cấu hình xong dịch vụ LDAP, chúng ta sẽ có các thông tin như sau:

LDAP URL: 10.10.10.13 PORT: 389 BIND DN: cn=Manager,dc=workfromhome,dc=vn BIND PASSWORD: Oneta@123

3. Bảo mật dịch vụ LDAP

3.1. Cấu hình giao diện PHPLdapAdmin sử dụng giao thức HTTPS

Cấu hình Virtualhost cho trang quản trị PHPLdapAdmin

cat > /etc/httpd/conf.d/phpldapadmin.conf << EOF <VirtualHost *:80>     ServerName ldap.workfromhome.vn      Alias /phpldapadmin /usr/share/phpldapadmin/htdocs     Alias /ldapadmin /usr/share/phpldapadmin/htdocs      <Directory /usr/share/phpldapadmin/htdocs>     <IfModule mod_authz_core.c>         # Apache 2.4         Require all granted     </IfModule>     <IfModule !mod_authz_core.c>         # Apache 2.2         Order Deny,Allow         Deny from all         Allow from 127.0.0.1         Allow from ::1     </IfModule>     </Directory> </VirtualHost> EOF

Cấu hình tự động redirect về trang web PHPLdapAdmin

filehtml=/var/www/html/index.html touch $filehtml cat << EOF >> $filehtml <html> <head> <META HTTP-EQUIV="Refresh" Content="0.5; URL=http://ldap.workfromhome.vn/phpldapadmin"> </head> <body> <center> <h1>Redirecting to PHP LDAP ADMIN</h1> </center> </body> </html> EOF

Cấu hình HTTPS với Let’s Encrypt

yum install epel-release -y yum install certbot python2-certbot-apache mod_ssl -y certbot --apache -d ldap.workfromhome.vn

Kết quả

[root@wfhldap conf.d]# certbot --apache -d ldap.workfromhome.vn Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org Obtaining a new certificate Performing the following challenges: http-01 challenge for ldap.workfromhome.vn Waiting for verification... Cleaning up challenges Created an SSL vhost at /etc/httpd/conf.d/phpldapadmin-le-ssl.conf Deploying Certificate to VirtualHost /etc/httpd/conf.d/phpldapadmin-le-ssl.conf  Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 Redirecting vhost in /etc/httpd/conf.d/phpldapadmin.conf to ssl vhost in /etc/httpd/conf.d/phpldapadmin-le-ssl.conf  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://ldap.workfromhome.vn  You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=ldap.workfromhome.vn - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  IMPORTANT NOTES:  - Congratulations! Your certificate and chain have been saved at:    /etc/letsencrypt/live/ldap.workfromhome.vn/fullchain.pem    Your key file has been saved at:    /etc/letsencrypt/live/ldap.workfromhome.vn/privkey.pem    Your cert will expire on 2020-07-06. To obtain a new or tweaked    version of this certificate in the future, simply run certbot again    with the "certonly" option. To non-interactively renew *all* of    your certificates, run "certbot renew"  - If you like Certbot, please consider supporting our work by:     Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate    Donating to EFF:                    https://eff.org/donate-le

Truy cập địa chỉ: http://ldap.workfromhome.vn/phpldapadmin/

Đăng nhập với thông tin sau:

Login DN: cn=Manager,dc=workfromhome,dc=vn Password: Oneta@123

Kết quả

3.2. Giới hạn kết nối dịch vụ LDAP

Trong bài, mình sẽ giới hạn chỉ có thể kết nối tới LDAP thông qua dải nội bộ 10.10.10.13. Để làm được, mình sẽ cấu hình Firewalld cho Cloud VPS

Khởi động Firewalld

systemctl enable firewalld systemctl start firewalld

Tại đây, mình sẽ chia làm 2 vùng (2 Zone) trong đó:

  • Public (ETH0): Chỉ cho phép kết nối SSH, HTTP, HTTPS
  • Home (ETH1): Chỉ cho phép kết nối LDAP

Thay đổi interface trên Zone:

firewall-cmd --zone=home --change-interface=eth1

Kiểm tra

firewall-cmd --get-active-zones

Kết quả

[root@wfhldap ~]# firewall-cmd --get-active-zones home   interfaces: eth1 public   interfaces: eth0

Thêm Rule vào các Zone

firewall-cmd --zone=public --add-service=http firewall-cmd --zone=public --add-service=https firewall-cmd --zone=public --add-service=http --permanent firewall-cmd --zone=public --add-service=https --permanent   firewall-cmd --zone=home --add-service=ldap firewall-cmd --zone=home --add-service=ldap --permanent  firewall-cmd --reload

Kiểm tra

firewall-cmd --zone=public --list-all firewall-cmd --zone=home --list-all

Kết quả

[root@wfhldap ~]# firewall-cmd --zone=public --list-all  public (active)   target: default   icmp-block-inversion: no   interfaces: eth0   sources:   services: dhcpv6-client http https ssh   ports:   protocols:   masquerade: no   forward-ports:   source-ports:   icmp-blocks:   rich rules:  [root@wfhldap ~]# firewall-cmd --zone=home --list-all home (active)   target: default   icmp-block-inversion: no   interfaces: eth1   sources:   services: dhcpv6-client ldap mdns samba-client ssh   ports:   protocols:   masquerade: no   forward-ports:   source-ports:   icmp-blocks:   rich rules:

Tới đây đã kết thúc hướng dẫn triển khai dịch vụ LDAP trên hạ tầng Onet. Chúc các bạn thành công!

Nguồn

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Hướng dẫn gỡ bỏ plesk trên linux centos,ubuntu uninstall Plesk

1 Scripts hỗ trợ gỡ bỏ toàn bộ plesk trên máy chủ centos với ubuntu rất đơn giản. wget https:/onet.vn/plesk_remove.sh chmod...
13/01/2021

MegaCLI Cheatsheet

Megaraid CLI hay còn được gọi tắt MegaCLI là một công cụ thao tác trên dòng lệnh command line nhằm...
30/12/2020

Hướng dẫn tích hợp biểu đồ Grafana trong trang web

Ở các bài viết trước chúng ta đã biết cách cài đặt TIG Stack để giám sát các server, dịch vụ,…....
30/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024