GCP 仮想マシンでポート 22 を強制的に閉じます。

GCP 仮想マシンでポート 22 を強制的に閉じます。

セキュリティ上の理由から、GCPで仮想マシンのポート22(ssh)を閉じたいと思います。現在のコマンドを実行すると、telnet xx.xx.xxx.xxx 22サーバーが応答します。

Trying xx.xx.xxx.xxx...
Connected to xx.xx.xxx.xxx.
Escape character is '^]'.
SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5

仮想マシンに接続するためのファイアウォールルールを正しく設定しようとしました。 「default-allow-ssh」ルールのターゲットから「apply to all」を削除し、仮想マシンとの接続を拒否する「close-ssh」というルールを作成しました。 machine 0.0.0.0/4 から始まるシステムのすべての接続ポート 22。

SSHルール

コマンドで設定を確認し、sudo iptables -Lポート22を公開するルールがあることを確認しました。

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy DROP)
target     prot opt source               destination         
DOCKER-USER  all  --  anywhere             anywhere            
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (3 references)
target     prot opt source               destination         

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination         
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-ISOLATION-STAGE-2 (3 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere            
DROP       all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-USER (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere       

コマンドを実行すると、nmap -p 22 xx.xx.xxx.xxx次のような出力が表示されます。

Starting Nmap 7.80 ( https://nmap.org ) at 2023-05-10 09:56 -03
Nmap scan report for xx.xx.xxx.xxx.bc.googleusercontent.com (xx.xx.xxx.xxx)
Host is up (0.32s latency).

PORT   STATE SERVICE
22/tcp open  ssh

Nmap done: 1 IP address (1 host up) scanned in 0.67 seconds

ベストアンサー1

ファイアウォールルールはリストの上から下に処理されます。 GCP VMでは、最初のルールはSSHを許可します。フィルタリング中にパケットがルール(またはACL)と一致すると、パケットは処理され、リスト内の他のルールを通過しなくなります。 「close-ssh」ルールは「default-allow-ssh」の上に配置する必要があります。

おすすめ記事