Skip to content

Commit

Permalink
Make S3 PutObject policy more specific
Browse files Browse the repository at this point in the history
This ensures that only the receipt rule for this application instance
gets permission to write to the bucket.
  • Loading branch information
mbland committed Apr 28, 2023
1 parent b2c2ee6 commit 38aabd2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ Resources:
Service: ses.amazonaws.com
Action:
- "s3:PutObject"
Resource: !Sub "arn:${AWS::Partition}:s3:::${BucketName}/*"
Resource: !Sub "arn:${AWS::Partition}:s3:::${BucketName}/${IncomingPrefix}/*"
Condition:
StringEquals:
"aws:referer": !Ref AWS::AccountId
ArnEquals:
"AWS:SourceArn": !Sub "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:receipt-rule-set/${ReceiptRuleSetName}:receipt-rule/${AWS::StackName}"

ReceiptRuleSetPermission:
Type: AWS::Lambda::Permission
Properties:
Action: "lambda:InvokeFunction"
FunctionName: !GetAtt Function.Arn
Principal: "ses.amazonaws.com"
SourceArn: !Sub "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:receipt-rule-set/${ReceiptRuleSetName}:receipt-rule/*"
SourceArn: !Sub "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:receipt-rule-set/${ReceiptRuleSetName}:receipt-rule/${AWS::StackName}"

ReceiptRule:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ses-receiptrule.html
Expand Down

0 comments on commit 38aabd2

Please sign in to comment.