Repository navigation
feat(iam): read Bedrock from the generated tables, its routes vendored - #9169
Conversation
PR Summary by QodoAuthorize Bedrock requests using generated IAM resource tables
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
Bedrock leaves ResourceArnBuilder's own branch and the registry's three resource-policy rules: its requests are matched on their botocore routes and checked on the resources the request-resources table reads. regen_rest_routes.py vendors the bedrock, bedrock-agent and bedrock-runtime models, all signed for the bedrock scope; bedrock-agent's are needed because its PutResourcePolicy carries resourceArn in its path where bedrock's carries it in its body, a member the two clients locate apart. regen_iam_request_resources.py reads bedrock instead of leaving it to the builder, so a guardrail request is checked on the guardrail its path names and a resource-policy request on the ARN it carries. The generator's reader of an ARN pattern's type words also reads one whose account is optional, so the tag actions are checked on the guardrail or application inference profile ARN they carry, and regen_iam_tag_on_create.py reads bedrock, so a create carrying tags also needs bedrock:TagResource. BedrockStoredResourceArns gives IAM the tags Bedrock holds on a guardrail or an application inference profile, for aws:ResourceTag, read in place and matched on the whole ARN; a guardrail's untag now replaces its tag map rather than editing it, so a reader never sees half of one, and both models keep their tags volatile.
e168232 to
e428430
Compare
Summary
Bedrock is read from the generated tables now, like S3 since #9155. This removes
ResourceArnBuilder's Bedrock branch and the registry's three Bedrock resource-policy rules.Its routes and the switch have to land together:
With Bedrock still built by hand, vendoring its routes would check every route on
*, refusing a grant scoped to a guardrail.Without its routes, reading it from the table would lose the resource-policy check the builder makes.
Routes.
regen_rest_routes.pyvendors thebedrock,bedrock-agentandbedrock-runtimemodels, all signed for thebedrockscope.bedrock-agentis needed because itsPutResourcePolicycarriesresourceArnin its path, wherebedrock's carries it in its body: a member the two clients locate apart, which is read for the client whose route the request matched.Resources.
regen_iam_request_resources.pyreadsbedrockinstead of leaving it to the builder: 283 operations joiniam-request-resources.json.GET /guardrails/<id>isarn:aws:bedrock:<region>:<account>:guardrail/<id>, where the builder gave*.TagResource,UntagResourceandListTagsForResourceare checked on the guardrail or application inference profile ARN inresourceARN. Botocore's pattern for that member makes the account optional,([0-9]{12}|), and the generator's reader of a pattern's type words only found words directly after a fixed account. It returnedcustom-modelalone, which dropped the other types from thebedrockclient's row. It now reads each:word/alternative after an optional account too. Regenerating changes only these three Bedrock rows.InvokeModelandInvokeModelWithResponseStreamare checked onmarketplace/model-endpoint/all-access. No generator rule reads the kindsmodelId's documentation lists one by one, so the action's one type with no variable of its own is what the table names. The docs say so.Tags.
BedrockStoredResourceArnsgives IAM the tags Bedrock holds on a guardrail or an application inference profile, foraws:ResourceTag, read in place and matched on the whole ARN.regen_iam_tag_on_create.pyreadsbedrockinstead of listing it as not covered, so aCreateGuardrailorCreateInferenceProfilecarrying tags also needsbedrock:TagResource, withaws:RequestTagandaws:TagKeysfrom those tags.Concurrency. A guardrail's untag now replaces its tag map instead of editing it, so a reader never sees half of one. Both models keep their tag maps
volatile.Tests.
ResourceArnBuilderTest's Bedrock test goes through the table on matching routes.BedrockResourcePolicyIamEnforcementIntegrationTestadds a Deny on one guardrail refusing its three tag calls and not another's, and a guardrail created with tags refused whenbedrock:TagResourceis denied.Docs:
docs/services/bedrock.md.Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
Botocore 1.43.118:
bedrock'sPutResourcePolicyisPOST /resource-policywithresourceArnin its body.bedrock-agent's isPUT /resourcepolicy/{resourceArn}, givingresourceArn"location": "uri".GetGuardrailisGET /guardrails/{guardrailIdentifier}.TagResource'sresourceARNisTaggableResourcesArn, whose pattern is...:([0-9]{12}|)((:(fine-tuning-job|model-customization-job|custom-model)/...)|(:guardrail/[a-z0-9]+$)|...|(:(inference-profile|application-inference-profile)/[a-zA-Z0-9-:.]+$)|...).CreateGuardrailandCreateInferenceProfilecarrytags, a list ofkey/valuepairs.The Service Reference gives
bedrock:GetGuardrailtheguardrailtype,arn:${Partition}:bedrock:${Region}:${Account}:guardrail/${GuardrailId}.Checklist
./mvnw testpasses locally (ranResourceArnBuilderTest,IamRestRouteCoverageTest,IamActionRegistryTest,RequestResourceMembersTest,RequestResourcesTest,IamRestRoutesTest,IamAuthorizedActionsTestTagOnCreateTest,TagOnCreateMembersTest,TagOnCreateNamespacesIntegrationTest,RequestResourceNamespacesIntegrationTestand Bedrock's and Bedrock Runtime's 18 test classes, not the whole suite)