

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用基于资源的策略进行护栏
<a name="guardrails-resource-based-policies"></a>

**注意**  
对 Amazon Bedrock Guardrails 使用基于资源的政策尚处于预览阶段，可能会发生变化。

Guardrails 支持基于资源的护栏和护栏推理配置文件策略。基于资源的策略允许您指定谁有权访问每个资源，以及允许他们对每个资源执行哪些操作，以此来定义访问权限。

您可以将基于资源的策略 (RBP) 附加到 Guardrails 资源（护栏或护栏推理配置文件）。[在此策略中，您可以为身份和访问管理 (IAM) 委托人指定权限，这些委托人可以对这些资源执行特定操作。](https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html#intro-structure-principal)例如，附加到护栏的策略将包含应用护栏或读取护栏配置的权限。

建议将基于资源的策略与账户级别的强制护栏一起使用，使用组织级别的强制护栏也是必需的，因为对于组织强制护栏，成员账户必须使用组织管理员账户中存在的护栏。要在其他账户中使用护栏，来电者身份必须有权在护栏上调用 `bedrock:ApplyGuardrail` API，并且护栏必须附加基于资源的策略，该策略向该呼叫者授予权限。有关更多信息，请参阅[跨账户策略评估逻辑](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic-cross-account.html)和[基于身份的策略和基于资源的策略。](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_identity-vs-resource.html)

RBPs 附在护栏详情页面上。如果护栏启用了跨区域推理 (CRIS)，则呼叫者还必须拥有与该配置文件关联的所有目标区域 guardrail-owner-account配置文件对象的`ApplyGuardrail`权限，并且 RBPs 必须依次附加到配置文件中。有关更多信息，请参阅 [将跨区域推理与 Amazon Bedrock 护栏结合使用的权限](guardrail-profiles-permissions.md)。可以从护栏仪表板上的 “系统定义的护栏配置文件” 部分访问配置文件详细信息页面，并从那里进行附加。 RBPs 

对于强制性护栏（组织级别或账户级别），所有无权呼叫该护栏的 Bedrock Invoke 或 Converse APIs 呼叫者都将开始看到他们的通话失败，但有例外。`AccessDenied`出于这个原因，强烈建议您在创建组织或账户强制的护栏配置之前，检查您是否能够从将要使用的身份、要强制使用的账户中调用护栏上的 [ApplyGuardrail](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_ApplyGuardrail.html)API。

基于资源的护栏和护栏配置文件策略所允许的策略语言目前受到限制，仅支持有限的政策声明。

## 支持的策略声明模式
<a name="supported-policy-statement-patterns"></a>

### 在自己的账户中共享护栏
<a name="share-guardrail-within-account"></a>

`account-id`必须是包含护栏的账号。

**护栏政策：**  


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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::111122223333:root"
        },
        "Action": [
            "bedrock:ApplyGuardrail",
            "bedrock:GetGuardrail"
        ],
	    "Resource": "arn:aws:bedrock:us-east-1:111122223333:guardrail/guardrail-id"
    }]
}
```

------

**护栏型材政策：**  


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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::111122223333:root"
        },
        "Action": [
            "bedrock:ApplyGuardrail"
        ],
        "Resource": "arn:aws:bedrock:us-east-1:111122223333:guardrail-profile/profile-id"
    }]
}
```

------

### 与您的组织共享护栏
<a name="share-guardrail-with-organization"></a>

`account-id`必须与您附加 RBP 的账户相匹配，并且该账户必须位于。`org-id`

**护栏政策：**  
 

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Principal": "*",
        "Action": [
            "bedrock:GetGuardrail",
            "bedrock:ApplyGuardrail"
        ],
        "Resource": "arn:aws:bedrock:us-east-1:111122223333:guardrail/guardrail-id",
        "Condition": {
            "StringEquals": { 
                "aws:PrincipalOrgID": "org-id"
            }
        }
    }]
}
```

------

**护栏型材政策：**  
 

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Principal": "*",
        "Action": [
            "bedrock:ApplyGuardrail"
        ],
        "Resource": "arn:aws:bedrock:us-east-1:111122223333:guardrail-profile/profile-id",
        "Condition": {
            "StringEquals": { 
                "aws:PrincipalOrgID": "org-id"
            }
        }
    }]
}
```

------

### 与特定人员共享护栏 OUs
<a name="share-guardrail-with-specific-ous"></a>

`account-id`必须与您附加 RBP 的账户相匹配，并且该账户必须位于。`org-id`

**护栏政策：**  
 

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Principal": "*",
        "Action": [
            "bedrock:ApplyGuardrail",
            "bedrock:GetGuardrail"
        ],
        "Resource": "arn:aws:bedrock:us-east-1:111122223333:guardrail/guardrail-id",
        "Condition": {
            "ForAnyValue:StringLike": {
                "aws:PrincipalOrgPaths": [
                    "org-id/*/org-unit-id/*"
                ]
            }
        }
    }]
}
```

------

**护栏型材政策：**  
 

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
        "Effect": "Allow",
        "Principal": "*",
        "Action": [
            "bedrock:ApplyGuardrail"
        ],
        "Resource": "arn:aws:bedrock:us-east-1:111122223333:guardrail-profile/profile-id",
        "Condition": {
            "ForAnyValue:StringLike": {
                "aws:PrincipalOrgPaths": [
                    "org-id/*/org-unit-id/*"
                ]
            }
        }
    }]
}
```

------

## 不支持的功能
<a name="unsupported-features"></a>

Guardrails 不支持在组织外部共享。

除上述或上面列出的条件外，护栏不支持 RBPs 。`PrincipalOrgId` `PrincipalOrgPaths`

Guardrails 不支持在没有组织或组织单位条件的情况下使用`*`校长。

Guardrails 仅支持中的`bedrock:ApplyGuardrail`和`bedrock:GetGuardrail`操作。 RBPs仅`ApplyGuardrail`支持护栏配置文件资源。