[CentOS6][OpenAM10] ロードバランサの背後で PolicyAgent を使う


Create: 2014/10/13
LastUpdate: 2014/10/13
≪ メニューに戻る

ロードバランサの背後にあるWEBサーバに PolicyAgent を導入して SSO を試してみます。
検証環境(XenServer6.2+CentOS6.5)で使用するドメインは、"blue21.local" とします。

1.シナリオ


ここでは、「 [CentOS6][OpenAM10] ロードバランサ+OpenAMの環境で PolicyAgent を使う」で構築した下図の環境を使用します。
追加したWEBサーバを exlb01 のロードバランサに組み込みます。



テスト用WEBサイトにロードバランサ経由でアクセスする場合のURLは以下とし、このURLにアクセスしたら OpenAM で SSO するようにします。
  • http://lvs.blue21.local:80/

2.ロードバランサの設定


exlb01、exlb02 の keepalived.conf にテスト用WEBサイトを登録します。(赤字部分)
LVSとテスト用WEBサイトを同一サブネットに置くので、 Direct Server Return(DSR) 方式にします。
! Configuration File for keepalived

global_defs {
   !notification_email {
   !  acassen@firewall.loc
   !  failover@firewall.loc
   !  sysadmin@firewall.loc
   !}
   !notification_email_from Alexandre.Cassen@firewall.loc
   !smtp_server 192.168.200.1
   !smtp_connect_timeout 30
   router_id LVS
}

vrrp_instance VI_EXT {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 101
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.90/24 dev eth0
        192.168.1.93/24 dev eth0
        192.168.1.94/24 dev eth0
    }
}

vrrp_instance VI_INT {
    state BACKUP
    interface eth1
    virtual_router_id 52
    priority 101
    nopreempt
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      10.0.0.90/24 dev eth1
    }
}

vrrp_sync_group VG {
  group {
    VI_EXT
    VI_INT
  }
}

virtual_server 192.168.1.90 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    !nat_mask 255.255.255.0
    !persistence_timeout 50
    protocol TCP

    real_server 192.168.1.82 80 {
        weight 10
        inhibit_on_failure
        HTTP_GET {
            url {
              path /status.html
              status_code 200
            }
            connect_timeout 3
            !nb_get_retry 3
            !delay_before_retry 3
        }
    }
}

virtual_server 192.168.1.90 8080 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    !nat_mask 255.255.255.0
    !persistence_timeout 50
    protocol TCP

    real_server 10.0.0.93 8080 {
        weight 10
        inhibit_on_failure
        HTTP_GET {
            url {
              path /openam/isAlive.jsp
              status_code 200
            }
            connect_timeout 3
            !nb_get_retry 3
            !delay_before_retry 3
        }
    }

    real_server 10.0.0.94 8080 {
        weight 10
        inhibit_on_failure
        HTTP_GET {
            url {
              path /openam/isAlive.jsp
              status_code 200
            }
            connect_timeout 3
            !nb_get_retry 3
            !delay_before_retry 3
        }
    }

}
テスト用WEBサイトのサーバで以下のコマンドを実行してロードバランサ宛てのパケットを自分自身に返すように設定します。
# iptables -t nat -A PREROUTING -p tcp -d 192.168.1.90 -j REDIRECT
テスト用WEBサイトには、ヘルスチェック用のページ(status.html)を用意します。
今回は、手抜きして index.html をコピーします。
# cd /var/www/html 
# cp index.html status.html
# ls
index.html  status.html
この時点でロードバランサの状態を見ると以下のとおり。
テスト用WEBサイトはSSOで保護されているのでヘルスチェックに失敗しています。
# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.1.90:80 rr
  -> 192.168.1.82:80              Route    0     0          0
TCP  192.168.1.90:8080 rr
  -> 10.0.0.93:8080               Masq    10     0          0
  -> 10.0.0.94:8080               Masq    10     0          0
後述のOpenAMの設定で、ヘルスチェック用のページはSSOから除外します。

3.OpenAM の設定


OpenAMにテスト用WEBサイトに導入するPolicyAgentの情報を登録します。
ブラウザで、以下のURLにアクセスして、exam01 のOpenAM管理画面を開きます。
  • http://exam01.blue21.local:8080/openam
[アクセス制御] > [ / (最上位のレルム)] > [エージェント] をクリックすると、下図の画面が表示されます。
[CentOS6][OpenAM10] ロードバランサ+OpenAMの環境で PolicyAgent を使う」 で登録した情報は削除します。



新規でエージェントを登録します。
[新規]ボタンをクリックします。



[名前]、[パスワード]に任意の値を入力します。
[設定] は、デフォルト値の "集中" を選択します。
[サーバーURL]は、ロードバランサ+OpenAMのURL(http://lvs.blue21.local:8080/openam)を入力します。
[エージェントURL]は、テスト用WEBサイトのURL(http://lvs.blue21.local:80)を入力します。
入力が完了したら、[作成]ボタンをクリックします。
なお、ここで入力した値は、後述のPolicyAgentの設定時に使用します。



下図の画面が表示され、[エージェント]の一覧に新規作成した "apache22-lvs80" が表示されます。
"apache22-lvs80" をクリックします。



画面を下にスクロールして、[一般] > [SSOのみモード] をチェックします。
今回は、SSO(認証)だけにして、認可はおこなません。



画面を上にスクロールして、[保存]ボタンをクリックします。
保存したら、[高度]タブをクリックします。



画面を下にスクロールして、[ロードバランサ]の項目を全部チェックします。



画面を上にスクロールして、[保存]ボタンをクリックします。
保存したら、[アプリケーション]タブをクリックします。



[適用されないURL]の[新しい値] に ヘルスチェック用のURL(http://lvs.blue21.local/status.html)を登録して、[追加]ボタンをクリックします。



[保存]ボタンをクリックします。



4.テスト用WEBサイトのPolicyAgent導入


PolicyAgnet を再インストールします。
Apache を停止します。
# service httpd stop
[CentOS6][OpenAM10] ロードバランサ+OpenAMの環境で PolicyAgent を使う」 でインストールした PolicyAgent は削除して、再度、アーカイブを解凍します。
また、httpd.conf は、PolicyAgent インストール前の状態に戻します。なお、httpd.conf のバックアップファイル名は環境により異なります。
# cd /opt
# rm -rf web_agents
# unzip apache_v22_Linux_agent_304.zip
#
# cd /etc/httpd/conf
# rm httpd.conf
# mv httpd.conf-preAmAgent-20141013-101355 httpd.conf
パスワードファイルを作成します。ここで使用するパスワードは、上記3で設定した値です。
# cd /opt/web_agents/apache22_agent
# echo -n "password" > pass.txt
PolicyAgent の インストーラを実行します。
# cd /opt/web_agents/apache22_agent
# ./bin/agentadmin --install

Please read the following License Agreement carefully:

[Press <Enter> to continue...] or [Enter n To Finish]
n

Do you completely agree with all the terms and conditions of this License
Agreement (yes/no): [no]: yes



************************************************************************
Welcome to the OpenSSO Policy Agent for Apache Server.

************************************************************************


Enter the complete path to the directory which is used by Apache Server to
store its configuration Files. This directory uniquely identifies the
Apache Server instance that is secured by this Agent.
[ ? : Help, ! : Exit ]
Enter the Apache Server Config Directory Path [/opt/apache22/conf]: /etc/httpd/conf


Enter the URL where the OpenSSO server is running. Please include the
deployment URI also as shown below:
(http://opensso.sample.com:58080/opensso)
[ ? : Help, < : Back, ! : Exit ]
OpenSSO server URL: http://lvs.blue21.local:8080/openam


Enter the Agent URL as shown below: (http://agent1.sample.com:1234)
[ ? : Help, < : Back, ! : Exit ]
Agent URL: http://lvs.blue21.local:80


Enter the Agent profile name
[ ? : Help, < : Back, ! : Exit ]
Enter the Agent Profile name: apache22-lvs80


Enter the path to a file that contains the password to be used for identifying
the Agent.
[ ? : Help, < : Back, ! : Exit ]
Enter the path to the password file: /opt/web_agents/apache22_agent/pass.txt


-----------------------------------------------
SUMMARY OF YOUR RESPONSES
-----------------------------------------------
Apache Server Config Directory : /etc/httpd/conf
OpenSSO server URL : http://lvs.blue21.local:8080/openam
Agent URL : http://lvs.blue21.local:80
Agent Profile name : apache22-lvs80
Agent Profile Password file name :
/opt/web_agents/apache22_agent/pass.txt

Verify your settings above and decide from the choices below.
1. Continue with Installation
2. Back to the last interaction
3. Start Over
4. Exit
Please make your selection [1]: <ENTER>

Creating directory layout and configuring Agent file for Agent_001
instance ...DONE.

Reading data from file /opt/web_agents/apache22_agent/pass.txt and
encrypting it ...DONE.

Generating audit log file name ...DONE.

Creating tag swapped OpenSSOAgentBootstrap.properties file for instance
Agent_001 ...DONE.

Creating a backup for file /etc/httpd/conf/httpd.conf ...DONE.

Adding Agent parameters to
/opt/web_agents/apache22_agent/Agent_001/config/dsame.conf file ...DONE.

Adding Agent parameters to /etc/httpd/conf/httpd.conf file ...DONE.


SUMMARY OF AGENT INSTALLATION
-----------------------------
Agent instance name: Agent_001
Agent Bootstrap file location:
/opt/web_agents/apache22_agent/Agent_001/config/OpenSSOAgentBootstrap.properties
Agent Configuration Tag file location
/opt/web_agents/apache22_agent/Agent_001/config/OpenSSOAgentConfiguration.properties
Agent Audit directory location:
/opt/web_agents/apache22_agent/Agent_001/logs/audit
Agent Debug directory location:
/opt/web_agents/apache22_agent/Agent_001/logs/debug


Install log file location:
/opt/web_agents/apache22_agent/installer-logs/audit/install.log

Thank you for using OpenSSO Policy Agent
Apache を起動します。
# service httpd start

5.動作確認


テスト用WEBサイトにアクセスしてSSOできるか確認します。
まず、ロードバランサの状態を確認します。
赤字部分のように Weight が 0 以外ならヘルスチェックに成功しているので、ロードバランサ経由でテスト用WEBサイトにアクセスできます。
# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.1.90:80 rr
  -> 192.168.1.82:80              Route   10     0          0
TCP  192.168.1.90:8080 rr
  -> 10.0.0.93:8080               Masq    10     0          0
  -> 10.0.0.94:8080               Masq    10     0          0
テスト用WEBサイトにアクセスします。
ブラウザで以下のURLにアクセスします。
  • http://lvs.blue21.local/index.html
OpenAMで認証していない場合は、下図のようにOpenAMのログイン画面にリダイレクトされます。
demo ユーザでログインします。



下図のようにテスト用WEBサイトが表示されたらSSO成功です。



ロードバランサの状態を見てみると以下のとおり。
Connection 数が0以上なので、ロードバランサでリクエストを振り分けてることがわかります。
# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.1.90:80 rr
  -> 192.168.1.82:80              Route   10     1          1
TCP  192.168.1.90:8080 rr
  -> 10.0.0.93:8080               Masq    10     0          1
  -> 10.0.0.94:8080               Masq    10     0          1