

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

# 身分型政策範例
<a name="security_iam_id-based-policy-examples"></a>

根據預設，具有 AWS CodeCommit、 AWS CodeBuild AWS CodeDeploy或 其中一個受管政策的 IAM 使用者和角色 AWS CodePipeline ，有權存取符合這些政策意圖的連線、通知和通知規則。例如，已套用其中一個完整存取政策 (**AWSCodeCommitFullAccess**、**AWSCodeBuildAdminAccess**、**AWSCodeDeployFullAccess** 或 **AWSCodePipeline\$1FullAccess**) 的 IAM 使用者或角色，也具有為這些服務資源建立的通知和通知規則之完整存取權。

其他 IAM 使用者和角色沒有建立或修改 AWS CodeStar Notifications 和 AWS CodeConnections 資源的許可。他們也無法使用 AWS 管理主控台 AWS CLI或 AWS API 執行任務。IAM 管理員必須建立 IAM 政策，授予使用者和角色在指定資源上執行 API 作業的所需許可。管理員接著必須將這些政策連接至需要這些許可的 IAM 使用者或群組。

# AWS CodeStar Notifications 的許可和範例
<a name="security_iam_id-based-policy-examples-notifications"></a>

下列政策陳述式和範例可協助您管理 AWS CodeStar Notifications。

## 完整存取受管政策中的通知相關許可
<a name="notifications-fullaccess"></a>

**AWSCodeCommitFullAccess**、**AWSCodeBuildAdminAccess**、**AWSCodeDeployFullAccess** 和 **AWSCodePipeline\$1FullAccess** 受管政策包括下列陳述式，允許完整存取開發人員工具主控台中的通知。已套用上述其中一個受管政策的使用者，也可以建立和管理通知的 Amazon SNS 主題、讓使用者訂閱和取消訂閱主題，以及列出可選擇作為通知規則目標的主題。

**注意**  
在受管理政策中，條件金鑰 `codestar-notifications:NotificationsForResource` 具有服務的資源類型所特有的值。例如，在 CodeCommit 的完整存取政策中，值為 `arn:aws:codecommit:*`。

```
    {
        "Sid": "CodeStarNotificationsReadWriteAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-notifications:CreateNotificationRule",
            "codestar-notifications:DescribeNotificationRule",
            "codestar-notifications:UpdateNotificationRule",
            "codestar-notifications:DeleteNotificationRule",
            "codestar-notifications:Subscribe",
            "codestar-notifications:Unsubscribe"
        ],
        "Resource": "*",
        "Condition" : {
            "StringLike" : {"codestar-notifications:NotificationsForResource" : "arn:aws:<vendor-code>:*"} 
        }
    },    
    {
        "Sid": "CodeStarNotificationsListAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-notifications:ListNotificationRules",
            "codestar-notifications:ListTargets",
            "codestar-notifications:ListTagsforResource",
            "codestar-notifications:ListEventTypes"
        ],
        "Resource": "*"
    },
    {
        "Sid": "CodeStarNotificationsSNSTopicCreateAccess",
        "Effect": "Allow",
        "Action": [
            "sns:CreateTopic",
            "sns:SetTopicAttributes"
        ],
        "Resource": "arn:aws:sns:*:*:codestar-notifications*"
    },
    {
        "Sid": "SNSTopicListAccess",
        "Effect": "Allow",
        "Action": [
            "sns:ListTopics"
        ],
        "Resource": "*"
    },
    {
        "Sid": "CodeStarNotificationsChatbotAccess",
        "Effect": "Allow",
        "Action": [
            "chatbot:DescribeSlackChannelConfigurations",
            "chatbot:ListMicrosoftTeamsChannelConfigurations"
          ],
       "Resource": "*"
    }
```

## 唯讀受管政策中的通知相關許可
<a name="notifications-readonly"></a>

**AWSCodeCommitReadOnlyAccess**、**AWSCodeBuildReadOnlyAccess**、**AWSCodeDeployReadOnlyAccess** 和 **AWSCodePipeline\$1ReadOnlyAccess** 受管政策包括下列陳述式，允許唯讀存取通知。例如，他們可以在開發人員主控台中檢視資源的通知，但無法建立、管理或訂閱通知。

**注意**  
在受管理政策中，條件金鑰 `codestar-notifications:NotificationsForResource` 具有服務的資源類型所特有的值。例如，在 CodeCommit 的完整存取政策中，值為 `arn:aws:codecommit:*`。

```
   {
        "Sid": "CodeStarNotificationsPowerUserAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-notifications:DescribeNotificationRule"
        ],
        "Resource": "*",
        "Condition" : {
            "StringLike" : {"codestar-notifications:NotificationsForResource" : "arn:aws:<vendor-code>:*"} 
        }
    },    
    {
        "Sid": "CodeStarNotificationsListAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-notifications:ListNotificationRules",
            "codestar-notifications:ListEventTypes",
            "codestar-notifications:ListTargets"
        ],
        "Resource": "*"
    }
```

## 其他受管政策中的通知相關許可
<a name="notifications-otheraccess"></a>

**AWSCodeCommitPowerUser**、**AWSCodeBuildDeveloperAccess** 和 **AWSCodeBuildDeveloperAccess** 受管政策括下列陳述式，允許已套用上述其中一個受管政策的開發人員，建立、編輯和訂閱通知。他們無法刪除通知規則或管理資源的標籤。

**注意**  
在受管理政策中，條件金鑰 `codestar-notifications:NotificationsForResource` 具有服務的資源類型所特有的值。例如，在 CodeCommit 的完整存取政策中，值為 `arn:aws:codecommit:*`。

```
    {
        "Sid": "CodeStarNotificationsReadWriteAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-notifications:CreateNotificationRule",
            "codestar-notifications:DescribeNotificationRule",
            "codestar-notifications:UpdateNotificationRule",
            "codestar-notifications:Subscribe",
            "codestar-notifications:Unsubscribe"
        ],
        "Resource": "*",
        "Condition" : {
            "StringLike" : {"codestar-notifications:NotificationsForResource" : "arn:aws:<vendor-code>:*"} 
        }
    },    
    {
        "Sid": "CodeStarNotificationsListAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-notifications:ListNotificationRules",
            "codestar-notifications:ListTargets",
            "codestar-notifications:ListTagsforResource",
            "codestar-notifications:ListEventTypes"
        ],
        "Resource": "*"
    },
    {
        "Sid": "SNSTopicListAccess",
        "Effect": "Allow",
        "Action": [
            "sns:ListTopics"
        ],
        "Resource": "*"
    },
    {
        "Sid": "CodeStarNotificationsChatbotAccess",
        "Effect": "Allow",
        "Action": [
            "chatbot:DescribeSlackChannelConfigurations",
            "chatbot:ListMicrosoftTeamsChannelConfigurations"
          ],
       "Resource": "*"
    }
```

## 範例：管理 AWS CodeStar Notifications 的管理員層級政策
<a name="security_iam_id-based-policy-examples-notifications-full-access"></a>

在此範例中，您想要授予 AWS 帳戶中的 IAM 使用者 AWS CodeStar Notifications 的完整存取權，讓使用者可以檢閱通知規則的詳細資訊，並列出通知規則、目標和事件類型。您也希望允許使用者新增、更新和刪除通知規則。這是完整存取政策，相當於納入 **AWSCodeBuildAdminAccess**、**AWSCodeCommitFullAccess**、**AWSCodeDeployFullAccess** 和 **AWSCodePipeline\$1FullAccess** 受管政策中的通知許可。如同這些受管政策，您應該只將這類政策陳述式連接到需要完整管理存取 AWS 您帳戶間通知和通知規則的 IAM 使用者、群組或角色。

**注意**  
此政策包含 `CreateNotificationRule`。將此政策套用至其 IAM 使用者或角色的任何使用者，將能夠為 AWS 帳戶中 AWS CodeStar Notifications 支援的任何和所有資源類型建立通知規則，即使該使用者本身無法存取這些資源。例如，具有此政策的使用者可以建立 CodeCommit 儲存庫的通知規則，而沒有存取 CodeCommit 本身的許可。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
      {
        "Sid": "AWSCodeStarNotificationsFullAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-notifications:CreateNotificationRule",
            "codestar-notifications:DeleteNotificationRule",
            "codestar-notifications:DescribeNotificationRule",
            "codestar-notifications:ListNotificationRules",
            "codestar-notifications:UpdateNotificationRule",
            "codestar-notifications:Subscribe",
            "codestar-notifications:Unsubscribe",
            "codestar-notifications:DeleteTarget",
            "codestar-notifications:ListTargets",
            "codestar-notifications:ListTagsforResource",
            "codestar-notifications:TagResource",
            "codestar-notifications:UntagResource"
        ],
        "Resource": "*"
     }
   ]
}
```

------

## 範例：使用 AWS CodeStar Notifications 的貢獻者層級政策
<a name="security_iam_id-based-policy-examples-notifications-contributor"></a>

在此範例中，您想要授予 AWS CodeStar Notifications day-to-day使用存取權，例如建立和訂閱通知，但不要授予更具破壞性的動作，例如刪除通知規則或目標。這相當於 **AWSCodeBuildDeveloperAccess**、**AWSCodeDeployDeveloperAccess** 和 **AWSCodeCommitPowerUser** 受管政策中提供的存取權。

**注意**  
此政策包含 `CreateNotificationRule`。將此政策套用至其 IAM 使用者或角色的任何使用者，將能夠為 AWS 帳戶中 AWS CodeStar Notifications 支援的任何和所有資源類型建立通知規則，即使該使用者本身無法存取這些資源。例如，具有此政策的使用者可以建立 CodeCommit 儲存庫的通知規則，而沒有存取 CodeCommit 本身的許可。

```
{
    "Version": "2012-10-17",		 	 	 
    "Sid": "AWSCodeStarNotificationsPowerUserAccess",
        "Effect": "Allow",
        "Action": [
            "codestar-notifications:CreateNotificationRule",
            "codestar-notifications:DescribeNotificationRule",
            "codestar-notifications:ListNotificationRules",
            "codestar-notifications:UpdateNotificationRule",
            "codestar-notifications:Subscribe",
            "codestar-notifications:Unsubscribe",
            "codestar-notifications:ListTargets",
            "codestar-notifications:ListTagsforResource"
        ],
        "Resource": "*"
        }
    ]
}
```

## 範例：使用 AWS CodeStar Notifications 的read-only-level政策
<a name="security_iam_id-based-policy-examples-notifications-read-only"></a>

在此範例中，您希望授予您帳戶中 IAM 使用者對 AWS 帳戶中的通知規則、目標和事件類型的唯讀存取權。此範例會示範如何建立允許檢視這些項目的政策。這相當於納入 **AWSCodeBuildReadOnlyAccess**、**AWSCodeCommitReadOnly** 和 **AWSCodePipeline\$1ReadOnlyAccess** 受管政策中的許可。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Id": "CodeNotificationforReadOnly",
    "Statement": [
        {
            "Sid": "ReadsAccess",
            "Effect": "Allow",
            "Action": [
                "codestar-notifications:DescribeNotificationRule",
                "codestar-notifications:ListNotificationRules",
                "codestar-notifications:ListTargets",
                "codestar-notifications:ListEventTypes"
            ],
            "Resource": "*"
        }
    ]
}
```

------

# 的許可和範例 AWS CodeConnections
<a name="security_iam_id-based-policy-examples-connections"></a>

下列政策陳述式和範例可協助您管理 AWS CodeConnections。

若要了解如何使用這些範例 JSON 政策文件來建立 IAM 身分型政策，請參閱《*IAM 使用者指南*》中的[在 JSON 標籤上建立政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html#access_policies_create-json-editor)。

## 範例： AWS CodeConnections 使用 CLI 建立和使用主控台檢視的政策
<a name="security_iam_id-based-policy-examples-connections-clisdk"></a>

指定使用 或 AWS CLI SDK 來檢視、建立、標記或刪除連線的角色或使用者，應具有僅限於下列項目的許可。

**注意**  
只具有下列許可，並無法在主控台中完成連線。您需要新增下一節中的許可。

若要使用主控台來檢視可用連線的清單、檢視標籤和使用連線，請使用下列政策。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
      {
        "Sid": "ConnectionsFullAccess",
        "Effect": "Allow",
        "Action": [
            "codeconnections:CreateConnection",
            "codeconnections:DeleteConnection",
            "codeconnections:UseConnection",
            "codeconnections:GetConnection",
            "codeconnections:ListConnections",
            "codeconnections:TagResource",
            "codeconnections:ListTagsForResource",
            "codeconnections:UntagResource"
        ],
        "Resource": "*"
     }
   ]
}
```

------

## 範例： AWS CodeConnections 使用主控台建立 的政策
<a name="security_iam_id-based-policy-examples-connections-console"></a>

指定要管理在主控台中連線的角色或使用者，應具備完成主控台中的連線及建立安裝所需的許可，包括授權供應商進行交握，以及建立供連線使用的安裝。也應該新增 `UseConnection` 以使用主控台中的連線。請使用下列政策來在主控台中檢視、使用、建立、標記或刪除連線。

**注意**  
從 2024 年 7 月 1 日開始，主控台會在資源 ARN `codeconnections`中建立與 的連線。具有兩個服務字首的資源將繼續顯示在主控台中。

**注意**  
對於使用主控台建立的資源，政策陳述式動作必須包含 `codestar-connections`做為服務字首，如下列範例所示。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "codestar-connections:CreateConnection",
                "codestar-connections:DeleteConnection",
                "codestar-connections:GetConnection",
                "codestar-connections:ListConnections",
                "codestar-connections:GetInstallationUrl",
                "codestar-connections:GetIndividualAccessToken",
                "codestar-connections:ListInstallationTargets",
                "codestar-connections:StartOAuthHandshake",
                "codestar-connections:UpdateConnectionInstallation",
                "codestar-connections:UseConnection",
                "codestar-connections:TagResource",
                "codestar-connections:ListTagsForResource",
                "codestar-connections:UntagResource"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------

## 範例：管理 的管理員層級政策 AWS CodeConnections
<a name="security_iam_id-based-policy-examples-connections-fullaccess"></a>

在此範例中，您想要授予 AWS 帳戶中的 IAM 使用者 CodeConnections 的完整存取權，讓使用者可以新增、更新和刪除連線。這是一個完整的存取政策，相當於 **AWSCodePipeline\$1FullAccess** 受管政策。如同該受管政策，您應該只將這類政策陳述式連接到需要完整管理存取 AWS 您帳戶間連線的 IAM 使用者、群組或角色。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
      {
        "Sid": "ConnectionsFullAccess",
        "Effect": "Allow",
        "Action": [
            "codeconnections:CreateConnection",
            "codeconnections:DeleteConnection",
            "codeconnections:UseConnection",
            "codeconnections:GetConnection",
            "codeconnections:ListConnections",
            "codeconnections:ListInstallationTargets",
            "codeconnections:GetInstallationUrl",
            "codeconnections:StartOAuthHandshake",
            "codeconnections:UpdateConnectionInstallation",
            "codeconnections:GetIndividualAccessToken",
            "codeconnections:TagResource",
            "codeconnections:ListTagsForResource",
            "codeconnections:UntagResource"
        ],
        "Resource": "*"
     }
   ]
}
```

------

## 範例：使用 的貢獻者層級政策 AWS CodeConnections
<a name="security_iam_id-based-policy-examples-connections-contributor"></a>

在此範例中，您想要授予 CodeConnections day-to-day使用存取權，例如建立和檢視連線的詳細資訊，但不要授予更具破壞性的動作，例如刪除連線。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "AWSCodeConnectionsPowerUserAccess",
            "Effect": "Allow",
            "Action": [
                "codeconnections:CreateConnection",
                "codeconnections:UseConnection",
                "codeconnections:GetConnection",
                "codeconnections:ListConnections",
                "codeconnections:ListInstallationTargets",
                "codeconnections:GetInstallationUrl",
                "codeconnections:GetIndividualAccessToken",
                "codeconnections:StartOAuthHandshake",
                "codeconnections:UpdateConnectionInstallation",
                "codeconnections:ListTagsForResource"
            ],
            "Resource": "*"
        }
    ]
}
```

------

## 範例：使用 的read-only-level政策 AWS CodeConnections
<a name="security_iam_id-based-policy-examples-connections-readonly"></a>

在此範例中，您想要授予帳戶中的 IAM 使用者對 AWS 帳戶中連線的唯讀存取權。此範例會示範如何建立允許檢視這些項目的政策。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Id": "ConnectionsforReadOnly",
    "Statement": [
        {
            "Sid": "ReadsAPIAccess",
            "Effect": "Allow",
            "Action": [
            "codeconnections:GetConnection",
            "codeconnections:ListConnections",
            "codeconnections:ListInstallationTargets",
            "codeconnections:GetInstallationUrl",
            "codeconnections:ListTagsForResource"
            ],
            "Resource": "*"
        }
    ]
}
```

------<a name="security_iam_id-based-policy-examples-connections-use"></a>

## 範例：使用 **VpcId** 內容金鑰限制主機 VPC 許可
<a name="security_iam_id-based-policy-examples-connections-vpc"></a>

在下列範例中，客戶可以使用 **VpcId** 內容金鑰，將主機的建立或管理限制為具有指定 VPC 的主機。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "codeconnections:CreateHost",
                "codeconnections:UpdateHost"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "codeconnections:VpcId": "vpc-EXAMPLE"
                }
            }
        }
    ]
}
```

------