Quantcast
Channel: 元うなぎ屋
Viewing all articles
Browse latest Browse all 341

#Splunk の通信をSSL対応させてみた

$
0
0


何とか、SplunkのSSL対応を終えた @snicker_jp です。

きっかけ

以前、セットアップ方法を書いたのですが。
その時は出来なかったSSL通信について、設定することが出来たのでその手順です。

前提条件

  • Splunk 5.0.2
  • Splunk Universal Forwarder 5.0.2 (以降Forwarder)
  • OSはどちらもLinux
先日記事アップした時点で「5.0.2」が出ていたので、新しいのでやりました。

大まかな流れ

  • Splunk(indexer)側で、証明書(RootCA、サーバー証明書)作成、conf反映
  • Splunk(indexer)から(Forwarder)側に証明書(RootCA)転送
  • Splunk(Forwarder)側で、サーバー証明書作成、conf反映
  • 確認



Splunk(indexer)側で、証明書(RootCA、サーバー証明書)作成、conf反映

以下のコマンド実行
export SPLUNK_HOME="/opt/splunk"
export OPENSSL_CONF=$SPLUNK_HOME/openssl/openssl.cnf
mkdir -m700 -p $SPLUNK_HOME/etc/certs
chown splunk: $SPLUNK_HOME/etc/certs
$SPLUNK_HOME/bin/splunk cmd genRootCA.sh -d $SPLUNK_HOME/etc/certs -l 2048
$SPLUNK_HOME/bin/splunk createssl server-cert -d $SPLUNK_HOME/etc/certs -c [COMMON_NAME] -n [証明書名] -l 2048 -p

追記:誤りがあったので修正しました。

上記の注意点、
重要:パスワードを必ず設定すること
設定しないで、ここでハマりました。

# $SPLUNK_HOME/bin/splunk createssl server-cert -d $SPLUNK_HOME/etc/certs -c [COMMON_NAME] -n splunk01  -l 2048 -p
No Common Name specified. If client side checks are enabled, connection negotiation may fail.

* Create certificate splunk01.pem signed by the root CA.
* Store the splunk01.pem key file locally with your client/server application.
* Enter a secret passphrase when requested.
* The passphrase is used to access splunk01.pem in your application.
* Enter the application's hostname as the Common Name when requested.
* Enter the root CA passphrase (Getting CA Private Key) to sign the keyfile.
* The keyfile will expire after one year or sooner if the root CA expires.

Generating a 2048 bit RSA private key
...........+++
...........................................................+++
writing new private key to 'splunk01key.pem'
Enter PEM pass phrase: #[※必ず設定]
Verifying - Enter PEM pass phrase: #[※必ず設定]
  • conf反映(例)
/opt/splunk/etc/system/local/inputs.conf
[default]
host = splunk01.example.com

[splunktcp-ssl:9997]
compressed = true

[SSL]
password = [設定したパスワード]
rootCA = $SPLUNK_HOME/etc/certs/cacert.pem
serverCert = $SPLUNK_HOME/etc/certs/splunk01.pem

password = [設定したパスワード]」は再起動でハッシュ化されるのでベタ書きで大丈夫です。


Splunk(indexer)から(Forwarder)側に証明書(RootCA)転送

以下のファイルを転送します
  • ca.pem
  • cacert.pem
scp ca.pem cacert.pem [ユーザー名]@[Splunk(Forwarder)側]:.

Splunk(Forwarder)側で、サーバー証明書作成、conf反映

同様に、以下のコマンド実行

export SPLUNK_HOME="/opt/splunkforwarder"
export OPENSSL_CONF=$SPLUNK_HOME/openssl/openssl.cnf
mkdir -m700 -p $SPLUNK_HOME/etc/certs
mv -v ca.pem cacert.pem $SPLUNK_HOME/etc/certs/.
chown splunk: -R $SPLUNK_HOME/etc/certs
cd $SPLUNK_HOME/etc/certs
$SPLUNK_HOME/bin/splunk createssl server-cert -d $SPLUNK_HOME/etc/certs -c [COMMON_NAME] -n [証明書名] -l 2048 -p

ここでも、
重要:パスワードを必ず設定すること

  • conf反映(例)
/opt/splunkforwarder/etc/system/local/outputs.conf
[tcpout]
defaultGroup = splunkssl
[tcpout:splunkssl]
server = 192.168.1.100:9997
compressed = true

[tcpout-server://192.168.1.100:9997]
sslRootCAPath = $SPLUNK_HOME/etc/certs/cacert.pem
sslCertPath = $SPLUNK_HOME/etc/certs/forwarder.pem
sslCommonNameToCheck = splunk01.example.com
sslPassword = [設定したパスワード]
sslVerifyServerCert = true


確認

確認はWebUIから、データが来ていればOKです。
または、「$SPLUNK_HOME/var/log/splunk/splunkd.log」を確認

こんな感じの設定でできると思います。

参考サイト

こちらにトラブルシュート例も書かれています。

How do I set up SSL forwarding with new, self-signed certificates and authentication? - Splunk Community
http://splunk-base.splunk.com/answers/7164/how-do-i-set-up-ssl-forwarding-with-new-self-signed-certificates-and-authentication


(コラム)参考サイトからの変更点


  • genRootCA.shではなく「splunk createssl server-cert
  • 「genRootCA.sh」だと、こんなメッセージが出るから 「getSignedServerCert.sh」にしてみた
    # $SPLUNK_HOME/genRootCA.sh
You must specify where your certificates are to be stored

Usage: getSignedServerCert.sh

-d Where to store the root CA. /opt/splunk/etc/certs REQUIRED

-l Length of RSA key to generate. OPTIONAL

「getSignedServerCert.sh」にしてみると、こんなメッセージが出て 今後なくなるらしいので「splunk createssl server-cert」にしました
    # $SPLUNK_HOME/bin/genSignedServerCert.sh
++python /opt/splunk/bin/genSignedServerCert.py
NOTE: This script is deprecated. Instead, use "splunk createssl server-cert".

Parameters:
-d: Directory where rootCa and other certs are stored.
(required)
-n: The name of the cert.
(required)
-c: The CommonName for the cert. This should match the DNS name.
If DNS is not available then the IP will suffice.
-l: Length of the RSA key to generate (default 1024).
-p: Prompt for optional arguments.

  • あとは既定で鍵長が「1024bit」なので、「2048bit」に。
  • 「-p」オプションつけると、「Common Name」聞かれるので「-c」なし
    つけても「CN」聞かれるけど、つけないとコマンドが通らない・・・
  • 「altCommonNameToCheck」エラーが出るので、なし

Viewing all articles
Browse latest Browse all 341

Trending Articles