OpenLDAP Proxy -- Installation and configuration

English 简体中文 繁体中文 ภาษาไทย Tiếng Việt
Summary

Installing and configuring an OpenLDAP proxy can be accomplished through either a local setup or a Docker-based deployment. For a local installation, developers typically install OpenLDAP server and client packages, update the `slapd.conf` file, regenerate the configuration directory, adjust ownership, and restart the `slapd` service. Alternatively, a Docker setup involves creating a `Dockerfile` to build an image with the necessary packages and configuration, a `start.sh` script to generate SSL certificates and serve as the container's entry point, and a `docker-compose.yml` file to define and run the proxy service with port mappings and volume mounts. Both approaches offer clear steps to get an OpenLDAP proxy operational.

หลังจากเข้าใจ การกำหนดค่าพร็อกซี OpenLDAP จะเป็นอย่างไร แล้ว ถึงเวลาอธิบายการติดตั้งพร็อกซี OpenLDAP และวิธีการใช้งาน ในโพสต์นี้ เราจะกล่าวถึงวิธีการติดตั้งพร็อกซี OpenLDAP ทั้งแบบโลคอลและแบบใช้ docker

การติดตั้งแบบโลคอล

การติดตั้งค่อนข้างง่าย มีแพ็คเกจอยู่ไม่กี่แพ็คเกจที่จะต้องติดตั้ง รวมถึงเซิร์ฟเวอร์ ldap ไคลเอนต์ ldap และยูทิลิตี้บางอย่าง ขั้นตอนด้านล่างนี้ใช้สำหรับ CentOS คำแนะนำสำหรับแพลตฟอร์มอื่นๆ ควรจะคล้ายคลึงกัน โดยมีความแตกต่างเล็กน้อยในชื่อแพ็คเกจและตำแหน่งของแพ็คเกจ

  1. ติดตั้ง openldap openldap-clients openldap-servers
    yum install openldap openldap-clients openldap-servers
  2. สร้าง /etc/openldap/slapd.conf ถ้ายังไม่มี
  3. อัปเดต /etc/openldap/slapd.conf เพิ่มรายการ LDAP (ตรวจสอบโพสต์ก่อนหน้าเกี่ยวกับการกำหนดค่า)
  4. ลบเนื้อหาปัจจุบันของ /etc/openldap/slapd.d/
    rm -rf /etc/openldap/slapd.d/*
  5. สร้างการกำหนดค่าใหม่
    slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/
  6. เปลี่ยนเจ้าของไดเร็กทอรีการกำหนดค่าเป็น ldap. สำหรับ Ubuntu คือ openldap.
    chown -R ldap:ldap /etc/openldap/slapd.d
  7. เริ่มบริการ slapd ใหม่
    /etc/init.d/slapd restart

สิ่งนี้ควรจะทำให้พร็อกซี OpenLDAP ทำงานพร้อมกับการกำหนดค่าที่คุณต้องการ ถ้าคุณไม่ต้องการใช้การกำหนดค่าแบบ LDIF คุณสามารถลบโฟลเดอร์ /etc/ldap/slapd.d หลังจากอัปเดตไฟล์ /etc/ldap/slapd.conf แล้ว

การตั้งค่า Docker

Docker ได้กลายเป็นวิธีการยอดนิยมในการโฮสต์บริการเดียวสำหรับวัตถุประสงค์เฉพาะ พร็อกซี OpenLDAP เหมาะสมอย่างยิ่งกับโมเดลนี้ ดังนั้นเราจะแนะนำวิธีการตั้งค่าพร็อกซี OpenLDAP โดยใช้ Docker และ docker-compose ถ้าคุณไม่ทราบเกี่ยวกับยูทิลิตี้เหล่านี้ โปรดอ่านแหล่งข้อมูลออนไลน์ก่อน

ขั้นตอนในการตั้งค่าพร็อกซี OpenLDAP คือ:

  1. สร้างไดเร็กทอรีชื่อ openldap_proxy คุณสามารถเลือกชื่อใดก็ได้ และเข้าไปในไดเร็กทอรี openldap_proxy
  2. สร้าง Dockerfile และใส่เนื้อหาดังต่อไปนี้ (นี่เป็นเพียงตัวอย่าง)
    # ดึงภาพพื้นฐานจากแหล่งที่ได้รับอนุญาต
    FROM centos:7
    
    # ติดตั้งแพ็คเกจที่จำเป็นสำหรับเซิร์ฟเวอร์พร็อกซี LDAP
    RUN yum install openldap openldap-clients openldap-servers -y
    
    # สร้างไดเร็กทอรีที่จำเป็น
    RUN mkdir -p /root/openldap_proxy && \
        mkdir -p /root/openldap_proxy/tmp && \
        mkdir -p /root/openldap_proxy/data && \
        mkdir -p /root/openldap_proxy/data/certs
    
    # ลบไดเร็กทอรีที่ไม่จำเป็น
    RUN rm -rf /etc/openldap/slapd.d
    
    # คัดลอกไฟล์ไปยังคอนเทนเนอร์
    COPY ./start.sh /root/openldap_proxy/start.sh
    COPY ./slapd.conf /etc/openldap/slapd.conf
    
    # เพิ่มสิทธิ์การใช้งาน
    RUN chmod 755 /root
    RUN chmod +x /root/openldap_proxy/start.sh
    
    # จุดเริ่มต้น
    ENTRYPOINT ["/root/openldap_proxy/start.sh"]
  3. บันทึก Dockerfile
  4. วางไฟล์ slapd.conf ในไดเร็กทอรี openldap_proxy และสร้างไฟล์ชื่อ start.sh ใน openldap_proxy
  5. ใน start.sh ให้ใส่เนื้อหาดังต่อไปนี้
    #!/bin/bash
    
    TOPDIR=$(dirname $0)
    cd $TOPDIR && TOPDIR=$PWD
    
    # สร้างใบรับรองถ้ายังไม่มี
    DESTDIR="$TOPDIR/data/certs"
    APP_FQDN=$(hostname -f)
    
    [[ -d $DESTDIR ]] || mkdir -p $DESTDIR
    
    APP_GEN_CERT='openssl req -x509 -nodes -days 365 -newkey rsa:2048'
    APP_GEN_CERT="$APP_GEN_CERT -keyout $DESTDIR/ldap.key -out $DESTDIR/ldap.crt"
    APP_GEN_CERT="$APP_GEN_CERT -subj '/CN=$APP_FQDN/OU=TestOU/O=Organization/L=Location/ST=State/C=Country'"
    APP_GEN_CERT="[[ -f $DESTDIR/ldap.crt ]] || $APP_GEN_CERT"
    
    eval $APP_GEN_CERT
    
    # เรียกใช้คำสั่ง docker-compose
    exec "$@"
  6. start.sh คือจุดเริ่มต้นของคอนเทนเนอร์ Docker และจะถูกคัดลอกไปยังคอนเทนเนอร์และเรียกใช้เมื่อคอนเทนเนอร์ Docker เริ่มต้น สคริปต์จะสร้างใบรับรองก่อนซึ่งจะถูกใช้โดยพร็อกซีถ้าให้บริการคำขอ SSL และจากนั้นจะจัดการการดำเนินการไปยังคำสั่งที่ส่งไปยัง start.sh ซึ่งจะเป็นตัวเลือก command ใน docker-compose.yml ที่จะสร้างขึ้นในภายหลัง 
  7. สร้างภาพ Docker ชื่อ my_openldap_proxy. 
    docker build -t my_openldap_proxy .
  8. ถัดไปออกไปหนึ่งระดับของไดเร็กทอรี openpldap_proxy (cd ../)
  9. สร้างไฟล์ docker-compose.yml พร้อมเนื้อหาดังต่อไปนี้
    my_openldap_proxy:
      image: my_openldap_proxy:latest
      container_name: my_openldap_proxy
      ports:
        - '389:389'
        - "636:636"
      volumes:
        - shared_data:/root/openldap_proxy/data
      command: bash -l -c "cd /root/openldap_proxy && /usr/sbin/slapd -h 'ldap:/// ldapi:/// ldaps:///' -g ldap -u ldap -d 2"
  10. บันทึกแล้วเรียกใช้คำสั่ง docker-compose up -d คำสั่งนี้จะสร้างคอนเทนเนอร์ถ้ายังไม่มีและเริ่มต้นในโหมดที่แยกออกจากกัน 

ขั้นตอนการติดตั้งที่ง่ายมาก จะมีการตั้งค่าอื่นๆ ถ้าคุณต้องการเพิ่มเซิร์ฟเวอร์ LDAP ระยะไกลที่เปิดใช้งาน SSL ในการกำหนดค่าของคุณ เราจะกล่าวถึงในโพสต์ต่อไป โปรดติดตาม

INSTALLATION CENTOS DOCKER OPENLDAP OPENLDAP PROXY

  RELATED

  COMMENTS

0

No comment for this article.