LoginSignup
0
2

More than 3 years have passed since last update.

Fluentd間でログを自己署名証明書で暗号化して送る

Posted at

概要

タイトルのとおり、Fluentdで送信元サーバーと送信先サーバー間のログ送信する際に自己署名証明書を使用する際の設定で苦戦したのでメモっておきます。

証明書の作成

とりあえず有効期間30年の証明書作成。頻繁に証明書を置き換えられるならもっと短くてもいいと思います。

$ openssl req -new -x509 -sha256 -days 10800 -newkey rsa:4096 -keyout fluentd.key -out fluentd.crt
# パスフレーズいれる
your_passphrese

Generating a 4096 bit RSA private key
..........................++
....................................++
writing new private key to 'fluentd.key'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:eg
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

ログ送信元での設定

上記で作成したcrtファイルをログ送信元に置きます。
今回は/etc/td-agent/certs/fluentd.crtに置いています。
shared_keyはまぁ適当に設定してください。
バッファーなどの設定は適当ですので適宜変えてください。

<match **.*>
    @type forward
    transport tls
    tls_cert_path /etc/td-agent/certs/fluentd.crt
    # 自己署名証明書を使用するにtrue
    tls_allow_self_signed_cert true
    # 自己署名証明書を使用する際にはfalseを設定する必要があります。
    tls_verify_hostname false
    <server>
      host forward.exmple.com
      port 24224
    </server>
    <security>
      self_hostname outputlog.exmple.com
      shared_key hogehoge
    </security>
    <buffer>
      @type file
      path /var/log/td-agent/buffer/sec_forward
    </buffer>
    flush_interval 60s
</match>

ログ送信先での設定

ログ受信時の設定を下記のようにします。
crtとkeyは作成したもの、shared_keyは送り元・送り先で同じフレーズを設定する必要があります。

<source>
  @type forward
  port 24224
  bind 0.0.0.0
  <security>
    self_hostname forward.exmple.com
    shared_key hogehoge
  </security>
  <transport tls>
    cert_path /etc/td-agent/certs/fluentd.crt
    private_key_path /etc/td-agent/certs/fluentd.key
    private_key_passphrase your_passphrese
  </transport>
</source>

あとがき

もしよかったら私のブログでも同じようなこと書いてるので来てくれたらうれしいです。

0
2
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
0
2