

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

# 設定 IAM 許可以進行 RDS for Oracle 與 Amazon EFS 的整合
<a name="oracle-efs-integration.iam"></a>

根據預設，Amazon EFS 整合功能不使用 IAM 角色：`USE_IAM_ROLE` 選項設定為 `FALSE`。若要整合 RDS for Oracle 與 Amazon EFS 和 IAM 角色，您的資料庫執行個體必須具有存取 Amazon EFS 檔案系統的 IAM 許可。

**Topics**
+ [步驟 1：針對您的資料庫執行個體建立 IAM 角色並附加您的政策](#oracle-efs-integration.iam.role)
+ [步驟 2：針對您的 Amazon EFS 檔案系統建立檔案系統政策](#oracle-efs-integration.iam.policy)
+ [步驟 3：將 IAM 角色與 RDS for Oracle 資料庫執行個體建立關聯](#oracle-efs-integration.iam.instance)

## 步驟 1：針對您的資料庫執行個體建立 IAM 角色並附加您的政策
<a name="oracle-efs-integration.iam.role"></a>

在此步驟中，您會針對 RDS for Oracle 資料庫執行個體建立一個角色，允許 Amazon RDS 存取您的 EFS 檔案系統。

### 主控台
<a name="oracle-efs-integration.iam.role.console"></a>

**建立 IAM 角色以允許 Amazon RDS 存取 EFS 檔案系統**

1. 開啟 [IAM 管理主控台](https://console.aws.amazon.com/iam/home?#home)。

1. 在導覽窗格中，選擇 **Roles** (角色)。

1. 選擇 **Create Role** (建立角色)。

1. 針對 **AWS 服務**，請選擇 **RDS**。

1. 針對 **Select your use case (選擇使用案例)** 選擇 **RDS – Add Role to Database (新增角色至資料庫)**。

1. 選擇**下一步**。

1. 請不要新增任何許可政策。選擇**下一步**。

1. 將 **Role Name (角色名稱)** 設為您的 IAM 角色名稱，例如 `rds-efs-integration-role`。您也可以新增選用的 **Description (描述) **值。

1. 選擇建**立角色**。

### AWS CLI
<a name="integration.preparing.role.CLI"></a>

若要將服務的許可限制為特定資源，建議您在資源型信任關係中使用 [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourcearn](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourcearn) 和 [https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceaccount](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-sourceaccount) 全域條件內容金鑰。這是防止[混淆代理人問題](https://docs.aws.amazon.com/IAM/latest/UserGuide/confused-deputy.html)最有效的方式。

您可以同時使用全域條件內容索引鍵和包含帳號 ID 的 `aws:SourceArn` 值。在此情況下，當在相同陳述式中使用 `aws:SourceAccount` 值和 `aws:SourceArn` 裡的帳户時，兩者必須使用同樣的帳户 ID。
+ 如果您想要跨服務存取單一資源，請使用 `aws:SourceArn`。
+ 如果您想要允許該帳戶中的任何資源與跨服務使用相關聯，請使用 `aws:SourceAccount`。

在信任關係中，請務必使用 `aws:SourceArn` 全域條件內容索引鍵，其中包含存取角色的資源之完整 Amazon 資源名稱 (ARN)。

下列 AWS CLI 命令`{{rds-efs-integration-role}}`會為此目的建立名為 的角色。

**Example**  
針對 Linux、macOS 或 Unix：  

```
aws iam create-role \
   --role-name {{rds-efs-integration-role}} \
   --assume-role-policy-document '{
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
            "Service": "rds.amazonaws.com"
          },
         "Action": "sts:AssumeRole",
         "Condition": {
             "StringEquals": {
                 "aws:SourceAccount": {{my_account_ID}},
                 "aws:SourceArn": "arn:aws:rds:{{Region}}:{{my_account_ID}}:db:{{dbname}}"
             }
         }
       }
     ]
   }'
```
在 Windows 中：  

```
aws iam create-role ^
   --role-name {{rds-efs-integration-role}} ^
   --assume-role-policy-document '{
     "Version": "2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Principal": {
            "Service": "rds.amazonaws.com"
          },
         "Action": "sts:AssumeRole",
         "Condition": {
             "StringEquals": {
                 "aws:SourceAccount": {{my_account_ID}},
                 "aws:SourceArn": "arn:aws:rds:{{Region}}:{{my_account_ID}}:db:{{dbname}}"
             }
         }
       }
     ]
   }'
```

如需詳細資訊，請參閱《*IAM 使用者指南*》中的[建立角色以將許可委派給 IAM 使用者](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user.html)。

## 步驟 2：針對您的 Amazon EFS 檔案系統建立檔案系統政策
<a name="oracle-efs-integration.iam.policy"></a>

在此步驟中，您會針對 EFS 檔案系統建立檔案系統政策。

**建立或編輯 EFS 檔案系統政策**

1. 開啟 [EFS 管理主控台](https://console.aws.amazon.com/efs/home?#home)。

1. 選擇 **File Systems (檔案系統)**。

1. 在 **File systems** (檔案系統) 頁面上，選擇您要編輯或針對其建立檔案系統政策的檔案系統。即會顯示該檔案系統的詳細資訊頁面。

1. 選擇 **File system policy** (檔案系統政策) 索引標籤。

   如果政策空白，表示正在使用預設 EFS 檔案系統政策。如需詳細資訊，請參閱《Amazon Elastic File System 使用者指南》**中的[預設 EFS 檔案系統政策](https://docs.aws.amazon.com/efs/latest/ug/iam-access-control-nfs-efs.html#default-filesystempolicy )。

1. 選擇**編輯**。**File system policy (檔案系統政策)** 頁面隨即顯示。

1. 在 **Policy editor** (原則編輯器) 中，輸入如下的政策，然後選擇 **Save** (儲存)。

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

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Id": "ExamplePolicy01",
       "Statement": [
           {
               "Sid": "ExampleStatement01",
               "Effect": "Allow",
               "Principal": {
                   "AWS": "arn:aws:iam::{{123456789012}}:role/rds-efs-integration-role"
               },
               "Action": [
                   "elasticfilesystem:ClientMount",
                   "elasticfilesystem:ClientWrite",
                   "elasticfilesystem:ClientRootAccess"
               ],
               "Resource": "arn:aws:elasticfilesystem:{{us-east-1}}:{{123456789012}}:file-system/{{fs-1234567890abcdef0}}"
           }
       ]
   }
   ```

------

## 步驟 3：將 IAM 角色與 RDS for Oracle 資料庫執行個體建立關聯
<a name="oracle-efs-integration.iam.instance"></a>

在此步驟中，您會將 IAM 角色與資料庫執行個體建立關聯。請注意下列需求：
+ 您必須有權存取必要 Amazon EFS 許可政策附加至其中的 IAM 角色。
+ 您一次只能將一個 IAM 角色與 RDS for Oracle 資料庫執行個體建立關聯。
+ 執行個體的狀態必須為 **Available** (可用)。

如需詳細資訊，請參閱《Amazon Elastic File System 使用者指南》**中的[適用於 Amazon EFS 的 Identity and Access Management](https://docs.aws.amazon.com/efs/latest/ug/auth-and-access-control.html)。

### 主控台
<a name="oracle-efs-integration.iam.instance.console"></a>

**如要建立 IAM 角色與 RDS for Oracle 資料庫執行個體的關聯**

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/)：// 開啟 Amazon RDS 主控台。

1. 選擇 **Databases** (資料庫)。

1. 如果您的資料庫執行個體無法使用，請選擇 **Actions** (動作)，然後選擇 **Start** (開始)。當執行個體狀態顯示 **Started** (已啟動) 時，請移至下一個步驟。

1. 選擇 Oracle 資料庫執行個體名稱以顯示其詳細資訊。

1. 在 **Connectivity & security (連線和安全)** 索引標籤上，向下捲動至頁面底部的 **Manage IAM roles (管理 IAM 角色)** 區段。

1. 在 **Add IAM roles to this instance (新增 IAM 角色到此執行個體)** 區段中選擇要新增的角色。

1. 針對 **Feature** (功能)，選擇 **EFS\_INTEGRATION**。

1. 選擇 **Add role (新增角色)**。

### AWS CLI
<a name="oracle-efs-integration.iam.instance.CLI"></a>

下列 AWS CLI 命令會將 角色新增至名為 的 Oracle 資料庫執行個體`{{mydbinstance}}`。

**Example**  
針對 Linux、macOS 或 Unix：  

```
aws rds add-role-to-db-instance \
   --db-instance-identifier {{mydbinstance}} \
   --feature-name EFS_INTEGRATION \
   --role-arn {{your-role-arn}}
```
在 Windows 中：  

```
aws rds add-role-to-db-instance ^
   --db-instance-identifier {{mydbinstance}} ^
   --feature-name EFS_INTEGRATION ^
   --role-arn {{your-role-arn}}
```

將 `{{your-role-arn}}` 替換為您前個步驟記下的角色 ARN。`EFS_INTEGRATION` 必須在 `--feature-name` 選項中指定。