タイトル長い。
fluent-plugin-secure-forward のバージョンが送り側・受け側で違うせいで Shared key mismatch
云々というエラーが出てしまったので、とりあえず docker-compose で再現できる環境を作ったメモ。
ソースを追ったところ、Change authentication protocol: fix to send nonce for shared_key check · tagomoris/fluent-plugin-secure-forward@6f1c4c1 が原因っぽいので、このコミットが入っていない v0.3.1 (送り側) と、このコミットが入った v0.3.2 (受け側) という構成で試してみた。
ディレクトリ作成
作業ディレクトリを作成し、移動。
$ mkdir secure-forwards
$ cd secure-forwards
必要なディレクトリを作っておく。
$ mkdir -p new/log
$ mkdir -p new/plugins
$ mkdir -p old/log
$ mkdir -p old/plugins
ファイル作成
docker-compose.yml 作成。
$ vi docker-compose.yml
version: '2'
services:
new:
build: ./new/
volumes:
- ./new/log:/fluentd/log
ports:
- 24284
old:
build: ./old/
volumes:
- ./old/log:/fluentd/log
ports:
- 24224
0.3.2 と 0.3.1 それぞれの Dockerfile を作成。
vi new/Dockerfile
FROM fluent/fluentd:latest-onbuild
MAINTAINER YOUR_NAME <...@...>
WORKDIR /home/fluent
ENV PATH /home/fluent/.gem/ruby/2.3.0/bin:$PATH
USER root
RUN apk --no-cache add sudo build-base ruby-dev && \
sudo -u fluent gem install fluent-plugin-secure-forward:0.3.2 && \
rm -rf /home/fluent/.gem/ruby/2.3.0/cache/*.gem && sudo -u fluent gem sources -c && \
apk del sudo build-base ruby-dev
EXPOSE 24284
USER fluent
CMD exec fluentd -c /fluentd/etc/$FLUENTD_CONF -p /fluentd/plugins $FLUENTD_OPT
$ vi old/Dockerfile
FROM fluent/fluentd:latest-onbuild
MAINTAINER YOUR_NAME <...@...>
WORKDIR /home/fluent
ENV PATH /home/fluent/.gem/ruby/2.3.0/bin:$PATH
USER root
RUN apk --no-cache add sudo build-base ruby-dev && \
sudo -u fluent gem install fluent-plugin-secure-forward:0.3.1 && \
rm -rf /home/fluent/.gem/ruby/2.3.0/cache/*.gem && sudo -u fluent gem sources -c && \
apk del sudo build-base ruby-dev
EXPOSE 24224
USER fluent
CMD exec fluentd -c /fluentd/etc/$FLUENTD_CONF -p /fluentd/plugins $FLUENTD_OPT
0.3.2 と 0.3.1 それぞれの fluent.conf を作成。
$ vi new/fluent.conf
<source>
type secure_forward
shared_key tekitou
secure no
self_hostname new
cert_auto_generate yes
allow_anonymous_source yes
authentication yes
bind 0.0.0.0
port 24284
<user>
username tekitou
password tekitou
</user>
</source>
<label @mainstream>
<match **>
@type stdout
</match>
</label>
$ vi old/fluent.conf
<source>
@type forward
port 24224
</source>
<filter **>
@type stdout
</filter>
<match **>
@type secure_forward
shared_key tekitou
secure no
self_hostname old
<server>
host new
port 24284
username tekitou
password tekitou
</server>
</match>
検証
docker-compose up -d
で 2 つのコンテナを起動。
$ docker-compose up -d
(略)
$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------------------------------
secureforwards_new_1 /bin/sh -c exec fluentd -c ... Up 24224/tcp, 0.0.0.0:32816->24284/tcp, 5140/tcp
secureforwards_old_1 /bin/sh -c exec fluentd -c ... Up 0.0.0.0:32815->24224/tcp, 5140/tcp
送り側の 0.3.1 のコンテナにログを流す。
$ docker-compose exec old sh -c "echo '{\"hello\":\"world\"}' | fluent-cat docker"
受け側のログを見てみると、Shared key mismatch エラーが出ていることが分かる。
$ docker-compose logs new
(略)
new_1 | 2017-02-08 03:59:56 +0000 [warn]: Shared key mismatch from 'old'
まとめ
fluent-plugin-secure-forward のバージョンが送り側・受け側で違うときに出る Shared key mismatch エラーを docker-compose で再現させることができた。設定ファイルで回避することができるか確認できていないので、もう少し調べてみよう。