すべてのプロダクト
Search
ドキュメントセンター

Object Storage Service:アクセスポイントポリシー、バケットポリシー、RAMポリシーの関係

最終更新日:Dec 13, 2024

このトピックでは、アクセスポイントを使用してObject Storage Service (OSS) で操作を実行する場合に、アクセスポイントポリシー、RAMポリシー、およびバケットポリシーが満たす必要がある条件について説明します。

アクセスポイントポリシー、バケットポリシー、RAMポリシーの関係

次の表は、次の両方の条件が満たされている場合にのみ、アクセスポイントを使用してOSSで操作を実行できることを示しています。

  • RAMポリシーとバケットポリシーのマージ結果が許可と判断されます。

  • アクセスポイントポリシーはAllowと判断されます。

入力結果

(RAMポリシーとバケットポリシーのマージ結果)

アクセスポイントポリシー結果

出力結果

許可

許可

許可

許可

拒否

拒否

許可

無視する

無視する

拒否

許可

拒否

拒否

拒否

拒否

拒否

無視する

拒否

無視する

許可

無視する

無視する

拒否

拒否

無視する

無視する

無視する

次の表は、上記の表の出力結果を示しています。

出力結果

説明

許可

リクエストがポリシーのDenyステートメントではなくAllowステートメントにヒットした場合、リクエストは許可され、出力結果はAllowと判断されます。

拒否 (明示的な拒否)

リクエストがポリシー内のDenyステートメントにヒットした場合、リクエストは拒否され、出力結果はDenyと判断されます。 リクエストがポリシー内のDenyステートメントとAllowステートメントにヒットした場合、DenyステートメントがAllowステートメントよりも優先されます。 この場合、要求は拒否され、出力結果はDeny (明示的拒否) と判定される。

無視 (暗黙の拒否)

リクエストがポリシー内のDenyステートメントまたはAllowステートメントにヒットしない場合、リクエストは拒否され、出力結果は無視 (暗黙の拒否) と判断されます。 デフォルトでは、RAMユーザーによって開始されたすべての要求は暗黙的に拒否されます。

例 1

入力結果

(RAMポリシーとバケットポリシーのマージ結果)

アクセスポイントポリシー結果

出力結果

許可

許可

許可

RAMポリシーとバケットポリシー

ポリシー

入力結果

RAM ポリシー

Empty

許可

UIDが205xxxxであるAlibaba CloudアカウントのUIDが137xxxxであるRAMユーザーには、example-ap-bucket-001バケットのfinance/ ディレクトリ内のリソースに対してすべての操作を実行する権限があります。

バケットポリシー

次のバケットポリシーを使用すると、UIDが205xxxxであるAlibaba CloudアカウントのUIDが137xxxxであるRAMユーザーは、example-ap-bucket-001バケットのfinance/ ディレクトリ内のリソースに対してすべての操作を実行できます。

{
    "Version": "1",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "oss:*"
            ],
            "Principal": [
                "205xxxx"
            ],
            "Resource": [
                "acs:oss:*:137xxxx:example-ap-bucket-001/finance/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "oss:ListObjects",
                "oss:GetObject"
            ],
            "Principal": [
                "205xxxx"
            ],
            "Resource": [
                "acs:oss:*:137xxxx:example-ap-bucket-001"
            ],
            "Condition": {
                "StringLike": {
                    "oss:Prefix": [
                        "finance/*"
                    ]
                }
            }
        }
    ]
}

A ccessポイントポリシー

次のアクセスポイントポリシーでは、UIDがxxxx 205のRAMユーザーが、アクセスポイントが関連付けられているバケットのfinance/ ディレクトリ内のリソースに対してすべての操作を実行できます。

{
    "Version":"1",
    "Statement":[
        {
            "Effect":"Allow",
            "Action":[
                "oss:*"
            ],
            "Principal":[
                "205xxxx"
            ],
            "Resource":[
                "acs:oss:cn-hangzhou:137xxxx:accesspoint/example-ap-001/object/finance/*"
            ]
        },
        {
            "Effect":"Allow",
            "Action":[
                "oss:ListObjects",
                "oss:GetObject"
            ],
            "Principal":[
                "205xxxx"
            ],
            "Resource":[
                "acs:oss:cn-hangzhou:137xxxx:accesspoint/example-ap-001"
            ],
            "Condition":{
                "StringLike":{
                    "oss:Prefix":[
                        "finance/*"
                    ]
                }
            }
        }
    ]
}

アクセスポイントポリシーで許可されているRAMユーザーを使用して、アクセスポイントを使用してローカルファイルをアップロード

次のサンプルコードは、アクセスポイントを使用してローカルファイルをfinance/ ディレクトリにアップロードするために、UIDがxxxx 205の許可されたRAMユーザーを使用する方法の例を示しています。

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the AccessKey pair of the RAM user is specified by using the environment variables. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the access point alias. 
bucket_name = "example-ap-001-14****-ossalias"
# Specify the region in which the bucket is located. Example: cn-hangzhou. 
region = "cn-hangzhou"
bucket = oss2.Bucket(auth, endpoint, bucket_name, region=region)
# Upload the local file to the directory specified by the access point policy. 
result = bucket.put_object('finance/exampleobject.txt', 'Hello OSS')

# Display the returned HTTP status code. 
print('http status: {0}'.format(result.status))
# Display the request ID. A request ID uniquely identifies the request. We recommend that you add this parameter to the logs. 
print('request_id: {0}'.format(result.request_id))
# Display the ETag value returned by the put_object method. The ETag value of an object is used to identify the object content. 
print('ETag: {0}'.format(result.etag))
# Display the HTTP response headers. 
print('date: {0}'.format(result.headers['date']))

次の返される結果は、アクセスポイントポリシーによって承認されたRAMユーザーが、アクセスポイントを使用して、アクセスポイントポリシーで指定されたディレクトリにファイルをアップロードできることを示しています。

http status: 200
request_id: 673AACB3478AB335343C****
ETag: F0F18C2C66AE1DD512BDCD4366F7****
date: Mon, 18 Nov 2024 02:55:47 GMT

例 2

入力結果

(RAMポリシーとバケットポリシーのマージ結果)

アクセスポイントポリシー結果

出力結果

許可

無視する

無視する

RAMポリシーとバケットポリシー

ポリシー

入力結果

RAM ポリシー

次のRAMポリシーは、UIDが137xxxxのAlibaba CloudアカウントのUIDが266xxxxのRAMユーザーにAdministratorAccess権限を付与します。

{
    "Statement": [
        {
            "Action": "*",
            "Effect": "Allow",
            "Resource": "*"
        }
    ],
    "Version": "1"
}

許可

UIDが266xxxxであるAlibaba CloudアカウントのUIDが137xxxxであるRAMユーザーには、example-ap-bucket-001バケットのfinance/ ディレクトリ内のリソースに対してすべての操作を実行する権限があります。

バケットポリシー

次のバケットポリシーでは、UIDが137xxxxのAlibaba CloudアカウントのすべてのRAMユーザーが、example-ap-bucket-001バケットのfinance/ ディレクトリ内のリソースに対してすべての操作を実行できます。

{
    "Version": "1",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "oss:*"
            ],
            "Principal": [
                "*"
            ],
            "Resource": [
                "acs:oss:*:137xxxx:example-ap-bucket-001/finance/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "oss:ListObjects",
                "oss:GetObject"
            ],
            "Principal": [
                "*"
            ],
            "Resource": [
                "acs:oss:*:137xxxx:example-ap-bucket-001"
            ],
            "Condition": {
                "StringLike": {
                    "oss:Prefix": [
                        "finance/*"
                    ]
                }
            }
        }
    ]
}

Aaccessポイントポリシー

次のアクセスポイントポリシーでは、UIDがxxxx 205のRAMユーザーが、アクセスポイントが関連付けられているバケットのfinance/ ディレクトリ内のリソースに対してすべての操作を実行できます。

{
    "Version":"1",
    "Statement":[
        {
            "Effect":"Allow",
            "Action":[
                "oss:*"
            ],
            "Principal":[
                "205xxxx"
            ],
            "Resource":[
                "acs:oss:cn-hangzhou:137xxxx:accesspoint/example-ap-001/object/finance/*"
            ]
        },
        {
            "Effect":"Allow",
            "Action":[
                "oss:ListObjects",
                "oss:GetObject"
            ],
            "Principal":[
                "205xxxx"
            ],
            "Resource":[
                "acs:oss:cn-hangzhou:137xxxx:accesspoint/example-ap-001"
            ],
            "Condition":{
                "StringLike":{
                    "oss:Prefix":[
                        "finance/*"
                    ]
                }
            }
        }
    ]
}

アクセスポイントポリシーで許可されていないRAMユーザーを使用して、アクセスポイントを使用してローカルファイルをアップロードする

次のサンプルコードは、アクセスポイントを使用してローカルファイルをfinance/ ディレクトリにアップロードするために、UIDがxxxx 266の無許可のRAMユーザーを使用する方法の例を示しています。

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the AccessKey pair of the RAM user is specified by using the environment variables. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the access point alias. 
bucket_name = "example-ap-001-14****-ossalias"
# Specify the region in which the bucket is located. Example: cn-hangzhou. 
region = "cn-hangzhou"
bucket = oss2.Bucket(auth, endpoint, bucket_name, region=region)
# Upload the local file to the directory specified by the access point policy. 
result = bucket.put_object('finance/exampleobject.txt', 'Hello OSS')

# Display the returned HTTP status code. 
print('http status: {0}'.format(result.status))
# Display the request ID. A request ID uniquely identifies the request. We recommend that you add this parameter to the logs. 
print('request_id: {0}'.format(result.request_id))
# Display the ETag value returned by the put_object method. The ETag value of an object is used to identify the object content. 
print('ETag: {0}'.format(result.etag))
# Display the HTTP response headers. 
print('date: {0}'.format(result.headers['date']))

次の結果は、アクセスポイントポリシーで許可されていないRAMユーザーが、アクセスポイントを使用して、アクセスポイントポリシーで指定されたディレクトリにファイルをアップロードできないことを示しています。

oss2.exceptions.AccessDenied: {'status': 403, 'x-oss-request-id': '673C375AECB4DB373307****', 
'details': {'Code': 'AccessDenied', 
'Message': 'You have no right to access this object because of bucket acl.', 
'RequestId': '673C375AECB4DB373307****', 
'HostId': 'example-ap-001-14****-ossalias.oss-cn-hangzhou.aliyuncs.com', 
'EC': '0003-00000001', 'RecommendDoc': 'https://api.aliyun.com/troubleshoot?q=0003-00000001'}}

関連ドキュメント