Skip to content

Commit a328411

Browse files
authored
fix: grant S3 permissions to Role instead of ManagedPolicy (#396)
The grant_read_write() method was incorrectly called with a ManagedPolicy instead of a Role. ManagedPolicy does not implement IGrantable and cannot be used as a Principal in IAM policies. This latent bug was exposed when CDK 2.174.0 added validation that rejects ManagedPolicy as a principal. The fix moves the grant call to after the Role is created and targets the model_execution_role instead of model_execution_policy, aligning with the pattern used elsewhere in this file and other sagemaker modules. Fixes: Cannot use a ManagedPolicy as the 'Principal' in an IAM Policy
1 parent 1e3af0d commit a328411

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### **Changed**
1313

14+
- fixed `sagemaker-templates` Model Deploy seed code incorrectly granting S3 permissions to a ManagedPolicy instead of a Role, which caused deployment failures with CDK 2.174.0+
1415
- update qs to 6.14.1 via npm override to address security vulnerability
1516
- pin @cdklabs/generative-ai-cdk-constructs to 0.1.311 to fix build compatibility
1617
- update starlette to 0.50.0 and fastapi to 0.128.0 to address security vulnerabilities

modules/sagemaker/sagemaker-templates/templates/model_deploy/seed_code/deploy_app/deploy_app/deploy_endpoint_stack.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def __init__(
134134
)
135135

136136
model_bucket = s3.Bucket.from_bucket_arn(self, "ModelBucket", MODEL_BUCKET_ARN)
137-
model_bucket.grant_read_write(model_execution_policy)
138137

139138
if ECR_REPO_ARN:
140139
model_execution_policy.add_statements(
@@ -152,6 +151,9 @@ def __init__(
152151
managed_policies=[model_execution_policy],
153152
)
154153

154+
# Grant S3 read/write permissions to the role (not the ManagedPolicy)
155+
model_bucket.grant_read_write(model_execution_role)
156+
155157
# setup timestamp to be used to trigger the custom resource update event to retrieve
156158
# latest approved model and to be used with model and endpoint config resources' names
157159
now = datetime.now().replace(tzinfo=timezone.utc)

0 commit comments

Comments
 (0)