aws-remediate-cis-securityhub/cft/aws-cis-securityhubactions.yml [773:838]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Code:
        ZipFile: |
          import boto3
          import json
          import os
          def lambda_handler(event, context):
              TrailName = os.environ['TrailName']
              S3BucketName = os.environ['S3BucketName']
              ssm = boto3.client('ssm')
              try:
                  response = ssm.start_automation_execution(
                      DocumentName='AWS-EnableCloudTrail',
                      DocumentVersion='1', # default
                      Parameters={
                          'TrailName': [ TrailName ],
                          'S3BucketName': [ S3BucketName]
                      }
                  )
              except Exception as e:
                  print(e)
                  print("SSM automation execution error")
                  raise

  CloudTrailEnabledLambdaRole:
    Type: AWS::IAM::Role
    Properties:
      Policies:
      - PolicyName: CloudTrailEnabledLambdaPolicy
        PolicyDocument:
          Version: 2012-10-17
          Statement:
          - Effect: Allow
            Action:
            - cloudwatch:PutMetricData
            Resource: '*'
          - Effect: Allow
            Action:
            - ssm:StartAutomationExecution
            - logs:CreateLogGroup
            - logs:CreateLogStream
            - logs:PutLogEvents
            - logs:DescribeLogGroups
            - iam:PassRole
            Resource: '*'
          - Effect: Allow
            Action:
            - cloudtrail:UpdateTrail
            - cloudtrail:*
            - securityhub:UpdateFindings
            Resource: '*'
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
        - Effect: Allow
          Principal: { Service: lambda.amazonaws.com }
          Action:
          - sts:AssumeRole
  
# -------------------------------------------------------------------------------------------------------------------------------------------------------
# CIS AWS Foundations Benchmark - 2.2 – Ensure CloudTrail log file validation is enabled
# -------------------------------------------------------------------------------------------------------------------------------------------------------

  CloudTrailLogFileValidationEnabledRule: 
    Type: AWS::Events::Rule
    Properties: 
      Name: CloudTrailLogFileValidationEnabledRule
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



aws-remediate-pci-securityhub/cft/aws-security-hub-pci-remediations-template2.yml [1617:1680]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Code:
        ZipFile: |
          import boto3
          import json
          import os
          def lambda_handler(event, context):
              TrailName = os.environ['TrailName']
              S3BucketName = os.environ['S3BucketName']
              ssm = boto3.client('ssm')
              try:
                  response = ssm.start_automation_execution(
                      DocumentName='AWS-EnableCloudTrail',
                      DocumentVersion='1', # default
                      Parameters={
                          'TrailName': [ TrailName ],
                          'S3BucketName': [ S3BucketName]
                      }
                  )
              except Exception as e:
                  print(e)
                  print("SSM automation execution error")
                  raise

  CloudTrailEnabledLambdaRole:
    Type: AWS::IAM::Role
    Properties:
      Policies:
      - PolicyName: CloudTrailEnabledLambdaPolicy
        PolicyDocument:
          Version: 2012-10-17
          Statement:
          - Effect: Allow
            Action:
            - cloudwatch:PutMetricData
            Resource: '*'
          - Effect: Allow
            Action:
            - ssm:StartAutomationExecution
            - logs:CreateLogGroup
            - logs:CreateLogStream
            - logs:PutLogEvents
            - logs:DescribeLogGroups
            - iam:PassRole
            Resource: '*'
          - Effect: Allow
            Action:
            - cloudtrail:UpdateTrail
            - cloudtrail:*
            - securityhub:UpdateFindings
            Resource: '*'
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
        - Effect: Allow
          Principal: { Service: lambda.amazonaws.com }
          Action:
          - sts:AssumeRole
  

# PCI.CloudTrail.3
  CloudTrailLogFileValidationEnabledRule: 
    Type: AWS::Events::Rule
    Properties: 
      Name: CloudTrailLogFileValidationEnabledRule
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



