Skip to content

Commit 79a0f5c

Browse files
authored
fix(sast): BCE-36172 fix cdk policies (bridgecrewio#6588)
* add the word test * fixes * fix id
1 parent 1144562 commit 79a0f5c

File tree

16 files changed

+367
-144
lines changed

16 files changed

+367
-144
lines changed
Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
1-
// FINDING
2-
import { CfnClusterParameterGroup } from '@aws-cdk/aws-redshift';
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as redshift from 'aws-cdk-lib/aws-redshift';
33

4-
// SINK
5-
// SINK: Vulnerability found due to Redshift not using SSL
6-
new CfnClusterParameterGroup(stack, 'MyClusterParameterGroup', {
7-
description: 'Parameter group for my Redshift cluster',
8-
family: 'redshift-1.0',
9-
parameters: {
10-
require_ssl: 'false', // This should be 'true' to enforce SSL
11-
},
12-
});
13-
new CfnClusterParameterGroup(stack, 'MyClusterParameterGroup', {
14-
description: 'Parameter group for my Redshift cluster',
15-
family: 'redshift-1.0',
16-
parameters: {
17-
random_param: 100
18-
},
19-
});
4+
class MyRedshiftClusterParameterGroupStack extends cdk.Stack {
5+
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
6+
super(scope, id, props);
7+
8+
// Define Redshift Cluster Parameter Group with require_ssl parameter
9+
new redshift.CfnClusterParameterGroup(this, 'MyRedshiftClusterParameterGroup', {
10+
description: 'My Redshift Parameter Group',
11+
parameterGroupFamily: 'redshift-1.0',
12+
parameters: [
13+
{
14+
parameterName: 'require_ssl',
15+
parameterValue: 'false',
16+
},
17+
// Add other parameters if needed
18+
],
19+
});
20+
}
21+
}
22+
23+
const app = new cdk.App();
24+
new MyRedshiftClusterParameterGroupStack(app, 'MyRedshiftClusterParameterGroupStack');
25+
app.synth();
26+
27+
class MyRedshiftClusterParameterGroupStack2 extends cdk.Stack {
28+
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
29+
super(scope, id, props);
30+
31+
// Define Redshift Cluster Parameter Group with abc parameter
32+
new redshift.CfnClusterParameterGroup(this, 'MyRedshiftClusterParameterGroup2', {
33+
description: 'My Redshift Parameter Group 2',
34+
parameterGroupFamily: 'redshift-1.0',
35+
});
36+
}
37+
}
38+
39+
new MyRedshiftClusterParameterGroupStack2(app, 'MyRedshiftClusterParameterGroupStack2');
40+
app.synth();
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
import { CfnClusterParameterGroup } from '@aws-cdk/aws-redshift';
1+
import * as cdk from 'aws-cdk-lib';
2+
import * as redshift from 'aws-cdk-lib/aws-redshift';
23

3-
new CfnClusterParameterGroup(stack, 'MyClusterParameterGroup', {
4-
description: 'Parameter group for my Redshift cluster',
5-
family: 'redshift-1.0',
6-
parameters: {
7-
require_ssl: 'true', // This should be 'true' to enforce SSL
8-
},
9-
});
4+
class MyRedshiftClusterParameterGroupStack extends cdk.Stack {
5+
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
6+
super(scope, id, props);
7+
8+
// Define Redshift Cluster Parameter Group with require_ssl parameter
9+
new redshift.CfnClusterParameterGroup(this, 'MyRedshiftClusterParameterGroup', {
10+
description: 'My Redshift Parameter Group',
11+
parameterGroupFamily: 'redshift-1.0',
12+
parameters: [
13+
{
14+
parameterName: 'require_ssl',
15+
parameterValue: 'true',
16+
},
17+
// Add other parameters if needed
18+
],
19+
});
20+
}
21+
}
22+
23+
const app = new cdk.App();
24+
new MyRedshiftClusterParameterGroupStack(app, 'MyRedshiftClusterParameterGroupStack');
25+
app.synth();

cdk_integration_tests/src/typescript/RedshiftClusterEncryption/fail.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as redshift from '@aws-cdk/aws-redshift-alpha';
2+
import * as kms from 'aws-cdk-lib/aws-kms';
3+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
4+
import { Stack, App } from 'aws-cdk-lib';
5+
6+
const app = new App();
7+
const stack = new Stack(app, 'RedshiftStack');
8+
9+
// Create a VPC
10+
const vpc = new ec2.Vpc(stack, 'Vpc', {
11+
maxAzs: 2
12+
});
13+
14+
// Create a KMS key for encryption
15+
const kmsKey = new kms.Key(stack, 'KmsKey');
16+
17+
const cluster = new redshift.Cluster(stack, 'MyCluster', {
18+
masterUser: {
19+
masterUsername: 'admin',
20+
},
21+
vpc,
22+
});
23+
24+
import * as redshift from 'aws-cdk-lib/aws_redshift';
25+
import * as kms from 'aws-cdk-lib/aws-kms';
26+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
27+
import { Stack, App } from 'aws-cdk-lib';
28+
29+
const app = new App();
30+
const stack = new Stack(app, 'RedshiftStack');
31+
32+
// Create a VPC
33+
const vpc = new ec2.Vpc(stack, 'Vpc', {
34+
maxAzs: 2
35+
});
36+
37+
// Create a KMS key for encryption
38+
const kmsKey = new kms.Key(stack, 'KmsKey');
39+
40+
const cfnCluster = new redshift.CfnCluster(stack, 'MyCfnCluster', {
41+
clusterType: 'multi-node',
42+
dbName: 'mydatabase',
43+
masterUsername: 'admin',
44+
masterUserPassword: 'password',
45+
nodeType: 'ds2.xlarge',
46+
numberOfNodes: 3,
47+
kmsKeyId: kmsKey.keyArn, // Use the specific KMS key
48+
vpcSecurityGroupIds: [ /* security group IDs */ ],
49+
clusterSubnetGroupName: vpc.selectSubnets({ subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }).subnetIds[0],
50+
});
51+
Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
1-
// SOURCE
2-
import { Cluster } from '@aws-cdk/aws-redshift';
1+
import * as redshift from '@aws-cdk/aws-redshift-alpha';
2+
import * as kms from 'aws-cdk-lib/aws-kms';
3+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
4+
import { Stack, App } from 'aws-cdk-lib';
35

4-
// SINK
5-
// SINK: Vulnerability found due to missing encryption at rest
6-
new Cluster(stack, 'MyRedshiftCluster', {
7-
masterUser: {
8-
masterUsername: 'admin',
9-
masterPassword: 'password',
10-
},
11-
vpc, encrypted: true
6+
const app = new App();
7+
const stack = new Stack(app, 'RedshiftStack');
8+
9+
// Create a VPC
10+
const vpc = new ec2.Vpc(stack, 'Vpc', {
11+
maxAzs: 2
1212
});
13-
new Cluster(stack, 'MyRedshiftCluster', {
13+
14+
// Create a KMS key for encryption
15+
const kmsKey = new kms.Key(stack, 'KmsKey');
16+
17+
const cluster = new redshift.Cluster(stack, 'MyCluster', {
1418
masterUser: {
1519
masterUsername: 'admin',
16-
masterPassword: 'password',
1720
},
18-
vpc
21+
vpc,
22+
encryption: true,
23+
});
24+
25+
import * as redshift from 'aws-cdk-lib/aws_redshift';
26+
import * as kms from 'aws-cdk-lib/aws-kms';
27+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
28+
import { Stack, App } from 'aws-cdk-lib';
29+
30+
const app = new App();
31+
const stack = new Stack(app, 'RedshiftStack');
32+
33+
// Create a VPC
34+
const vpc = new ec2.Vpc(stack, 'Vpc', {
35+
maxAzs: 2
1936
});
37+
38+
// Create a KMS key for encryption
39+
const kmsKey = new kms.Key(stack, 'KmsKey');
40+
41+
const cfnCluster = new redshift.CfnCluster(stack, 'MyCfnCluster', {
42+
clusterType: 'multi-node',
43+
dbName: 'mydatabase',
44+
masterUsername: 'admin',
45+
masterUserPassword: 'password',
46+
nodeType: 'ds2.xlarge',
47+
numberOfNodes: 3,
48+
encryption: true,
49+
kmsKeyId: kmsKey.keyArn, // Use the specific KMS key
50+
vpcSecurityGroupIds: [ /* security group IDs */ ],
51+
clusterSubnetGroupName: vpc.selectSubnets({ subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }).subnetIds[0],
52+
});
53+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Stack, App } from 'aws-cdk-lib';
3+
import * as s3 from 'aws-cdk-lib/aws-s3';
4+
5+
const app = new App();
6+
const stack = new Stack(app, 'S3BucketStack');
7+
8+
// Create an S3 bucket with blockPublicAcls enabled
9+
const bucket = new s3.Bucket(stack, 'MyBucket', {
10+
blockPublicAccess: s3.BlockPublicAccess.IGNORE_ACLS,
11+
versioned: true,
12+
removalPolicy: cdk.RemovalPolicy.DESTROY,
13+
autoDeleteObjects: true,
14+
});
15+
16+
app.synth();

cdk_integration_tests/src/typescript/S3BlockPublicACLs/fail__2__.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Stack, App } from 'aws-cdk-lib';
3+
import { Bucket, BlockPublicAccess } from 'aws-cdk-lib/aws-s3';
4+
5+
const app = new App();
6+
const stack = new Stack(app, 'S3BucketStack');
7+
8+
// Create an S3 bucket with blockPublicAcls enabled
9+
const bucket = new Bucket(stack, 'MyBucket', {
10+
blockPublicAccess: BlockPublicAccess.IGNORE_ACLS,
11+
versioned: true,
12+
removalPolicy: cdk.RemovalPolicy.DESTROY,
13+
autoDeleteObjects: true,
14+
});
15+
16+
const bucket2 = new Bucket(stack, 'MyBucket', {
17+
versioned: true,
18+
removalPolicy: cdk.RemovalPolicy.DESTROY,
19+
autoDeleteObjects: true,
20+
});
21+
22+
app.synth();
23+
24+
import * as cdk from 'aws-cdk-lib';
25+
import { Stack, App } from 'aws-cdk-lib';
26+
import * as s3 from 'aws-cdk-lib/aws-s3';
27+
28+
const app = new App();
29+
const stack = new Stack(app, 'S3BucketStack');
30+
31+
// Create an S3 bucket with blockPublicAcls enabled
32+
const bucket = new s3.CfnBucket(stack, 'MyBucket', {
33+
bucketName: 'my-bucket-name', // Optional: Specify a bucket name
34+
versioningConfiguration: {
35+
status: 'Enabled',
36+
},
37+
publicAccessBlockConfiguration: {
38+
blockPublicAcls: false, // Only block public ACLs
39+
ignorePublicAcls: true,
40+
},
41+
});
42+
43+
bucket.applyRemovalPolicy(cdk.RemovalPolicy.DESTROY);
44+
45+
app.synth();
46+
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
// FINDING
2-
import { Bucket } from '@aws-cdk/aws-s3';
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Stack, App } from 'aws-cdk-lib';
3+
import * as s3 from 'aws-cdk-lib/aws-s3';
34

4-
// SINK
5-
// SINK: Vulnerability found due to S3 bucket missing block public ACLs
6-
new Bucket(stack, 'MyBucket', {
7-
blockPublicAcls: true, // This should be 'true' to block public ACLs
5+
const app = new App();
6+
const stack = new Stack(app, 'S3BucketStack');
7+
8+
// Create an S3 bucket with blockPublicAcls enabled
9+
const bucket = new s3.Bucket(stack, 'MyBucket', {
10+
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ACLS, // Only block public ACLs
11+
versioned: true,
12+
removalPolicy: cdk.RemovalPolicy.DESTROY, // NOT recommended for production code
13+
autoDeleteObjects: true, // NOT recommended for production code
14+
});
15+
16+
const bucket2 = new s3.Bucket(stack, 'MyBucket', {
17+
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, // Only block public ACLs
18+
versioned: true,
19+
removalPolicy: cdk.RemovalPolicy.DESTROY, // NOT recommended for production code
20+
autoDeleteObjects: true, // NOT recommended for production code
821
});
22+
23+
app.synth();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Stack, App } from 'aws-cdk-lib';
3+
import { Bucket, BlockPublicAccess } from 'aws-cdk-lib/aws-s3';
4+
5+
const app = new App();
6+
const stack = new Stack(app, 'S3BucketStack');
7+
8+
// Create an S3 bucket with blockPublicAcls enabled
9+
const bucket = new Bucket(stack, 'MyBucket', {
10+
blockPublicAccess: BlockPublicAccess.BLOCK_ACLS, // Only block public ACLs
11+
versioned: true,
12+
removalPolicy: cdk.RemovalPolicy.DESTROY, // NOT recommended for production code
13+
autoDeleteObjects: true, // NOT recommended for production code
14+
});
15+
16+
const bucket2 = new Bucket(stack, 'MyBucket', {
17+
blockPublicAccess: BlockPublicAccess.BLOCK_ALL, // Only block public ACLs
18+
versioned: true,
19+
removalPolicy: cdk.RemovalPolicy.DESTROY, // NOT recommended for production code
20+
autoDeleteObjects: true, // NOT recommended for production code
21+
});
22+
23+
app.synth();
24+

0 commit comments

Comments
 (0)