Skip to content

JamesWoolfenden/terraform-aws-security-alerts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-aws-security-alerts

Build Status Latest Release GitHub tag (latest SemVer) Terraform Version Infrastructure Tests pre-commit checkov Infrastructure Tests

This module is to help implement compliance with the CIS benchmarks as tested in the Bridgecrew checks https://docs.bridgecrew.io/docs/monitoring-policies:

  • BC_AWS_MONITORING_1
  • BC_AWS_MONITORING_2
  • BC_AWS_MONITORING_3
  • BC_AWS_MONITORING_4
  • BC_AWS_MONITORING_5
  • BC_AWS_MONITORING_6
  • BC_AWS_MONITORING_7
  • BC_AWS_MONITORING_8
  • BC_AWS_MONITORING_9
  • BC_AWS_MONITORING_10
  • BC_AWS_MONITORING_11
  • BC_AWS_MONITORING_12
  • BC_AWS_MONITORING_13
  • BC_AWS_MONITORING_14

This module is 100% Open Source and licensed under the APACHE2.

Introduction

This module deploys security-alerts for an AWS account. TODO: Update to use lambda rather than SNS Email - https://aws.amazon.com/premiumsupport/knowledge-center/change-sns-email-for-cloudwatch-events/

Usage

Include this repository as a module in your existing Terraform code:

module "security-alerts" {
  source            = "JamesWoolfenden/security-alerts/aws"
  version           = "v0.0.3"
  endpoint          = var.endpoint
}

Testing

aws cloudwatch set-alarm-state --alarm-name "vpc_changes_alarm" --state-reason "Testing the Amazon Cloudwatch alarm" --state-value ALARM --region eu-west-2

Costs

Calculated monthly cost estimate

Project: .

 Name                                                      Monthly Qty  Unit           Monthly Cost

 module.alerts.aws_cloudwatch_metric_alarm.bucket_mod
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.cloudtrail_cfg
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.cmk
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.config_change
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.gateway
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.nacl
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.nomfa
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.policychange
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.root
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.routes
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.sg
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.signfail
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.unauth
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_cloudwatch_metric_alarm.vpc
 └─ Standard resolution                                              1  alarm metrics         $0.10

 module.alerts.aws_sns_topic.trail-unauthorised
 └─ Requests                                                         0  1M requests           $0.00

 PROJECT TOTAL                                                                                $1.40

----------------------------------
1 resource type wasn't estimated as it's not supported yet.
1 x aws_sns_topic_subscription

Requirements

No requirements.

Providers

Name Version
archive n/a
aws n/a

Modules

No modules.

Resources

Name Type
aws_cloudwatch_log_group.processor resource
aws_cloudwatch_log_metric_filter.bucket_mod resource
aws_cloudwatch_log_metric_filter.cloudtrail_cfg resource
aws_cloudwatch_log_metric_filter.cmk resource
aws_cloudwatch_log_metric_filter.config_change resource
aws_cloudwatch_log_metric_filter.gateway resource
aws_cloudwatch_log_metric_filter.nacl resource
aws_cloudwatch_log_metric_filter.nomfa resource
aws_cloudwatch_log_metric_filter.policychange resource
aws_cloudwatch_log_metric_filter.root resource
aws_cloudwatch_log_metric_filter.routes resource
aws_cloudwatch_log_metric_filter.sg resource
aws_cloudwatch_log_metric_filter.signfail resource
aws_cloudwatch_log_metric_filter.unauth resource
aws_cloudwatch_log_metric_filter.vpc resource
aws_cloudwatch_metric_alarm.bucket_mod resource
aws_cloudwatch_metric_alarm.cloudtrail_cfg resource
aws_cloudwatch_metric_alarm.cmk resource
aws_cloudwatch_metric_alarm.config_change resource
aws_cloudwatch_metric_alarm.gateway resource
aws_cloudwatch_metric_alarm.nacl resource
aws_cloudwatch_metric_alarm.nomfa resource
aws_cloudwatch_metric_alarm.policychange resource
aws_cloudwatch_metric_alarm.root resource
aws_cloudwatch_metric_alarm.routes resource
aws_cloudwatch_metric_alarm.sg resource
aws_cloudwatch_metric_alarm.signfail resource
aws_cloudwatch_metric_alarm.unauth resource
aws_cloudwatch_metric_alarm.vpc resource
aws_iam_role.SNSFailureFeedback resource
aws_iam_role.SNSSuccessFeedback resource
aws_iam_role.lambda-messageprocessor resource
aws_iam_role_policy.failure resource
aws_iam_role_policy.lambda resource
aws_iam_role_policy.success resource
aws_kms_alias.alarm resource
aws_kms_key.alarm resource
aws_lambda_function.email resource
aws_lambda_permission.with_sns resource
aws_sns_topic.processed-message resource
aws_sns_topic.trail-unauthorised resource
aws_sns_topic_subscription.Emailfromlambda resource
aws_sns_topic_subscription.lambda resource
archive_file.notify data source
aws_caller_identity.current data source

Inputs

Name Description Type Default Required
concurrency n/a number 1 no
endpoint n/a string n/a yes
function_name n/a string "message-processor" no
kms-alias n/a string "alias/alarms" no
kms_key n/a string "alias/aws/sns" no
log_group_name n/a string "cloudtrail" no
protocol n/a string "sms" no

Outputs

Name Description
alarms The alarms created
lambda The lambda
metrics The metrics filters for the Alarms
sns_topic_processed The final SNS endpoint for a processed message
sns_topic_subscription_lambda The SNS subcription that pulls messages into being processed by the Lambda

Policy

This is the policy required to build this project:

The Terraform resource required is:

resource "aws_iam_policy" "terraform_pike" {
  name_prefix = "terraform_pike"
  path        = "/"
  description = "Pike Autogenerated policy from IAC"

  policy = jsonencode({
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "SNS:CreateTopic",
                "SNS:DeleteTopic",
                "SNS:GetTopicAttributes",
                "SNS:ListTagsForResource",
                "SNS:SetTopicAttributes"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
                "cloudwatch:DeleteAlarms",
                "cloudwatch:DescribeAlarms",
                "cloudwatch:ListTagsForResource",
                "cloudwatch:PutMetricAlarm"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor2",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeAccountAttributes"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor3",
            "Effect": "Allow",
            "Action": [
                "iam:CreateRole",
                "iam:DeleteRole",
                "iam:DeleteRolePolicy",
                "iam:GetRole",
                "iam:GetRolePolicy",
                "iam:ListAttachedRolePolicies",
                "iam:ListInstanceProfilesForRole",
                "iam:ListRolePolicies",
                "iam:PassRole",
                "iam:PutRolePolicy"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor4",
            "Effect": "Allow",
            "Action": [
                "kms:CreateAlias",
                "kms:CreateKey",
                "kms:DeleteAlias",
                "kms:DescribeKey",
                "kms:EnableKeyRotation",
                "kms:GetKeyPolicy",
                "kms:GetKeyRotationStatus",
                "kms:ListAliases",
                "kms:ListResourceTags",
                "kms:PutKeyPolicy",
                "kms:ScheduleKeyDeletion"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor5",
            "Effect": "Allow",
            "Action": [
                "lambda:AddPermission",
                "lambda:CreateFunction",
                "lambda:DeleteFunction",
                "lambda:GetFunction",
                "lambda:GetFunctionCodeSigningConfig",
                "lambda:GetPolicy",
                "lambda:ListVersionsByFunction",
                "lambda:RemovePermission"
            ],
            "Resource": "*"
        },
        {
            "Sid": "VisualEditor6",
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:DeleteLogGroup",
                "logs:DeleteMetricFilter",
                "logs:DeleteRetentionPolicy",
                "logs:DescribeLogGroups",
                "logs:DescribeMetricFilters",
                "logs:ListTagsLogGroup",
                "logs:PutMetricFilter",
                "logs:PutRetentionPolicy"
            ],
            "Resource": "*"
        }
    ]
})
}

Related Projects

Check out these related projects.

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Copyrights

Copyright © 2021-2022 James Woolfenden

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors

James Woolfenden
James Woolfenden