LoginSignup
7
6

More than 5 years have passed since last update.

VulsをDockerで構築したけどHostKeyを登録しろと永遠言われる問題

Last updated at Posted at 2017-12-26

前提

公式の手順を元にDockerをセットアップした。
https://github.com/future-architect/vuls/tree/master/setup/docker

問題

Dockerのホストからサーバに接続はできる。
しかし、HostKeyを登録しろと怒られる。それは100年前に登録してある。

[Dec 26 09:28:48] ERROR [localhost] (5/5) Failed: SERVER, err: [Failed to detect OS: Unable to connect via SSH. Check SSH settings. If you have never SSH to the host to be scanned, SSH to the host before scanning in order to add the HostKey. user@172.17.2.62 port: 22
execResult: servername: SERVER
  cmd: /usr/bin/ssh -tt -o StrictHostKeyChecking=yes -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none user@172.17.2.62 -p 22 -i /root/.ssh/id_rsa_vuls -o PasswordAuthentication=no stty cols 1000; ls /etc/debian_version
  exitstatus: 255
  stdout: 
  stderr: 
  err: %!s(<nil>)]

原因

接続先のセグメントが、
Docker bridgeのデフォルトのIPとバッティングしていた。

調査結果

debugモードで実施すると、
getsockopt: no route to hostというエラーが大量に吐かれていた。

$ docker run --rm -it    -v ~/.ssh:/root/.ssh:ro     -v $PWD:/vuls     -v $PWD/vuls-log:/var/log/vuls     vuls/vuls configtest     -config=./config.toml --debug
(略)
o SERVER, err: dial tcp 172.17.2.62:22: getsockopt: no route to host, Retrying in 3.749548963s...
[Dec 26 09:37:36] DEBUG [localhost] Failed to Dial to SERVER, err: dial tcp 172.17.2.61:22: getsockopt: no route to host, Retrying in 5.535907099s... 

コンテナ内に入り、対象のサーバへping/sshを実施。繋がらない。
他のセグメントや他のサーバには繋がる。
恥ずかしながらここで初めてDocker内のネットワークを疑う。

対応方法

Docker bridge のIPを使っていないセグメント帯に変更

まずはdockerのネットワーク一覧を表示

# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
ae5bb0c38a2c        bridge              bridge              local
dd1c38f5429e        host                host                local
6519945407d0        none                null                local
#

bridgeが怪しいので中身を調査

$ docker network inspect ae5bb0c38a2c
[
    {
        "Name": "bridge",
 (略)
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },

ビンゴ。

Docker bridgeのセグメントを変更。

# vi /usr/lib/systemd/system/docker.service 
(略)
[Service]
(略)
#ExecStart=/usr/bin/dockerd
ExecStart=/usr/bin/dockerd --bip=10.0.0.1/8

docker再起動。。。
と思ったけど、OS再起動しても構わないサーバだったので
念のためOS再起動

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         GATEWAY         0.0.0.0         UG    100    0        0 eth0
10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 docker0

docker0のセグメントが変更された。

Vulsを起動

$ docker run --rm -it    -v ~/.ssh:/root/.ssh:ro     -v $PWD:/vuls     -v $PWD/vuls-log:/var/log/vuls     vuls/vuls scan   -config=./config.toml
(略)
 (5/5) Detected: SERVER: centos 7.4

成功!

参考情報

Dockerのbridgeのセグメントを変更する方法
http://tigertaizo.hatenablog.com/entry/2016/08/06/173101#1-Docker%E3%83%8D%E3%83%83%E3%83%88%E3%83%AF%E3%83%BC%E3%82%AF%E7%8F%BE%E7%8A%B6%E7%A2%BA%E8%AA%8D

7
6
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
7
6