

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

# 管理 CloudWatch Logs 資源的存取許可概觀
<a name="iam-access-control-overview-cwl"></a>

若要提供存取權，請新增權限至您的使用者、群組或角色：
+ 中的使用者和群組 AWS IAM Identity Center：

  建立權限合集。請按照《*AWS IAM Identity Center 使用者指南*》中的[建立權限合集](https://docs.aws.amazon.com//singlesignon/latest/userguide/howtocreatepermissionset.html)說明進行操作。
+ 透過身分提供者在 IAM 中管理的使用者：

  建立聯合身分的角色。遵循《*IAM 使用者指南*》的[為第三方身分提供者 (聯合) 建立角色](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_roles_create_for-idp.html)中的指示。
+ IAM 使用者：
  + 建立您的使用者可擔任的角色。請按照《*IAM 使用者指南*》的[為 IAM 使用者建立角色](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_roles_create_for-user.html)中的指示。
  + (不建議) 將政策直接附加至使用者，或將使用者新增至使用者群組。請遵循《*IAM 使用者指南*》的[新增許可到使用者 (主控台)](https://docs.aws.amazon.com//IAM/latest/UserGuide/id_users_change-permissions.html#users_change_permissions-add-console) 中的指示。

**Topics**
+ [CloudWatch Logs 資源和操作](#CWL_ARN_Format)
+ [了解資源所有權](#understanding-resource-ownership-cwl)
+ [管理 資源的存取](#managing-access-resources-cwl)
+ [指定政策元素：動作、效果和委託人](#actions-effects-principals-cwl)
+ [在政策中指定條件](#policy-conditions-cwl)

## CloudWatch Logs 資源和操作
<a name="CWL_ARN_Format"></a>

在 CloudWatch Logs 中，主資源為日誌群組、日誌串流和目的地。CloudWatch Logs 不支援子資源 (搭配主資源使用的其他資源)。

這些資源和子資源都有獨一無二的 Amazon Resource Name (ARN) 與其相關聯，如下表所示。


| Resource Type (資源類型) | ARN 格式 | 
| --- | --- | 
|  日誌群組  |  以下兩種方式皆可使用。以 `:*` 結尾的第二種，是由 `describe-log-groups` CLI 命令和 **DescribeLogGroups** API 所傳回的。 arn:aws:logs:*region*:*account-id*:log-group:*log\$1group\$1name* arn:aws:logs:*region*:*account-id*:log-group:*log\$1group\$1name*:\$1 在下列情況下，使用第一個沒有結尾 `:*`的版本： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/logs/iam-access-control-overview-cwl.html) 在 IAM 政策中指定所有其他 API 動作的許可時，使用第二個版本搭配結尾 來`:*`參考 ARN。  | 
|  日誌串流  |  arn:aws:logs:*region*:*account-id*:log-group:*log\$1group\$1name*:log-stream:*log-stream-name*  | 
|  目標  |  arn:aws:logs:*region*:*account-id*:destination:*destination\$1name*  | 

如需 ARN 的詳細資訊，請參閱《IAM 使用者指南》**中的 [ARN](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html#Identifiers_ARNs)。如需 CloudWatch Logs ARN 的相關資訊，請參閱 *Amazon Web Services 一般參考* 中的 [Amazon Resource Name (ARN)](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arn-syntax-cloudwatch-logs)。有關 CloudWatch Logs 適用的政策範例，請參閱[對 CloudWatch Logs 使用以身分為基礎的政策 (IAM 政策)](iam-identity-based-access-control-cwl.md)。

CloudWatch Logs 提供一組操作來使用 CloudWatch Logs 資源。如需可用操作的清單，請參閱 [CloudWatch Logs 許可參考](permissions-reference-cwl.md)。

## 了解資源所有權
<a name="understanding-resource-ownership-cwl"></a>

無論誰建立資源， AWS 帳戶都會擁有在帳戶中建立的資源。具體而言，資源擁有者是驗證資源建立請求的[委託人實體](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html) AWS 帳戶 （即根帳戶、使用者或 IAM 角色）。下列範例說明其如何運作：
+ 如果您使用 AWS 帳戶的根帳戶登入資料來建立日誌群組， AWS 您的帳戶即為 CloudWatch Logs 資源的擁有者。
+ 如果您在 AWS 帳戶中建立使用者，並將建立 CloudWatch Logs 資源的許可授予該使用者，則使用者可以建立 CloudWatch Logs 資源。不過，使用者所屬 AWS 的帳戶擁有 CloudWatch Logs 資源。
+ 如果您在 AWS 帳戶中建立具有建立 CloudWatch Logs 資源許可的 IAM 角色，則任何可以擔任該角色的人都可以建立 CloudWatch Logs 資源。該角色所屬 AWS 的帳戶擁有 CloudWatch Logs 資源。

## 管理 資源的存取
<a name="managing-access-resources-cwl"></a>

*許可政策*描述誰可以存取哪些資源。下一節說明可用來建立許可政策的選項。

**注意**  
本節討論如何在 CloudWatch Logs​ 的環境中使用 IAM。它不提供 IAM 服務的詳細資訊。如需完整的 IAM 文件，請參閱《IAM 使用者指南》**中的[什麼是 IAM？](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html)。如需有關 IAM 政策語法和說明的資訊，請參閱《IAM 使用者指南》**中的 [IAM 政策參考](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html)。

連接到 IAM 身分的政策稱為身分類型政策 (IAM 政策)，而連接到資源的政策參考資源類型政策。CloudWatch Logs 支援以身分為基礎的政策，也支援以資源為基礎的政策來管理目的地，以用於啟用跨帳戶訂閱。如需詳細資訊，請參閱[跨帳戶跨區域訂閱](CrossAccountSubscriptions.md)。

**Topics**
+ [日誌群組許可和 Contributor Insights](#cloudwatch-logs-permissions-and-contributor-insights)
+ [資源型政策](#resource-based-policies-cwl)

### 日誌群組許可和 Contributor Insights
<a name="cloudwatch-logs-permissions-and-contributor-insights"></a>

Contributor Insights 是 CloudWatch 的一項功能，可讓您分析日誌群組的資料，以及建立時間序列來顯示參與者資料。您可以查看與前 N 個參與者有關的指標、唯一參與者的總數及其用量。如需詳細資訊，請參閱[使用 Contributor Insights 來分析高基數資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ContributorInsights.html)。

當您將 `cloudwatch:PutInsightRule` 和 `cloudwatch:GetInsightRuleReport` 許可授予使用者時，該使用者就可以建立規則來評估 CloudWatch Logs 中的任何日誌群組，然後查看結果。結果可能包含這些日誌群組的參與者資料。請務必將這些許可只授予允許檢視此資料的使用者。

### 資源型政策
<a name="resource-based-policies-cwl"></a>

​CloudWatch Logs 支援以資源為基礎的政策來管理目的地，可用於啟用跨帳戶訂閱。如需詳細資訊，請參閱[步驟 1：建立目的地](CreateDestination.md)。您可以使用 [PutDestination](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutDestination.html) API 建立目的地，也可以使用 [PutDestinationPolicy](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutDestinationPolicy.html) API 將資源政策新增至目的地。以下範例可讓帳戶 ID 為 111122223333 的另一個 AWS 帳戶將日誌群組訂閱到目的地 `arn:aws:logs:us-east-1:123456789012:destination:testDestination`。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement" : [
    {
      "Sid" : "",
      "Effect" : "Allow",
      "Principal" : {
        "AWS" : "111122223333"
      },
      "Action" : "logs:PutSubscriptionFilter",
      "Resource" : "arn:aws:logs:us-east-1:123456789012:destination:testDestination"
    }
  ]
}
```

------

## 指定政策元素：動作、效果和委託人
<a name="actions-effects-principals-cwl"></a>

 對於每項 CloudWatch Logs 資源，該服務定義一組 API 操作。CloudWatch Logs 定義一組您可在政策中指定的動作，以授予這些 API 操作的許可。為了執行 API 操作，某些 API 操作可能需要多個動作的許可。如需資源與 API 操作的詳細資訊，請參閱 [CloudWatch Logs 資源和操作](#CWL_ARN_Format) 與 [CloudWatch Logs 許可參考](permissions-reference-cwl.md).

以下是基本的政策元素：
+ **資源** - 您使用 Amazon Resource Name (ARN) 識別欲套用政策的資源。如需詳細資訊，請參閱[CloudWatch Logs 資源和操作](#CWL_ARN_Format)。
+ **動作**：使用動作關鍵字識別您要允許或拒絕的資源操作。例如，`logs.DescribeLogGroups` 許可允許使用者執行 `DescribeLogGroups` 操作。
+ **效果** – 您可以指定使用者請求特定動作時會有什麼效果 (允許或拒絕)。如果您未明確授予存取 (允許) 資源，則隱含地拒絕存取。您也可以明確拒絕資源存取，這樣做可確保使用者無法存取資源，即使不同政策授予存取也是一樣。
+ **委託人**：在以身分為基礎的政策 (IAM 政策) 中，政策所連接的使用者就是隱含委託人。對於資源型政策，您可以指定想要收到許可的使用者、帳戶、服務或其他實體 (僅適用於資源型政策)。CloudWatch Logs 支援以資源為基礎的政策來管理目的地。

如需進一步了解 IAM 政策語法和說明，請參閱《IAM 使用者指南》**中的 [AWS IAM 政策參考](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies.html)。

如需查看所有 CloudWatch Logs API 動作及其適用資源的表格，請參閱 [CloudWatch Logs 許可參考](permissions-reference-cwl.md)。

## 在政策中指定條件
<a name="policy-conditions-cwl"></a>

當您授予許可時，可以使用存取政策語言來指定政策應該何時生效的條件。例如，建議只在特定日期之後套用政策。如需使用政策語言指定條件的詳細資訊，請參閱*IAM 使用者指南*中的[條件](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition.html)。

欲表示條件，您可以使用預先定義的條件金鑰。如需每個 AWS 服務支援的內容金鑰清單，以及 AWS全政策金鑰清單，請參閱[AWS 服務和全域條件內容金鑰的動作、資源](https://docs.aws.amazon.com/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html)[AWS 和條件金鑰。 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)

**注意**  
您可以使用標籤來控制對 CloudWatch Logs 資源的存取，包括對日誌群組和目的地的存取。由於日誌群組與日誌串流之間的階層關係，系統會在日誌群組層級控制對日誌串流的存取。如需有關使用標籤來控制存取的詳細資訊，請參閱[使用標籤控制對 Amazon Web Services 資源的存取](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_tags.html)。