Skip to content
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

Add support for AWS config resources - terminator and hacking policy #133

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions aws/policy/security-services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Statement:
- Sid: AllowGlobalUnrestrictedResourceActionsWhichIncurNoFees
Effect: Allow
Action:
- config:DeleteConfigRule
- config:DeleteConfigurationRecorder
- config:DeleteDeliveryChannel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- config:DeleteDeliveryChannel
- config:DeleteDeliveryChannel
- config:DescribeAggregationAuthorizations
- config:DescribeConfigurationAggregators

- config:DescribeConfigRules
- config:DescribeConfigurationRecorders
- config:DescribeDeliveryChannels
- iam:GetRole
- iam:ListAttachedRolePolicies
- iam:ListRoles
Expand Down
108 changes: 108 additions & 0 deletions aws/terminator/security_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,114 @@ def terminate(self):
self.client.delete_saml_provider(SAMLProviderArn=self.id)


class ConfigRecorder(DbTerminator):
@staticmethod
def create(credentials):
return Terminator._create(
credentials, ConfigRecorder, 'config',
lambda client: client.describe_configuration_recorders()['ConfigurationRecorders']
)

@property
def id(self):
return self.instance['name']

@property
def name(self):
return self.instance['name']

def terminate(self):
self.client.delete_configuration_recorder(ConfigurationRecorderName=self.name)


class ConfigAggregator(DbTerminator):
@staticmethod
def create(credentials):
return Terminator._create(
credentials, ConfigAggregator, 'config',
lambda client: client.describe_configuration_aggregators()['ConfigurationAggregators']
)

@property
def id(self):
return self.instance['ConfigurationAggregatorArn']

@property
def name(self):
return self.instance['ConfigurationAggregatorName']

def terminate(self):
self.client.delete_configuration_aggregator(ConfigurationAggregatorName=self.name)


class ConfigAggregationAuthorization(DbTerminator):
@staticmethod
def create(credentials):
return Terminator._create(
credentials, ConfigAggregationAuthorization, 'config',
lambda client: client.describe_aggregation_authorizations()['AggregationAuthorizations']
)

@property
def region(self):
return self.instance['AuthorizedAwsRegion']

@property
def account(self):
return self.instance['AuthorizedAccountId']

@property
def id(self):
return self.instance['AggregationAuthorizationArn']

@property
def name(self):
return self.instance['AuthorizedAccountId'] + ":" + self.instance['AuthorizedAwsRegion']

def terminate(self):
self.client.delete_aggregation_authorization(AuthorizedAccountId=self.account, AuthorizedAwsRegion=self.region)


class ConfigDeliveryChannel(DbTerminator):
@staticmethod
def create(credentials):
return Terminator._create(
credentials, ConfigDeliveryChannel, 'config',
lambda client: client.describe_delivery_channels()['DeliveryChannels']
)

@property
def id(self):
return self.instance['name']

@property
def name(self):
return self.instance['name']

def terminate(self):
self.client.delete_delivery_channel(DeliveryChannelName=self.name)


class ConfigRule(DbTerminator):
@staticmethod
def create(credentials):
return Terminator._create(
credentials, ConfigRule, 'config',
lambda client: client.describe_config_rules()['ConfigRules']
)

@property
def id(self):
return self.instance['ConfigRuleId']

@property
def name(self):
return self.instance['ConfigRuleName']

def terminate(self):
self.client.delete_config_rule(ConfigRuleName=self.name)


class KMSKey(Terminator):
@staticmethod
def create(credentials):
Expand Down
18 changes: 18 additions & 0 deletions hacking/aws_config/test_policies/security-services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
Version: '2012-10-17'
Statement:

- Sid: AllowManagedPolicyAttachments
Effect: Allow
Action:
- iam:AttachRolePolicy
- iam:DetachRolePolicy
Resource:
- 'arn:aws:iam::{{ aws_account_id }}:role/ansible-test-*'
Condition:
ArnLike:
iam:PolicyArn:
- 'arn:aws:iam::aws:policy/service-role/AWSConfigRole'

- Sid: AllowGlobalUnrestrictedResourceActionsWhichIncurNoFees
Effect: Allow
Action:
Expand All @@ -21,6 +34,9 @@ Statement:
- Sid: AllowGlobalUnrestrictedResourceActionsWhichIncurFees
Effect: Allow
Action:
# Config has limited support for resource level restrictions
- config:PutConfigurationRecorder
- config:PutDeliveryChannel
# Legacied because the current (minimal) tests don't use
# { resource_prefix } yet
- iam:DeleteServerCertificate
Expand Down Expand Up @@ -77,13 +93,15 @@ Statement:
- Sid: AllowGlobalRestrictedResourceActionsWhichIncurFees
Effect: Allow
Action:
- config:PutConfigRule
- logs:CreateLogGroup
- logs:PutRetentionPolicy
- logs:DeleteLogGroup
# Legacied
- cloudtrail:*
- secretsmanager:*
Resource:
- 'arn:aws:config:{{ aws_region }}:{{ aws_account_id }}:config-rule/*'
- 'arn:aws:cloudtrail:{{ aws_region }}:{{ aws_account_id }}:trail/ansible-test-*'
- 'arn:aws:logs:{{ aws_region }}:{{ aws_account_id }}:log-group:ansible-test*'
- 'arn:aws:secretsmanager:{{ aws_region }}:{{ aws_account_id }}:secret:ansible-test*'
Expand Down