Knowledge Base Retrieve calls return AccessDenied despite a grant being present
Symptom. Agent tool calls that invoke Bedrock Knowledge Base Retrieve fail with
AccessDeniedException at runtime. CloudWatch Logs show that the retrieval tool returns
{"available": false} or falls back to local corpora rather than querying the Knowledge
Base. IAM policy simulation (iam:SimulatePrincipalPolicy) on the AgentCore execution role
returns allowed for the action that was granted — yet the live Retrieve still fails, or the
simulation returns implicitDeny even though the CDK stack shows a statement.
Root cause. Two distinct misconfigurations produce this symptom and are frequently confused:
-
Wrong IAM action namespace. The boto3 client ID for the Bedrock agent-runtime service is
bedrock-agent-runtime, but the IAM action namespace isbedrock:. A statement that grantsbedrock-agent-runtime:Retrieveorbedrock-agent-runtime:RetrieveAndGenerateis syntactically valid IAM but grants nothing — these action strings do not exist in the IAM service authorization tables. The correct actions arebedrock:Retrieveandbedrock:RetrieveAndGenerate. A policy containing only the wrong-namespace actions will produce animplicitDenyon simulation and anAccessDeniedExceptionat runtime. -
Missing cross-account Knowledge Base ID in the agent configuration. If the agent’s
Configobject is populated from environment variables but the field for the Knowledge Base identifier is not declared in the dataclass and not wired through the deployment pipeline,getattr(config, "adp_kb_id", "")resolves to the empty string. Retrieve calls issued against an empty KB ID silently fall back to local corpora rather than raising an exception, making the misconfiguration invisible until grounding quality is inspected.
Resolution.
-
Audit every IAM policy statement on the AgentCore execution role that references Bedrock Knowledge Base actions. Replace any
bedrock-agent-runtime:Retrieveorbedrock-agent-runtime:RetrieveAndGenerateaction strings withbedrock:Retrieveandbedrock:RetrieveAndGenerate. Redeploy the role policy and confirm withiam:SimulatePrincipalPolicythat the result changes fromimplicitDenytoallowed. -
Verify that the Knowledge Base ID field is declared in the agent configuration dataclass, populated in
from_env()from the correct environment variable, and that the deployment pipeline threads the environment variable through to the AgentCore runtime container. Add a pre-flight assertion in the deployment Makefile that fails the deploy if the Knowledge Base ID variable is empty — silent fallback to local corpora is not acceptable in a production-grounded deployment. -
For cross-account Knowledge Base deployments, confirm that the Knowledge Base resource policy in the ADP account grants
bedrock:Retrieveto the AVX AgentCore execution role principal, and that the AVX role’s identity policy grantsbedrock:Retrieveon the cross-account Knowledge Base ARN. Both sides of the cross-account trust must be present; either side alone is insufficient. -
Add a smoke test that runs
iam:SimulatePrincipalPolicyagainst the deployed role forbedrock:Retrieveon the Knowledge Base ARN, and separately issues a liveRetrievecall with a known query, asserting that the result set contains at least one chunk with a source URI matching the expected S3 prefix.