

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

# Amazon SNS 中的資料保護政策操作
<a name="sns-message-data-protection-operations"></a>

**重要**  
Amazon SNS 訊息資料保護不再提供給新客戶。如需替代方案的詳細資訊和指引，請參閱 [Amazon SNS 訊息資料保護可用性變更](https://docs.aws.amazon.com/sns/latest/dg/sns-message-data-protection-availability-change.html)。

以下是您可以用來稽核和拒絕敏感資料的資料保護政策的範例。如需包含範例應用程式的完整教學課程，請參閱 [Introducing message data protection for Amazon SNS](https://aws.amazon.com/blogs/compute/introducing-message-data-protection-for-amazon-sns/) (Amazon SNS 的訊息資料保護簡介) 部落格文章。

## Audit 操作
<a name="statement-operation-json-properties-audit"></a>

**稽核**操作會範例傳入訊息主題，並記錄 AWS 目的地中的敏感資料問題清單。取樣率可以是介於 0-99 之間的整數。此操作需要下列其中一種記錄目的地類型：

1. **FindingsDestination** - Amazon SNS 主題在承載中找到敏感資料時的記錄目的地。

1. **NoFindingsDestination** - Amazon SNS 主題在承載中找不到敏感資料時的記錄目的地。

您可以在下列每種日誌目的地類型 AWS 服務 中使用下列項目：
+ **Amazon CloudWatch Logs** (選用) - `LogGroup` 必須在主題區域中，且名稱開頭必須是 **/aws/vendedlogs/**。
+ ** **（選用） – `DeliveryStream`必須在主題區域中，並以 **Direct PUT** 做為交付串流的來源。如需其他詳細資訊，請參閱《*Amazon Data Firehose 開發人員指南*》中的[來源、目的地和名稱](https://docs.aws.amazon.com/firehose/latest/dev/create-name.html)。
+ **Amazon S3** (選用) - Amazon S3 儲存貯體名稱。[在啟用 SSE-KMS 加密的情況下使用 Amazon S3 儲存貯體，需要採取額外動作](#flow-logs-s3-cmk-policy)。

```
{
  "Operation": {
    "Audit": {
      "SampleRate": "99",
      "FindingsDestination": {
            "CloudWatchLogs": {
                "LogGroup": "/aws/vendedlogs/log-group-name"
            },
            "Firehose": {
                "DeliveryStream": "delivery-stream-name"
            },
            "S3": {
                "Bucket": "bucket-name"
            }
      },
      "NoFindingsDestination": {
            "CloudWatchLogs": {
                "LogGroup": "/aws/vendedlogs/log-group-name"
            },
            "Firehose": {
                "DeliveryStream": "delivery-stream-name"
            },
            "S3": {
                "Bucket": "bucket-name"
            }
      }
    }
  }
}
```

### 指定日誌目的地時所需的許可
<a name="required-permissions-log-operations"></a>

當您在資料保護政策中指定記錄目的地時，必須使用 `--data-protection-policy` 參數，將下列許可新增至呼叫 Amazon SNS `PutDataProtectionPolicy` API 或 `CreateTopic` API 之 IAM 主體的 IAM 身分政策。


| 稽核目的地 | IAM 許可 | 
| --- | --- | 
| 預設 | logs:CreateLogDelivery<br />logs:GetLogDelivery<br />logs:UpdateLogDelivery<br />logs:DeleteLogDelivery<br />logs:ListLogDeliveries | 
| CloudWatchLogs | logs:PutResourcePolicy<br />logs:DescribeResourcePolicies<br />logs:DescribeLogGroups | 
| Firehose | iam:CreateServiceLinkedRole<br />firehose:TagDeliveryStream | 
| S3 | s3:PutBucketPolicy<br />s3:GetBucketPolicy<br />[在啟用 SSE-KMS 加密的情況下使用 Amazon S3 儲存貯體，需要採取額外動作](#flow-logs-s3-cmk-policy)。 | 

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogDelivery",
                "logs:GetLogDelivery",
                "logs:UpdateLogDelivery",
                "logs:DeleteLogDelivery",
                "logs:ListLogDeliveries"
            ],
            "Resource": [
                "*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:PutResourcePolicy",
                "logs:DescribeResourcePolicies",
                "logs:DescribeLogGroups"
            ],
            "Resource": [
                "arn:aws:logs:us-west-1:123456789012:SampleLogGroupName:*:*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "iam:CreateServiceLinkedRole",
                "firehose:TagDeliveryStream"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutBucketPolicy",
                "s3:GetBucketPolicy"
            ],
            "Resource": [
                "arn:aws:s3:::bucket-name"
            ]
        }
    ]
}
```

------

#### 搭配 SSE-KMS 使用的必要金鑰政策
<a name="flow-logs-s3-cmk-policy"></a>

如果您使用 Amazon S3 儲存貯體做為日誌目的地，您可以透過啟用伺服器端加密搭配 Amazon S3-Managed管金鑰 (SSE-S3) 或伺服器端加密搭配 AWS KMS keys (SSE-KMS) 來保護儲存貯體中的資料。如需詳細資訊，請參閱《*Amazon S3 使用者指南*》中的[使用伺服器端加密保護資料](https://docs.aws.amazon.com/AmazonS3/latest/userguide/serv-side-encryption.html)。

如果您選擇 SSE-S3，則不需要其他組態。Amazon S3 會處理加密金鑰。

若您選擇 SSE-KMS，則必須使用客戶受管金鑰。您必須更新客戶受管金鑰的金鑰政策，以讓日誌傳遞帳戶能夠寫入您的 S3 儲存貯體。如需詳細資訊，請參閱《Amazon CloudWatch Logs 使用者指南》中的 [Amazon S3 儲存貯體伺服器端加密](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AWS-logs-and-resource-policy.html#AWS-logs-SSE-KMS-S3)。

### 稽核目的地日誌範例
<a name="data-protection-policy-audit-destination-log"></a>

在以下範例中，`callerPrincipal` 用於識別敏感內容來源，`messageID` 用作檢查 `Publish` API 回應的參考。

```
{
  "messageId": "34d9b400-c6dd-5444-820d-fbeb0f1f54cf",
  "auditTimestamp": "2022-05-12T2:10:44Z",
  "callerPrincipal": "arn:aws:iam::123412341234:role/Publisher",
  "resourceArn": "arn:aws:sns:us-east-1:123412341234:PII-data-topic",
  "dataIdentifiers": [
    {
      "name": "Name",
      "count": 1,
      "detections": [
        {
          "start": 1,
          "end": 2
        }
      ]
    },
    {
      "name": "PhoneNumber",
      "count": 2,
      "detections": [
        {
          "start": 3,
          "end": 4
        },
        {
          "start": 5,
          "end": 6
        }
      ]
    }
  ]
}
```

### Audit 操作指標
<a name="data-protection-policy-audit-metrics"></a>

當 audit 操作已指定 `FindingsDestination` 或 `NoFindingsDestination` 屬性時，主題擁有者也會收到 CloudWatch `MessagesWithFindings` 和 `MessagesWithNoFindings` 指標。

![顯示指定期間內資料的稽核範例。](http://docs.aws.amazon.com/zh_tw/sns/latest/dg/images/audit-operations-metrics.png)


## 去識別化操作
<a name="statement-operation-json-properties-deidentify"></a>

**去識別化**操作會遮罩或修訂已發布或交付訊息中的敏感資料。此操作適用於傳入與傳出訊息，且需要下列其中一種設定類型：
+ **MaskConfig** - 使用下表中支援的字元進行遮罩。例如，ssn:`123-45-6789` 變成 ssn:`###########`。

  ```
  {
  "Operation": {
      "Deidentify": {
          "MaskConfig": {
              "MaskWithCharacter": "#"
            }
      }
  }
  ```    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/sns/latest/dg/sns-message-data-protection-operations.html)
+ **RedactConfig** - 完全刪除資料以進行修訂。例如，ssn:`123-45-6789` 變成 ssn:` `。

  ```
  {
  "Operation": {
      "Deidentify": {
          "RedactConfig": {}
      }
  }
  ```

在傳入訊息上，會在稽核操作後去識別化敏感資料，且當整則訊息皆敏感時，`SNS:Publish` API 呼叫者會收到下列無效參數錯誤。

`Error code: AuthorizationError ...`

## Deny 操作
<a name="statement-operation-json-properties-deny"></a>

如果訊息包含敏感資料，**Deny** 操作會中斷 `Publish` API 請求或訊息傳遞。Deny 操作物件是空的，因為它不需要額外的組態。

```
"Operation": {
    "Deny": {}
}
```

在傳入訊息上，`SNS:Publish` API 呼叫者會收到授權錯誤。

`Error code: AuthorizationError ...`

在傳出訊息上，Amazon SNS 主題不會將訊息傳遞至訂閱。若要追蹤未經授權的傳遞，請啟用主題的[傳遞狀態記錄](sns-topic-attributes.md)。下列為傳遞狀態日誌的範例：

```
{
    "notification": {
        "messageMD5Sum": "29638742ffb68b32cf56f42a79bcf16b",
        "messageId": "34d9b400-c6dd-5444-820d-fbeb0f1f54cf",
        "topicArn": "arn:aws:sns:us-east-1:123412341234:PII-data-topic",
        "timestamp": "2022-05-12T2:12:44Z"
    },
    "delivery": {
        "deliveryId": "98236591c-56aa-51ee-a5ed-0c7d43493170",
        "destination": "arn:aws:sqs:us-east-1:123456789012:NoNameAccess",
        "providerResponse": "The topic's data protection policy prohibits this message from being delivered to <subscription-arn>",
        "dwellTimeMs":20,
        "attempts":1,
        "statusCode": 403
    },
    "status": "FAILURE"
}
```