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

adds cfn guard checks #18

Merged
merged 8 commits into from
Aug 12, 2024
Merged
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
18 changes: 18 additions & 0 deletions .github/workflows/cfn-guard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CloudFormation Guard Validate

on:
pull_request:

jobs:
guard:
runs-on: ubuntu-latest
permissions:
# only required when create-review is true (default)
pull-requests: write
name: CloudFormation Guard validate
steps:
- name: CloudFormation Guard validate
uses: aws-cloudformation/[email protected]
with:
rules: './cfn-guard-rules/'
data: './MultiAccountApplication/'
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Parameters:
Resources:
CCFTReadAccountDataRole:
Type: 'AWS::IAM::Role'
Metadata:
guard:
SuppressedRules:
# we don't need to reuse the policy in other roles and inline it
- IAM_NO_INLINE_POLICY_CHECK
Properties:
RoleName:
!Ref CCFTReadDataRole
Expand Down
79 changes: 79 additions & 0 deletions MultiAccountApplication/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,83 @@ Resources:

CarbonEmissionsDataBucket:
Type: AWS::S3::Bucket
Metadata:
guard:
SuppressedRules:
# We neither log nor version the bucket for the code sample to reduce storage.
# Do versioning and lifecycling of deleted versions as needed.
- S3_BUCKET_LOGGING_ENABLED
- S3_BUCKET_VERSIONING_ENABLED
Properties:
BucketName: !Sub "${AWS::AccountId}-${AWS::Region}-${CarbonEmissionsDataBucketName}"
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256

CarbonEmissionsDataBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref CarbonEmissionsDataBucket
PolicyDocument:
Statement:
- Effect: Deny
Principal: "*"
Action: "s3:*"
Resource: "*"
Condition:
Bool:
aws:SecureTransport: false

# -------------------------------------------------------------------------------------------------------------------
# Create an S3 bucket to be used as Athena output location, with a retention time of files of 1 day.
# -------------------------------------------------------------------------------------------------------------------

AthenaResultBucket:
Type: AWS::S3::Bucket
Metadata:
guard:
SuppressedRules:
# We neither log nor version the bucket for the code sample to reduce storage.
# Do versioning and lifecycling of deleted versions as needed.
- S3_BUCKET_LOGGING_ENABLED
- S3_BUCKET_VERSIONING_ENABLED
Properties:
BucketName: !Sub "${AWS::AccountId}-${AWS::Region}-athenaresults"
LifecycleConfiguration:
Rules:
- Id: DeleteAfterOneDay
Status: Enabled
ExpirationInDays: 1
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256

AthenaResultBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref AthenaResultBucket
PolicyDocument:
Statement:
- Effect: Deny
Principal: "*"
Action: "s3:*"
Resource: "*"
Condition:
Bool:
aws:SecureTransport: false


# -------------------------------------------------------------------------------------------------------------------
# Create an AWS Step Function State Machine and a EventBridge rule to trigger the Step Functions workflow.
Expand Down Expand Up @@ -132,6 +193,12 @@ Resources:

GetAccountIDsFunctionLogGroup:
Type: AWS::Logs::LogGroup
Metadata:
guard:
SuppressedRules:
# Log group data is always encrypted in CloudWatch Logs.
# By default, CloudWatch Logs uses server-side encryption for the log data at rest.
- CLOUDWATCH_LOG_GROUP_ENCRYPTED
Properties:
LogGroupName: !Sub "/aws/lambda/${GetAccountIDsFunction}"
RetentionInDays: 1
Expand Down Expand Up @@ -170,6 +237,12 @@ Resources:

CheckFirstInvocationFunctionLogGroup:
Type: AWS::Logs::LogGroup
Metadata:
guard:
SuppressedRules:
# Log group data is always encrypted in CloudWatch Logs.
# By default, CloudWatch Logs uses server-side encryption for the log data at rest.
- CLOUDWATCH_LOG_GROUP_ENCRYPTED
Properties:
LogGroupName: !Sub "/aws/lambda/${CheckFirstInvocationFunction}"
RetentionInDays: 1
Expand Down Expand Up @@ -213,6 +286,12 @@ Resources:

ExtractCarbonEmissionsFunctionLogGroup:
Type: AWS::Logs::LogGroup
Metadata:
guard:
SuppressedRules:
# Log group data is always encrypted in CloudWatch Logs.
# By default, CloudWatch Logs uses server-side encryption for the log data at rest.
- CLOUDWATCH_LOG_GROUP_ENCRYPTED
Properties:
LogGroupName: !Sub "/aws/lambda/${ExtractCarbonEmissionsFunction}"
RetentionInDays: 1
Expand Down
Loading