-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from atulgoel126/main-week3-day5-7
Adding compliance checks using cfn-nag-scan
- Loading branch information
Showing
6 changed files
with
89 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
RulesToSuppress: | ||
- id: W58 | ||
reason: "Suppressing Lambda VPC rule for functions that don't need VPC access" | ||
- id: W89 | ||
reason: "Suppressing Lambda permission rule for functions with necessary permissions" | ||
- id: F1000 | ||
reason: "Suppressing IAM role check for internal resources" | ||
- id: W11 | ||
reason: "Suppressing IAM resource * rule for specific use cases" | ||
- id: W12 | ||
reason: "Suppressing IAM action * rule for specific use cases" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- main-week2-day5-6 | ||
- main-week3-day5-7 | ||
pull_request: | ||
branches: | ||
- main | ||
|
@@ -38,7 +38,6 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
# Checkov scan | ||
- uses: bridgecrewio/checkov-action@v12 | ||
with: | ||
|
@@ -56,7 +55,14 @@ jobs: | |
exit-code: '1' | ||
ignore-unfixed: true | ||
severity: 'CRITICAL,HIGH' | ||
# | ||
|
||
- name: Stelligent cfn_nag | ||
uses: stelligent/[email protected] | ||
with: | ||
input_path: cdk.out | ||
extra_args: --template-pattern .template.json | ||
|
||
|
||
docker: | ||
needs: security-scan | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# Exit on error | ||
set -e | ||
|
||
echo "Synthesizing CloudFormation templates..." | ||
npm run cdk-synth | ||
|
||
echo "Running cfn-nag scans..." | ||
|
||
# Scan all CloudFormation templates | ||
for template in cdk.out/*.template.json; do | ||
echo "Scanning $template..." | ||
cfn_nag_scan --input-path "$template" --blacklist-path .cfn-nag-blacklist.yml || exit 1 | ||
done | ||
|
||
echo "All compliance checks completed successfully!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
import * as kms from 'aws-cdk-lib/aws-kms'; | ||
import { Construct } from "constructs"; | ||
|
||
export interface CompliantStorageProps { | ||
bucketName?: string; | ||
logRetention?: number; | ||
} | ||
|
||
export class CompliantStorage extends Construct { | ||
public readonly bucket: s3.Bucket; | ||
public readonly key: kms.Key; | ||
|
||
constructor(scope: Construct, id: string, props?: CompliantStorageProps) { | ||
super(scope, id); | ||
|
||
// Create KMS key for encryption | ||
this.key = new kms.Key(this, 'EncryptionKey', { | ||
enableKeyRotation: true, | ||
removalPolicy: cdk.RemovalPolicy.RETAIN, | ||
description: 'KMS key for compliant storage encryption' | ||
}); | ||
|
||
// Create compliant S3 bucket | ||
this.bucket = new s3.Bucket(this, 'CompliantBucket', { | ||
bucketName: props?.bucketName, | ||
encryption: s3.BucketEncryption.KMS, | ||
encryptionKey: this.key, | ||
enforceSSL: true, | ||
versioned: true, | ||
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, | ||
serverAccessLogsBucket: new s3.Bucket(this, 'AccessLogs', { | ||
encryption: s3.BucketEncryption.KMS, | ||
encryptionKey: this.key, | ||
removalPolicy: cdk.RemovalPolicy.RETAIN, | ||
autoDeleteObjects: false, | ||
}), | ||
removalPolicy: cdk.RemovalPolicy.RETAIN, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import { Construct } from 'constructs'; | ||
import { SecureS3Bucket } from '../constructs/storage/SecureS3Bucket'; | ||
import {CompliantStorage} from "../constructs/storage/compliant-storage"; | ||
|
||
export class StorageStack extends cdk.Stack { | ||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
new SecureS3Bucket(this, 'SecureS3Bucket'); | ||
new CompliantStorage(this, 'CompliantS3Bucket') | ||
} | ||
} |