7
8

踏み台Compute(VM) に PrivateリソースのSSH鍵を置いてはいけない。Pageant と Putty, TeraTerm, WinSCP で、踏み台ComputeにSSH鍵を置かずに Private Compute に接続してみる。(Oracle Cloud Infrastructure)

Last updated at Posted at 2024-07-16

タイトルが長い彡(^)(^) 踏み台Compute(VM) に PrivateリソースのSSH鍵を置いてはいけません。踏み台Compute(VM)自体を使うな??たしかに OCI にも Bastionサービスというものはあるのですが、ちょっと使い勝手が悪いのです。

この記事では SSH Agent の一つである Pageant と Putty, TeraTerm, WinSCP で、踏み台ComputeにSSH鍵を置かずに Private Compute に接続してみます。

1. なぜ 踏み台Compute(VM) に PrivateリソースのSSH鍵を置いてはいけないのか?

Public Subnet = インターネットに開放された Compute(VM) は常に攻撃に晒されていて、OS等の脆弱性を衝かれてクラック(乗っ取り)される可能性があります(※)。Privateリソースの SSH秘密鍵 を 踏み台Compute(VM) に置くと、踏み台Compute(VM) がクラックされた際に Privateリソースへの侵入を簡単に許してしまいます。従って踏み台Compute(VM) には SSH秘密鍵を置いてはいけません。
※余談ですが接続元のIP/CIDRをファイヤーウォールで限定する境界型防御は、この観点では有効です。

踏み台Compute(VM)にはSSH鍵に限らず、あらゆる認証の情報(パスワードなど)を残してはいけません。

……こう書いてみると、踏み台には Compute(VM) を使用せずに Bastion等のサービスを使った方が良くはありますね。OCI なら Bastion、AWS なら SSM を使うのがより安全ではあります。
彡(゚)(゚)

OCI Bastion
https://www.oracle.com/jp/security/cloud-security/bastion/

ステップ 8: (オプション) Session Manager を通して SSH 接続のアクセス許可を付与および制御する
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/session-manager-getting-started-enable-ssh-connections.html

もちろんPC等の端末に格納したSSH鍵を端末ごと物理的に奪取されたり、端末自体をクラックされてメモリ内を覗き見されたりする可能性はあるのですが、踏み台Compute(VM)に鍵を格納するよりはリスクは低くなります。

2. 検証したOCI環境

お馴染み?のこれです。アイコンが古いやつのまま(゚ε゚ )

image.png

3. Pageant(Putty) のインストール

詳細は省略、下記から Putty をダウンロードしてインストールしましょう。Pageant も付いてきます。
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

4. Pageant の起動とSSH鍵の読み込み

Pageant を起動して SSH秘密鍵を読み込ませます。ここも難しいところは特に無いので詳細は省略

image.png

5. Pageant + Putty で Private Compute に 踏み台Compute経由で接続

Putty で 踏み台Computeに接続します。この時Connection-SSH-Authの「Attempt authentication using Pageant」「Allow agent forwarding」にチェックを入れます。
image.png

image.png

踏み台接続後に Private Compute にSSH接続します。

Using username "opc".
Authenticating with public key "" from agent
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Tue Jul 16 22:08:25 2024 from xxx.xxx.xxx.xxx
[opc@ayu-bastion001 ~]$ ssh xxx.xxx.xxx.xxx
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Tue Jul 16 18:59:34 2024 from xxx.xxx.xxx.xxx
[opc@ayu-private001 ~]$

Private Compute にSSH接続できました。

6. Pageant + TeraTerm で Private Compute に 踏み台Compute経由で接続

TeraTerm で踏み台Computeに接続します。この時「エージェント転送する」「Pageantを使う」にチェックを入れます。
image.png

踏み台接続後に Private Compute にSSH接続します。ポップアップが出るので「はい」をクリックします。
image.png

Activate the web console with: systemctl enable --now cockpit.socket

Last login: Tue Jul 16 22:19:11 2024 from xxx.xxx.xxx.xxx
[opc@ayu-bastion001 ~]$ ssh xxx.xxx.xxx.xxx
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Tue Jul 16 22:11:35 2024 from xxx.xxx.xxx.xxx
[opc@ayu-private001 ~]$

Private Compute にSSH接続できました。

7. Pageant + WinSCP で Private Compute に 踏み台Compute経由で接続

WinSCP で Private Compute に接続します。接続先は Private Compute の Private IP, SSHトンネルに踏み台Computeの Public IPを設定します。SSH認証のオプションとして「Pageantでの認証を試みる」「エージェントの転送を許可する」をチェックして下さい。

image.png
image.png
image.png

ログインボタンを押すと接続できました。

image.png
image.png

8. まとめ

昨今はセキュリティ系の剣呑な話題が多いので自衛していきましょう。冒頭でも話した通りBastion等のサービスを活用した方が安全なので、そちらも進められるようにしていくぜ?過去に下記みたいなのも書きましたけど。
彡(^)(^)

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