@@ -96,22 +96,26 @@ Parameters:
9696Conditions :
9797 CreateSNSTopic : !Equals [ !Ref CreateTopic, "true" ]
9898 HasKMSKey : !Not [ !Equals [ !Ref KMSKeyARN, "" ] ]
99- # Matches Terraform's: is_cross_account = var.bucket_account_id != null && var.bucket_account_id != data.aws_caller_identity.current.account_id
100- IsCrossAccount : !And [
99+ BucketCrossAccount : !And [
101100 !Not [ !Equals [ !Ref BucketAccountId, "" ] ],
102101 !Not [ !Equals [ !Ref BucketAccountId, !Ref "AWS::AccountId" ] ]
103102 ]
104- NotIsCrossAccount : !Not [IsCrossAccount]
105- HasKMSAndNotCrossAccount : !And [HasKMSKey, NotIsCrossAccount]
106- HasKMSAndIsCrossAccount : !And [HasKMSKey, IsCrossAccount]
103+ BucketInTargetAccount : !Not [BucketCrossAccount]
104+ # Extract KMS account ID from KMS key ARN
105+ KMSAccountId : !Select [4, !Split [":", !Ref KMSKeyARN]]
106+ # Check if KMS key is in a different account from bucket
107+ NeedKMSPolicy : !And [
108+ HasKMSKey,
109+ !Equals [ !Ref KMSAccountId, !Ref BucketAccountId ]
110+ ]
107111 IsTopicAccount : !Equals [ !Select [4, !Split [":", !Ref TopicARN]], !Ref "AWS::AccountId" ]
108112 IsBucketAccount : !Equals [ !Ref BucketAccountId, !Ref "AWS::AccountId" ]
109113
110114Resources :
111115 # Role and resources for same-account deployments
112116 CloudLogsRole :
113117 Type : " AWS::IAM::Role"
114- Condition : NotIsCrossAccount
118+ Condition : BucketInTargetAccount
115119 Properties :
116120 RoleName : !Sub sysdig-secure-cloudlogs-${NameSuffix}
117121 AssumeRolePolicyDocument :
@@ -186,7 +190,7 @@ Resources:
186190 # StackSet for cross-account bucket access
187191 BucketAccessStackSet :
188192 Type : AWS::CloudFormation::StackSet
189- Condition : IsCrossAccount
193+ Condition : BucketCrossAccount
190194 Properties :
191195 StackSetName : !Sub sysdig-secure-cloudlogs-bucket-access-${NameSuffix}
192196 Description : IAM Role for S3 bucket and KMS access for Sysdig Cloud Logs integration
@@ -346,20 +350,20 @@ Outputs:
346350 Value : !If [ CreateSNSTopic, !Ref CloudTrailNotificationsTopic, !Ref TopicARN ]
347351 RoleARN :
348352 Description : " The ARN of the IAM Role created for CloudTrail logs access."
349- Condition : NotIsCrossAccount
353+ Condition : BucketInTargetAccount
350354 Value : !GetAtt CloudLogsRole.Arn
351355 CrossAccountRoleARN :
352356 Description : " ARN of the Cross-Account IAM Role for accessing the S3 bucket."
353- Condition : IsCrossAccount
357+ Condition : BucketCrossAccount
354358 Value : !Sub "arn:${Partition}:iam::${BucketAccountId}:role/sysdig-secure-cloudlogs-${AWS::AccountId}-${NameSuffix}"
355- KMSPolicyInstructionsSameAccount :
359+ KMSPolicyInstructions :
356360 Description : " Instructions for updating KMS key policy when KMS encryption is enabled"
357- Condition : HasKMSAndNotCrossAccount
361+ Condition : NeedKMSPolicy
358362 Value : !Sub |
359363 IMPORTANT: MANUAL ACTION REQUIRED
360364
361365 Please add the following statement to your KMS key policy to allow Sysdig to decrypt logs.
362- This is necessary when KMS encryption is enabled for your S3 bucket.
366+ This is necessary when KMS encryption is enabled for your S3 bucket and the KMS key is in a different account .
363367 Without this policy addition, Sysdig may not be able to read your encrypted logs.
364368
365369 {
@@ -371,22 +375,3 @@ Outputs:
371375 "Action": "kms:Decrypt",
372376 "Resource": "*"
373377 }
374- KMSPolicyInstructionsCrossAccount :
375- Description : " Instructions for updating KMS key policy when KMS encryption is enabled (Cross-Account)"
376- Condition : HasKMSAndIsCrossAccount
377- Value : !Sub |
378- IMPORTANT: MANUAL ACTION REQUIRED
379-
380- Please add the following statement to your KMS key policy to allow Sysdig to decrypt logs.
381- This is necessary when KMS encryption is enabled for your S3 bucket.
382- Without this policy addition, Sysdig may not be able to read your encrypted logs.
383-
384- {
385- "Sid": "Sysdig-Decrypt",
386- "Effect": "Allow",
387- "Principal": {
388- "AWS": "arn:${Partition}:iam::${BucketAccountId}:role/sysdig-secure-cloudlogs-${AWS::AccountId}-${NameSuffix}"
389- },
390- "Action": "kms:Decrypt",
391- "Resource": "*"
392- }
0 commit comments