Skip to content

Commit 8b02808

Browse files
authored
Merge pull request #541 from slashdevops/chore/template-cleanups
chore(template): drop dead IAM grants and standardize on AWS::Partition
2 parents 6420e21 + 1e7a89c commit 8b02808

2 files changed

Lines changed: 27 additions & 42 deletions

File tree

docs/Whats-New.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ This document tracks notable changes, new features, and bug fixes across release
44

55
## Unreleased
66

7+
### Template housekeeping: remove dead/misleading IAM grants and standardize on `${AWS::Partition}`
8+
9+
Cleans up the Lambda execution role, the KMS key policy, and a few hardcoded partition strings in `template.yaml`. No runtime behavior change — every removal is a permission or grant that was never reached or never matched at runtime.
10+
11+
**Lambda role (`CustomLambdaPolicy`):**
12+
13+
* **Removed `s3:ListBucket` statement** (`S3ListBucketPolicy`). The runtime code only calls `s3:GetObject` and `s3:PutObject` on the single state object ([`internal/repository/s3.go`](../internal/repository/s3.go)) — `ListBucket` / `ListObjectsV2` / `HeadObject` are never issued, so the statement and its `s3:prefix` condition were unreachable.
14+
* **Removed `kms:GenerateDataKeyPair` statement** (`KMSGetDataPolicy`). `GenerateDataKeyPair` is an asymmetric-key API; the state-bucket CMK is the default symmetric KMS key, so this action could never be called against it. The remaining symmetric action `kms:GenerateDataKey` (needed by S3 for SSE-KMS with bucket keys) is already granted by the renamed `KMSStateObjectPolicy` statement.
15+
* **Removed `secretsmanager:GetResourcePolicy` action.** The code only calls `GetSecretValue` ([`pkg/aws/secretsmanager.go`](../pkg/aws/secretsmanager.go)). `GetResourcePolicy` reads the secret's resource-policy JSON — nothing in this Lambda needs it. Renamed the surviving statement to `SecretsManagerGetSecretValuePolicy` (the old name `SSMGetParameterPolicy` was a copy-paste from a different service).
16+
17+
**KMS key policy:**
18+
19+
* **Removed `AllowAWSLambdaToRetrieveKMSKey` statement.** Its principal was `Service: lambda.amazonaws.com`, but at runtime KMS sees the Lambda's **assumed-role** ARN (not the Lambda service) when S3 forwards the `kms:Decrypt` / `kms:GenerateDataKey` calls. The statement therefore granted nothing at runtime — the real grant comes from `AllowIAMThisAccount` (the standard "delegate to IAM" pattern), combined with the role's identity-based policy. Removing the dead statement makes the grant model unambiguous.
20+
21+
**Partition portability:**
22+
23+
* Replaced four hardcoded `arn:aws:…` ARNs with `arn:${AWS::Partition}:…`:
24+
* `KMSKey` key-policy principal (`AllowIAMThisAccount`)
25+
* `Bucket` `BucketEncryption.KMSMasterKeyID`
26+
* `BucketPolicy` `AllowAWSLambdaFunction` principal
27+
* The rest of the template already used `${AWS::Partition}`; these were the last holdouts. The template is now deployable in non-commercial AWS partitions (GovCloud, China) without manual edits.
28+
729
### CI fix: cosign now signs the published container manifest by tag (closes the v0.45.0 signing failure)
830

931
Fixes the `Cosign sign published container manifest (keyless / Sigstore)` step of the release workflow, which failed with **`MANIFEST_UNKNOWN: manifest unknown`** on every release attempt after the multi-arch build was restored (see ["CI fix: restore multi-arch container builds"](#ci-fix-restore-multi-arch-container-builds-in-the-release-workflow)).

template.yaml

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,9 @@ Resources:
332332
PolicyDocument:
333333
Version: "2012-10-17"
334334
Statement:
335-
- Sid: SSMGetParameterPolicy
335+
- Sid: SecretsManagerGetSecretValuePolicy
336336
Effect: Allow
337337
Action:
338-
- secretsmanager:GetResourcePolicy
339338
- secretsmanager:GetSecretValue
340339
Resource:
341340
- !Ref AWSGWSServiceAccountFileSecret
@@ -352,27 +351,7 @@ Resources:
352351
- s3:PutObjectAcl
353352
Resource:
354353
- !Sub "arn:${AWS::Partition}:s3:::${BucketNamePrefix}-${AWS::AccountId}-${AWS::Region}/${BucketKey}"
355-
- Sid: S3ListBucketPolicy
356-
Effect: Allow
357-
Action:
358-
- s3:ListBucket
359-
Resource:
360-
- !Sub "arn:${AWS::Partition}:s3:::${BucketNamePrefix}-${AWS::AccountId}-${AWS::Region}"
361-
Condition:
362-
StringLike:
363-
s3:prefix:
364-
- !Ref BucketKey
365-
- Sid: KMSGetDataPolicy
366-
Effect: Allow
367-
Action:
368-
- kms:GenerateDataKeyPair
369-
Resource:
370-
- !GetAtt KMSKey.Arn
371-
Condition:
372-
StringEquals:
373-
kms:ViaService: !Sub "s3.${AWS::Region}.amazonaws.com"
374-
kms:EncryptionContext:aws:s3:arn: !Sub "arn:${AWS::Partition}:s3:::${BucketNamePrefix}-${AWS::AccountId}-${AWS::Region}"
375-
- Sid: KMSDecryptPolicy
354+
- Sid: KMSStateObjectPolicy
376355
Effect: Allow
377356
Action:
378357
- kms:Decrypt
@@ -420,25 +399,9 @@ Resources:
420399
- Sid: AllowIAMThisAccount
421400
Effect: Allow
422401
Principal:
423-
AWS: !Sub "arn:aws:iam::${AWS::AccountId}:root"
402+
AWS: !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:root"
424403
Action: "kms:*"
425404
Resource: "*"
426-
- Sid: AllowAWSLambdaToRetrieveKMSKey
427-
Effect: Allow
428-
Principal:
429-
Service: "lambda.amazonaws.com"
430-
#AWS: !GetAtt LambdaFunctionRole.Arn # Fails because circular reference
431-
#AWS: !Sub "arn:aws:iam::${AWS::AccountId}:role/serverless-idp-scim-sync-${AWS::AccountId}-${AWS::Region}" # Fails in runtime because the roles is not created yet
432-
Action:
433-
- kms:Encrypt
434-
- kms:Decrypt
435-
- kms:ReEncrypt*
436-
- kms:GenerateDataKey*
437-
- kms:DescribeKey
438-
Resource: "*"
439-
Condition:
440-
StringEquals:
441-
kms:CallerAccount: !Ref "AWS::AccountId"
442405

443406
KMSKeyAlias:
444407
Type: AWS::KMS::Alias
@@ -461,7 +424,7 @@ Resources:
461424
BucketEncryption:
462425
ServerSideEncryptionConfiguration:
463426
- ServerSideEncryptionByDefault:
464-
KMSMasterKeyID: !Sub "arn:aws:kms:${AWS::Region}:${AWS::AccountId}:${KMSKeyAlias}"
427+
KMSMasterKeyID: !Sub "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:${KMSKeyAlias}"
465428
SSEAlgorithm: "aws:kms"
466429
BucketKeyEnabled: true # https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-key.html
467430

@@ -475,7 +438,7 @@ Resources:
475438
- Sid: AllowAWSLambdaFunction
476439
Principal:
477440
AWS:
478-
- !Sub "arn:aws:iam::${AWS::AccountId}:role/serverless-idp-scim-sync-${AWS::AccountId}-${AWS::Region}${RoleNameSuffix}"
441+
- !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/serverless-idp-scim-sync-${AWS::AccountId}-${AWS::Region}${RoleNameSuffix}"
479442
Effect: Allow
480443
Action:
481444
- s3:GetObject

0 commit comments

Comments
 (0)