新人エンジニアがShibbolethを学ぶ ~その3:LDAPって何?~

◆ Live配信スケジュール ◆
サイオステクノロジーでは、Microsoft MVPの武井による「わかりみの深いシリーズ」など、定期的なLive配信を行っています。
⇒ 詳細スケジュールはこちらから
⇒ 見逃してしまった方はYoutubeチャンネルをご覧ください
【5/21開催】Azure OpenAI ServiceによるRAG実装ガイドを公開しました
生成AIを活用したユースケースで最も一番熱いと言われているRAGの実装ガイドを公開しました。そのガイドの紹介をおこなうイベントです!!
https://tech-lab.connpass.com/event/315703/

こんにちは。サイオステクノロジーの有村です。

前回までに

新卒がShibbolethを学ぶ ~その1:HTTP,HTTPS,SSLって何?~
新卒がShibbolethを学ぶ ~その2:シングルサインオンって何?~

を学びました。

今回はShibbolethのデータベースとして使うLDAPの勉強とOpenLDAPを使ったLDAPサーバの実装をしたのでアウトプットしていきたいと思います。

LDAPとは

LDAP(Lightweight Directory Access Protocol)とはディレクトリサービス(情報を一元管理し情報提供を行うサービス)を提供するサーバへアクセスするときに使うプロトコルのことです。LDAPに対応してディレクトリサービスを提供するサーバをLDAPサーバといい、ツリー構造のデータベースを使って情報を管理します。

LDAPを使う事で出来ること

LDAPの「LDAP認証」や「LDAP連携」を使う事で以下のような機能を実装することが出来ます。

    • Linuxのシステムアカウント情報(/etc/passwdや/etc/shadow)の一元化
    • Linuxサーバの各種アプリでのIDパスワードの統一
    • シングルサインオンの実装
    • 社員情報の共有
    • アカウント自動作成等のLDAP連携

一部抜粋しましたが、他にも様々な機能をLDAPを使う事で実装出来ます。

LDAPとRDBの違い

RDBでは頻繁に更新が行われ、レコードを更新したときに別のテーブルが更新されることも多いので一連の処理に一貫性と整合性が担保されています。なので、複雑なテーブル構造の更新処理に適している反面、負荷が大きくなってしまいます。

一方、LDAPはツリー構造をとっているのでRDBのような複雑な構造は取れない代わり負荷が軽くなっています。

なので、データベースの更新は少ないが、検索はよくするという場合(電話帳やアカウントシステムの管理)にはLDAPが適しています。

OpenLDAPを使ったLDAPサーバの実装

今回は簡単なLDAPサーバを構築してLDAP Adminでユーザーを追加するとこまで実装したいと思います。実装するLDAPのイメージは下のイラストです。

LDAPサーバの環境はAzure上にCentOS7.6を構築しています。
(構築方法は下のリンクに乗っています)
Azureに仮想マシン(CentOS)を構築する Ver.2.0

LDAPサーバの実装

LDAPサーバの実装方法は以下のようになります。

    1. CentOS上にOpenLDAPをインストール
      //OpenLDAPのインストール
      # yum -y install openldap-servers openldap-clients
      
      //DB設定ファイルの用意
      # cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
      
      //権限の変更
      # chown ldap. /var/lib/ldap/DB_CONFIG
      
      //LDAPサーバの起動
      # systemctl start slapd
      
      //LDAPサーバの自動起動の有効化
      # systemctl enable slapd
    2. OpenLDAPの管理者パスワードの設定
      //管理者パスワードの設定
      # slappasswd
      
      New password:
      Re-enter new password:
      {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
      
      //管理者設定変更用ldifファイルの作成
      //olcRootPWに生成した管理者パスワードを指定
      # vi chrootpw.ldif
      
      dn: olcDatabase={0}config,cn=config
      changetype: modify
      add: olcRootPW
      olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
      
      //管理者設定の変更
      # ldapmodify -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif
      
      SASL/EXTERNAL authentication started
      SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
      SASL SSF: 0
      modifying entry "olcDatabase={0}config,cn=config"
    3. 基本的なスキーマの読み込み
      # ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
      
      SASL/EXTERNAL authentication started
      SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
      SASL SSF: 0
      adding new entry "cn=cosine,cn=schema,cn=config"
      
      # ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
      
      SASL/EXTERNAL authentication started
      SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
      SASL SSF: 0
      adding new entry "cn=nis,cn=schema,cn=config"
      
      # ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
      
      SASL/EXTERNAL authentication started
      SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
      SASL SSF: 0
      adding new entry "cn=inetorgperson,cn=schema,cn=config"
    4. ディレクトリマネージャーの設定
      //ディレクトリマネージャーのパスワードの設定
      # slappasswd
      New password:
      Re-enter new password:
      {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
      
      //ディレクトリマネージャーの設定変更用ldifファイルの作成
      # vi chdomain.ldif
      
      dn: olcDatabase={1}monitor,cn=config
      changetype: modify
      replace: olcAccess
      olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth"
        read by dn.base="cn=Manager,dc=srv,dc=world" read by * none
      
      dn: olcDatabase={2}hdb,cn=config
      changetype: modify
      replace: olcSuffix
      olcSuffix: dc=srv,dc=world
      
      dn: olcDatabase={2}hdb,cn=config
      changetype: modify
      replace: olcRootDN
      olcRootDN: cn=Manager,dc=srv,dc=world
      
      dn: olcDatabase={2}hdb,cn=config
      changetype: modify
      add: olcRootPW
      olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
      
      dn: olcDatabase={2}hdb,cn=config
      changetype: modify
      add: olcAccess
      olcAccess: {0}to attrs=userPassword,shadowLastChange by
        dn="cn=Manager,dc=srv,dc=world" write by anonymous auth by self write by * none
      olcAccess: {1}to dn.base="" by * read
      olcAccess: {2}to * by dn="cn=Manager,dc=srv,dc=world" write by * read
      
      //ディレクトリマネージャーの設定変更
      # ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif
      
      SASL/EXTERNAL authentication started
      SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
      SASL SSF: 0
      modifying entry "olcDatabase={1}monitor,cn=config"
      
      modifying entry "olcDatabase={2}hdb,cn=config"
      
      modifying entry "olcDatabase={2}hdb,cn=config"
      
      modifying entry "olcDatabase={2}hdb,cn=config"

LDAP Adminでユーザーの追加

LDAP Adminをダウンロードしていない人は下のリンクからダウンロードできます。

https://www.ldapadmin.org/

LDAP AdminからOpenLDAPサーバへの接続

  1. LDAP Adminを起動する
  2. メニューから「Start」→「Connect」を選択
  3. New connectionを選択
    1. 「Connection name」に「OpenLDAPサーバのIP」を入力
    2. 「Host」に「OpenLDAPサーバのIP」を入力
    3. 「Base」に「dc=srv,dc=world」を入力
    4. 「Username」に「cn=Manager,dc=srv,dc=world」を入力
    5. 「Password」に「任意のパスワード」を入力
    6. 「OK」ボタンをクリック
  4. 作成されたサーバのIPをクリックして「OK」ボタンをクリック
  5. 接続されていることを確認する

LDAP AdminからOpenLDAPにPeopleを追加する

  1. ウィンドウから「ou=People」を選択。
  2. 右クリックから「New」⇒「User」を選択
    1. 「First name」に「名前」を入力。
    2. 「Second name」に「名前」を入力
    3. 「Username」に「ユーザ名(ログインID)」を入力
    4. 「Home Directory」に「ユーザ名のホームディレクトリ」を入力
    5. 「OK」ボタンをクリック。
  3. ユーザーができていることを確認する
  4. 作成されたユーザーを右クリックして「Set Password」を選択
      1. 「New password」に「パスワード」を入力
      2. 「Confirm password」に「パスワード』を入力
        「OK」ボタンをクリック
  5. パスワードが設定出来ていることを確認する。

まとめ

今回はLDAPについて学びました。実装の部分は
https://www.server-world.info/query?os=CentOS_7&p=openldap&f=1
この記事を参考にしています。

次回は今回作ったLDAPサーバを用いてShibbolethの実装をしていきたいと思います。

アバター画像
About サイオステクノロジーの中の人 3 Articles
サイオステクノロジーで働く中の人です。
ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

1人がこの投稿は役に立ったと言っています。


ご覧いただきありがとうございます。
ブログの最新情報はSNSでも発信しております。
ぜひTwitterのフォロー&Facebookページにいいねをお願い致します!



>> 雑誌等の執筆依頼を受付しております。
   ご希望の方はお気軽にお問い合わせください!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


質問はこちら 閉じる