5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OCI Bastionサービス で Private Compute に SSH接続してみる。(Oracle Cloud Infrastructure)

Last updated at Posted at 2021-08-30

表題の通り、OCI Bastionサービスで Private Compute に SSH接続してみますやで彡(゚)(゚)
Bastionセッションには Managed SSH と Port forwarding の二種類が有るのですが、本記事では Managed SSH を対象とします。

1. Bastionサービスとは?

いわゆる踏み台のサービスです。無料です。手元のPC等から OCI Compute への SSH接続、
Windows Compute へのリモートデスクトップ接続(DB)、DB系サービスへの SQL*Net接続などを
Bastionサービスを経由して実行可能です。サービス紹介やマニュアルは下記となります。

要塞概要
https://docs.oracle.com/ja-jp/iaas/Content/Bastion/Concepts/bastionoverview.htm
※要塞……Bastion の直訳らしいです。踏み台と訳した方がエエですね……彡(-)(-)

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

2. 検証環境

下記記事の構成を流用します。ただし Public Subnet は今回使用しません。
Private Subnet に Compute と Bastionサービス を作成します。

検証によく使う Oracle Cloud Infrastructure(OCI) の 環境構成(VCN, Seculity List, 各種Gateway, Route Table, Subnet, Compute)まとめ
https://qiita.com/ora_gonsuke777/items/08e4781af8c4f7e114ff

3. ポリシー(権限)の付与

Bastionサービスを作成するIAMユーザーにBastionサービスに必要なポリシー(権限)を付与します。

要塞IAMポリシー
https://docs.oracle.com/ja-jp/iaas/Content/Bastion/Reference/bastionpolicyreference.htm

今回は下記のポリシーをIAMユーザーに付与しています。

Allow group ayu-group-bastion1 to manage bastion-family in tenancy
Allow group ayu-group-bastion1 to manage virtual-network-family in tenancy
Allow group ayu-group-bastion1 to read instance-family in tenancy
Allow group ayu-group-bastion1 to read instance-agent-plugins in tenancy
Allow group ayu-group-bastion1 to inspect work-requests in tenancy

4. Compute の Bastion Plugin有効化

Private Subnet に作成した Compute をコンソールで参照して Bastion Plugin を有効化します。
Bastion Plugin有効化 は Managed SSH で接続する場合には必須です。Port forwarding の場合は不要。
Oracle Provided Image の Oracle Linux等で作成した Compute なら「OCI Cloud Agent」のサブタブから制御可能です。
bastion099.jpg

bastion001.jpg

bastion002.jpg

5. Bastionサービスの作成

Identity&Security → Bastion で画面遷移して、Bastionサービスを作成します。

今回は Private Subnet に Bastionサービスを作成します。
CIDR Block Allowed は接続元(PC端末など)の IP を CIDR で指定します。単体のIPの場合は xxx.xxx.xxx.xxx/32 で。

bastion000.jpg

6. Bastionセッションの作成

Managed SSH の Bastionセッションを作成します。セッションを作成すると、このセッションが生存している間は
対象リソースに接続可能になります。セッション作成時に 4. の Plugin を有効化していないとエラーになります。

bastion010.jpg
bastion011.jpg

7. SSHコマンドのコピー/編集/接続

セッションが作成されると接続のためのSSHコマンドがコピー可能になります。
bastion020.jpg

編集前のSSHコマンド

ssh -i <privateKey> -o ProxyCommand="ssh -i <privateKey> -W %h:%p -p 22 ocid1.bastionsession.oc1.phx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@host.bastion.us-phoenix-1.oci.oraclecloud.com" -p 22 opc@10.0.x.x

編集後のSSHコマンド(※5. Bastionサービス作成時の公開鍵に対応する秘密鍵を指定)

ssh -i C:\Users\user\Desktop\bastion\ayu-bastion.key -o ProxyCommand="ssh -i C:\Users\user\Desktop\bastion\ayu-bastion.key -W %h:%p -p 22 ocid1.bastionsession.oc1.phx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@host.bastion.us-phoenix-1.oci.oraclecloud.com" -p 22 opc@10.0.x.x

編集後のSSHコマンドを実行します。今回は PC端末(Windows10)の PowerShell上 で実行してみました。

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

新しいクロスプラットフォームの PowerShell をお試しください https://aka.ms/pscore6

PS C:\Users\user> ssh -i C:\Users\user\Desktop\bastion\ayu-bastion.key -o ProxyCommand="ssh -i C:\Users\user\Desktop\bastion\ayu-bastion.key -W %h:%p -p 22 ocid1.bastionsession.oc1.phx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@host.bastion.us-phoenix-1.oci.oraclecloud.com" -p 22 opc@10.0.x.x
Last login: Mon Aug 30 11:53:24 2021 from 10.0.6.94
Last login: Mon Aug 30 11:53:24 2021 from 10.0.6.94
[opc@ayu-compute1 ~]$ id -a
uid=1000(opc) gid=1000(opc) groups=1000(opc),4(adm),10(wheel),190(systemd-journal) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[opc@ayu-compute1 ~]$ hostname
ayu-compute1
[opc@ayu-compute1 ~]$ 

Bastionサービスのセッション経由で Compute に Managed SSH接続できました彡(^)(^)

8. まとめ

上記 4. の Bastion Plugin有効化 がちょっとしたハマりポイントでしょうか。
Public Subnet に作成する必要が無いというのも留意すべきかもしれません。

今回は SSH接続 でしたが、ポートフォワードの要領で 22(SSH)ポート以外 でも接続可能です。
無料のサービスなので、どんどん活用して下さいね。彡(^)(^)

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?