티스토리 뷰

Server/EtcServer

OpenLDAP

Jacob_baek 2012. 5. 8. 09:32

LDAP(Lightweight Directory Access Protocol)

TCP/IP 위에서 디렉토리 서비스를 조회하고 수정하는 응용 프로토콜
디렉토리 서비스의 하나로 자원(파일이나 장치 등)의 위치를 찾을수 있게 해주는 소프트웨어

Directory Service 란?
아래와 같이 대표적으로 사용되어진다.

  • 장치/사용자 인증
  • 사용자/시스템 그룹
  • 자산 추적, 이메일 주소 검색
  • 사용자 자원 관리
  • 어플리케이션 설정 저장 등..
    간략히 정의하자면 데이터베이스이고 잦은 요청이 일어나나 업데이트는 드물게 하도록 구현된 데이터베이스이다.
    실제 다량의 lookup이나 검색연산이 이루어지고 이를 빠르게 응답하는 과정이 주 목적이된다.

참고로 아래 링크는 LDAP에 대한 기본적인 개념을 잡기 좋다.

OpenLDAP 기본 용어 및 개념들

LDAP 서비스중 OpenSource 제품인 OpenLDAP을 기준으로 사용되는 용어 및 관련 개념들을 알아보자.

주요용어

  • SLAPD(Stand alone LDAP Daemon): https://en.wikipedia.org/wiki/Slapd
    실제 openldap 서버 slapd
  • SLURPD(Stand alone LDAP update replication daemon):
    복제를 통한 이중화의 개념으로 LDAP을 운영할수 있게 해주는 Daemon
  • LDIF(LDAP Data Interchange Format): https://en.wikipedia.org/wiki/LDAP_Data_Interchange_Format
    LDAP 디렉토리 content와 요청에 대한 업데이트에 대한 표준 Plain Text data 교환 format이다.
    즉, LDAP 디렉토리 content에 대한 표현 및 업데이트 등을 수행하는 format 이라 보면 된다.
    구성은 dn,dc,ou,cn으로 이루어지며 예제는 다음과 같다.
  • dn: cn=The Postmaster,dc=example,dc=com objectClass: organizationalRole cn: The Postmaster
  • CN (common Name)
  • DN (Distinguish Name)
  • LDAPI(ldap url) : https://ldapwiki.com/wiki/LDAPI
    LDAPI는 TCP 세션대신 IPC 매커니즘을 사용하는 LDAP의 축약형 통신방법이다.
  • SASL : http://www.openldap.org/doc/admin24/sasl.html

일반적인 설정을 아래 명령으로 확인해볼수 있다.

I have no name!@openldap-844f77bdd6-69xck:/$ ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=1001,cn=peercred,cn=external,cn=auth
SASL SSF: 0
# extended LDIF
#
# LDAPv3
# base <cn=config> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# config
dn: cn=config
objectClass: olcGlobal
cn: config
olcArgsFile: /opt/bitnami/openldap/var/run/slapd.args
olcPidFile: /opt/bitnami/openldap/var/run/slapd.pid

# schema, config
dn: cn=schema,cn=config
objectClass: olcSchemaConfig
cn: schema
olcObjectIdentifier: OLcfg 1.3.6.1.4.1.4203.1.12.2
olcObjectIdentifier: OLcfgAt OLcfg:3
olcObjectIdentifier: OLcfgGlAt OLcfgAt:0
olcObjectIdentifier: OLcfgBkAt OLcfgAt:1
olcObjectIdentifier: OLcfgDbAt OLcfgAt:2
olcObjectIdentifier: OLcfgOvAt OLcfgAt:3
olcObjectIdentifier: OLcfgCtAt OLcfgAt:4
olcObjectIdentifier: OLcfgOc OLcfg:4

...

# {0}core, schema, config
dn: cn={0}core,cn=schema,cn=config
objectClass: olcSchemaConfig
cn: {0}core
olcAttributeTypes: {0}( 2.5.4.2 NAME 'knowledgeInformation' DESC 'RFC2256: kno
 wledge information' EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.
 1.15{32768} )
olcAttributeTypes: {1}( 2.5.4.4 NAME ( 'sn' 'surname' ) DESC 'RFC2256: last (f
 amily) name(s) for which the entity is known by' SUP name )

... 

 # {0}bdb, config
dn: olcBackend={0}bdb,cn=config
objectClass: olcBackendConfig
olcBackend: {0}bdb

# {-1}frontend, config
dn: olcDatabase={-1}frontend,cn=config
objectClass: olcDatabaseConfig
objectClass: olcFrontendConfig
olcDatabase: {-1}frontend

# {0}config, config
dn: olcDatabase={0}config,cn=config
objectClass: olcDatabaseConfig
olcDatabase: {0}config
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=1001,cn=peercred,cn=exter
 nal,cn=auth" manage by * none

# {1}monitor, config
dn: olcDatabase={1}monitor,cn=config
objectClass: olcDatabaseConfig
olcDatabase: {1}monitor
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external
 , cn=auth" read by dn.base="cn=admin,dc=jacobbaek,dc=com" read by * none

# {2}hdb, config
dn: olcDatabase={2}hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {2}hdb
...

주요구성

LDAP 구성

slapd가 동작되는 LDAP 서버와 이를 조회하는 client 로 나뉘어질수 있다.
실제 client는 조회에 대해서만 기록한것이며 LDAP 인증을 연동할 application이 될수 있다.

LDAP Server 구성방법

package 설치를 이용

kustomize 이용

아래는 kustomize를 이용한 openldap 배포이다.

helm chart 이용

docker-compose 이용

LDAP client

LDAPSearch tool

yum install openldap-clients nss-pam-ldapd pam_krb5

openldap-clients를 설치하면 ldapsearch command를 사용할 수 있다.

ldapsearch -x -H ldap:///
# extended LDIF
#
# LDAPv3
# base <> (default) with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# search result
search: 2
result: 32 No such object

# numResponses: 1

phpldapadmin

openldap과 함께 phpldapadmin이라는 web service가 많이 사용되고 있다.
phpldapadmin은 php admin web 기반에 LDAP 관리 도구이다.

sshpublickey 항목이 포함된 template 설정

phpldapadmin에 아래와 같은 속성정보가 확인됨.

objectclass 에 아래 ldappublickey 추가
attribute 에 아래 sshpublickey 추가

sshpublickey 10 1

LDIF 파일을 통한 ldap object 변경

openldap을 사용하면서 제일 애매했던 부분이 object의 수정부분이다.
이를 어떤 경우는 ldapvi 와 같은 직접 파일 변경방식으로도 할수 있었지만 주석으로 해당 파일마다 기입되어 있던 방식은
ldapmodify를 이용해달라는 권장안이었다.

권장되는 방식인 ldapmodify를 이용하기 위해선 LDIF 파일을 생성하여 ldapmodify와 함께 적용을 해야한다.
아래 예제가 포함된 링크를 참고하여 LDIF 파일 생성 및 ldapmodify/ldapadd 등을 수행해보자.

ldif examples

dn: olcDatabase={2}hdb,cn=config
changetype: add
add: olcAccess
olcAccess: {1} to dn.subtree="ou=users,dc=jacobbaek,dc=com" by
 dn="cn=admin,dc=jacobbaek,dc=com" write
dn: cn=jacob,ou=users,dc=jacobbaek,dc=com
changetype: modify
add: mail
mail: jacob@jacobbaek.com

아래와 같이 수정작업도 가능하며 멀티로도 수행이 가능하다.

dn: cn=testuser1,ou=users,dc=jacobbaek,dc=com
changetype: modify
replace: cn
cn: testuser1

dn: cn=jacob,ou=users,dc=jacobbaek,dc=com
changetype: modify
replace: cn
cn: jacob

위 ldif 파일들은 다음 ldapmodify 명령을 통해 적용이 가능하다.

ldapmodify -H ldapi:// -Y EXTERNAL -f file.ldif

admin password 변경
rootPW 변경을 하고자 할 경우 아래와 같이 조회를 통해 olcDatabaseConfig의 dn을 확인하고

root@openldap-6c455d9f45-xcqnd:/$ ldapsearch -Q -Y EXTERNAL -H ldapi:/// -b cn=config '(objectClass=olcHdbConfig)'
# extended LDIF
#
# LDAPv3
# base <cn=config> with scope subtree
# filter: (objectClass=olcHdbConfig)
# requesting: ALL
#

# {2}hdb, config
dn: olcDatabase={2}hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {2}hdb

확인된 dn을 기반으로 아래와 같은 LDIF 파일을 생성하여

root@openldap-6c455d9f45-xcqnd:/$ cat adminpw.ldif
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}+HMwK1EKhYgNdIW7xL4/BGm/HdjK09Wc

ldapmodify로 적용을 하면 된다.

ldapmodify -H ldapi:// -Y EXTERNAL -f adminpw.ldif

Issues

ACL Update

아래와 같은 acl 문제로 특정 필드의 value update가 이루어지지 않았다.

Insufficient access (LDAP_INSUFFICIENT_ACCESS)

하여 다음과 같은 환경변수 추가 및 ldapvi 명령을 수행하여 olcAccess 항목을 수정한다.

root@openldap-6c455d9f45-xcqnd:/etc/ldap/slapd.d/cn=config# cat ~/.ldaprc 
TLS_CERT /container/run/service/slapd/assets/certs/ldap.crt
TLS_KEY /container/run/service/slapd/assets/certs/ldap.key
HOST localhost
BASE dc=hanu-ci,dc=io
BINDDN cn=admin,dc=hanu-ci,dc=io

root@openldap-6c455d9f45-xcqnd:/etc/ldap/slapd.d/cn=config# ldapvi -h ldapi:/// -Y EXTERNAL -b cn=config

기존에는 olcAccess에 self read 로 설정되어 있었고 self write로 변경하여 수정이 가능하도록 한다.

olcAccess: {0}to attrs=userPassword,shadowLastChange by self write by dn="cn=admin,dc=hanu-ci,dc=io" write by anonymous auth by * none

## 기존 olcAccess 
# olcAccess: {1}to * by self read by dn="cn=admin,dc=jacobbaek,dc=com" write by * none

## 변경된 olcAccess
olcAccess: {1}to * by self write by dn="cn=admin,dc=jacobbaek,dc=com" write by * none

이후 저장하면 정상적으로 write가 이루어진다.

권장방법
가능한 ldapmodify를 이용하는것을 권장하기에 아래와 같이 ldapsearch로 object 조회 및 확인하고 ldapmodify를 이용하여 변경사항을 적용하는것이 좋다.
먼저 ldapsearch로 cn=config 를 검색해보면 아래와 같은 객체들을 확인한다.

root@openldap-6c455d9f45-xcqnd:/# ldapsearch  -Y EXTERNAL -H ldapi:/// -b cn=config 'olcDatabase={1}hdb'
\SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
# extended LDIF
#
# LDAPv3
# base <cn=config> with scope subtree
# filter: olcDatabase={1}hdb
# requesting: ALL
#

# {1}hdb, config
dn: olcDatabase={1}hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {1}hdb
olcDbDirectory: /var/lib/ldap
olcSuffix: dc=hanu-ci,dc=io
olcAccess: {0}to attrs=userPassword,shadowLastChange by self write by dn="cn=a
 dmin,dc=hanu-ci,dc=io" write by anonymous auth by * none
olcAccess: {1}to * by self read by dn="cn=admin,dc=hanu-ci,dc=io" write by * n
 one
olcLastMod: TRUE
olcRootDN: cn=admin,dc=hanu-ci,dc=io
olcRootPW: {SSHA}JuUhUei+Ot2Xnol5g03Bvz0l35MtDWQF
olcDbCheckpoint: 512 30
olcDbConfig: {0}set_cachesize 0 2097152 0
olcDbConfig: {1}set_lk_max_objects 1500
olcDbConfig: {2}set_lk_max_locks 1500
olcDbConfig: {3}set_lk_max_lockers 1500
olcDbIndex: uid eq
olcDbIndex: mail eq
olcDbIndex: memberOf eq
olcDbIndex: entryCSN eq
olcDbIndex: entryUUID eq
olcDbIndex: objectClass eq

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1

이중 olcAccess 속성이 ACL을 의미한다.

아래 명령으로 database 정보를 확인

ldapsearch -Q -Y EXTERNAL -H ldapi:/// -b 'cn=config' "(olcDatabase=*)"

ldif 파일 생성

dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcAccess
olcAccess: {0}to * by dn.base="ou=users,gidNumber=0+uidNumber=1001,cn=peercred,cn=ext
 ernal,cn=auth" manage by * none

ldapmodify로 적용

조회된 object에 매칭되는 내용을 LDIF 파일로 생성하여 이를 ldapmodify로 적용한다.

ldap_sasl_bind(SIMPLE): Can's contact LDAP server (-1) error message 출력시

/etc/openldap/ldap.conf 내에 아래 주석을 해제 및 추가

# URI ldap://localhost:389 ldap://192.168.1.1:389

ldap log내 "SEARCH RESULT tag=101 err=0 nentries=1 text=" 출력

참고로 아래 링크를 보고 확인하였다.

다양한 tag code가 아래에 설명되어 있으니 이를 참고한다.

참고사이트

'Server > EtcServer' 카테고리의 다른 글

Graylog  (0) 2017.10.12
jenkins with scp plugin  (0) 2013.01.30
wiki engine  (0) 2013.01.04
install vmplayer in ubuntu  (0) 2012.08.06
Net-Snmp  (0) 2012.05.02
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함