Skip to content

Commit 5168650

Browse files
feat: Added OrgId and SourceAccounts to SNS topic policy
1 parent 246ebde commit 5168650

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

apps/stack/template.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Metadata:
3131
- ConfigDeliveryBucketName
3232
- IncludeResourceTypes
3333
- ExcludeResourceTypes
34+
- OrgId
35+
- SourceAccounts
3436
- Label:
3537
default: CloudWatch Logs
3638
Parameters:
@@ -215,6 +217,23 @@ Parameters:
215217
OpenTelemetry endpoint to send additional telemetry to.
216218
Default: ''
217219
AllowedPattern: "^(http(s)?:\/\/.*)?$"
220+
OrgId:
221+
Type: String
222+
Description: >-
223+
Optional AWS Organizations ID. If set, adds an AllowAWSConfigFromOrg
224+
statement on the SNS topic that allows publishes by aws:PrincipalOrgID.
225+
Useful for AWS Control Tower integrations.
226+
Default: ''
227+
AllowedPattern: '^(o-[a-z0-9]{10,32})?$'
228+
SourceAccounts:
229+
Type: CommaDelimitedList
230+
Description: >-
231+
List of AWS account IDs allowed to publish to the SNS topic via
232+
AWS Config. Useful for sub-accounts in AWS Organizations and
233+
Control Tower integrations. The current account ID is automatically
234+
included when this list is non-empty.
235+
Default: ''
236+
AllowedPattern: '^\d*$'
218237

219238
Conditions:
220239
EmptyConfigDeliveryBucketName: !Equals
@@ -269,6 +288,16 @@ Conditions:
269288
- !Equals
270289
- !Ref ObserveAwsAccountId
271290
- ""
291+
HasOrgId: !Not
292+
- !Equals
293+
- !Ref OrgId
294+
- ""
295+
HasSourceAccounts: !Not
296+
- !Equals
297+
- !Join
298+
- ','
299+
- !Ref SourceAccounts
300+
- ''
272301
Resources:
273302
Topic:
274303
Type: "AWS::SNS::Topic"
@@ -307,6 +336,40 @@ Resources:
307336
- "sns:Publish"
308337
Resource:
309338
- !Ref Topic
339+
- !If
340+
- HasOrgId
341+
- Sid: "AllowAWSConfigFromOrg"
342+
Effect: "Allow"
343+
Principal:
344+
Service:
345+
- "config.amazonaws.com"
346+
Action:
347+
- "SNS:Publish"
348+
Resource:
349+
- !Ref Topic
350+
Condition:
351+
StringEquals:
352+
"aws:PrincipalOrgID": !Ref OrgId
353+
- !Ref AWS::NoValue
354+
- !If
355+
- HasSourceAccounts
356+
- Sid: "AllowAWSConfigFromSourceAccounts"
357+
Effect: "Allow"
358+
Principal:
359+
Service:
360+
- "config.amazonaws.com"
361+
Action:
362+
- "SNS:Publish"
363+
Resource:
364+
- !Ref Topic
365+
Condition:
366+
StringEquals:
367+
"AWS:SourceAccount": !Split
368+
- ','
369+
- !Sub
370+
- '${Accounts},${AWS::AccountId}'
371+
- Accounts: !Join [',', !Ref SourceAccounts]
372+
- !Ref AWS::NoValue
310373
Topics:
311374
- !Ref Topic
312375
Bucket:

docs/stack.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ The Observe stack provisions the following components:
3232
| `ConfigDeliveryBucketName` | String | If AWS Config is already enabled in this account and region, provide the S3 bucket snapshots are written to. |
3333
| `IncludeResourceTypes` | CommaDelimitedList | If AWS Config is not enabled in this account and region, provide a list of resource types to collect. Use a wildcard to collect all supported resource types. |
3434
| `ExcludeResourceTypes` | CommaDelimitedList | Exclude a subset of resource types from configuration collection. This parameter can only be set if IncludeResourceTypes is wildcarded. |
35+
| `OrgId` | String | Optional AWS Organizations ID. If set, adds an AllowAWSConfigFromOrg statement on the SNS topic that allows publishes by aws:PrincipalOrgID. Useful for AWS Control Tower integrations. |
36+
| `SourceAccounts` | CommaDelimitedList | List of AWS account IDs allowed to publish to the SNS topic via AWS Config. Useful for sub-accounts in AWS Organizations and Control Tower integrations. The current account ID is automatically included when this list is non-empty. |
3537
| `LogGroupNamePatterns` | CommaDelimitedList | Comma separated list of patterns. If not empty, the lambda function will only apply to log groups that have names that match one of the provided strings based on a case-sensitive substring search. |
3638
| `LogGroupNamePrefixes` | CommaDelimitedList | Comma separated list of prefixes. If not empty, the lambda function will only apply to log groups that start with a provided string. |
3739
| `ExcludeLogGroupNamePatterns` | CommaDelimitedList | Comma separated list of patterns. This paramter is used to filter out log groups from subscription, and supports the use of regular expressions. |

0 commit comments

Comments
 (0)