Skip to content

Add support per-account exclusions for Config Recorder via environmen… #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ct_configrecorder_override_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,17 @@ def assume_role(account_id, role='AWSControlTowerExecution'):


CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING = os.getenv('CONFIG_RECORDER_OVERRIDE_EXCLUDED_RESOURCE_LIST')
CONFIG_RECORDER_EXCLUSION_RESOURCE_LIST = CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING.split(
',') if CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING != '' else []
CONFIG_RECORDER_EXCLUSION_RESOURCE_LIST = CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING.split(',') if CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING else []

SPECIAL_EXCLUDED_ACCOUNTS_STRING = os.getenv('CONFIG_RECORDER_SPECIAL_EXCLUDED_ACCOUNTS', '')
SPECIAL_EXCLUDED_ACCOUNTS = [x.strip() for x in SPECIAL_EXCLUDED_ACCOUNTS_STRING.split(',') if x.strip()]

SPECIAL_EXCLUSION_RESOURCE_STRING = os.getenv('CONFIG_RECORDER_OVERRIDE_SPECIAL_EXCLUDED_RESOURCE_LIST', '')
SPECIAL_EXCLUSION_RESOURCE_LIST = SPECIAL_EXCLUSION_RESOURCE_STRING.split(',') if SPECIAL_EXCLUSION_RESOURCE_STRING else []

if account_id in SPECIAL_EXCLUDED_ACCOUNTS:
CONFIG_RECORDER_EXCLUSION_RESOURCE_LIST = SPECIAL_EXCLUSION_RESOURCE_LIST

CONFIG_RECORDER_DEFAULT_RECORDING_FREQUENCY = os.getenv('CONFIG_RECORDER_DEFAULT_RECORDING_FREQUENCY')

#remove any resource type from daily list that are in exclision list
Expand Down
12 changes: 12 additions & 0 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ Parameters:
- CONTINUOUS
- DAILY

ConfigRecorderSpecialExcludedAccounts:
Description: Comma-separated list of accounts to apply special exclusions
Default: "111111111111,222222222222,333333333333,444444444444,555555555555"
Type: String

ConfigRecorderOverrideSpecialExcludedResourceList:
Description: Comma-separated list of resource types to exclude for the special accounts
Default: "AWS::EC2::Volume,AWS::EC2::NetworkInterface"
Type: String

CloudFormationVersion:
Type: String
Default: 1
Expand Down Expand Up @@ -118,6 +128,8 @@ Resources:
CONFIG_RECORDER_OVERRIDE_EXCLUDED_RESOURCE_LIST: !Ref ConfigRecorderExcludedResourceTypes
CONFIG_RECORDER_DEFAULT_RECORDING_FREQUENCY: !Ref ConfigRecorderDefaultRecordingFrequency
CONTROL_TOWER_HOME_REGION: !Ref 'AWS::Region'
CONFIG_RECORDER_SPECIAL_EXCLUDED_ACCOUNTS: !Ref ConfigRecorderSpecialExcludedAccounts
CONFIG_RECORDER_OVERRIDE_SPECIAL_EXCLUDED_RESOURCE_LIST: !Ref ConfigRecorderOverrideSpecialExcludedResourceList

ConsumerLambdaEventSourceMapping:
Type: AWS::Lambda::EventSourceMapping
Expand Down