

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

# 使用 AWS KMS 金鑰加密 EventBridge 管道資料
<a name="eb-encryption-pipes-cmkey"></a>

您可以指定 EventBridge 使用客戶受管金鑰來加密靜態儲存的管道資料，而不是 AWS 擁有的金鑰 使用預設的 。您可以在建立或更新管道時指定客戶受管金鑰。如需金鑰類型的詳細資訊，請參閱 [KMS 金鑰選項](eb-encryption-at-rest-key-options.md)。

EventBridge 靜態加密的管道資料包括：
+ [事件模式](eb-event-patterns.md)
+ [輸入轉換器](eb-pipes-input-transformation.md)

流經管道的事件絕不會靜態存放。

## EventBridge 管道加密內容
<a name="eb-encryption-at-rest-context-pipes"></a>

[加密內容](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#encrypt_context)是一組金鑰/值對，其中包含任意非私密資料。在加密資料的請求中包含加密內容時， AWS KMS 會以密碼編譯方式將加密內容繫結至加密的資料。若要解密資料，您必須傳遞相同的加密內容。

您也可以使用加密內容做為政策和授權的條件。

如果您使用客戶受管金鑰來保護 EventBridge 資源，您可以使用加密內容來識別稽核記錄和日誌 KMS key 中的 使用情況。它也會以純文字顯示在日誌中，例如 [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html) 和 [Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html)。

對於 EventBridge 管道，EventBridge 在所有 AWS KMS 密碼編譯操作中使用相同的加密內容。內容包含單一索引鍵/值對，其中包含管道 ARN。

```
"encryptionContext": {
    "kms:EncryptionContext:aws:pipes:arn": "{{pipe-arn}}"
}
```

對於付費日誌，EventBridge 使用以下加密內容。

```
"encryptionContext": {
    "kms:EncryptionContext:SourceArn": "arn:{{partition}}:logs:{{region}}:{{account}}:*"
}
```

## AWS KMS EventBridge 管道的金鑰政策
<a name="eb-encryption-key-policy-pipe"></a>

下列範例金鑰政策提供管道所需的許可：
+ `kms:DescribeKey`
+ `kms:GenerateDataKey`
+ `kms:Decrypt`

作為安全最佳實務，我們建議您在金鑰政策中包含條件金鑰，以協助確保 EventBridge 僅將 AWS KMS 金鑰用於指定的資源或帳戶。如需詳細資訊，請參閱[安全考量](eb-encryption-key-policy.md#eb-encryption-event-bus-confused-deputy)。

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

****  

```
{
  "Id": "CMKKeyPolicy",
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
      "AWS": "arn:aws:iam::{{123456789012}}:role/{{pipe-execution-role}}"
      },
      "Action": [
        "kms:DescribeKey"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Principal": {
      "AWS": "arn:aws:iam::{{123456789012}}:role/{{pipe-execution-role}}e"
      },
      "Action": [
        "kms:GenerateDataKey",
        "kms:Decrypt"
      ],
      "Resource": "*",
      "Condition": {
        "ArnLike": {
        "kms:EncryptionContext:aws:pipe:arn": "arn:aws:pipes:{{us-east-1}}:{{123456789012}}:pipe/{{pipe-name}}"
        },
        "ForAnyValue:StringEquals": {
          "kms:EncryptionContextKeys": [
            "aws:pipe:arn"
          ]
        }
      }
    }
  ]
}
```

------

### 包含執行資料的管道日誌許可
<a name="eb-encryption-key-policy-pipe-logs"></a>

如果您已設定管道記錄以包含執行資料，金鑰政策必須包含記錄服務的下列許可：
+ `kms:Decrypt`
+ `kms:GenerateDataKey`

如需詳細資訊，請參閱[在 EventBridge 管道日誌中包含執行資料](eb-pipes-logs.md#eb-pipes-logs-execution-data)。

下列範例金鑰政策提供管道記錄的必要許可：

```
{
  "Sid": "Enable log service encryption",
  "Effect": "Allow",
  "Principal": {
    "Service": "delivery.logs.amazonaws.com"
  },
  "Action": [
    "kms:Decrypt",
    "kms:GenerateDataKey"
  ],
  "Resource": "*",
  "Condition": {
    "StringLike": {
      "kms:EncryptionContext:SourceArn": "arn:{{partition}}:logs:{{region}}:{{account}}:*"
    }
  }
}
```

此外，管道執行角色需要 `kms:GenerateDataKey` 許可。

```
{
  "Sid": "Enable log service encryption",
  "Effect": "Allow",
  "Principal": {
    "AWS": "arn:aws:iam::{{account}}:role/pipe-execution-role"
  },
  "Action": [
    "kms:GenerateDataKey"
  ],
  "Resource": "*",
  "Condition": {
    "StringLike": {
      "kms:EncryptionContext:SourceArn": "arn:{{partition}}:logs:{{region}}:{{account}}:*"
    }
  }
}
```

管道執行角色也應該包含：

```
"Action": [
    "kms:GenerateDataKey"
  ],
  "Resource": "{{key-arn}}",
  "Condition": {
    "StringLike": {
      "kms:EncryptionContext:SourceArn": "arn:{{partition}}:logs:{{region}}:{{account}}:*"
    }
  }
```