티스토리 뷰

LDAP: 네트워크 상에서 조직이나 개인정보 혹은 파일이나 디바이스 정보 등을 찾아 보는 것을 가능하게 만든 소프트웨어 프로토콜. LDAP의 구조는 총 4가지 모델로 나눌 수 있습니다.

 

Information 모델: LDAP의 데이터에 대한 종류와 디렉토리에 저장되는 정보에 대한 기본단위를 정의. Entries, Attributes, Values 등 3가지로 정의

 

  • Entry

디렉토리 정보에 대한 기본단위이며, 속성(attributes)으로 구성된다. attribute는 하나 이상의 값(value)로 구성되고 모든 attribute는 하나 이상의 objectClass로부터 정의된다. 각각의 Entry는 DN(Distinguish Name)으로 구분되고 Tree구조를 형성합니다. 이러한 Tree형태의 구조를 DIT(Directory Information Tree)라고 칭합니다.

  • Attributes

Entry를 구성하는 단위이며 각 Attribute마다 Type과 Value가 존재합니다.

 

  • Value

Attribute의 실질적인 데이터를 나타냅니다. 또한 Value는 Sytax와 Matching Rules와 관련이 있습니다.

 


LDAP RUN

▶ LDAP_DOMAIN의 base domain을 입력하고 LDAP WEB은 PHPldapadmin으로 실행시킬것이기 때문에 traefik.enable false 옵션을 줍니다.

docker run \
  --detach \
  --name ldap \
  --restart=always \
  --network hskim-net \
  --publish 389:389 \
  --env LDAP_ORGANISATION='hskim' \
  --env LDAP_DOMAIN='hskim.kr' \
  --env LDAP_ADMIN_PASSWORD='hskim123#@!' \
  --env LDAP_CONFIG_PASSWORD='hskim123#@!' \
  --mount type=volume,src=ldapdb,dst=/var/lib/ldap \
  --mount type=volume,src=ldapconfig,dst=/etc/ldap/slapd.d \
  --label traefik.enable=false \
  osixia/openldap

LDAP RUN WEB

▶ 실제로 LDAP WEB으로 접속할 수 있는 PHPldapadmin을 실행시킵니다. 똑같이 traefik.port 80 및 frontend.rule를 지정해줍니다.

docker run \
  --detach \
  --name ldapadmin \
  --restart=always \
  --network hskim-net \
  --env PHPLDAPADMIN_LDAP_HOSTS=ldap \
  --env PHPLDAPADMIN_HTTPS=false \
  --mount type=volume,src=ldapadmin,dst=/container/service/phpldapadmin/assets/config \
  --mount type=volume,src=ldapadmin-conf,dst=/var/www/phpldapadmin \
  --label traefik.port=80 \
  --label traefik.frontend.rule=Host:ldapadmin.hskim.kr \
  osixia/phpldapadmin

LDAP Config

아래의 정보는 LDIF(LDAP Data interchange Format)형식으로 작성된 entry의 모습입니다. RDN은 "dc=example, dc=com"이며. dc는 suffix(naming context)라고 하는데, 일반적으로 도메인이름을 사용합니다.

vi /data/volumes/ldapadmin-conf/_data/config
$servers->newServer('ldap_pla');
$servers->setValue('server','name','HSKIM LDAP Server');
$servers->setValue('server','host','ldap');
$servers->setValue('server','base',array('dc=docker,dc=hskim,dc=kr'));
$servers->setValue('login','bind_id','cn=admin,dc=docker,dc=hskim,dc=kr');
vi /data/volumes/ldapadmin-conf/_data/templates/creation/custom_posixAccount.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE template SYSTEM "../template.dtd">


<template>
<askcontainer>1</askcontainer>
<description>New User Account</description>
<icon>ldap-user.png</icon>
<invalid>0</invalid>
<rdn>cn</rdn>
<!--<regexp>^ou=People,o=.*,</regexp>-->
<title>hskim.kr : User Account</title>
<visible>1</visible>


<objectClasses>
<objectClass id="inetOrgPerson"></objectClass>
<objectClass id="posixAccount"></objectClass>
</objectClasses>


<attributes>
<attribute id="givenName">
        <display>First name</display>
        <icon>ldap-uid.png</icon>
        <onchange>=autoFill(cn;%givenName% %sn%)</onchange>
        <onchange>=autoFill(uid;%givenName|0-1/l%%sn/l%)</onchange>
        <order>1</order>
        <page>1</page>
</attribute>
<attribute id="sn">
        <display>Last name</display>
        <onchange>=autoFill(cn;%givenName% %sn%)</onchange>
        <onchange>=autoFill(uid;%givenName|0-1/l%%sn/l%)</onchange>
        <!-- <onchange>=autoFill(homeDirectory;/home/users/%uid|0-1/l%/%uid%)</onchange> -->
        <order>2</order>
        <page>1</page>
</attribute>
<attribute id="cn">
        <display>Common Name</display>
        <order>3</order>
        <page>1</page>
</attribute>
<attribute id="uid">
        <display>User ID</display>
        <onchange>=autoFill(homeDirectory;/home/users/%uid%)</onchange>
        <order>4</order>
        <page>1</page>
        <spacer>1</spacer>
</attribute>
<attribute id="homeDirectory">
        <display>Home directory</display>
        <!-- <onchange>=autoFill(homeDirectory;/home/users/%gidNumber|0-0/T%/%uid|3-%)</onchange> -->
        <order>8</order>
        <page>1</page>
</attribute>
<attribute id="uidNumber">
        <display>UID Number</display>
        <icon>terminal.png</icon>
        <order>6</order>
        <page>1</page>
        <readonly>1</readonly>
        <value>=php.GetNextNumber(/;uidNumber)</value>
</attribute>
<attribute id="gidNumber">
        <display>GID Number</display>
        <!-- <onchange>=autoFill(homeDirectory;/home/users/%gidNumber|0-0/T%/%uid|3-%)</onchange> -->
        <order>7</order>
        <page>1</page>
        <value><![CDATA[=php.PickList(/;(&(objectClass=posixGroup));gidNumber;%cn%;;;;cn)]]></value>
</attribute>
<attribute id="loginShell">
        <display>Login shell</display>
        <order>9</order>
        <page>1</page>
        <!-- <value><![CDATA[=php.PickList(/;(&(objectClass=posixAccount));loginShell;%loginShell%;;;;loginShell)]]></value> -->
        <type>select</type>
        <value id="/bin/bash">Bash</value>
        <value id="/bin/csh">C Shell</value>
        <value id="/bin/dash">Dash</value>
        <value id="/bin/sh">Shell</value>
        <value id="/bin/tsh">Turbo C Shell</value>
        <value id="/bin/false">False</value>
        <value id="/usr/sbin/nologin">No Login</value>
</attribute>
<attribute id="userPassword">
        <display>Password</display>
        <!-- <helper>
                <display>Encryption</display>
                <id>enc</id>
                <value>=php.PasswordEncryptionTypes()</value>
        </helper> -->
        <icon>lock.png</icon>
        <order>5</order>
        <page>1</page>
        <post>=php.PasswordEncrypt(%enc%;%userPassword%)</post>
        <spacer>1</spacer>
        <verify>1</verify>
</attribute>
<!-- add -->
<attribute id="mail">
<display>Email</display>
        <order>10</order>
        <page>1</page>
</attribute>
</attributes>


</template>

 

▶ 이제 아래 URL로 접속해서 위에서 지정했던 admin password를 입력하고 접속합니다.

http://ldap.hskim.kr

LDAP Groups 및 User 만들기

▶ Create new entry here 클릭

▶ Generic: Posix Group 클릭

▶ Generic: Group 이름을 지정해주고 User를 선택해 주고 Commit을 눌러줍니다.

▶ 입력한 정보 확인 후 Update Object 클릭하여 생성합니다. 위에는 hskim이지만 아래는 hckang인데, 위에서 선택을 hckang으로 했습니다ㅠㅠ

그렇다면 이제 gitlab2 그룹에 들어간 아이디들은 아래 ldap & gitlab 연동 후 gitlab에 접속할 수 있습니다. 지금은 계정을 제가 미리 만들어놓고 진행한 상태라 Group을 만들때 아이디들이 보였는데요. 아래는 그룹을 만들어놓은 상태에서 계정을 만들때 원하는 그룹에 지정할 수 있습니다. 지금은 gitlab2 그룹에 추가해야 하므로, 아래와 같이 계정을 생성해 주시면 됩니다.

 

▶ Templates의 오른쪽 하단에 보안상 박스를 친 User Account를 클릭해 줍니다.

▶ 이제 생성할 아이디 정보를 입력해주시고 제일 중요한 GID Number에 gitlab2를 선택하여 유저를 생성합니다. 그렇다면 지정한대로 앞서 만든 gitlab2 groups에 사용자가 추가됩니다.


Gitlab & LDAP 연동

 

▶ 서버에서 gitlab config를 아래와 같이 수정해 줍니다. (혹시 몰으니 gitlab.rb를 백업시키고 진행합니다.) 만약 도메인이 gitlab.hskim.it.kr 이라면 build_dn 부분과 base 부분에 'DC=it'를 추가해주시면 됩니다.

vi /data/volumes/gitlab-conf/_data/gitlab.rb
external_url 'http://gitlab.hskim.kr'
gitlab_rails['gitlab_ssh_host'] = 'gitlab.hskim.kr'
gitlab_rails['time_zone'] = 'Asia/Seoul'
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
    main: # 'main' is the GitLab 'provider ID' of this LDAP server
      label: 'LDAP'
      host: 'ldap'
      port: 389
      uid: 'uid'
      bind_dn: 'CN=admin,DC=hskim,DC=kr'
      password: 'hskim123#@!'
      encryption: 'plain'
      verify_certificates: false
      smartcard_auth: true
      active_directory: false
      allow_username_or_email_login: true
      lowercase_usernames: false
      block_auto_created_users: false
      base: 'OU=users,DC=hskim,DC=kr'
      user_filter: ''
      attributes:
       username: ['uid', 'userid', 'sAMAccountName']
       email:    ['mail', 'email', 'userPrincipalName']
       name:      'cn'
       first_name: 'givenName'
       last_name:  'sn'
EOS

▶ 이제 앞서 Gitlab 서비스에 들어가서 LDAP 등록한 계정으로 로그인을 할 수 있습니다.

 

'DevOps > CI - CD' 카테고리의 다른 글

[NBP] CI / CD - Gitlab runner를 활용한 WAR 배포  (8) 2020.08.08
[NBP] CI / CD - Nexus3 및 LDAP 연동  (0) 2020.06.22
[NBP] CI / CD - Gitlab  (0) 2020.06.16
[NBP] CI / CD - Traefik  (0) 2020.04.14
댓글
«   2024/05   »
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