logwatch で VPN(strongswan )用の出力

スポンサーリンク
スポンサーリンク

CentOS で strongswan によるVPN(設定方法は こちらの記事) を運用している場合、logwatch での ログレポートでは、以下のように接続ログが Unmatched Entries として扱われます。
これを Strongswan の項目としてレポートされるようにする設定です。

 --------------------- Connections (secure-log) Begin ------------------------ 
 
 **Unmatched Entries**
    charon: 05[IKE] yy.yy.yy.yy is initiating a Main Mode IKE_SA: 1 Time(s)
    charon: 05[IKE] deleting IKE_SA L2TP-PSK-NAT[7] between xx.xx.xx.xx[xx.xx.xx.xx]...yy.yy.yy.yy[192.168.1.54]: 1 Time(s)
    charon: 09[IKE] yy.yy.yy.yy is initiating a Main Mode IKE_SA: 1 Time(s)
    charon: 09[IKE] CHILD_SA L2TP-PSK-NAT{6} established with SPIs ca184f34_i 57def128_o and TS xx.xx.xx.xx/32[udp/l2tp] === yy.yy.yy.yy/32[udp/l2tp]: 1 Time(s)
    charon: 09[IKE] CHILD_SA L2TP-PSK-NAT{7} established with SPIs c66a80d0_i e97a01a6_o and TS xx.xx.xx.xx/32[udp/l2tp] === yy.yy.yy.yy/32[udp/l2tp]: 1 Time(s)
    charon: 13[IKE] closing CHILD_SA L2TP-PSK-NAT{7} with SPIs c66a80d0_i (30086 bytes) e97a01a6_o (12210 bytes) and TS xx.xx.xx.xx/32[udp/l2tp] === yy.yy.yy.yy/32[udp/l2tp]: 1 Time(s)
    charon: 14[IKE] IKE_SA L2TP-PSK-NAT[6] established between xx.xx.xx.xx[xx.xx.xx.xx]...yy.yy.yy.yy[192.168.1.54]: 1 Time(s)
    charon: 14[IKE] IKE_SA L2TP-PSK-NAT[7] established between xx.xx.xx.xx[xx.xx.xx.xx]...yy.yy.yy.yy[192.168.1.54]: 1 Time(s)
    charon: 14[IKE] deleting IKE_SA L2TP-PSK-NAT[6] between xx.xx.xx.xx[xx.xx.xx.xx]...yy.yy.yy.yy[192.168.1.54]: 1 Time(s)
    charon: 15[IKE] closing CHILD_SA L2TP-PSK-NAT{6} with SPIs ca184f34_i (149821 bytes) 57def128_o (1337245 bytes) and TS xx.xx.xx.xx/32[udp/l2tp] === yy.yy.yy.yy/32[udp/l2tp]: 1 Time(s)
 
 ---------------------- Connections (secure-log) End ------------------------- 
スポンサーリンク

設定方法

本記事の設定により、次のように logwatch でレポートされるようになります。

 --------------------- Strongswan Begin ------------------------ 
 
 IKE_SA Connections Initiated:
    Main Mode IKE_SA:
       yy.yy.yy.yy    9 Time(s)
 
 IKE_SA Connections:
    L2TP-PSK-NAT:
       xx.xx.xx.xx[xx.xx.xx.xx]...yy.yy.yy.yy[192.168.1.2]
          Established   1 Time(s)
          Destroyed     1 Time(s)
 
       xx.xx.xx.xx[xx.xx.xx.xx]...yy.yy.yy.yy[192.168.1.54]
          Established   2 Time(s)
          Destroyed     2 Time(s)
 
 
 CHILD_SA Connections:
    L2TP-PSK-NAT:
       xx.xx.xx.xx/32[udp/l2tp] === yy.yy.yy.yy/32[udp/l2tp]
          Established   3 Time(s)
          Destroyed     3 Time(s)
          Data In       60.537K
          Data Out      72.614K
 
 
 ---------------------- Strongswan End ------------------------- 

以下、設定方法です。

次のようにしてファイルをコピーします。

cp /etc/logwatch/scripts/services/secure /etc/logwatch/scripts/services/secure_custom

次のファイルで、緑色の行を追加します。

/etc/logwatch/scripts/services/secure_custom

   if (( $ThisLine =~ /pam_succeed_if(\([a-zA-Z]*:[a-zA-Z]*\))?: requirement \"uid (<|>)=? (5|10)00?\" (was|not) met by user /) or
      <strong>( $ThisLine =~ /charon/ ) or</strong>
      ( $ThisLine =~ /pam_rhosts_auth\[\d+\]: allowed to [^ ]+ as \w+/) or

次の内容のファイルを作成します。
2020.10.15 修正
$secure_ip_lookup の $ が抜けていました

/etc/logwatch/conf/services/secure_custom.conf

Title = "Connections (secure-log)"
LogFile = secure
$secure_ip_lookup = No
$ignore_services = sshd Pluto stunnel proftpd saslauthd imapd postfix/smtpd

次の行を追加します。

/etc/logwatch/conf/logwatch.conf

Service = "-secure"

2020.10.15 追記

次を実行します。strongswan 用の設定ファイル・スクリプトがコピーされます。

wget https://github.com/jbeker/logwatch-strongswan/archive/master.zip
unzip master.zip
cd logwatch-strongswan-master/
cp -a logwatch/* /etc/logwatch/

2020.10.15 追記 ここまで

これで設定できました。

確認するには、以下コマンドを実行してください。
メール送付と同じ内容が、画面に表示されます。
ここで、Strongswan の項目としてレポートされているか確認してください。

logwatch --print

コメント

タイトルとURLをコピーしました