Register a third-party guardrail provider
To use a third-party provider, store your provider API key in AgentCore Identity, give the gateway’s execution role permission to read it, and register the provider on your policy engine.
Topics
Prerequisites
-
An account with the provider, and an API key for the provider’s guardrail API. To get a key, follow the provider’s documentation. For links, see Supported providers.
-
A policy engine attached to a gateway. For more information, see Create a policy engine.
Step 1: Store the provider API key
Store the key as an API key credential provider in AgentCore Identity. For console steps, see Add API key.
Example
Keep the credentialProviderArn from the response. You use it when you register the provider.
Store the credential that your provider uses to authenticate its guardrail API. For which credential to use, see the provider’s documentation.
If you store the key in your own AWS Secrets Manager secret instead (Provide API key via Secrets Manager in
the console), tag the secret with BedrockAgentCoreThirdPartyGuardrailsSecret = true, so that the permissions in Step 2
let the gateway read it.
Step 2: Let the gateway read the key
Policy in AgentCore reads the API key with credentials derived from the gateway’s execution role, the same way it calls Amazon Bedrock Guardrails. Use the following permission policy for the gateway’s execution role. It includes the permissions to evaluate policies and Amazon Bedrock Guardrails checks, and the permissions for third-party providers.
Replace these placeholders:
-
us-east-1with the AWS Region -
123456789012with the AWS account ID -
<gateway-name>with the gateway name -
<policy-engine-id>with the policy engine ID
{ "Version": "2012-10-17", "Statement": [ { "Sid": "EvaluatePoliciesForGateway", "Effect": "Allow", "Action": [ "bedrock-agentcore:AuthorizeAction", "bedrock-agentcore:PartiallyAuthorizeActions" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:123456789012:gateway/<gateway-name>-*", "arn:aws:bedrock-agentcore:us-east-1:123456789012:policy-engine/<policy-engine-id>" ] }, { "Sid": "GetPolicyEngineForValidation", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetPolicyEngine" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:123456789012:policy-engine/<policy-engine-id>" ] }, { "Sid": "EvaluatePoliciesGuardrailsForGateway", "Effect": "Allow", "Action": [ "bedrock:InvokeGuardrailChecks" ], "Resource": "*" }, { "Sid": "GetWorkloadAccessTokenForThirdPartyGuardrails", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetWorkloadAccessToken" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default/workload-identity/*" ] }, { "Sid": "GetResourceApiKeyForThirdPartyGuardrails", "Effect": "Allow", "Action": [ "bedrock-agentcore:GetResourceApiKey" ], "Resource": [ "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default", "arn:aws:bedrock-agentcore:us-east-1:123456789012:token-vault/default/apikeycredentialprovider/*", "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default", "arn:aws:bedrock-agentcore:us-east-1:123456789012:workload-identity-directory/default/workload-identity/*" ] }, { "Sid": "GetManagedThirdPartyGuardrailApiKeySecrets", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue" ], "Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:bedrock-agentcore-identity!default/apikey/*" }, { "Sid": "GetTaggedExternalThirdPartyGuardrailApiKeySecrets", "Effect": "Allow", "Action": [ "secretsmanager:GetSecretValue" ], "Resource": "arn:aws:secretsmanager:us-east-1:123456789012:secret:*", "Condition": { "StringEquals": { "secretsmanager:ResourceTag/BedrockAgentCoreThirdPartyGuardrailsSecret": "true" } } } ] }
The statements do the following:
-
EvaluatePoliciesForGatewayandGetPolicyEngineForValidationlet the gateway evaluate the policies of its policy engine. -
EvaluatePoliciesGuardrailsForGatewaylets Policy in AgentCore call Amazon Bedrock Guardrails checks. -
GetWorkloadAccessTokenForThirdPartyGuardrailsandGetResourceApiKeyForThirdPartyGuardrailslet Policy in AgentCore get the provider API key from AgentCore Identity. -
GetManagedThirdPartyGuardrailApiKeySecretslets it read API keys that AgentCore Identity stores for you. -
GetTaggedExternalThirdPartyGuardrailApiKeySecretslets it read API keys that you store in your own Secrets Manager secrets. It applies only to secrets taggedBedrockAgentCoreThirdPartyGuardrailsSecret=true. If you don’t use your own secrets, you can omit this statement.
For the trust policy and the other permissions of the execution role, see AgentCore Gateway and Policy in AgentCore IAM Permissions. If the role can’t read the key, every request that reaches a third-party check is denied.
If the secret uses a customer managed key
If the Secrets Manager secret that holds the API key is encrypted with a customer managed AWS KMS key, the gateway’s execution role also needs permission to decrypt with that key, through Secrets Manager.
Add the following statement to the gateway’s execution role:
{ "Sid": "DecryptThirdPartyGuardrailApiKeySecrets", "Effect": "Allow", "Action": "kms:Decrypt", "Resource": "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab", "Condition": { "StringEquals": { "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com" } } }
The key policy must also allow the gateway’s execution role to use the key. Add a statement like the following to the key policy:
{ "Sid": "AllowGatewayExecutionRoleDecryptViaSecretsManager", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:role/my-gateway-execution-role" }, "Action": "kms:Decrypt", "Resource": "*", "Condition": { "StringEquals": { "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com" } } }
This applies to your own secrets that use a customer managed key. To use a customer managed key on the AgentCore Identity token vault, see Set customer managed key policy.
Step 3: Register the provider on the policy engine
To register a provider, add it to the engine’s policyInformationProviderConfiguration map. The key is the
provider ID. For each provider’s ID, see Supported providers. The value names
the credential provider and, optionally, your provider URL.
-
credentialProvider -
The ARN of the API key credential provider from Step 1, as
{"apiKey": {"arn": "…"}}. -
url -
Your provider URL. If you omit it, the provider’s default URL is used. Set it if your provider account uses a different Region or deployment. For the URL to use, see the provider’s documentation. The URL must use
https, its host must be one of the provider’s allowed hosts, and it must not include a port. For each provider’s rule, see Third-party guardrail reference.
You can register providers on an existing engine, or when you create the engine. The two operations use different shapes for each entry:
-
CreatePolicyEnginetakescredentialProviderandurldirectly in the entry.urlis a string. -
UpdatePolicyEnginewraps the fields inproviderConfiguration, andurlis an object,{"optionalValue": "<URL>"}. The wrapper lets an update change only the fields that you name.
Example
An update changes only the providers and fields that you name. To register another provider, call
UpdatePolicyEngine with that provider’s ID and a credentialProvider. To change the URL back to the provider’s
default URL, send "url": {}.
Remove a provider
To remove a provider from an engine, call UpdatePolicyEngine with an empty object for the provider ID:
aws bedrock-agentcore-control update-policy-engine \ --policy-engine-id my_policy_engine-a1b2c3d4e5 \ --policy-information-provider-configuration '{"<ProviderId>": {}}'
You can’t remove a provider while a policy of the engine calls its checks. Delete or update those policies first.
Otherwise the request fails with a ConflictException. You can’t remove BedrockGuardrails.
Verifying the API key
When you register a provider, AgentCore verifies your API key by sending a short test request to the provider. If
the provider rejects the key, can’t be reached, or the URL isn’t found, the registration fails. The engine status
becomes CREATE_FAILED or UPDATE_FAILED, and statusReasons names the provider and the reason, for example:
<ProviderId>: Invalid credentials for provider <ProviderId> (HTTP 401)
Fix the API key or URL and register the provider again.
Step 4: Check the configuration
In the console, the Guardrail providers section of the policy engine lists each registered provider with its
endpoint and authentication type. With the API, GetPolicyEngine returns each registered provider with its credential provider, URL, settings, and the checks
it offers. BedrockGuardrails always appears in the list. It’s built in and managed by the service.
aws bedrock-agentcore-control get-policy-engine \ --policy-engine-id my_policy_engine-a1b2c3d4e5 \ --query 'policyInformationProviderConfiguration'
Configuration rules
-
The URL must be an absolute
httpsURL without a port, credentials, or whitespace, and its host must be one of the provider’s allowed hosts. Other URLs are rejected with aValidationException, for exampleURL host is not an endpoint of this providerorURL must not set a port. -
settings.windowSizeis set by the service for each provider. It appears inGetPolicyEngineoutput, but you can’t set it. A request that includes it is rejected. The gateway uses the window size when it screens a streamed response. For more information, see When you receive the text. -
You can’t configure
BedrockGuardrailsinpolicyInformationProviderConfiguration. A request that includes it is rejected withThe BedrockGuardrails configuration is managed by the service and cannot be modified.
Next, write policies that call the provider. See Write policies with third-party checks.