2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AWSで学ぶFreeIPAの構築 (CentOS7)

Last updated at Posted at 2021-08-21

IPA Server セットアップ

事前準備

EC2の起動

CentOS 7 (x86_64) - with Updates HVM を用いました。インスタンスタイプとしては今回 t2.midium を利用しています。EC2の起動方法の説明は省略します。

image.png

HOST名の変更

HOST名とIPアドレスを決定します。ldap-clientは同じsubnet内でテストするため、今回プライベートアドレスで設定しています。

command
PRIVATE_IP="172.31.0.113"
HOSTNAME="freeipa.daikumatan.com"

HOST名を変更します。CentOS7.4以上は下記にて変更可能です。ホスト名変更の詳細はAWSの公式ページを参照してください。

command
sudo hostnamectl set-hostname --static ${HOSTNAME}

ホスト名変更に伴い、/etc/hostsも予め変更します。対話型のIPAサーバセットアップ時に、自動的にこのファイルをチェックするためです。

command
sudo sh -c "echo \"${PRIVATE_IP}    ${HOSTNAME}\" >> /etc/hosts"

インスタンスを再起動します。

sudo reboot

Route53 Private Hosted Zone の設定 (必要に応じて)

${HOSTNAME} の値、この例では、freeipa.daikumatan.com をroute53のPrivate Hosted Zoneで名前解決できるようにしておきます。

Private Hosted Zoneの作成

Route53 > Hosted Zones > Create hosted zone を実行し、Private Hosted Zoneを作成します。
- Domain Name を登録します。この例だと、daikumatan.com
- Private hosted zone を選択します
- Regionを選択します
- VPC IDを選択します
- Create hosted zone のボタンをクリックします

レコードの作成

作成されたhosted zoneを選択し、freeipa.daikumatan.comをAレーコードで登録し、名前解決できるようにします。
- 作成されたPrivate hosted zoneを選択します
- Create record のボタンをクリックします
- この例だと Record name に freeipa を入力します
- Record typeとして、A レコードを選択します
- ValueにPrivate Addressを入力します
- Create recordsのボタンをクリックします

FreeIPAのインストール

パッケージのインストール

command
sudo yum -y install ipa-server ipa-server-dns

IPAサーバのセットアップ

route53の設定をした場合は以下でインストールをスタートします。

command
# route53の設定をした場合
sudo ipa-server-install

route53の設定をしなかった場合は以下でインストールをスタートします。
参考: Server World "FreeIPA : サーバーの設定"

# route53の設定をしなかった場合
# sudo ipa-server-install --setup-dns

質問1: 無回答でリターン (noと答える)

Do you want to configure integrated DNS (BIND)? [no]:

質問2: 無回答でリターン

Server host name [freeipa.daikumatan.com]:

質問3: 無回答でリターン

Please confirm the domain name [daikumatan.com]:

質問4: 無回答でリターン

Please provide a realm name [DAIKUMATAN.COM]: 

質問5: パスワードを入力

Directory Manager password: <適当なパスワード>
Password (confirm): <適当なパスワード>

質問6: パスワードを入力

IPA admin password: <適当なパスワード>
Password (confirm): <適当なパスワード>

質問7: yesと回答

Continue to configure the system with these values? [no]: yes

インストールが完了すると下記のように表示されます。
次にこれに従って各種設定をしていきましょう。

Please add records in this file to your DNS system: /tmp/ipa.system.records.CTjCFU.db
==============================================================================
Setup complete

Next steps:
    1. You must make sure these network ports are open:
        TCP Ports:
          * 80, 443: HTTP/HTTPS
          * 389, 636: LDAP/LDAPS
          * 88, 464: kerberos
        UDP Ports:
          * 88, 464: kerberos
          * 123: ntp

    2. You can now obtain a kerberos ticket using the command: 'kinit admin'
       This ticket will allow you to use the IPA tools (e.g., ipa user-add)
       and the web user interface.

Be sure to back up the CA certificates stored in /root/cacert.p12
These files are required to create replicas. The password for these
files is the Directory Manager password

Firewallの設定

AWSの場合は上記のポートに対して Security Group の Inbound Ruleを設定してください。
オンプレのときはFirewalldの設定が必要となります。

IPAツールの利用準備

はじめに下記コマンドでKerberos認証のTGT(Ticket-Granting Ticket)の状態を確認します。はじめて利用するためTGTはまだ得られていないことをが確認できるでしょう。Kerberos認証をざっくり知りたい場合は、Youtubeの以下のコンテンツがおすすめです。

【#26 SSO ケルベロス認証】シングルサインオン セキュリティのお勉強

command
sudo klist
response
sudo klist: Credentials cache keyring 'persistent:1000:1000' not found

次のコマンドを使用して、KerberosのTGTを取得します。 このチケットを使用すると、IPAツール(ipa user-addなど)やIPAのWebユーザーインターフェイスに接続できるようになります。コマンド実行後のレスポンスに対し上記質問5で入力したパスワードを入力します。

command
sudo kinit admin
response
Password for admin@DAIKUMATAN.COM: <質問6のpassword>

klistコマンドでKerberosのTGTが付与されていることを確認しますkrbtgt(Kerberos Ticket Granting Ticket)を確認できるでしょう。期限切れがあることに注意してください。期限がきれた場合は再度、上記の kinit コマンドを実行してください。

command
sudo klist
response
Ticket cache: KEYRING:persistent:0:0
Default principal: admin@DAIKUMATAN.COM

Valid starting       Expires              Service principal
08/21/2021 03:31:07  08/22/2021 03:31:00  krbtgt/DAIKUMATAN.COM@DAIKUMATAN.COM

作成するユーザに対するデフォルトシェル指定(bash)

command
sudo ipa config-mod --defaultshell=/bin/bash
response
  Maximum username length: 32
  Home directory base: /home
  Default shell: /bin/bash
  Default users group: ipausers
  Default e-mail domain: daikumatan.com
  Search time limit: 2
  Search size limit: 100
  User search fields: uid,givenname,sn,telephonenumber,ou,title
  Group search fields: cn,description
  Enable migration mode: FALSE
  Certificate Subject base: O=DAIKUMATAN.COM
  Password Expiration Notification (days): 4
  Password plugin features: AllowNThash, KDC:Disable Last Success
  SELinux user map order: guest_u:s0$xguest_u:s0$user_u:s0$staff_u:s0-s0:c0.c1023$sysadm_u:s0-s0:c0.c1023$unconfined_u:s0-s0:c0.c1023
  Default SELinux user: unconfined_u:s0-s0:c0.c1023
  Default PAC types: MS-PAC, nfs:NONE
  IPA masters: freeipa.daikumatan.com
  IPA master capable of PKINIT: freeipa.daikumatan.com
  IPA CA servers: freeipa.daikumatan.com
  IPA NTP servers: freeipa.daikumatan.com
  IPA CA renewal master: freeipa.daikumatan.com

テストユーザの作成

ここでは Daisuke Nagao という名前でユーザを作成します。下記、ユーザ作成とパスワード設定を分けていますが、もしまとめて行う場合は、sudo ipa user-add daisuke --first=Daisuke --last=Nagao --password のコマンドを使うことができます。

command
sudo ipa user-add
response
First name: Daisuke
Last name: Nagao
User login [dnagao]: daisuke
--------------------
Added user "daisuke"
--------------------
  User login: daisuke
  First name: Daisuke
  Last name: Nagao
  Full name: Daisuke Nagao
  Display name: Daisuke Nagao
  Initials: DN
  Home directory: /home/daisuke
  GECOS: Daisuke Nagao
  Login shell: /bin/sh
  Principal name: daisuke@DAIKUMATAN.COM
  Principal alias: daisuke@DAIKUMATAN.COM
  Email address: daisuke@daikumatan.com
  UID: 132400001
  GID: 132400001
  Password: False
  Member of groups: ipausers
  Kerberos keys available: False

以下のコマンドで初期パスワードを設定します。コマンド実行後、パスワードを聞かれますので入力します。

command
sudo ipa passwd <password>
response
New Password:
Enter New Password again to verify:
---------------------------------------------
Changed password for "daisuke@DAIKUMATAN.COM"
---------------------------------------------

登録したユーザを確認します。

command
sudo ipa user-find daisuke
response
--------------
1 user matched
--------------
  User login: daisuke
  First name: Daisuke
  Last name: Nagao
  Home directory: /home/daisuke
  Login shell: /bin/sh
  Principal name: daisuke@DAIKUMATAN.COM
  Principal alias: daisuke@DAIKUMATAN.COM
  Email address: daisuke@daikumatan.com
  UID: 132400001
  GID: 132400001
  Account disabled: False

ここで再度 klist を実行してみましょう。 信頼関係を結んだサービスとして、HTTPが追加されたことが分かります。

command
sudo klist
response
Ticket cache: KEYRING:persistent:0:0
Default principal: admin@DAIKUMATAN.COM

Valid starting       Expires              Service principal
08/21/2021 04:14:28  08/22/2021 03:31:00  HTTP/freeipa.daikumatan.com@DAIKUMATAN.COM
08/21/2021 03:31:07  08/22/2021 03:31:00  krbtgt/DAIKUMATAN.COM@DAIKUMATAN.COM

その他

BaseDNの確認

以下、どちらかで確認可能

/etc/ipa/default.conf
[global]
host = freeipa.daikumatan.com
basedn = dc=daikumatan,dc=com
realm = DAIKUMATAN.COM
domain = daikumatan.com
xmlrpc_uri = https://freeipa.daikumatan.com/ipa/xml
ldap_uri = ldapi://%2fvar%2frun%2fslapd-DAIKUMATAN-COM.socket
enable_ra = True
ra_plugin = dogtag
dogtag_version = 10
mode = production
/etc/openldap/ldap.conf
TLS_CACERTDIR   /etc/openldap/certs
SASL_NOCANON    on
URI ldaps://freeipa.daikumatan.com
BASE dc=daikumatan,dc=com
TLS_CACERT /etc/ipa/ca.crt
SASL_MECH GSSAPI

IPAクライアントセットアップ

事前準備

CentOS7のEC2インスタンス起動

IPAサーバと同じため省略します。

IPAサーバの/etc/hostsへの登録

クライアント側が名前解決できるように登録します。Route53の設定を使ってもよいでしょう。

command
IPA_SERVER_IP="172.31.0.113"
IPA_SERVER_NAME="freeipa.daikumatan.com"
sudo sh -c "echo \"${IPA_SERVER_IP}    ${IPA_SERVER_NAME}\" >> /etc/hosts"

/etc/hostsの編集確認

command
tail -1 /etc/hosts

もし、Route53で設定済みで、この例ならIPA Clientからもfreeipa.daikumatan.comが名前解決できるなら、以下は不要です。

response
172.31.0.113    freeipa.daikumatan.com

IPAクライアントのインストール

command
sudo yum install -y ipa-client

IPAクライアントの設定

command
sudo ipa-client-install --force-ntpd

質問1: IPサーバのドメインを回答 daikumatan.com

Provide the domain name of your IPA server (ex: example.com): daikumatan.com

質問2: IPサーバネームをFQDNで回答 freeipa.daikumatan.com

Provide your IPA server name (ex: ipa.example.com): freeipa.daikumatan.com

質問3: 固定値で続行し、DNS検出は行いませんか? yesで回答

Proceed with fixed values and no DNS discovery? [no]: yes

質問4: 設定を続けるため、yesで回答

Continue to configure the system with these values? [no]: yes

質問4: コンピューターの登録を許可されたユーザーとのことなので、admin を入力

User authorized to enroll computers: admin

質問5: adminのパスワードを入力する

Password for admin@DAIKUMATAN.COM: <admin のパスワード>

設定が進み、最終行に The ipa-client-install command was successful と出ていれば成功です。

response
Enrolled in IPA realm DAIKUMATAN.COM
Created /etc/ipa/default.conf
New SSSD config will be created
Configured sudoers in /etc/nsswitch.conf
Configured /etc/sssd/sssd.conf
Configured /etc/krb5.conf for IPA realm DAIKUMATAN.COM
trying https://freeipa.daikumatan.com/ipa/json
[try 1]: Forwarding 'schema' to json server 'https://freeipa.daikumatan.com/ipa/json'
trying https://freeipa.daikumatan.com/ipa/session/json
[try 1]: Forwarding 'ping' to json server 'https://freeipa.daikumatan.com/ipa/session/json'
[try 1]: Forwarding 'ca_is_enabled' to json server 'https://freeipa.daikumatan.com/ipa/session/json'
Systemwide CA database updated.
Adding SSH public key from /etc/ssh/ssh_host_rsa_key.pub
Adding SSH public key from /etc/ssh/ssh_host_ecdsa_key.pub
Adding SSH public key from /etc/ssh/ssh_host_ed25519_key.pub
[try 1]: Forwarding 'host_mod' to json server 'https://freeipa.daikumatan.com/ipa/session/json'
Could not update DNS SSHFP records.
SSSD enabled
Configured /etc/openldap/ldap.conf
No SRV records of NTP servers found. IPA server address will be used
NTP enabled
Configured /etc/ssh/ssh_config
Configured /etc/ssh/sshd_config
Configuring daikumatan.com as NIS domain.
Client configuration complete.
The ipa-client-install command was successful

初回ログイン時にホームディレクトリを自動生成設定

command
sudo authconfig --enablemkhomedir --update
response
(返り値なし)

初回ログインテスト

先程作成したユーザでログインします。Homeディレクトリーが作成されていることを確認してください。

command
sudo su - daisuke
response
Creating home directory for daisuke.

使い方例

以下は少しずつ増やして行く予定です。

検索関連

ldapsearch コマンドを利用

よく使うオプション

  • -D: Bind-DN であり、LDAPへログインするユーザ
  • -b: Base-DN であり、ユーザが所属するOUを指定するときのDN
  • -x : サーバ上でソート
  • -h : LDAPサーバのhostnameまたはIPアドレス
command
IPA_SVR="freeipa.daikumatan.com"
BASE_DN="dc=daikumatan,dc=com"
SEARCH_USER="admin"
ldapsearch -x -h ${IPA_SVR} -b ${BASE_DN} uid=${SEARCH_USER}

ipa user-find コマンドを利用

以下コマンドで、ipa: ERROR: did not receive Kerberos credentials と出た場合は、kinit admin を実行してください。

全ユーザを表示します。

$ sudo ipa user-find
---------------
4 users matched
---------------
  User login: admin
  Last name: Administrator
  Home directory: /home/admin
  Login shell: /bin/bash
  Principal alias: admin@DAIKUMATAN.COM
  UID: 132400000
  GID: 132400000
  Account disabled: False

  (snip)

キーワードでフィルタリングします。

command
sudo ipa user-find <keyword>

特定のユーザネームで検索します。

command
sudo ipa user-find --user=user_name

特定のユーザネームを含まないで検索します。

command
sudo ipa user-find --no-user=user_name

Appendix

ipa-server-install 実行時のエラー

  • 名前を解決できず、ipa-server-install でインストールを行った時
    • ipa-server-install --setup を入れた時は出ません。そのかわりDNS設定のQ/Aがあります。
[try 1]: Forwarding 'host_mod' to json server 'https://freeipa.daikumatan.com/ipa/json'
Could not update DNS SSHFP records.
SSSD enabled
Configured /etc/openldap/ldap.conf
Configured /etc/ssh/ssh_config
Configured /etc/ssh/sshd_config
Configuring daikumatan.com as NIS domain.
Client configuration complete.
The ipa-client-install command was successful

ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipaserver.dns_data_management: ERROR    unable to resolve host name freeipa.daikumatan.com. to IP address, ipa-ca DNS record will be incomplete
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipapython.dnsutil: ERROR    DNS query for freeipa.daikumatan.com. 1 failed: All nameservers failed to answer the query freeipa.daikumatan.com. IN A: Server 10.0.0.2 UDP port 53 answered SERVFAIL
ipaserver.dns_data_management: ERROR    unable to resolve host name freeipa.daikumatan.com. to IP address, ipa-ca DNS record will be incomplete
Please add records in this file to your DNS system: /tmp/ipa.system.records.l1DwcD.db
==============================================================================
Setup complete

Next steps:
        1. You must make sure these network ports are open:
                TCP Ports:
                  * 80, 443: HTTP/HTTPS
                  * 389, 636: LDAP/LDAPS
                  * 88, 464: kerberos
                UDP Ports:
                  * 88, 464: kerberos
                  * 123: ntp

        2. You can now obtain a kerberos ticket using the command: 'kinit admin'
           This ticket will allow you to use the IPA tools (e.g., ipa user-add)
           and the web user interface.

Be sure to back up the CA certificates stored in /root/cacert.p12
These files are required to create replicas. The password for these
files is the Directory Manager password

プライベートsubnetにあるipa-serverのGUIにVNC+ssh tunnelで接続させる

private subnetにある、ipaサーバのGUIにアクセスする方法を記載します。

VNC Serverのインストール

ipaサーバにVNC Serverをインストールします。

command
sudo yum -y groups install "GNOME Desktop"
sudo yum install tigervnc-server
# テンプレートベースにsystemdの設定ファイルを複製
sudo cp /lib/systemd/system/vncserver@.service /lib/systemd/system/vncserver@:1.service
# ユーザ名を変更
sudo vim /lib/systemd/system/vncserver@:1.service
# centosユーザのVNCパスワード設定
vncpasswd

ssh tunnelの形成

command
ssh -i <private key> <ユーザ名>@<public領域のサーバ> -L 5901:<ipa server>:5901

vncサーバへの接続

Macのサーバに接続の機能を使って以下を入力します。

vnc://localhost:5901

参考資料

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?