From 471bd218406e2928154e2e304a031870478fe1eb Mon Sep 17 00:00:00 2001 From: Anna Shcherbak Date: Fri, 15 Sep 2023 15:11:36 +0300 Subject: [PATCH] new: added policy ecc-aws-552-dynamodb_tables_unused --- iam/All-permissions.json | 1 + .../ecc-aws-552-dynamodb_tables_unused.yml | 46 +++++++++++++++++++ .../green/dynamodb.tf | 28 +++++++++++ .../green/provider.tf | 2 +- .../green/terraform.tfvars | 0 .../green/variables.tf | 0 .../iam/552-policy.json} | 6 ++- .../red/dynamodb.tf | 13 ++++++ .../red/provider.tf | 2 +- .../red/terraform.tfvars | 0 .../red/variables.tf | 0 .../green/waf.tf | 34 -------------- .../red/waf.tf | 4 -- .../dynamodb.DescribeTable_1.json | 42 +++++++++++++++++ .../placebo-green/dynamodb.ListTables_1.json | 9 ++++ .../monitoring.GetMetricStatistics_1.json | 23 ++++++++++ .../monitoring.GetMetricStatistics_2.json | 23 ++++++++++ .../placebo-green/tagging.GetResources_1.json | 22 +++++++++ .../placebo-red/dynamodb.DescribeTable_1.json | 42 +++++++++++++++++ .../placebo-red/dynamodb.ListTables_1.json | 9 ++++ .../monitoring.GetMetricStatistics_1.json | 23 ++++++++++ .../monitoring.GetMetricStatistics_2.json | 23 ++++++++++ .../placebo-red/tagging.GetResources_1.json | 22 +++++++++ .../red_policy_test.py | 11 +++++ 24 files changed, 343 insertions(+), 42 deletions(-) create mode 100644 policies/ecc-aws-552-dynamodb_tables_unused.yml create mode 100644 terraform/ecc-aws-552-dynamodb_tables_unused/green/dynamodb.tf rename terraform/{ecc-aws-916-waf_global_rulegroup_not_empty => ecc-aws-552-dynamodb_tables_unused}/green/provider.tf (78%) rename terraform/{ecc-aws-916-waf_global_rulegroup_not_empty => ecc-aws-552-dynamodb_tables_unused}/green/terraform.tfvars (100%) rename terraform/{ecc-aws-916-waf_global_rulegroup_not_empty => ecc-aws-552-dynamodb_tables_unused}/green/variables.tf (100%) rename terraform/{ecc-aws-916-waf_global_rulegroup_not_empty/iam/916-policy.json => ecc-aws-552-dynamodb_tables_unused/iam/552-policy.json} (51%) create mode 100644 terraform/ecc-aws-552-dynamodb_tables_unused/red/dynamodb.tf rename terraform/{ecc-aws-916-waf_global_rulegroup_not_empty => ecc-aws-552-dynamodb_tables_unused}/red/provider.tf (78%) rename terraform/{ecc-aws-916-waf_global_rulegroup_not_empty => ecc-aws-552-dynamodb_tables_unused}/red/terraform.tfvars (100%) rename terraform/{ecc-aws-916-waf_global_rulegroup_not_empty => ecc-aws-552-dynamodb_tables_unused}/red/variables.tf (100%) delete mode 100644 terraform/ecc-aws-916-waf_global_rulegroup_not_empty/green/waf.tf delete mode 100644 terraform/ecc-aws-916-waf_global_rulegroup_not_empty/red/waf.tf create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-green/dynamodb.DescribeTable_1.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-green/dynamodb.ListTables_1.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-green/monitoring.GetMetricStatistics_1.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-green/monitoring.GetMetricStatistics_2.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-green/tagging.GetResources_1.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-red/dynamodb.DescribeTable_1.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-red/dynamodb.ListTables_1.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-red/monitoring.GetMetricStatistics_1.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-red/monitoring.GetMetricStatistics_2.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/placebo-red/tagging.GetResources_1.json create mode 100644 tests/ecc-aws-552-dynamodb_tables_unused/red_policy_test.py diff --git a/iam/All-permissions.json b/iam/All-permissions.json index a9622fae7..73d519d7d 100644 --- a/iam/All-permissions.json +++ b/iam/All-permissions.json @@ -27,6 +27,7 @@ "cloudtrail:DescribeTrails", "cloudtrail:GetEventSelectors", "cloudtrail:GetTrailStatus", + "cloudwatch:GetMetricStatistics", "cloudwatch:DescribeAlarms", "codebuild:BatchGetProjects", "codebuild:ListProjects", diff --git a/policies/ecc-aws-552-dynamodb_tables_unused.yml b/policies/ecc-aws-552-dynamodb_tables_unused.yml new file mode 100644 index 000000000..657de2102 --- /dev/null +++ b/policies/ecc-aws-552-dynamodb_tables_unused.yml @@ -0,0 +1,46 @@ +# Copyright (c) 2023 EPAM Systems, Inc. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + + +policies: + - name: ecc-aws-552-dynamodb_tables_unused + comment: '010002062000' + description: | + Unused Amazon DynamoDB tables + resource: aws.dynamodb-table + filters: + - and: + - type: value + key: ProvisionedThroughput.ReadCapacityUnits + op: ne + value: 0 + - type: value + key: TableStatus + value: ACTIVE + - type: value + key: CreationDateTime + value_type: age + value: 60 + op: ge + - or: + - type: value + key: ItemCount + value: 0 + - and: + - type: metrics + name: ConsumedWriteCapacityUnits + namespace: AWS/DynamoDB + statistics: Maximum + days: 60 + value: 0 + op: equal + - type: metrics + name: ConsumedReadCapacityUnits + namespace: AWS/DynamoDB + statistics: Maximum + days: 60 + value: 0 + op: equal \ No newline at end of file diff --git a/terraform/ecc-aws-552-dynamodb_tables_unused/green/dynamodb.tf b/terraform/ecc-aws-552-dynamodb_tables_unused/green/dynamodb.tf new file mode 100644 index 000000000..2c9bad15d --- /dev/null +++ b/terraform/ecc-aws-552-dynamodb_tables_unused/green/dynamodb.tf @@ -0,0 +1,28 @@ +resource "aws_dynamodb_table" "this" { + name = "552_dynamodb_table_green" + hash_key = "GreenTableHashKey" + billing_mode = "PROVISIONED" + read_capacity = 1 + write_capacity = 1 + + + attribute { + name = "GreenTableHashKey" + type = "S" + } +} + +resource "aws_dynamodb_table_item" "this" { + table_name = aws_dynamodb_table.this.name + hash_key = aws_dynamodb_table.this.hash_key + + item = <