

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

# 手動建立適用於 SQL Server 稽核的IAM 角色
<a name="Appendix.SQLServer.Options.Audit.IAM"></a>

一般而言，當您建立新的選項時， 會為您AWS 管理主控台建立 IAM 角色和 IAM 信任政策。然而，您可以手動建立新的 IAM 角色，並使用於 SQL Server 稽核，以便使用您可能有的其他要求自訂該角色。若要這麼做，請建立一個 IAM 角色，並委派許可，以便 Amazon RDS 服務可以使用 Amazon S3 儲存貯體。當您建立 IAM 角色時，您需要附加信任和許可政策。信任政策允許 Amazon RDS 擔任此角色。許可政策定義此角色可以執行的動作。如需詳細資訊，請參閱《 *AWSIdentity and Access Management 使用者指南*》中的[建立角色以將許可委派給 AWS服務](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-service.html)。

您可以使用本節的範例建立您需要的信任關係和許可政策。

以下範例說明 SQL Server Audit 的信任關係。該政策會使用*服務主體* `rds.amazonaws.com`，以允許 RDS 寫入 S3 儲存貯體。「服務委託人」**是用來將許可授予給服務的識別符。當您允許以此種方式存取 `rds.amazonaws.com` 時，就是允許 RDS 代表您執行動作。如需服務委託人的詳細資訊，請參閱 [AWS JSON 政策元素：委託人](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html)。

**Example SQL Server Audit 的信任關係**    
****  

```
{
	    "Version":"2012-10-17",		 	 	 
	    "Statement": [
	        {
	            "Effect": "Allow",
	            "Principal": {
	                "Service": "rds.amazonaws.com"
	            },
	            "Action": "sts:AssumeRole"
	        }
	    ]
	}
```

建議您在資源型信任關係中使用 [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)。針對 SQL Server Audit，請確認同時包括資料庫選項群組和資料庫執行個體，如以下範例所示。

**Example SQL Server Audit 的全域條件內容索引鍵信任關係**    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "rds.amazonaws.com"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "StringEquals": {
                    "aws:SourceArn": [
                        "arn:aws:rds:Region:my_account_ID:db:db_instance_identifier",
                        "arn:aws:rds:Region:my_account_ID:og:option_group_name"
                    ]
                }
            }
        }
    ]
}
```

在以下 SQL Server Audit 的許可政策範例中，我們指定了 Amazon S3 儲存貯體的 ARN。您可以使用 ARN 識別您想要授予存取權的特定帳戶、使用者或角色。如需使用 ARN 的詳細資訊，請參閱 [ Amazon 資源名稱 (ARN)](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)。

**Example SQL Server Audit 的許可政策**    
****  

```
{
	    "Version":"2012-10-17",		 	 	 
	    "Statement": [
	        {
	            "Effect": "Allow",
	            "Action": "s3:ListAllMyBuckets",
	            "Resource": "*"
	        },
	        {
	            "Effect": "Allow",
	            "Action": [
	                "s3:ListBucket",
	                "s3:GetBucketACL",
	                "s3:GetBucketLocation"
	            ],
	            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket"
	        },
	        {
	            "Effect": "Allow",
	            "Action": [
	                "s3:PutObject",
	                "s3:ListMultipartUploadParts",
	                "s3:AbortMultipartUpload"
	            ],
	            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/key_prefix/*"
	        }
	    ]
	}
```

**注意**  
驗證相同AWS帳戶同時擁有 S3 儲存貯體和 SQL Server 資料庫執行個體時，需要 `s3:ListAllMyBuckets`動作。此動作會列出帳戶中儲存貯體的名稱。  
S3 儲存貯體命名空間是全域的。如果您不小心刪除了儲存貯體，其他使用者可在不同帳戶中建立相同名稱的儲存貯體。然後 SQL Server 稽核資料將會寫入新的儲存貯體。