manywaypark's Blog
개발, 검색, 함수

'OPENLDAP'에 해당되는 글 1건

  1. 2013.04.14 OpenLDAP(slapd) 설치 및 설정

OpenLDAP(slapd)의 설치 및 설정에 관해서 간단히 알아본다.
언제나 그렇듯 Ubuntu (12.04.2 LTS) 기준이다.
Ubutu 10.04부터 OpenLDAP 기본 패키지 설치는 RTC(RunTime Configuration)를 사용한다.
(예전에 내가 알던 그 slapd.conf 방식이 아닌 것이다. 한참 삽질한 후에 알았다. Orz)
ldap-utils에 포함된 도구를 사용해서 그냥 일반적인 레코드 수정하듯이 cn=config의 엔트리를 조작하면 된다. 이름대로 변경하면 반영된다고 한다.

준비:
먼저 테스트 접속을 위해 Apache Directory Studio(이하 ADS)를 다운 받아 설치한다.

설치:

$ sudo apt-get install slapd ldap-utils

설치 과정에서는 admin password만 입력하면 된다.

설정: (dc 등이 제대로 설정되지 않을 때만 필요. hostname 설정이 제대로 되어 있다면 설치 과정에서 dc도 제대로 설정되었을 것이다.)

$ sudo dpkg-reconfigure slapd

주의 깊게 설명을 읽고 답변을 선택하거나 값을 입력한다 (내 경우에는 dc를 입력하는 것 말고는 별달리 할 것이 없다). DB 지우는 것을 물어보는 부분이 조금은 혼란을 일으키지만, Yes로 답하면 된다 (방금 설치했는데 뭘...)

여기서부터 편의 상 dc설정을 "dc=foo,dc=bar"로 가정한다.
확인하려면 대충 이렇게 해보자;

$ sudo ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config | grep cn=admin


시험:
ADS에서 새로운 연결을 만든다.
왼쪽 아래에 보면 Connections pane이 있고 LDAP+ 아이콘이 있다. 클릭!
Network Parameter 입력:

Connection name: 연결이름 아무거나
Hostname: 호스트의 FQDN 또는 IP 주소
Port: 389 (기본값)
Encryption method: No encryption (기본값)
Provider: Apache Directory LDAP Client API (기본값)

입력후 Check Network Parameter 버튼을 눌러서 확인.
성공했다면 Next로 가서 인증정보를 입력한다.

Authentication 입력:

Authentication Method: Simple Authentication
Bind DN or user: cn=admin,dc=foo,dc=bar
Bind password: [package 설치시 입력했던 password]

입력후 Check Authentication 버튼을 눌러서 확인.

TLS 설정:
참조링크에 자세히 나오는데, 그대로 발췌했다.

Here, we will be our own Certificate Authority and then create and sign our LDAP server certificate as that CA. Since slapd is compiled using the gnutls library, we will use the certtool utility to complete these tasks.

  1. Install the gnutls-bin and ssl-cert packages:

    sudo apt-get install gnutls-bin ssl-cert
    
  2. Create a private key for the Certificate Authority:

    sudo sh -c "certtool --generate-privkey > /etc/ssl/private/cakey.pem"
    
  3. Create the template/file /etc/ssl/ca.info to define the CA:

    cn = Example Company
    ca
    cert_signing_key
    
  4. Create the self-signed CA certificate:

    sudo certtool --generate-self-signed \
    --load-privkey /etc/ssl/private/cakey.pem \ 
    --template /etc/ssl/ca.info \
    --outfile /etc/ssl/certs/cacert.pem
    
  5. Make a private key for the server:

    sudo certtool --generate-privkey \
    --bits 1024 \
    --outfile /etc/ssl/private/ldap01_slapd_key.pem
    

    Replace ldap01 in the filename with your server's hostname. Naming the certificate and key for the host and service that will be using them will help keep things clear.

  6. Create the /etc/ssl/ldap01.info info file containing:

    organization = Example Company
    cn = ldap01.example.com
    tls_www_server
    encryption_key
    signing_key
    expiration_days = 3650
    

    The above certificate is good for 10 years. Adjust accordingly.

  7. Create the server's certificate:

    sudo certtool --generate-certificate \
    --load-privkey /etc/ssl/private/ldap01_slapd_key.pem \
    --load-ca-certificate /etc/ssl/certs/cacert.pem \
    --load-ca-privkey /etc/ssl/private/cakey.pem \
    --template /etc/ssl/ldap01.info \
    --outfile /etc/ssl/certs/ldap01_slapd_cert.pem
    

Create the file certinfo.ldif with the following contents (adjust accordingly, our example assumes we created certs using https://www.cacert.org):

dn: cn=config
add: olcTLSCACertificateFile
olcTLSCACertificateFile: /etc/ssl/certs/cacert.pem
-
add: olcTLSCertificateFile
olcTLSCertificateFile: /etc/ssl/certs/ldap01_slapd_cert.pem
-
add: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/ssl/private/ldap01_slapd_key.pem

Use the ldapmodify command to tell slapd about our TLS work via the slapd-config database:

sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f /etc/ssl/certinfo.ldif

Contratry to popular belief, you do not need ldaps:// in /etc/default/slapd in order to use encryption. You should have just:

SLAPD_SERVICES="ldap:/// ldapi:///"

LDAP over TLS/SSL (ldaps://) is deprecated in favour of StartTLS. The latter refers to an existing LDAP session (listening on TCP port 389) becoming protected by TLS/SSL whereas LDAPS, like HTTPS, is a distinct encrypted-from-the-start protocol that operates over TCP port 636.

Tighten up ownership and permissions:

sudo adduser openldap ssl-cert
sudo chgrp ssl-cert /etc/ssl/private/ldap01_slapd_key.pem
sudo chmod g+r /etc/ssl/private/ldap01_slapd_key.pem
sudo chmod o-r /etc/ssl/private/ldap01_slapd_key.pem

Restart OpenLDAP:

sudo service slapd restart

Check your host's logs (/var/log/syslog) to see if the server has started properly.


TLS 시험:
ADS에서 새로운 연결을 하나 만들어서 테스트한다. 연결설정에서 다른 설정들은 모두 이전과 같이 하고 Encryption methodUse StartTLS extension으로 선택한다.
연결시 인증서 관련 경고 비슷한게 나오는데, 사설(self-signed) 인증서라 그런 것이므로 무시하고, trust하는 것으로....

refs:
https://help.ubuntu.com/12.10/serverguide/openldap-server.html

https://help.ubuntu.com/community/OpenLDAPServer

http://www.openldap.org/faq/data/cache/185.html

happy hackin'

1 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-20 18:28