

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

# AWS 資料來源的 Amazon Managed Grafana 許可和政策
<a name="AMG-manage-permissions"></a>

Amazon Managed Grafana 提供三種許可模式：
+ 目前帳戶的服務受管許可
+ 組織的服務受管許可
+ 客戶受管許可

建立工作區時，您可以選擇要使用的許可模式。您也可以稍後視需要進行變更。

在任一服務受管許可模式中，Amazon Managed Grafana 會建立存取和探索您帳戶或組織中 AWS 資料來源所需的角色和政策。您可以選擇在 IAM 主控台中編輯這些政策。

## 單一帳戶的服務受管許可
<a name="AMG-service-managed-account"></a>

在此模式中，Amazon Managed Grafana 會建立名為 **AmazonGrafanaServiceRole-{{random-id}}** 的角色。然後，Amazon Managed Grafana 會針對您選取要從 Amazon Managed Grafana 工作區存取的每個 AWS 服務，將政策連接至此角色。

**CloudWatch**  
Amazon Managed Grafana 連接 AWS 受管政策 **AmazonGrafanaCloudWatchAccess**。  
對於在建立 CloudWatch 的工作區，Amazon Managed Grafana 建立了名為 **AmazonGrafanaCloudWatchPolicy-{{random-id}} **的客戶受管政策。 **AmazonGrafanaCloudWatchAccess** 

**Amazon OpenSearch Service**  
Amazon Managed Grafana 會建立名為 **AmazonGrafanaOpenSearchPolicy-{{random-id}}** 的客戶受管政策。資料來源存取需要 Get/Post 許可。Amazon Managed Grafana 會使用 List/Describe 許可進行資料來源探索，但資料來源外掛程式不需要這些許可即可運作。政策的內容如下：    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "es:ESHttpGet",
                "es:DescribeElasticsearchDomains",
                "es:ListDomainNames"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "es:ESHttpPost",
            "Resource": [
                "arn:aws:es:*:*:domain/*/_msearch*",
                "arn:aws:es:*:*:domain/*/_opendistro/_ppl"
            ]
        }
    ]
}
```

**AWS IoT SiteWise**  
Amazon Managed Grafana 連接 AWS 受管政策 **AWSIoTSiteWiseReadOnlyAccess**。

**Amazon Redshift**  
Amazon Managed Grafana 會連接 AWS 受管政策 **AmazonGrafanaRedshiftAccess**。

**Amazon Athena**  
Amazon Managed Grafana 連接 AWS 受管政策 **AmazonGrafanaAthenaAccess**。

**Amazon Managed Service for Prometheus**  
Amazon Managed Grafana 會建立名為 **AmazonGrafanaPrometheusPolicy-{{random-id}}** 的客戶受管政策。Amazon Managed Grafana 會將 List/Describe 許可用於資料來源探索，外掛程式不需要這些許可即可運作。政策的內容如下：    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "aps:ListWorkspaces",
                "aps:DescribeWorkspace",
                "aps:QueryMetrics",
                "aps:GetLabels",
                "aps:GetSeries",
                "aps:GetMetricMetadata"
            ],
            "Resource": "*"
        }
    ]
}
```

**Amazon SNS**  
Amazon Managed Grafana 會建立名為 **AmazonGrafanaSNSPolicy-{{random-id}} **的客戶受管政策。此政策限制您只能使用帳戶中以字串 開頭的 SNS 主題`grafana`。如果您建立自己的政策，則不需要這麼做。政策的內容如下：    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "sns:Publish"
            ],
            "Resource": [
                "arn:aws:sns:*:{{111122223333}}:grafana*"
            ]
        }
    ]
}
```

**Timestream**  
Amazon Managed Grafana 會連接 AWS 受管政策 **AmazonTimestreamReadOnlyAccess**。

**X-Ray**  
Amazon Managed Grafana 會連接 AWS 受管政策 **AWSXrayReadOnlyAccess**。

## 組織的服務受管許可
<a name="AMG-service-managed-organization"></a>

此模式僅支援在管理帳戶或組織中委派管理員帳戶中建立的工作區。委派的管理員帳戶可以為組織建立和管理堆疊集。如需委派管理員帳戶的詳細資訊，請參閱[註冊委派管理員](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-delegated-admin.html)。

**注意**  
在組織的管理帳戶中建立 資源，例如 Amazon Managed Grafana 工作區，違反 AWS 安全最佳實務。

在此模式中，Amazon Managed Grafana 會建立存取 AWS AWS 組織中其他帳戶中資源所需的所有 IAM 角色。在您選取的組織單位的每個帳戶中，Amazon Managed Grafana 會建立名為 **AmazonGrafanaOrgMemberRole-{{random-id}}** 的角色。此角色建立是透過與 AWS CloudFormation StackSets 的整合來執行。

此角色會為您選取要在工作區中使用的每個 AWS 資料來源附加政策。如需這些資料政策的內容，請參閱 [單一帳戶的服務受管許可](#AMG-service-managed-account)。

Amazon Managed Grafana 也會在組織的管理帳戶中建立名為 **AmazonGrafanaOrgAdminRole-{{random-id}}** 的角色。此角色可讓 Amazon Managed Grafana 工作區存取 organization. AWS service 通知管道政策中的其他帳戶。使用工作區中的**AWS 資料來源**功能表，快速為您的工作區可存取的每個帳戶佈建資料來源

若要使用此模式，您必須在組織中 AWS 啟用 CloudFormation Stacksets 做為信任的服務。如需詳細資訊，請參閱[使用 啟用受信任存取 AWS Organizations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-orgs-enable-trusted-access.html)。

以下是 **AmazonGrafanaStackSet-{{random-id }}**堆疊集的內容：

```
Parameters:
  IncludePrometheusPolicy:
    Description: Whether to include Amazon Prometheus access in the role
    Type: String
    AllowedValues:
      - true
      - false
    Default: false
  IncludeAESPolicy:
    Description: Whether to include Amazon Elasticsearch access in the role
    Type: String
    AllowedValues:
      - true
      - false
    Default: false
  IncludeCloudWatchPolicy:
    Description: Whether to include CloudWatch access in the role
    Type: String
    AllowedValues:
      - true
      - false
    Default: false
  IncludeTimestreamPolicy:
    Description: Whether to include Amazon Timestream access in the role
    Type: String
    AllowedValues:
      - true
      - false
    Default: false
  IncludeXrayPolicy:
    Description: Whether to include AWS X-Ray access in the role
    Type: String
    AllowedValues:
      - true
      - false
    Default: false
  IncludeSitewisePolicy:
    Description: Whether to include AWS IoT SiteWise access in the role
    Type: String
    AllowedValues:
      - true
      - false
    Default: false
  IncludeRedshiftPolicy:
    Description: Whether to include Amazon Redshift access in the role
    Type: String
    AllowedValues:
      - true
      - false
    Default: false
  IncludeAthenaPolicy:
    Description: Whether to include Amazon Athena access in the role
    Type: String
    AllowedValues:
      - true
      - false
    Default: false
  RoleName:
    Description: Name of the role to create
    Type: String
  AdminAccountId:
    Description: Account ID of the Amazon Grafana org admin
    Type: String
Conditions:
  addPrometheus: !Equals [!Ref IncludePrometheusPolicy, true]
  addAES: !Equals [!Ref IncludeAESPolicy, true]
  addCloudWatch: !Equals [!Ref IncludeCloudWatchPolicy, true]
  addTimestream: !Equals [!Ref IncludeTimestreamPolicy, true]
  addXray: !Equals [!Ref IncludeXrayPolicy, true]
  addSitewise: !Equals [!Ref IncludeSitewisePolicy, true]
  addRedshift: !Equals [!Ref IncludeRedshiftPolicy, true]
  addAthena: !Equals [!Ref IncludeAthenaPolicy, true]

Resources:
  PrometheusPolicy:
    Type: AWS::IAM::Policy
    Condition: addPrometheus
    Properties:
      Roles: 
       - !Ref GrafanaMemberServiceRole
      PolicyName: AmazonGrafanaPrometheusPolicy
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Action:
              - aps:QueryMetrics
              - aps:GetLabels
              - aps:GetSeries
              - aps:GetMetricMetadata
              - aps:ListWorkspaces
              - aps:DescribeWorkspace
            Resource: '*'

  AESPolicy:
    Type: AWS::IAM::Policy
    Condition: addAES
    Properties:
      Roles: 
       - !Ref GrafanaMemberServiceRole
      PolicyName: AmazonGrafanaElasticsearchPolicy
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Sid: AllowReadingESDomains
            Effect: Allow
            Action:
              - es:ESHttpGet
              - es:ESHttpPost
              - es:ListDomainNames
              - es:DescribeElasticsearchDomains
            Resource: '*'

  CloudWatchPolicy:
    Type: AWS::IAM::Policy
    Condition: addCloudWatch
    Properties:
      Roles: 
       - !Ref GrafanaMemberServiceRole
      PolicyName: AmazonGrafanaCloudWatchPolicy
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Sid: AllowReadingMetricsFromCloudWatch
            Effect: Allow
            Action:
              - cloudwatch:DescribeAlarmsForMetric
              - cloudwatch:DescribeAlarmHistory
              - cloudwatch:DescribeAlarms
              - cloudwatch:ListMetrics
              - cloudwatch:GetMetricStatistics
              - cloudwatch:GetMetricData
              - cloudwatch:GetInsightRuleReport
            Resource: "*"
          - Sid: AllowReadingLogsFromCloudWatch
            Effect: Allow
            Action:
              - logs:DescribeLogGroups
              - logs:GetLogGroupFields
              - logs:StartQuery
              - logs:StopQuery
              - logs:GetQueryResults
              - logs:GetLogEvents
            Resource: "*"
          - Sid: AllowReadingTagsInstancesRegionsFromEC2
            Effect: Allow
            Action:
              - ec2:DescribeTags
              - ec2:DescribeInstances
              - ec2:DescribeRegions
            Resource: "*"
          - Sid: AllowReadingResourcesForTags
            Effect: Allow
            Action:
              - tag:GetResources
            Resource: "*"
  GrafanaMemberServiceRole:
    Type: 'AWS::IAM::Role'
    Properties:
      RoleName: !Ref RoleName
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              AWS: !Sub arn:aws:iam::${AdminAccountId}:root
            Action:
              - 'sts:AssumeRole'
      Path: /service-role/
      ManagedPolicyArns:
        - !If [addTimestream, arn:aws:iam::aws:policy/AmazonTimestreamReadOnlyAccess, !Ref AWS::NoValue]
        - !If [addXray, arn:aws:iam::aws:policy/AWSXrayReadOnlyAccess, !Ref AWS::NoValue]
        - !If [addSitewise, arn:aws:iam::aws:policy/AWSIoTSiteWiseReadOnlyAccess, !Ref AWS::NoValue]
        - !If [addRedshift, arn:aws:iam::aws:policy/service-role/AmazonGrafanaRedshiftAccess, !Ref AWS::NoValue]
        - !If [addAthena, arn:aws:iam::aws:policy/service-role/AmazonGrafanaAthenaAccess, !Ref AWS::NoValue]
```

以下是 **AmazonGrafanaOrgAdminPolicy-{{random-id}}** 的內容。

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

****  

```
{ 
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Action": [
            "organizations:ListAccountsForParent", 
            "organizations:ListOrganizationalUnitsForParent"
        ],
        "Resource": "*",
        "Condition": {
            "StringEquals": {
                "aws:PrincipalOrgID": "o-{{organizationId}}"
            }
        }
    },
    {
        "Effect": "Allow",
        "Action": [
            "sts:AssumeRole"
        ],
        "Resource": "arn:aws:iam::*:role/service-role/AmazonGrafanaOrgMemberRole-{{random-Id}}" 
    }]
}
```

------

## 客戶受管許可
<a name="AMG-customer-managed"></a>

如果您選擇使用客戶受管許可，您可以在建立 Amazon Managed Grafana 工作區時，在帳戶中指定現有的 IAM 角色。角色必須具有信任 的信任政策`grafana.amazonaws.com`。

以下是這類政策的範例：

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

****  

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

------

若要讓該角色存取該帳戶中的 AWS 資料來源或通知管道，該角色必須具有本節先前列出的政策許可。例如，若要使用 CloudWatch 資料來源，它必須具有 中列出的 CloudWatch 政策中的許可[單一帳戶的服務受管許可](#AMG-service-managed-account)。

中顯示的 Amazon OpenSearch Service 和 Amazon Managed Service for Prometheus 政策中的 `List`和 `Describe`許可[單一帳戶的服務受管許可](#AMG-service-managed-account)，只需要資料來源探索和佈建才能正常運作。如果您只想要手動設定這些資料來源，則不需要它們。

**跨帳戶存取**

在帳戶 111111111111 中建立工作區時，必須提供帳戶 1111111111111 中的角色。在此範例中，請呼叫此角色 *WorkspaceRole*。若要存取帳戶 999999999999 中的資料，您必須在帳戶 999999999999 中建立角色。呼叫該 *DataSourceRole*。然後，您必須在 *WorkspaceRole* 和 *DataSourceRole* 之間建立信任關係。如需在兩個角色之間建立信任的詳細資訊，請參閱 [IAM 教學課程：使用 IAM 角色在 AWS 帳戶之間委派存取權](https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html)。

*DataSourceRole* 需要包含本節先前針對您要使用的每個資料來源列出的政策陳述式。建立信任關係後，您可以在工作區中任何 AWS 資料來源的資料來源組態頁面上的擔任角色 ARN 欄位中指定 *DataSourceRole* 的 ARN (arn：aws：iam：：999999999999：role：DataSourceRole)。 ****資料來源接著會使用 *DataSourceRole* 中定義的許可存取帳戶 999999999999。