

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 IAM Identity Center 設定 Amazon S3 Access Grants
<a name="tip-tutorial-s3"></a>

[Amazon S3 Access Grants](https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-get-started.html) 提供將身分型精細存取控制授予 S3 位置的彈性。您可以使用 Amazon S3 Access Grants 將 Amazon S3 儲存貯體存取權直接授予公司使用者和群組。請依照下列步驟，Access Grants透過 IAM Identity Center 啟用 S3，並實現受信任的身分傳播。

## 先決條件
<a name="tip-tutorial-s3-prereqs"></a>

您必須先設定下列項目，才能開始使用本教學課程：
+ [啟用 IAM Identity Center](enable-identity-center.md)。建議使用[組織執行個體](organization-instances-identity-center.md)。如需詳細資訊，請參閱[先決條件和考量事項](trustedidentitypropagation-overall-prerequisites.md)。

## 透過 IAM Identity Center 設定受信任身分傳播的 S3 存取授權
<a name="tip-tutorial-s3-configure"></a>

**如果您已經有已註冊位置的 Amazon S3 Access Grants執行個體，請遵循下列步驟：**

1. [建立 IAM Identity Center 執行個體的關聯](https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-instance-idc.html)。

1. [建立授予](#tip-tutorial-s3-create-grant)。

**如果您Access Grants尚未建立 Amazon S3，請遵循下列步驟：**

1. [https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-instance-create.html](https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-instance-create.html) - 您可以為每個執行個體建立一個 S3 Access Grants執行個體 AWS 區域。當您建立 S3 Access Grants執行個體時，請務必勾選**新增 IAM Identity Center 執行個體**方塊，並提供 IAM Identity Center 執行個體的 ARN。選取**下一步**。

   下圖顯示 Amazon S3 Access Grants主控台中的建立 S3 Access Grants執行個體頁面： Amazon S3   
![\[在 S3 Access Grants 主控台中建立 S3 Access Grants執行個體頁面。\]](http://docs.aws.amazon.com/zh_tw/singlesignon/latest/userguide/images/s3-tutorial-step-1.1.png)

1. **註冊位置** - 在 AWS 區域 帳戶中的 中[建立 Amazon S3 Access Grants執行個體](https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-instance-create.html)後，您會在該執行個體中[註冊 S3 位置](https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-location-register.html)。S3 Access Grants位置會將預設 S3 區域 (`S3://`)、儲存貯體或字首映射至 IAM 角色。S3 Access Grants會擔任此 Amazon S3 角色，將臨時登入資料提供給存取該特定位置的承授者。您必須先在 S3 Access Grants執行個體中註冊至少一個位置，才能建立存取授權。

   針對**位置範圍**，指定 `s3://`，其中包含該區域中的所有儲存貯體。這是大多數使用案例的建議位置範圍。如果您有進階存取管理使用案例，您可以將位置範圍設定為儲存貯體 中的特定儲存貯體`s3://bucket`或字首`s3://bucket/prefix-with-path`。如需詳細資訊，請參閱《*Amazon Simple Storage Service 使用者指南*》中的[註冊位置](https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-location-register.html)。
**注意**  
請確定您要授予存取權之 AWS Glue 資料表的 S3 位置包含在此路徑中。

   此程序要求您為位置設定 IAM 角色。此角色應包含存取位置範圍的許可。您可以使用 S3 主控台精靈來建立角色。您需要在此 IAM 角色的政策中指定 S3 Access Grants執行個體 ARN。S3 Access Grants執行個體 ARN 的預設值為 `arn:aws:s3:Your-Region:Your-AWS-Account-ID:access-grants/default`。

   下列範例許可政策會將 Amazon S3 許可授予您建立的 IAM 角色。之後的範例信任政策允許 S3 Access Grants服務主體擔任 IAM 角色。

   1. **許可政策**

      若要使用這些政策，請以您自己的資訊取代範例政策中的*斜體預留位置文字*。如需其他指示，請參閱[建立政策](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies_create.html)或[編輯政策](https://docs.aws.amazon.com//IAM/latest/UserGuide/access_policies_manage-edit.html)。

------
#### [ JSON ]

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Sid": "ObjectLevelReadPermissions",
                  "Effect": "Allow",
                  "Action": [
                      "s3:GetObject",
                      "s3:GetObjectVersion",
                      "s3:GetObjectAcl",
                      "s3:GetObjectVersionAcl",
                      "s3:ListMultipartUploadParts"
                  ],
                  "Resource": [
                      "arn:aws:s3:::*"
                  ],
                  "Condition": {
                      "StringEquals": {
                          "aws:ResourceAccount": "111122223333"
                      },
                      "ArnEquals": {
                          "s3:AccessGrantsInstanceArn": [
                          "arn:aws:s3:::access-grants/instance-id"
                          ]
                      }
                  }
              },
              {
                  "Sid": "ObjectLevelWritePermissions",
                  "Effect": "Allow",
                  "Action": [
                      "s3:PutObject",
                      "s3:PutObjectAcl",
                      "s3:PutObjectVersionAcl",
                      "s3:DeleteObject",
                      "s3:DeleteObjectVersion",
                      "s3:AbortMultipartUpload"
                  ],
                  "Resource": [
                      "arn:aws:s3:::*"
                  ],
                  "Condition": {
                      "StringEquals": {
                      "aws:ResourceAccount": "111122223333"
                      },
                      "ArnEquals": {
                          "s3:AccessGrantsInstanceArn": [
                          "arn:aws:s3:::access-grants/instance-id"
                          ]
                      }
                  }
              },
              {
                  "Sid": "BucketLevelReadPermissions",
                  "Effect": "Allow",
                  "Action": [
                      "s3:ListBucket"
                  ],
                  "Resource": [
                      "arn:aws:s3:::*"
                  ],
                  "Condition": {
                      "StringEquals": {
                      "aws:ResourceAccount": "111122223333"
                      },
                      "ArnEquals": {
                          "s3:AccessGrantsInstanceArn": [
                          "arn:aws:s3:::access-grants/instance-id"
                          ]
                      }
                  }
              },
              {
                  "Sid": "OptionalKMSPermissionsForSSEEncryption",
                  "Effect": "Allow",
                  "Action": [
                      "kms:Decrypt",
                      "kms:GenerateDataKey"
                  ],
                  "Resource": [
                      "*"
                  ]
              }
          ]
      }
      ```

------

   1. **信任政策**

       在 IAM 角色信任政策中，授予 S3 存取授權服務 (`access-grants.s3.amazonaws.com`) 主體對您建立之 IAM 角色的存取權。若要完成此操作，您可以建立包含下列陳述式的 JSON 檔案。若要將信任政策新增至您的帳戶，請參閱[使用自訂信任政策建立角色](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_roles_create_for-custom.html)。

------
#### [ JSON ]

****  

      ```
      {
          "Version":"2012-10-17",		 	 	 
          "Statement": [
              {
                  "Sid": "Stmt1234567891011",
                  "Effect": "Allow",
                  "Action": [
                      "sts:AssumeRole",
                      "sts:SetSourceIdentity"
                  ],
                  "Resource": "*",
                  "Condition": {
                      "StringEquals": {
                          "aws:SourceAccount": "111122223333",
                          "aws:SourceArn": "Your-Custom-Access-Grants-Location-ARN"
                      }
                  }
              },
      
              {
                  "Sid": "Stmt1234567891012",
                  "Effect": "Allow",
                  "Action": "sts:SetContext",
                  "Resource": "*",
                  "Condition": {
                      "StringEquals": {
                          "aws:SourceAccount": "111122223333",
                          "aws:SourceArn": "Your-Custom-Access-Grants-Location-ARN"
                      },
                      "ForAllValues:ArnEquals": {
                          "sts:RequestContextProviders": "arn:aws:iam::aws:contextProvider/IdentityCenter"
                      }
                  }
              }
          ]
      }
      ```

------

## 建立 Amazon S3 存取授權
<a name="tip-tutorial-s3-create-grant"></a>

如果您有已註冊位置的 Amazon S3 Access Grants執行個體，且您已將 IAM Identity Center 執行個體與其建立關聯，則可以[建立授權](https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-grant-create.html)。在 S3 **主控台建立授予**頁面中，完成下列操作：

**建立授與**

1. 選取在上一個步驟中建立的位置。您可以新增子字首，以減少授予的範圍。子字首可以是 `bucket`、 `bucket/prefix`或 儲存貯體中的物件。如需詳細資訊，請參閱《*Amazon Simple Storage Service 使用者指南*》中的 [Subprefix](https://docs.aws.amazon.com//AmazonS3/latest/userguide/access-grants-grant-create.html#subprefix)。

1. 在**許可和存取**下，根據您的需求選取**讀取**和或**寫入**。

1. 在**授予者類型**中，選擇**目錄身分表單 IAM Identity Center**。

1. 提供 IAM Identity Center **使用者或群組 ID**。您可以在 IAM Identity Center 主控台的使用者和群組[區段下找到**使用者**和**群組**](howtoviewandchangepermissionset.md) IDs。選取**下一步**。

1. 在**檢閱和完成**頁面上，檢閱 S3 的設定，Access Grant然後選取**建立授予**。

   下圖顯示 Amazon S3 Access Grants主控台中的建立授予頁面：  
![\[在 Amazon S3 Access Grants 主控台中建立授予頁面。\]](http://docs.aws.amazon.com/zh_tw/singlesignon/latest/userguide/images/s3-tutorial-step-1.4.png)