

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# モデル推論リクエストで特定のガードレールの使用を強制する
<a name="guardrails-permissions-id"></a>

IAM ポリシーに `bedrock:GuardrailIdentifier` 条件キーを含めると、モデル推論に特定のガードレールの使用を強制できます。これにより、IAM ポリシーで設定されたガードレールを含まない推論 API リクエストを拒否できます。

この強制は、次の推論 API に適用できます。
+ [Converse](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html)
+ [ConverseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html)
+ [InvokeModel](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html)
+ [InvokeModelWithResponseStream](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModelWithResponseStream.html)

`bedrock:GuardrailIdentifier` 条件キーを使用するいくつかの方法は、以下の例のとおりです。

**例 1: 特定のガードレールとその数値バージョンの使用を強制する**  
モデル推論中に特定のガードレール (`{{guardrail-id}}`) とその数値バージョン 1 の使用を強制するには、次のポリシーを使用します。  
明示的な拒否により、ユーザーが他のアクセス許可を持っていたとしても、いかなる `GuardrailIdentifier` およびガードレールバージョンでも、ユーザーリクエストによるリストされたアクションの呼び出しを禁止します。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "InvokeFoundationModelStatement1",
            "Effect": "Allow",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "StringEquals": {
                    "bedrock:GuardrailIdentifier": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}:{{1}}"
                }
            }
        },
        {
            "Sid": "InvokeFoundationModelStatement2",
            "Effect": "Deny",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "StringNotEquals": {
                    "bedrock:GuardrailIdentifier": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}:{{1}}"
                }
            }
        },
        {
            "Sid": "ApplyGuardrail",
            "Effect": "Allow",
            "Action": [
                "bedrock:ApplyGuardrail"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}"
            ]
        }
    ]
}
```

**例 2: 特定のガードレールとそのドラフトバージョンの使用を強制する**  
モデル推論中に特定のガードレール (`{{guardrail-id}}`) とそのドラフトバージョンの使用を強制するには、次のポリシーを使用します。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "InvokeFoundationModelStatement1",
            "Effect": "Allow",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "StringEquals": {
                    "bedrock:GuardrailIdentifier": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}"
                }
            }
        },
        {
            "Sid": "InvokeFoundationModelStatement2",
            "Effect": "Deny",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "StringNotEquals": {
                    "bedrock:GuardrailIdentifier": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}"
                }
            }
        },
        {
            "Sid": "ApplyGuardrail",
            "Effect": "Allow",
            "Action": [
                "bedrock:ApplyGuardrail"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}"
            ]
        }
    ]
}
```

**例 3: 特定のガードレールとその任意の数値バージョンの使用を強制する**  
モデル推論中に特定のガードレール (`{{guardrail-id}}`) とその任意の数値バージョンの使用を強制するには、次のポリシーを使用します。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "InvokeFoundationModelStatement1",
            "Effect": "Allow",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "ArnLike": {
                    "bedrock:GuardrailIdentifier": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}:*"
                }
            }
        },
        {
            "Sid": "InvokeFoundationModelStatement2",
            "Effect": "Deny",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "ArnNotLike": {
                    "bedrock:GuardrailIdentifier": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}:*"
                }
            }
        },
        {
            "Sid": "ApplyGuardrail",
            "Effect": "Allow",
            "Action": [
                "bedrock:ApplyGuardrail"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}"
            ]
        }
    ]
}
```

**例 4: 特定のガードレールとその任意のバージョンの使用を強制する**  
モデル推論中に特定のガードレール (`{{guardrail-id}}`) とその任意の数値バージョン (ドラフトバージョンも含む) の使用を強制するには、次のポリシーを使用します。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "InvokeFoundationModelStatement1",
            "Effect": "Allow",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "ArnLike": {
                    "bedrock:GuardrailIdentifier": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}*"
                }
            }
        },
        {
            "Sid": "InvokeFoundationModelStatement2",
            "Effect": "Deny",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "ArnNotLike": {
                    "bedrock:GuardrailIdentifier": "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}*"
                }
            }
        },
        {
            "Sid": "ApplyGuardrail",
            "Effect": "Allow",
            "Action": [
                "bedrock:ApplyGuardrail"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-id}}"
            ]
        }
    ]
}
```

**例 5: 特定のガードレールとそのバージョンのペアの使用を強制する**  
次のポリシーを使用して、ガードレールのセットとその対応するバージョンのモデル推論のみを許可します。    
****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "InvokeFoundationModelStatement1",
            "Effect": "Allow",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "StringEquals": {
                    "bedrock:GuardrailIdentifier": [
                        "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-1-id}}:{{1}}",
                        "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-2-id}}:{{2}}",
                        "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-3-id}}"
                    ]
                }
            }
        },
        {
            "Sid": "InvokeFoundationModelStatement2",
            "Effect": "Deny",
            "Action": [
                "bedrock:InvokeModel",
                "bedrock:InvokeModelWithResponseStream"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}::foundation-model/*"
            ],
            "Condition": {
                "StringNotEquals": {
                    "bedrock:GuardrailIdentifier": [
                        "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-1-id}}:{{1}}",
                        "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-2-id}}:{{2}}",
                        "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-3-id}}"
                    ]
                }
            }
        },
        {
            "Sid": "ApplyGuardrail",
            "Effect": "Allow",
            "Action": [
                "bedrock:ApplyGuardrail"
            ],
            "Resource": [
                "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-1-id}}",
                "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-2-id}}",
                "arn:aws:bedrock:{{us-east-1}}:{{123456789012}}:guardrail/{{guardrail-3-id}}"
            ]
        }
    ]
}
```

**制限事項**  
ユーザーが `bedrock:GuardrailIdentifier` 条件キーを使用して設定された特定のガードレールを持つ IAM ロールを引き受ける場合:  
+ ユーザーに代わって、`InvokeModel` コールを行う、`RetrieveAndGenerate` や `InvokeAgent` などの Bedrock API を呼び出す際に、追加のアクセス許可を持つ同じロールを使用すべきではありません。`RetrieveAndGenerate` や `InvokeAgent` は、複数の `InvokeModel` コールを行いますが、これらのコールの一部にはガードレールが含まれないため、アクセス拒否エラーにつながる可能性があります。
+ ユーザーは、[ガードレール入力タグ](guardrails-tagging.md)を使用して、プロンプトへのガードレールの適用をバイパスできます。ただし、ガードレールは常にレスポンスには適用されます。
+ Amazon Bedrock ガードレールは現時点では、クロスアカウントアクセス用のリソースベースのポリシーはサポートしていないため、ガードレールはリクエストを行う IAM ロールと同じ AWS アカウント に配置する必要があります。