0
1

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 1 year has passed since last update.

OCIのリソースへのアクセスを指定したIPアドレスからに制限する

Posted at

はじめに

OCIのネットワーク・ソースを活用して、指定したIPアドレスからのアクセスのみ許可する方法を確認します。

設定前の動作確認

今回はObject Storageに外部からアクセスして動作を確認します。

まずは普通に以下の権限を与えてアクセスできることを確認します。

allow group グループ名 to manage object-family in compartment コンパートメント名	

外部からアクセスできることを確認します。
-cはコンパートメントのOCID、-nsはオブジェクトストレージネームスペースを指定しますが、環境変数に設定しています。

$ oci os bucket list --profile PROFILE -c $NC -ns $NN
{
  "data": [
    {
      "compartment-id": "ocid1.compartment.oc1..aaaaaaaae7aecc522jiytxxxxxxxxxxxxxxx",
      "created-by": "ocid1.user.oc1..aaaaaaaaefqcqse6glpgvqmbaxjmfs76xxxxxxxxxx",
      "defined-tags": null,
      "etag": "3bab46ec-e0cb-4eeb-8b70-607d70424509",
      "freeform-tags": null,
      "name": "nrt-bucket01",
      "namespace": "nrxxxxxxxxxxx",
      "time-created": "2024-01-23T02:09:55.981000+00:00"
    }
  ]
}

IPアドレス制限

ネットワーク・ソースの設定

OCIコンソールのアイデンティティとセキュリティアイデンティティネットワーク・ソースをクリックし、ネットワーク・ソースの作成をクリックします。

今回は以下のようにアクセスを許可するIPアドレスを設定します。

スクリーンショット 2024-01-25 11.00.57.png

ポリシーの設定

ポリシーを以下のように書き換えます。
(where句を追加します)

allow group グループ名 to manage object-family in compartment コンパートメント名 where request.networkSource.name='allow-lhr'

確認

設定したIPアドレス以外の端末からアクセスすると、以下のように拒否されます。
ネットワーク・ソースで設定した端末からは設定前と同様にアクセスできます。

oci os bucket list --profile PROFILE -c $NC -ns $NN
ServiceError:
{
    "client_version": "Oracle-PythonSDK/2.118.0, Oracle-PythonCLI/3.37.1",
    "code": "NamespaceNotFound",
    "logging_tips": "Please run the OCI CLI command using --debug flag to find more debug information.",
    "message": "You do not have authorization to perform this request, or the requested resource could not be found.",
    "opc-request-id": "nrt-1:R5AAn3RsCE7GRefd7FMbMni_kiIffedceafTAJOsnFRXP9i_yiuV8XwNkPqcOZS5",
    "operation_name": "list_buckets",
    "request_endpoint": "GET https://objectstorage.ap-tokyo-1.oraclecloud.com/n/nrjxxxxxx/b",
    "status": 404,
    "target_service": "object_storage",
    "timestamp": "2024-01-25T02:08:07.756790+00:00",
    "troubleshooting_tips": "See [https://docs.oracle.com/iaas/Content/API/References/apierrors.htm] for more information about resolving this error. If you are unable to resolve this issue, run this CLI command with --debug option and contact Oracle support and provide them the full error message."
}

ログを確認すると、ネットワーク・ソースで指定したIPアドレスからのアクセス(下)は成功していますが、それ以外のIPアドレスからのアクセス(上)は404で失敗しています。

スクリーンショット 2024-01-25 11.10.19.png

失敗したログの中身を見ると、このように詳細が確認できます。

スクリーンショット 2024-01-25 11.11.39.png

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?