

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

# AWS Organizations 和 的服務控制政策範例 AWS RAM
<a name="security-scp"></a>

AWS RAM 支援服務控制政策 SCPs)。SCP 是您附加至組織中元素的政策，藉此管理該組織內的許可。SCP 適用於 AWS 帳戶 [您連接 SCP 的 元素下](https://docs.aws.amazon.com//organizations/latest/userguide/orgs_manage_policies_inheritance_auth.html)的所有 。SCP 可集中控制組織中所有帳戶可用的許可上限。他們可協助您確保 AWS 帳戶 遵守組織的存取控制準則。如需詳細資訊，請參閱《AWS Organizations 使用者指南》中的[服務控制政策](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_type-auth.html)。

## 先決條件
<a name="scp-prereqs"></a>

若要使用 SCP，您必須執行下列動作：
+ 啟用您組織的所有功能。如需詳細資訊，請參閱*AWS Organizations 《 使用者指南*》[中的啟用組織中的所有功能](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_org_support-all-features.html) 
+ 啟用 SCP 以便於您的組織內使用。如需詳細資訊，請參閱*AWS Organizations 《 使用者指南*》中的[啟用和停用政策類型](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_enable-disable.html) 
+ 建立您需要的 SCP。如需建立 SCPs的詳細資訊，請參閱*AWS Organizations 《 使用者指南*》中的[建立和更新 SCPs](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scp-create.html)。

## 服務控制政策的範例
<a name="scp-examples"></a>

**Contents**
+ [範例 1：防止外部共用](#example-one)
+ [範例 2：防止使用者接受來自組織外部帳戶的資源共用邀請](#example-two)
+ [範例 3：允許特定帳戶共用特定資源類型](#example-three)
+ [範例 4：防止與整個組織或組織單位共用](#example-four)
+ [範例 5：僅允許與特定委託人共用](#example-five)
+ [範例 6：防止已啟用 RetainSharingOnAccountLeaveOrganization 的資源共用](#example-six)

下列範例展示您可以如何控制組織中資源共享的各個層面。

### 範例 1：防止外部共用
<a name="example-one"></a>

下列 SCP 可防止使用者建立允許與共用使用者組織外部主體共用的資源共用。

AWS RAM 會針對呼叫中列出的每個委託人和資源分別授權 APIs。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Deny",
            "Action": [
                "ram:CreateResourceShare",
                "ram:UpdateResourceShare"
            ],
            "Resource": "*",
            "Condition": {
                "Bool": {
                    "ram:RequestedAllowsExternalPrincipals": "true"
                }
            }
        }
    ]
}
```

------

### 範例 2：防止使用者接受來自組織外部帳戶的資源共用邀請
<a name="example-two"></a>

下列 SCP 會阻止受影響帳戶中的任何主體接受使用資源共享的邀請。與共用帳戶相同組織中的其他帳戶共用的資源共用不會產生邀請，因此不受此 SCP 影響。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Deny",
            "Action": "ram:AcceptResourceShareInvitation",
            "Resource": "*"
        }
    ]
}
```

------

### 範例 3：允許特定帳戶共用特定資源類型
<a name="example-three"></a>

下列 SCP *僅允許*帳戶 `111111111111`和 `222222222222` 建立新的資源共用，以共用 Amazon EC2 字首清單或將字首清單與現有資源共用建立關聯。

AWS RAM 會針對呼叫中列出的每個委託人和資源分別授權 APIs。

如果請求不包含資源類型參數，或者如果它包含該參數，則運算子`StringEqualsIfExists`允許請求，其值完全符合指定的資源類型。如果您要包含委託人，您必須擁有 `...IfExists`。

如需何時和為何使用`...IfExists`運算子的詳細資訊，請參閱 [...《IAM 使用者指南》中的 IfExists 條件運算子](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_IfExists)。 **

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Deny",
            "Action": [
                "ram:AssociateResourceShare",
                "ram:CreateResourceShare"
            ],
            "Resource": "*",
            "Condition": {
                "StringNotEquals": {
                    "aws:PrincipalAccount": [
                        "111111111111",
                        "222222222222"
                    ]
                },
                "StringEqualsIfExists": {
                    "ram:RequestedResourceType": "ec2:PrefixList"
                }
            }
        }
    ]
}
```

------

### 範例 4：防止與整個組織或組織單位共用
<a name="example-four"></a>

下列 SCP 可防止使用者建立與整個組織或任何組織單位共用資源的資源共用。使用者可以與 AWS 帳戶 組織中的個人共用，或與 IAM 角色或使用者**共用。

AWS RAM 會針對呼叫中列出的每個委託人和資源分別授權 APIs。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Deny",
            "Action": [
                "ram:CreateResourceShare",
                "ram:AssociateResourceShare"
            ],
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "ram:Principal": [
                        "arn:aws:organizations::*:organization/*",
                        "arn:aws:organizations::*:ou/*"
                    ]
                }
            }
        }
    ]
}
```

------

### 範例 5：僅允許與特定委託人共用
<a name="example-five"></a>

下列範例 SCP 允許使用者*僅*與`o-12345abcdef,`組織單位 `ou-98765fedcba`、 和 AWS 帳戶 共用資源`111111111111`。

如果您使用具有 等否定條件運算子的 `"Effect": "Deny"`元素`StringNotEqualsIfExists`，即使條件索引鍵不存在，請求仍會遭到拒絕。使用 `Null` 條件運算子檢查授權時是否沒有條件索引鍵。

AWS RAM 會針對呼叫中列出的每個委託人和資源分別授權 APIs。

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

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Deny",
      "Action": [
        "ram:AssociateResourceShare",
        "ram:CreateResourceShare"
      ],
      "Resource": "*",
      "Condition": {
        "StringNotEquals": {
          "ram:Principal": [
            "arn:aws:organizations::123456789012:organization/o-12345abcdef",
            "arn:aws:organizations::123456789012:ou/o-12345abcdef/ou-98765fedcba",
            "111111111111"
          ]
        },
        "Null": {
          "ram:Principal": "false"
        }
      }
    }
  ]
}
```

------

### 範例 6：防止已啟用 RetainSharingOnAccountLeaveOrganization 的資源共用
<a name="example-six"></a>

下列 SCP 可防止使用者在`ram:RetainSharingOnAccountLeaveOrganization`條件金鑰設定為 時建立或修改資源共用`true`。

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Deny",
            "Action": [
                "ram:CreateResourceShare",
                "ram:AssociateResourceShare",
                "ram:DisassociateResourceShare"
            ],
            "Resource": "*",
            "Condition": {
                "Bool": {
                    "ram:RetainSharingOnAccountLeaveOrganization": "true"
                }
            }
        }
    ]
}
```