はじめに
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アドレスを設定します。
ポリシーの設定
ポリシーを以下のように書き換えます。
(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で失敗しています。
失敗したログの中身を見ると、このように詳細が確認できます。