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

feat(sast): CDK TS policies p3 #6157

Merged
merged 29 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions cdk_integration_tests/src/typescript/EC2PublicIP/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const vpc = new ec2.Vpc(this, 'VPC', {
cidr: '10.0.0.0/16',
natGateways: 0,
maxAzs: 2,
subnetConfiguration: [
{
name: 'public-subnet-1',
subnetType: ec2.SubnetType.PUBLIC,
cidrMask: 24,
},
],
});

const instance = new ec2.Instance(this, 'Instance', {
vpc,
vpcSubnets: {subnetGroupName: 'public-subnet-1'},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.NANO),
machineImage: new ec2.AmazonLinuxImage({generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2}),
detailedMonitoring: true,
associatePublicIpAddress: true
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
37 changes: 37 additions & 0 deletions cdk_integration_tests/src/typescript/EC2PublicIP/fail_2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const vpc = new ec2.Vpc(this, 'VPC', {
cidr: '10.0.0.0/16',
natGateways: 0,
maxAzs: 2,
subnetConfiguration: [
{
name: 'public-subnet-1',
subnetType: ec2.SubnetType.PUBLIC,
cidrMask: 24,
},
],
});

const sg1 = new ec2.SecurityGroup(this, 'sg1', {
vpc: vpc,
});

const launchTemplate = new ec2.LaunchTemplate(this, 'LaunchTemplate', {
machineImage: ec2.MachineImage.latestAmazonLinux2023(),
securityGroup: sg1,
associatePublicIpAddress: true
});

}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
35 changes: 35 additions & 0 deletions cdk_integration_tests/src/typescript/EC2PublicIP/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const vpc = new ec2.Vpc(this, 'VPC', {
cidr: '10.0.0.0/16',
natGateways: 0,
maxAzs: 2,
subnetConfiguration: [
{
name: 'public-subnet-1',
subnetType: ec2.SubnetType.PUBLIC,
cidrMask: 24,
},
],
});

const instance = new ec2.Instance(this, 'Instance', {
vpc,
vpcSubnets: {subnetGroupName: 'public-subnet-1'},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.NANO),
machineImage: new ec2.AmazonLinuxImage({generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2}),
detailedMonitoring: true,
associatePublicIpAddress: false
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
14 changes: 14 additions & 0 deletions cdk_integration_tests/src/typescript/ECRImageScanning/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as cdk from 'aws-cdk-lib';
import * as ecr from 'aws-cdk-lib/aws-ecr';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repository = new ecr.Repository(this, 'Repo', {} );
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
16 changes: 16 additions & 0 deletions cdk_integration_tests/src/typescript/ECRImageScanning/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as cdk from 'aws-cdk-lib';
import * as ecr from 'aws-cdk-lib/aws-ecr';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repository = new ecr.Repository(this, 'Repo', {
imageScanOnPush: true
} );
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
14 changes: 14 additions & 0 deletions cdk_integration_tests/src/typescript/ECRImmutableTags/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as cdk from 'aws-cdk-lib';
import * as ecr from 'aws-cdk-lib/aws-ecr';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repository = new ecr.Repository(this, 'Repo', {} );
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
16 changes: 16 additions & 0 deletions cdk_integration_tests/src/typescript/ECRImmutableTags/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as cdk from 'aws-cdk-lib';
import * as ecr from 'aws-cdk-lib/aws-ecr';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repository = new ecr.Repository(this, 'Repo', {
imageTagMutability: ecr.TagMutability.IMMUTABLE
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as cdk from 'aws-cdk-lib';
import * as ecr from 'aws-cdk-lib/aws-ecr';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repository = new ecr.Repository(this, 'Repo', {} );
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as cdk from 'aws-cdk-lib';
import * as ecr from 'aws-cdk-lib/aws-ecr';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repository = new ecr.Repository(this, 'Repo', {
encryption: ecr.RepositoryEncryption.KMS
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as cdk from 'aws-cdk-lib';
import * as ecr from 'aws-cdk-lib/aws-ecr';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const repository = new ecr.Repository(this, 'Repo', {
encryptionKey: new kms.Key(this, 'Key')
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'Vpc', {maxAzs: 1});
const cluster = new ecs.Cluster(this, 'EcsCluster', {vpc});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, 'Vpc', {maxAzs: 1});
const cluster = new ecs.Cluster(this, 'EcsCluster', {vpc, containerInsights: true});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef', {
volumes:
[
{
name:"my-volume",
efsVolumeConfiguration:{
transitEncryption: "DISABLED"
}
}
]
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
volumes:
[
{
name:"my-volume",
efsVolumeConfiguration:{
transitEncryption: "DISABLED"
}
}
]
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef', {
volumes:
[
{
name:"my-volume",
efsVolumeConfiguration:{
transitEncryption: "ENABLED"
}
}
]
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
17 changes: 17 additions & 0 deletions cdk_integration_tests/src/typescript/EFSEncryptionEnabled/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as efs from 'aws-cdk-lib/aws-efs';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
vpc: new ec2.Vpc(this, 'VPC')
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
18 changes: 18 additions & 0 deletions cdk_integration_tests/src/typescript/EFSEncryptionEnabled/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as efs from 'aws-cdk-lib/aws-efs';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
vpc: new ec2.Vpc(this, 'VPC'),
encrypted: true
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();
21 changes: 21 additions & 0 deletions cdk_integration_tests/src/typescript/EKSSecretsEncryption/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as cdk from 'aws-cdk-lib';
import {aws_eks as eks} from 'aws-cdk-lib';
import {Construct} from 'constructs';

export class exampleStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const cfnCluster = new eks.CfnCluster(this, 'MyCfnCluster', {
resourcesVpcConfig: {
subnetIds: ['subnetIds']
},
roleArn: 'roleArn',
name: 'name',
version: 'version'
});
}
}

const app = new cdk.App();
new exampleStack(app, 'example-stack');
app.synth();