

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

# 授予 Amazon Managed Service for Prometheus 許可，以傳送提醒訊息到您的 Amazon SNS 主題
<a name="AMP-alertmanager-receiver-AMPpermission"></a>

您必須授予 Amazon Managed Service for Prometheus 權限，以便將訊息傳送到您的 Amazon SNS 主題。下列政策陳述式將提供該許可。它包含一個`Condition`陳述式，可協助防止稱為*混淆代理人*問題的安全問題。`Condition` 聲明限制 Amazon SNS 主題的存取權，以便僅允許來自此特定帳戶和 Amazon Managed Service for Prometheus 工作區的作業。如需有關混淆代理人問題的詳細資訊，請參閱 [預防跨服務混淆代理人](#cross-service-confused-deputy-prevention)。

**授予 Amazon Managed Service for Prometheus 的許可，以訊息傳送到您的 Amazon SNS 主題**

1. 在 [https://console.aws.amazon.com/sns/v3/home](https://console.aws.amazon.com/sns/v3/home) 開啟 Amazon SNS 主控台。

1. 在導覽窗格中，選擇**主題**。

1. 選擇您與 Amazon Managed Service for Prometheus 搭配使用的主題名稱。

1. 選擇 **[編輯]** 。

1. 選擇**存取政策**，然後將下列政策陳述式新增至現有政策。

   ```
   {
       "Sid": "Allow_Publish_Alarms",
       "Effect": "Allow",
       "Principal": {
           "Service": "aps.amazonaws.com"
       },
       "Action": [
           "sns:Publish",
           "sns:GetTopicAttributes"
       ],
       "Condition": {
           "ArnEquals": {
               "aws:SourceArn": "workspace_ARN"
           },
           "StringEquals": {
               "AWS:SourceAccount": "account_id"
           }
       },
       "Resource": "arn:aws:sns:region:account_id:topic_name"
   }
   ```

   【選用】 如果您的 Amazon SNS 主題已啟用服務端加密 (SSE)，您需要將 `kms:GenerateDataKey*`和 `kms:Decrypt`許可新增至用於加密主題之金鑰的 AWS KMS 金鑰政策，以允許 Amazon Managed Service for Prometheus 傳送訊息至此加密主題。

   例如，您可以將下列項目新增至政策：

   ```
   {
     "Statement": [{
       "Effect": "Allow",
       "Principal": {
         "Service": "aps.amazonaws.com"
       },
       "Action": [
         "kms:GenerateDataKey*",
         "kms:Decrypt"
       ],
       "Resource": "*"
     }]
   }
   ```

   如需詳細資訊，請參閱 [SNS 主題的AWS KMS 許可](https://docs.aws.amazon.com/sns/latest/dg/sns-key-management.html#sns-what-permissions-for-sse)。

1. 選擇「**Save changes (儲存變更)**」。

**注意**  
 依預設，Amazon SNS 在於 `AWS:SourceOwner` 上建立含條件的存取政策。如需詳細資訊，請參閱 [SNS 存取政策](https://docs.aws.amazon.com/sns/latest/dg/sns-access-policy-use-cases.html#source-account-versus-source-owner)。

**注意**  
IAM 遵循[最嚴格的政策第一條](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html)規則。在您的 SNS 主題中，如果政策區塊的限制比記錄的 Amazon SNS 政策區塊更嚴格，則不會授予主題政策的權限。若要評估您的原則並找出已授與的項目，請參閱[政策評估邏輯](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html)。

## 選擇加入區域的 SNS 主題組態
<a name="AMP-alertmanager-sns-regional-config"></a>

您可以使用 在 AWS 區域 與 Amazon Managed Service for Prometheus 工作區相同的 中`aps.amazonaws.com`設定 Amazon SNS 主題。 Amazon SNS 若要將non-opt-in區域 （例如 us-east-1) 中的 SNS 主題與加入區域 （例如 af-south-1) 搭配使用，您需要使用區域服務主體格式。在區域服務原則中，將 *us-east-1* 取代為您想要使用non-opt-in區域：**aps.*us-east-1*.amazonaws.com**。

下表列出選擇加入的區域及其對應的區域服務主體：


**選擇加入區域及其區域服務主體**  

| 區域名稱 | 區域 | 區域服務主體 | 
| --- | --- | --- | 
| Africa (Cape Town) | af-south-1 | af-south-1.aps.amazonaws.com | 
| 亞太地區 (香港) | ap-east-1 | ap-east-1.aps.amazonaws.com | 
| 亞太區域 (泰國) | ap-southeast-7 | ap-southeast-7.aps.amazonaws.com | 
| 歐洲 (米蘭) | eu-south-1 | eu-south-1.aps.amazonaws.com | 
| 歐洲 (蘇黎世) | eu-central-2 | eu-central-2.aps.amazonaws.com | 
| 中東 (阿拉伯聯合大公國) | me-central-1 | me-central-1.aps.amazonaws.com | 
| 亞太地區 (馬來西亞) | ap-southeast-5 | ap-southeast-5.aps.amazonaws.com | 

如需啟用選擇加入區域的詳細資訊，請參閱《》中的 *IAM 使用者指南*中的[管理 AWS 區域](https://docs.aws.amazon.com/accounts/latest/reference/manage-acct-regions.html) Amazon Web Services 一般參考。

為這些選擇加入區域設定 Amazon SNS 主題時，請務必使用正確的區域服務主體來啟用跨區域警示傳遞。

## 預防跨服務混淆代理人
<a name="cross-service-confused-deputy-prevention"></a>

混淆代理人問題屬於安全性問題，其中沒有執行動作許可的實體可以強制具有更多許可的實體執行該動作。在 中 AWS，跨服務模擬可能會導致混淆代理人問題。在某個服務 (*呼叫服務*) 呼叫另一個服務 (*被呼叫服務*) 時，可能會發生跨服務模擬。可以操縱呼叫服務來使用其許可，以其不應有存取許可的方式對其他客戶的資源採取動作。為了預防這種情況， AWS 提供的工具可協助您保護所有服務的資料，而這些服務主體已獲得您帳戶中資源的存取權。

我們建議在資源政策中使用 [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) 全域條件內容索引鍵，來限制 Amazon Managed Service for Prometheus 給予 Amazon SNS 對資源的許可。如果同時使用全域條件內容索引鍵，則在相同政策陳述式中使用 `aws:SourceAccount` 值和 `aws:SourceArn` 值中的帳戶時，必須使用相同的帳戶 ID。

`aws:SourceArn` 的值必須是 Amazon Managed Service for Prometheus 工作區的 ARN。

防範混淆代理人問題最有效的方法，是使用 `aws:SourceArn` 全域條件內容金鑰，以及資源的完整 ARN。如果不知道資源的完整 ARN，或者如果您指定了多個資源，請使用 `aws:SourceArn` 全域條件內容金鑰，同時使用萬用字元 (`*`) 表示 ARN 的未知部分。例如 `arn:aws:servicename::123456789012:*`。

[授予 Amazon Managed Service for Prometheus 許可，以傳送提醒訊息到您的 Amazon SNS 主題](#AMP-alertmanager-receiver-AMPpermission) 中顯示的政策會顯示您可在 Amazon Managed Service for Prometheus 中使用 `aws:SourceArn` 和 `aws:SourceAccount` 全域條件內容索引鍵防止混淆代理人問題。