TORIPIYO DIARY

recent events, IoT, programming, security topics

How to create OpenVPN server on AWS environment at low cost

This article is a translation of this article.
openvpnを使ってaws環境にVPNサーバを比較的低コストで構築する方法 - TORIPIYO DIARY

I created VPN server with OpenVPN to connect my home network to AWS environment. I referred to several web sites. I want to share the procedure in this article. I think this method can be applied to small and medium-sized enterprises company's network. The cost of VPN network is only t2.neno running cost. You don't need to install new network hardware. So we can get VPN network at relatively low cost.

f:id:ha107chan:20170723204801p:plain

As the above diagram shows, VPN server will be constructed on AWS side.

By adopting the above architecture

  • Users can make a connection of SSH and HTTP protocol through VPN server. The services doesn't need to be exposed to external network. For example, if developers want to directly access to database server from their local Mac machine, exposing database server into Internet environment is not required.
  • By issuing certificate and key for individual user, If some users left from the development project, we can flexibly remove the access right of the users.

This article creates 1 VPN server for 1 VPC. So if you would like to use VPN server on multiple VPC environment, please take care that you need to create VPN server on each VPC environment.

Create VPN environment

VPN server construction

We don't need high spec instance for VPN server. It is enough to work for a few users usage.
spec

  • AMI:amzn-ami-hvm-2017.03.1.20170623-x86_64-gp2, SSD Volume Type
  • Subnet: subnet1 (Please configure subnet1's routing table to be able to communication with Internet.)
  • instance type: t2.nano
  • root volume: ebs

security group settings
Set below inbound configuration.

# 1194 port is used for VPN connection
TCP/1194
# 22 port is open for ssh operation. you may close this port after ssh operation
SSH/TCP/22


elastic IP settings
Fix VPN server's global IP address with AWS console.

adjust to be local time

modify clock file

vi /etc/sysconfig/clock

# ZONE="UTC"
ZONE="Japan" # this example is Japan time
UTC=true

modify symbolic link

# this example is Japan localtime
ln -sf /usr/share/zoneinfo/Japan /etc/localtime
Modify network configuration of OS

enable ip forwarding

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -w net.ipv4.ip_forward=1
cat /proc/sys/net/ipv4/ip_forward # confirm the value is 1

enable ip masquerade

echo "iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE" >> /etc/rc.local (enable ip masquerade on boot)
install openvpn

package update

yum update -y

install openvpn package

yum install -y openvpn

install easy-rsa package

yum install easy-rsa -y --enablerepo=epel
generate certificate

generate CA certificate and key

cd /usr/share/easy-rsa/2.0
vi vars

# set adequate values to align with your organization
export KEY_COUNTRY="JP"
export KEY_PROVINCE="Tokyo"
export KEY_CITY="Ota-ku"
export KEY_ORG="Cat Inc."
export KEY_EMAIL="admin@toripiyo.com"
export KEY_OU="Development Unit"

. ./vars
./clean-all # "NOTE: If you run ./clean-all, I will be doing a rm -rf on /usr/share/easy-rsa/2.0/keys" message will be shown.
./build-ca # use default value

generate server certificate and key

./build-key-server server  # set "common name" => vpn host name


generate client certificate and key

  • basically default values are fine on input prompt
  • below is a example of "tama" user's client certificate and key generation
./build-key tama

generate Diffie Hellman parameters

# it takes a while
./build-dh
configuration of certificate revocation
  • create a dummy certificate tentatively to make a certificate revocation list
cd /usr/share/easy-rsa/2.0
. ./vars
./build-key dummy # use default value
./revoke-full dummy # keys/crl.pem file will be generated
openvpn server configuration

edit server.conf file
some sites describe to use udp. however tcp was more stable on my environment

sudo cp /usr/share/doc/openvpn-*/sample/sample-config-files/server.conf /etc/openvpn/

vi /etc/openvpn/server.conf

# update with below configuration
port 1194
proto tcp
dev tun
ca /usr/share/easy-rsa/2.0/keys/ca.crt
cert /usr/share/easy-rsa/2.0/keys/server.crt
key /usr/share/easy-rsa/2.0/keys/server.key  # This file should be kept a secret
dh /usr/share/easy-rsa/2.0/keys/dh2048.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "route 10.1.0.0 255.255.0.0" #in the case vpc internal private ip range is 10.1.0.0/16
keepalive 10 120
comp-lzo
max-clients 20
persist-key
persist-tun
status openvpn-status.log
log-append  /var/log/openvpn.log
verb 3
crl-verify /usr/share/easy-rsa/2.0/keys/crl.pem

enable openvpn service on boot

chkconfig openvpn on

start openvpn service

openvpn /etc/openvpn/server.conf

server restart

  • confirm openvpn server works as expected even if server is restarted
reboot

VPN client configuration

configure a client side for VPN connection after VPN server construction

install tunnelbrick

install with cask

brew cask install tunnelblick
get certificate and key

(user name).key, (user name).crt, ca.crt files are required. Please transfer these files to client machine by some methods (ex. scp)

generate client.conf file
  • create .vpn directory under Mac's home directory.
  • put (user name).key, (user name).crt, ca.crt files into .vpn directory.
  • generate client.conf file with below configuration on .vpn directory. (client.conf file name can be changed as you like)
  • client.conf
client
dev tun
proto tcp
remote (vpn server's global ip address) 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca (ca.crt file's path)
cert ((user name).crt file's path)
key ((user name).key file's path)
remote-cert-tls server
comp-lzo
verb 3
tunnelbrick usage
  • start tunnelbrick application
  • drag and drop client.conf file into screen's right above side tunnelbrick icon.
  • click "Only Me" button when prompt is presented.
  • system ask mac's password. input your password. you can establish VPN connection between your mac machine and VPN server.

VPN server operation

how to add new client

if new user want to join your VPN server, please follow below procedure.
then share the generated (user name).crt, (user name).key, ca.crt files to new user.

cd /usr/share/easy-rsa/2.0
. ./vars
./build-key (new user name) # use default value
* openvpn service reboot is not required

how to remove existing client

if you want to remove specific user (ex. retired), please follow below procedure.

cd /usr/share/easy-rsa/2.0
. ./vars
./revoke-full (target user name) (keys/crl.pem file is generated)
* openvpn service reboot is not required

Raspberry Pi Zero WHにRaspbian OSを導入する

f:id:ha107chan:20180408193229j:plain

これは、
introduce Raspbian OS into Raspberry Pi Zero WH - TORIPIYO DIARY
の日本語訳です。

最近、スイッチサイエンスでrasbperry pi zero whを1800円で購入しました。複雑な心境ですが、実際このデバイスは私が大学入学時に初めて購入したパソコンよりスペックが良いです。当時、そのパソコンは15万円以上しました。

Raspberry Pi Zero WHにRaspbian OSを導入する方法を紹介したいと思います。この手順では、外部ディスプレイやキーボードは必要ありません。Raspberry Pi Zeroへの初回のWifi設定は、USB経由で実施されます。

必要なもの

電子工作のためにヘッダピンが欲しかったのでWH版にしています。
www.switch-science.com

  • micro SD カード 8GB

Rasbian OSのイメージを、このmicroSDカードに書き込みます。

  • micro SD カードリーダー

Macからraspberry pi のOSイメージを書き込む時に使います。
http://www2.elecom.co.jp/data-media/memory-rw/mr-c22/image/MR-C22WHF1_01.jpg

USB経由で、raspberry pi zero whに電源を供給するに利用しています。
akizukidenshi.com

1. 公式サイトからOSイメージを取得

まず、Raspbian OSのイメージをmicro SDカードに書き込む必要があります。以下のページにアクセスして、"RASPBIAN STRETCH LITE"のzipファイルをダウンロードしてください。(デスクトップバージョンの方ではありません。)
www.raspberrypi.org

2. etcherでOSイメージをmicro SDカードに書き込む

f:id:ha107chan:20180409203557j:plain
etcherというアプリケーションを使用します。etcherは、"brew cask install etcher"コマンドでインストールされます。(homebrew cask をインストールしてない場合は、こちらなどを参照 homebrewインストール個人メモ) etcherを起動して、ダウンロードされたイメージと書き込むmicro SD カードを選択して、'Flash'をクリックします。OS イメージのmicro SDカードへの書き込みが始まります。
f:id:ha107chan:20180416111646p:plain

3. SSH接続の有効化

OSイメージの書き込み後、micro SDカードをMacに繋げると、boot driveがマウントされます。SSHサービスを有効化させるために、sshファイルを作成します。

touch /Volumes/boot/ssh
4. USB経由のインターネット接続有効化

"rootwait" と "quiet" の間に、"modules-load=dwc2,g_ether" の設定を追加します。

vi /Volumes/boot/cmdline.txt

"dtoverlay=dwc2"をconfig.txtファイルの最終行に追加します。

echo "dtoverlay=dwc2" >> /Volumes/boot/config.txt

ここまで設定したら、boot driveをアンマウントして、micro SDカードをRaspberry Pi Zero WHに差し込みます。

5. USB経由でRaspberry Pi Zeroと接続

Macの共有設定を変更します。("System Preference" => "Sharing").
f:id:ha107chan:20180416112728p:plain

f:id:ha107chan:20180415234758j:plain
(micro USBは、Raspberry Pi Zero WHのアダプターに挿入されています。)

MacRaspberry Pi Zero WHをmicro USBコネクターで繋ぎます。

ユーザ名は"pi", パスワードは"raspberry"です。

~: ssh pi@raspberrypi.local
pi@raspberrypi.local's password:
Linux raspberrypi 4.9.80+ #1098 Fri Mar 9 18:51:28 GMT 2018 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
6. Wifi 設定

Raspberry Pi Zero に接続させる予定のWifiの"ESSID"と"password"を控えておきます。Raspberry Pi Zero が認識できるWifiのESSIDの一覧は、"sudo iwlist wlan0 scan | grep -i essid"コマンドで確認できます。

_ESSID="target ESSID name"
vi pass.txt (write wifi password into pass.txt file)
sudo cp -ipv /etc/wpa_supplicant/wpa_supplicant.conf{,.backup}
sudo sh -c "wpa_passphrase ${_ESSID} < pass.txt >> /etc/wpa_supplicant/wpa_supplicant.conf"

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf # remove "#psk" line for security
rm -i pass.txt # remove pass.txt file for security

sudo wpa_cli -i wlan0 reconfigure # reconfigure wlan0 interface

ifconfig wlan0 # take a note of assigned IP address of wlan0

wifiに接続できたら、wlan0インターフェースにIPアドレスアサインされるので、鍵認証作業のためにIPアドレスをメモしておきます。

7. 鍵認証の作成
# on mac
cd ~/.ssh
ssh-keygen -t rsa -f pizero

ssh-copy-id -i pizero.pub pi@<ip address of raspberrypi zero>   # transfer public key to raspberrypi zero

ssh -i pizero.pub pi@<ip address of raspberrypi zero>

# on Raspberry Pi Zero
# disable password authentication
sudo cp -ipv /etc/ssh/sshd_config{,.backup}
sudo sh -c 'echo "PasswordAuthentication no" >> /etc/ssh/sshd_config'

sudo systemctl restart ssh
8. MacのUSB接続設定の無効化

"System Preference" => "Sharing" で、5番と逆の設定をする。

9. Raspberry Pi Zero のUSB接続設定の無効化
# on raspberry pi shell
# remove "dtoverlay=dwc2"
sudo vi /boot/config.txt

# remove "modules-load=dwc2,g_ether"
sudo vi /boot/cmdline.txt

これで、Raspberry Pi Zero WHで、Raspbian OSが使えるようになりました。

参考

100円ショップのType-C充電通信ケーブルを使ってMacBook Proを充電する

GWで実家に帰省したら、MacBook Pro (13inch, 2017モデル) の電源ケーブルを忘れてしまいました。
ということで、100円ショップのセリアで緊急にType-C用のケーブルを購入しました。

「3.0A急速充電対応 Type-C充電通信ケーブル」
f:id:ha107chan:20180502161057j:plain

iPhone用の充電機は持っていたので、以下のように配線します。特に警告メッセージは表示されません。
f:id:ha107chan:20180503105236j:plain

Macを使っている間は、ほとんど充電されませんが、電池が減らないようになります。Macをsleepさせて、ケーブルを繋いだまま2~3時間放って置くと結構充電されます。一晩おいておくと、100%まで充電されていました。

旅行とか出張とかの緊急時には一時的に利用できるのではないかと思います。ただ、純正品ではないので、本当に一時的な利用に留めた方が無難でしょう。

introduce Raspbian OS into Raspberry Pi Zero WH

f:id:ha107chan:20180408193229j:plain

These days I purchased raspberrypi zero WH in switch science online shop for 1800 yen. (actually this device is more powerful than my first PC that I purchased when I enter university... It was over 150000 yen in those days.)

I would like to introduce how to use Raspbian OS on Raspberry Pi Zero WH. This method doesn't require external display or keyboard. Initial Wifi configuration for Raspberry Pi Zero is set up through USB connection.

1. Get OS image from official site

At first we need to install Raspbian OS image into micro SD card. Please access to this page and download "RASPBIAN STRETCH LITE" zip file. (not Desktop version)
www.raspberrypi.org

2. Write OS image into micro SD with etcher software

f:id:ha107chan:20180409203557j:plain
Use etcher software (which can be installed by "brew cask install etcher" command).
Select downloaded image and micro SD device, then Click 'Flash'. Installing OS image into micro SD will start.
f:id:ha107chan:20180416111646p:plain

3. Enable SSH connection

When micro SD is connected to Mac, boot drive will be mounted. Create ssh file to enable SSH service.

touch /Volumes/boot/ssh
4. Enable Internet connectivity through USB

Add "modules-load=dwc2,g_ether" configuration between "rootwait" and "quiet".

vi /Volumes/boot/cmdline.txt

Add "dtoverlay=dwc2" at the end of config.txt file as well.

echo "dtoverlay=dwc2" >> /Volumes/boot/config.txt
5. Connect to Raspberry Pi Zero through USB

Change Mac's Sharing configuration ("System Preference" => "Sharing").
f:id:ha107chan:20180416112728p:plain

Username is "pi", password is "raspberry".
f:id:ha107chan:20180415234758j:plain
(micro USB is inserted into adaptor of Raspberry Pi Zero WH)

~: ssh pi@raspberrypi.local
pi@raspberrypi.local's password:
Linux raspberrypi 4.9.80+ #1098 Fri Mar 9 18:51:28 GMT 2018 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
6. Wifi configuration

Take a note of Wifi "ESSID" and "password". Recognized ESSID by Raspberry Pi Zero can be found by "sudo iwlist wlan0 scan | grep -i essid" command.

vim pass.txt (write wifi password into pass.txt file)
sudo cp -ipv /etc/wpa_supplicant/wpa_supplicant.conf{,backup}
sudo sh -c 'wpa_passphrase "target ESSID name" < pass.txt >> /etc/wpa_supplicant/wpa_supplicant.conf'

sudo vi /etc/wpa_supplicant/wpa_supplicant.conf # remove "#psk" line for security
rm -i pass.txt # remove pass.txt file for security

sudo wpa_cli -i wlan0 reconfigure # reconfigure wlan0 interface

In this point if you restart Raspberry Pi Zero, assigned IP address might be changed, in that case try to connect with other IP address.

7. Make key authentication
# on mac
cd ~/.ssh
ssh-keygen -t rsa -f pizero

ssh-copy-id -i pizero.pub pi@<ip address of raspberrypi zero>   # transfer public key to raspberrypi zero

ssh -i pizero.pub pi@<ip address of raspberrypi zero>

# on Raspberry Pi Zero
# disable password authentication
sudo cp -ipv /etc/ssh/sshd_config{,.backup}
sudo sh -c 'echo "PasswordAuthentication no" >> /etc/ssh/sshd_config'

sudo systemctl restart ssh
8. Disable USB connectivity of Mac

Do reverse operation on "System Preference" => "Sharing".

9. Disable USB connectivity of Raspberry Pi Zero
# remove "dtoverlay=dwc2"
vi /Volumes/boot/config.txt

# remove "modules-load=dwc2,g_ether"
vi /Volumes/boot/cmdline.txt
References

pythonでburpのextensionを作成してリクエストヘッダーに新しいヘッダーを追加する

burpという脆弱性診断ツールを使うときに、リクエストヘッダーに新しいヘッダーを追加する処理が必要だったのでpythonを使ってヘッダーを追加で付与するextensionを作成しました。

下記のpythonスクリプトは、
labs.neohapsis.com
の記事を参考に作成しています。あとは、burpのAPIドキュメントを参考にしました。
https://portswigger.net/Burp/extender/api/index.html


gist.github.com

registerExtenderCallbacks

  • registerExtenderCallbacksの関数は、extensionの作成にはだいたいいつも必要。setExtensionNameで、好きなextension名を引数として与える

processHttpMessage

  • "# header"の箇所で、リクエストヘッダーの情報を抜き出して、listとしてheadersArrayに格納する
  • "# body"の箇所で、リクエストボディの情報を抜き出して、stringとしてbodyStrに格納する
  • "# add X-TORIPIYO"の箇所で、リクエストのホスト情報を抜き出して、'toripiyo.hatenablog.com'へのリクエストの場合は、X-TORIPIYOヘッダーを追加している。このスクリプトではpiyopiyoという値だけど、もっと複雑な計算をして値を入れたい場合は、ロジックを記載してnewHeader = "X-TORIPIYO: " + value という感じで入れる
  • "# set new request"の箇所で、リクエストを発行する

pythonのextensionをburpで使う場合は、jythonのjarファイルを読み込むようにburpに設定させる必要があります。詳しい読み込み方は、下記サイトなど参照。
tech.pjin.jp

作成したpythonスクリプトをextensionとしてburpに読み込ませて、extensionをロードした状態でbrowserからburpを経由してtoripiyo.hatenablog.comにリクエストを送ると、X-TORIPIYOヘッダーの追加を確認できます。
f:id:ha107chan:20180325112414p:plain

ちなみに、extensionを読み込んだburpのHTTP historyのレコードからは、X-TORIPIYOヘッダーの追加を確認できません。確認方法は2通りあります。

1. Logger++ エクステンションを利用する
Logger++というエクステンションをインストールして有効化すれば、Logger++タブには送信直前のリクエスト内容がログとして記録されます。X-TORIPIYOヘッダーも追加されていることが確認できます。

2. burpインスタンスを2個立ち上げる
burpインスタンスを2個ローカルマシンに立ち上げて、browser => burp1 => burp2 => toripiyo.hatenablog.comという形でリクエストを送ります。X-TORIPIYOヘッダーの追加を確認できるのは、burp2のHTTP historyのレコードからです。複数のburpインスタンスの立ち上げ方は、下記の記事を参照してみてください。
Running Multiple Burp Suite Instances

Restart nodejs application on file change or error output in "heroku local" command

This article is English translation of http://toripiyo.hatenablog.com/entry/2018/03/11/185532 Japanese article.

I am deploying nodejs application on heroku platform as production. In local environment I use "heroku local" command to run application on local machine.
I googled to find a way to make nodejs application automatically restart on file change or error message output by "heroku local" command.
However I couldn't find a proper article to explain it. So I would like to summarize it as note to myself.

By following below steps, the application can automatically restart on file change or stop by error message output.

0. install forever

npm install forever -g

1. insert below line on Procfile which located on application's root directory

development: forever -w -m 500 -c "node --inspect=5858" app.js
  • -w option is used to restart application on file change
  • -m option is used to specify how many times restart application (in this example the application can be restarted 500 times if error output stops the application)
  • -c option is used to specify the command which executed when "heroku local development" command is run. --inspect option is used to open 5858 port for debug purpose.

2. put .foreverignore file on application root directory

(.foreverignore)
=====================================
**/.idea/**
**/.git/**

**/.tmp/**
**/views/**
**/assets/**

# Restart only when js files are changed.
!*.js
=====================================
  • notice: .foreverignore writing style is different from .gitignore style. the application can decide to restart by referring to .foreverignore contents.

foreverignore syntax/documentation · Issue #417 · foreverjs/forever · GitHub


3. run application with "heroku local" command

heroku local development

By following above steps, the application which managed by "heroku local" command can automatically restart even on file change or stop by error message output.

Dockerを利用してローカル環境のmongoDBをhomebrewの3.2からdockerコンテナの3.6に移行させる

現在開発中のアプリケーションで利用しているmongooseをバージョンアップさせたら正しくアプリケーションが動作しなくなり、直すには、mongoDBのバージョンを3.6に上げることが必要なことがわかりました。
ローカル環境のmongoDBは、brew install mongoでインストールしたmongoDB 3.2系を利用していたので、brew upgrade mongodbを実行して3.6系にバージョンを変更。
これで、問題なく動くようになると思ったら、、、

mongod --config /usr/local/etc/mongod.conf

を実行すると以下のメッセージが表示されてmongoDBを起動出来ません。

2018-03-12T00:01:13.020+0900 F CONTROL  [initandlisten] ** IMPORTANT: UPGRADE PROBLEM: The data files need to be fully upgraded to version 3.4 before attempting an upgrade to 3.6; see http://dochub.mongodb.org/core/3.6-upgrade-fcv for more details.
2018-03-12T00:01:13.020+0900 I NETWORK  [initandlisten] shutdown: going to close listening sockets...

エラーメッセージを見た限りでは、/usr/local/var/mongodbに置いてあるデータは、異なるバージョン間では互換性が無いようでうまく読み込みが出来ない様子。そこで、mongoDB3.2からデータをダンプして、mongoDB3.6にダンプしたデータを読み込ませることにしました。

brew switch mongodb 3.2.1 

でバージョンを3.6から3.2に戻して、

mongodump -v --out data-`date +"%m-%d-%y"` 

を実行すると、なぜかコマンドから応答が帰ってこなくてdumpファイルを取得できない。もしかしたら、正しい場所に繋ぎに行こうと出来ていないのかもしれませんが、原因わからず。ここまで来て、dockerを使ってデータのダンプとリストアを実行することにしました。

mongoDB 3.2からdumpファイルの取得

まず、mongoDB3.2のコンテナを動かします。この時、ローカル環境のmongoDBデータを読み込ませられるように、-vオプションでローカルの/usr/local/var/mongodbを、コンテナの/data/dbパス上にマウントさせます。

docker run --name mongo-3.2 -v /usr/local/var/mongodb:/data/db -d mongo:3.2

稼働しているmongo-3.2コンテナに対して、mongodumpコマンドを実行してdumpファイルをmongo-3.2コンテナ上の/tmpディレクトリ配下に作成します。

docker exec mongo-3.2 mongodump -v --out /tmp/data-`date +"%m-%d-%y"`

コンテナ上のdumpファイルをローカル上にコピーします。

docker cp mongo-3.2:/tmp/data-`date +"%m-%d-%y"` .

これで、dockerを利用してmongoDBのdumpファイルを取得できました。

mongoDB 3.6でdumpファイルの読み込み

mongoDB3.6のコンテナを稼働させて、mongoDB 3.2から取得したdumpファイルを読み込ませるようにします。3.6ではdockerボリューム上にデータを置きたいので、まず、mongoDB用のdockerボリュームを作成します。

docker volume create db

mongoDB 3.6を稼働させます。-vオプションで、dbボリュームをコンテナの/data/dbパスにマウント。-pオプションで、ローカルマシンの27017ポートに繋ぐとコンテナの27017ポートに転送されるように設定します。

docker run --name mongo-3.6 -v db:/data/db -p 27017:27017 -d mongo:3.6

ローカル上のdumpファイルをmongoDB 3.6のコンテナ上にコピーします。

docker cp data-`date +"%m-%d-%y"` mongo-3.6:/tmp

稼働しているmongoDB 3.6のコンテナに対して、mongorestoreコマンドを実行させてdumpデータを読み込ませます。

docker exec mongo-3.6 mongorestore /tmp/data-`date +"%m-%d-%y"`


===========================================

これで、homebrewでインストールしたmongoDB 3.2を、dockerコンテナのmongoDB 3.6コンテナに切り替えることができるようになりました。これからは、ローカル環境のmongoDBはdockerで管理したいと思います。