How to fix docker and ufw security problem


Example: we use docker to install nodes for mongodb replica set : http://tutorialspots.com/use-docker-to-run-mongodb-replica-set-6859.html

But we can access port 27017 any where !!! how to fix this security problem ?

Step 1: download ufw-docker

sudo wget -O /usr/local/bin/ufw-docker https://github.com/chaifeng/ufw-docker/raw/master/ufw-docker

root@ubuntu-16gb-ash-1:~# sudo wget -O /usr/local/bin/ufw-docker https://github.com/chaifeng/ufw-docker/raw/master/ufw-docker
--2022-04-12 15:05:41--  https://github.com/chaifeng/ufw-docker/raw/master/ufw-docker
Resolving github.com (github.com)... 140.82.121.3
Connecting to github.com (github.com)|140.82.121.3|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/chaifeng/ufw-docker/master/ufw-docker [following]
--2022-04-12 15:05:41--  https://raw.githubusercontent.com/chaifeng/ufw-docker/master/ufw-docker
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 2606:50c0:8002::154, 2606:50c0:8003::154, 2606:50c0:8000::154, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|2606:50c0:8002::154|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14799 (14K) 1
Saving to: ‘/usr/local/bin/ufw-docker’

/usr/local/bin/ufw- 100%[===================>]  14.45K  --.-KB/s    in 0s

2022-04-12 15:05:41 (97.4 MB/s) - ‘/usr/local/bin/ufw-docker’ saved [14799/14799]

Step 2: chmod
sudo chmod +x /usr/local/bin/ufw-docker

Step 3:
ufw-docker install

Step 4:
sudo systemctl restart ufw

Done!

1 Comment

Leave a Reply