https://blogs.oracle.com/felcey/entry/dynamic_authorised_hosts
Coherenceクラスタを安全に保つ簡単な方法は、クラスタへ追加できる認可されたホストを設定することです。Coherenceアプリケーションがクラスタに参加しようとしても、許可されたホストのサーバで実行していなければ拒否されます。認可ホストを設定するためには、以下のようにホスト名もしくはIPアドレスを明示的にtangosol-coherence-override.xmlファイルの認可ホストセクションに追加します。
しかし、Coherenceクラスタを拡張する必要があるとき、認可ホストリストに記載のない別のサーバを追加せざるを得ないとき、もしくはクラスタトポロジの変更(ファイルに含まれないサーバのホスト名やIPアドレスの変更を含む)が必要な場合、どうすればよいでしょう。異なる構成で完全なクラスタ再起動も、時にはオプションの一つですが、その他の場合はこの限りではありません。幸いなことに、この問題に対する解決策があります。しかも、完全なクラスタの再起動は不要です。192.168.56.101 192.168.56.1
まず、ローリング再起動(各ノードを順に停止し、構成を変更して再起動する)という方法がありますが、この方法はキャッシュの再構成が必要なため、クラスタの性能に影響があります。二つ目の選択肢として、(明示的に名前付けするのではなく)認可済みホストの範囲を指定する、というものです。この方法はクラスタを安全を担保しつつ、将来の時点での構成の変更も担保するというものです。クラスタに追加可能なホストの範囲は以下のように指定することができます。
3番目のオプションは、Coherenceのフィルタを使用して、どのホストがクラスタへの参加を許可されているかを決定する方法です。カスタムフィルタは、ホスト、LDAPサーバーまたはデータベースのリストを別のファイルにアクセスすることができるため、この方法を使うと、もっと動的な構成が可能です。フィルタを使用すると、どのホストがクラスタメンバを実行できるかを正確に指定することができます。それと同時に、これを使って動的にホストを変更することができます。192.168.56.101 192.168.56.190
以下のように、認可済みホストを決定するフィルタをクラスタ構成(
tangosol-coherence-override.xmlファイル)に追加することができます。1個のURLでホストのリストを定期的にチェックするカスタムフィルタのサンプルは以下のような感じになります。com.oracle.coherence.test.AuthroizedHostsFilter String file:/Users/Dave/workspace/CoherenceAuthorizedHostsTest/hosts.txt Int 10000
/**
* File: AuthorizedHostFilter.java
*
* Copyright (c) 2012. All Rights Reserved. Oracle Corporation.
*
* Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
*
* This software is the confidential and proprietary information of Oracle
* Corporation. You shall not disclose such confidential and proprietary
* information and shall use it only in accordance with the terms of the license
* agreement you entered into with Oracle Corporation.
*
* Oracle Corporation makes no representations or warranties about the
* suitability of the software, either express or implied, including but not
* limited to the implied warranties of merchantability, fitness for a
* particular purpose, or non-infringement. Oracle Corporation shall not be
* liable for any damages suffered by licensee as a result of using, modifying
* or distributing this software or its derivatives.
*
* This notice may not be removed or altered.
*/
package com.oracle.coherence.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import com.tangosol.net.CacheFactory;
import com.tangosol.util.Filter;
/**
* Simple filter to check if a host is in an authoirsed host list
* Note: this implementation checks the IP address of a host not the hostname
*
* @author Dave Felcey
*/
public class AuthroizedHostsFilter implements Filter {
/**
* List of authorised hosts. Thi list is synchronised in case an update and check are being
* perform at the same time
*/
private List hosts = Collections.synchronizedList(new ArrayList());
/**
* URL where authorised host list is located
*/
private String hostsFileUrl;
/**
* Timer use to re-read authorised hosts
*/
private Timer timer = new Timer();
/**
* Constructor for AuthroizedHostsFilter
* @param hostsFileUrl the URL where authorised hosts list is located
* @param reLoadInterval interval in ms at which authorised hosts list is re-read
*/
public AuthroizedHostsFilter(String hostsFileUrl, int reLoadInterval) {
this.hostsFileUrl = hostsFileUrl;
// Load values
load();
// Schedule periodic reload
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
CacheFactory.log("About to refresh host list");
load();
}
}, reLoadInterval, reLoadInterval);
}
/**
* Loads authorised host list
*/
private void load() {
try {
CacheFactory.log("Curent dir: " + System.getProperty("user.dir"), CacheFactory.LOG_DEBUG);
CacheFactory.log("Loading hosts file from URL: " + hostsFileUrl, CacheFactory.LOG_DEBUG);
URL url = new URL(hostsFileUrl);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
CacheFactory.log("Host IP address: " + inputLine, CacheFactory.LOG_DEBUG);
hosts.add(inputLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public boolean evaluate(Object host) {
String h = host.toString();
h = h.substring(h.indexOf('/') + 1);
CacheFactory.log("Validating host IP address: " + host + "(" + h + "), " + hosts.contains(h), CacheFactory.LOG_DEBUG);
return hosts.contains(h);
}
}
上記の例では、動的ルックアップは、ルックアップに何らかの資格証明を要求することでよりセキュアにすることができるでしょう。また、リソースをポーリングするのではなく、何らかの変更通知を使って、認可されたホストの再読込タイミングをフィルタに知らせることができるでしょう。しかし、多くの場合は上記のアプローチが適切でしょう。上記フィルタの完全なサンプルはこちらから入手できます。
0 件のコメント:
コメントを投稿