Skip to content

Commit

Permalink
Gr04 (#76)
Browse files Browse the repository at this point in the history
* Added lambda for guardrail 4 v2
  • Loading branch information
TylerTMizuyabu authored Dec 10, 2024
1 parent 9d79bae commit 943658b
Show file tree
Hide file tree
Showing 11 changed files with 798 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/lza_extensions/customizations/GCGuardrailsRoles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Resources:
"arn:aws:sts::${AuditAccountID}:assumed-role/${RolePrefix}default_assessment_role/${OrganizationName}gc03_check_endpoint_access_config",
"arn:aws:sts::${AuditAccountID}:assumed-role/${RolePrefix}default_assessment_role/${OrganizationName}gc03_check_iam_cloudwatch_alarms",
"arn:aws:sts::${AuditAccountID}:assumed-role/${RolePrefix}default_assessment_role/${OrganizationName}gc03_check_trusted_devices_admin_access",
"arn:aws:sts::${AuditAccountID}:assumed-role/${RolePrefix}default_assessment_role/${OrganizationName}gc04_check_alerts_flag_misuse",
"arn:aws:sts::${AuditAccountID}:assumed-role/${RolePrefix}default_assessment_role/${OrganizationName}gc04_check_enterprise_monitoring",
"arn:aws:sts::${AuditAccountID}:assumed-role/${RolePrefix}default_assessment_role/${OrganizationName}gc05_check_data_location",
"arn:aws:sts::${AuditAccountID}:assumed-role/${RolePrefix}default_assessment_role/${OrganizationName}gc07_check_secure_network_transmission_policy",
Expand Down
14 changes: 14 additions & 0 deletions arch/templates/AuditAccountPreRequisitesPart5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ Resources:
LoggingConfig:
LogGroup: !Sub "${OrganizationName}gc_guardrails"
LogFormat: "JSON"

GC04CheckAlertsFlagMisuseLambda:
Condition: IsAuditAccount
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "${OrganizationName}gc04_check_alerts_flag_misuse"
Code: "../../src/lambda/gc04_check_alerts_flag_misuse/build/GC04CheckAlertsFlagMisuseLambda/"
Handler: app.lambda_handler
Role: !Sub "arn:aws:iam::${AuditAccountID}:role/${RolePrefix}default_assessment_role"
Runtime: !Ref PythonRuntime
Timeout: 90
LoggingConfig:
LogGroup: !Sub "${OrganizationName}gc_guardrails"
LogFormat: "JSON"

## GC05
GC05CheckDataLocationLambda:
Expand Down
36 changes: 36 additions & 0 deletions arch/templates/ConformancePack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,42 @@ Resources:
SourceDetails:
- EventSource: "aws.config"
MessageType: "ScheduledNotification"
GC04CheckAlertsFlagMisuseConfigRule:
Type: "AWS::Config::ConfigRule"
Properties:
ConfigRuleName: gc04_check_alerts_flag_misuse
Description: Confirms that alerts to authorized personnel have been implemented to flag misuse, suspicious sign-in attempts, or when changes are made to the cloud broker account.
InputParameters:
IAM_Role_Name:
Fn::If:
- enterpriseMonitoringIAMRoleName
- Ref: EnterpriseMonitoringIAMRoleName
- Ref: AWS::NoValue
ExecutionRoleName:
Fn::If:
- GCLambdaExecutionRoleName
- Ref: GCLambdaExecutionRoleName
- Ref: AWS::NoValue
AuditAccountID:
Fn::If:
- auditAccountID
- Ref: AuditAccountID
- Ref: AWS::NoValue
Scope:
ComplianceResourceTypes:
- AWS::Account
MaximumExecutionFrequency: TwentyFour_Hours
Source:
Owner: CUSTOM_LAMBDA
SourceIdentifier:
Fn::Join:
- ""
- - "arn:aws:lambda:ca-central-1:"
- Ref: AuditAccountID
- !Sub ":function:${OrganizationName}gc04_check_alerts_flag_misuse"
SourceDetails:
- EventSource: "aws.config"
MessageType: "ScheduledNotification"
# GC05
GC05CheckDataLocationConfigRule:
Type: "AWS::Config::ConfigRule"
Expand Down
1 change: 1 addition & 0 deletions src/lambda/aws_lambda_permissions_setup/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def apply_lambda_permissions():
f"{organization_name}gc03_check_endpoint_access_config": ["GC03CheckEndpointAccessConfigLambda"],
f"{organization_name}gc03_check_iam_cloudwatch_alarms": ["GC03CheckIAMCloudWatchAlarmsLambda"],
f"{organization_name}gc03_check_trusted_devices_admin_access": ["GC03CheckTrustedDevicesAdminAccessLambda"],
f"{organization_name}gc04_check_alerts_flag_misuse": ["GC04CheckAlertsFlagMisuseLambda"],
f"{organization_name}gc04_check_enterprise_monitoring": ["GC04CheckEnterpriseMonitoringLambda"],
f"{organization_name}gc05_check_data_location": ["GC05CheckDataLocationLambda"],
f"{organization_name}gc06_check_encryption_at_rest_part1": ["GC06CheckEncryptionAtRestPart1Lambda"],
Expand Down
244 changes: 244 additions & 0 deletions src/lambda/gc04_check_alerts_flag_misuse/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@

# Created by https://www.gitignore.io/api/osx,linux,python,windows,pycharm,visualstudiocode

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### PyCharm ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Ruby plugin and RubyMine
/.rakeTasks

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### PyCharm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule.*

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# Build folder

*/build/*

# End of https://www.gitignore.io/api/osx,linux,python,windows,pycharm,visualstudiocode
37 changes: 37 additions & 0 deletions src/lambda/gc04_check_alerts_flag_misuse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*This readme file was created by AWS Bedrock: anthropic.claude-v2*

# ./src/lambda/gc04_check_alerts_flag_misuse/app.py

## Overview

This Lambda function checks alerts to authorized personnel have been implemented to flag misuse, suspicious sign-in attempts, or when changes are made to the cloud broker account.

## Functions

### lambda_handler

Main entry point for the Lambda function.

- Checks if this is a scheduled invocation and if we're in the Management Account
- Gets the required AWS clients
- Calls `check_enterprise_monitoring_accounts` to validate the IAM role
- Builds an evaluation with the result and puts it via AWS Config

### build_evaluation

Helper to build an evaluation object for AWS Config.

### Other functions

- `get_client`: Helper to get boto3 clients, supporting assume role
- `get_assume_role_credentials`: Get temporary credentials via assume role
- `is_scheduled_notification`: Check if the event is a scheduled notification
- `evaluate_parameters`: Validate input parameters

## Testing

No automated tests are included.

## Logging

Uses Python's standard logging library to log information.
Empty file.
Loading

0 comments on commit 943658b

Please sign in to comment.