Skip to content

AWS CDK rules

Finds API Gateway methods and routes without authorization, such as a CfnMethod or CfnRoute without an authorizationType, or an addMethod call with AuthorizationType.NONE.

On in the recommended and all configs.

A method without authorization lets anyone on the internet call the API.

Set authorizationType to an authorizer, such as AuthorizationType.IAM or AuthorizationType.COGNITO, on the method or in defaultMethodOptions.

The call api.root.addMethod("GET", integration) reports omitted when the API has no default authorization. Pass { authorizationType: apigateway.AuthorizationType.IAM }.

Finds new efs.FileSystem constructions with encrypted: false, and new efs.CfnFileSystem constructions that leave out encrypted or do not set it to true.

On in the recommended and all configs.

An unencrypted file system exposes its files to anyone who gets a copy of its storage or backups.

Set encrypted: true, or leave it out of efs.FileSystem, whose default encrypts.

The construction new efs.FileSystem(this, "Files", { vpc, encrypted: false }) reports invalid. Remove encrypted: false.

Finds IAM policy statements that allow every action with *: new iam.PolicyStatement, iam.PolicyStatement.fromJson, and the statements of iam.PolicyDocument.fromJson.

On in the recommended and all configs.

A policy that allows every action gives far more power than any task needs, so a stolen credential can do anything.

List only the actions that the task needs, such as s3:GetObject.

The statement new iam.PolicyStatement({ actions: ["*"], resources: [bucket.bucketArn] }) reports allActions. Use actions: ["s3:GetObject"].

Finds IAM policy statements without principals or conditions that allow an action that can raise privileges, such as iam:PassRole or iam:AttachUserPolicy, on every resource or on every role, user, or group.

On in the recommended and all configs.

These actions on every resource let the holder of the policy give itself more permissions, up to full control of the account.

Remove the action, or limit resources to the specific roles, users, or groups that the task needs.

The statement new iam.PolicyStatement({ actions: ["iam:PassRole"], resources: ["*"] }) reports escalation. Use resources: [role.roleArn].

Finds IAM policy statements that allow any principal: new iam.StarPrincipal(), new iam.AnyPrincipal(), new iam.ArnPrincipal("*"), or a JSON Principal of * or { AWS: "*" }.

On in the recommended and all configs.

A policy that allows any principal lets every AWS account, and often anyone on the internet, use the resource.

Name the accounts, roles, or services that need access as principals.

The statement new iam.PolicyStatement({ principals: [new iam.AnyPrincipal()], actions, resources }) reports publicPrincipal. Use principals: [new iam.AccountPrincipal(accountId)].

Finds new s3.Bucket constructions that leave out enforceSSL or set it to false.

On in the recommended and all configs.

A bucket that accepts plain HTTP requests sends its objects and credentials in clear text over the network.

Set enforceSSL: true, so that the bucket policy denies requests without TLS.

The construction new s3.Bucket(this, "Assets") reports omitted. Use new s3.Bucket(this, "Assets", { enforceSSL: true }).

Finds AWS CDK security group rules that open the SSH port 22 or the RDP port 3389 to every IPv4 or IPv6 address: allowFrom, allowFromAnyIpv4, allowDefaultPortFrom, allowDefaultPortFromAnyIpv4, addIngressRule, CfnSecurityGroup, and CfnSecurityGroupIngress.

On in the recommended and all configs.

An administration port open to the internet invites password guessing and attacks on the service behind it.

Allow the port only from the addresses of trusted networks, or reach the hosts through a bastion or AWS Systems Manager.

The call group.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(22)) reports openRange. Use ec2.Peer.ipv4("203.0.113.0/24").

Finds OpenSearch and Elasticsearch domain constructions whose encryption at rest is missing or has enabled: false.

On in the recommended and all configs.

An unencrypted search domain exposes its indexed data to anyone who gets a copy of its storage or snapshots.

Set encryptionAtRest: { enabled: true }, or encryptionAtRestOptions: { enabled: true } for a CfnDomain.

The construction new opensearch.Domain(this, "Search", { version }) reports omitted. Add encryptionAtRest: { enabled: true }.

Finds S3 buckets and bucket deployments with a public accessControl (PUBLIC_READ, PUBLIC_READ_WRITE, or AUTHENTICATED_READ), buckets with publicReadAccess: true, and grantPublicAccess calls on buckets.

On in the recommended and all configs.

Public access lets anyone on the internet, or any AWS user, read or change the objects of the bucket.

Keep the default private access, and grant access to the roles that need it.

The construction new s3.Bucket(this, "Site", { publicReadAccess: true }) reports unrestricted. Serve the files through CloudFront with an origin access control instead.

Finds EC2 instances, RDS database instances, and DMS replication instances that a public subnet or a public IP address makes reachable from the internet.

On in the recommended and all configs.

A public network address exposes the instance to attacks from the whole internet.

Place the instance in a private subnet, and set publiclyAccessible or associatePublicIpAddress to false.

The construction new ec2.Instance(this, "Host", { vpc, vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC } }) reports publicNetwork. Use ec2.SubnetType.PRIVATE_WITH_EGRESS.

Finds RDS database and cluster constructions that leave out storageEncrypted or set it to false, unless a KMS key or alias passed as storageEncryptionKey turns the encryption on.

On in the recommended and all configs.

An unencrypted database exposes its data to anyone who gets a copy of its storage, snapshots, or backups.

Set storageEncrypted: true, or pass a KMS key as storageEncryptionKey.

The construction new rds.DatabaseInstance(this, "Db", { engine, vpc }) reports omitted. Add storageEncrypted: true.

Finds new s3.Bucket constructions that leave out versioned or set it to false.

On in the recommended and all configs.

Without versioning, a deleted or overwritten object is lost for good, by mistake or by an attacker.

Set versioned: true.

The construction new s3.Bucket(this, "Records") reports omitted. Use new s3.Bucket(this, "Records", { versioned: true }).

Finds new sns.Topic constructions without a masterKey and new sns.CfnTopic constructions without a kmsMasterKeyId.

On in the recommended and all configs.

Without a key, the messages of the topic are not encrypted at rest with a key that you control.

Set masterKey or kmsMasterKeyId to a KMS key.

The construction new sns.Topic(this, "Alerts") reports omitted. Use new sns.Topic(this, "Alerts", { masterKey: key }).

Finds new sqs.Queue constructions that leave out encryption or set it to QueueEncryption.UNENCRYPTED, and new sqs.CfnQueue constructions without a kmsMasterKeyId.

On in the recommended and all configs.

An unencrypted queue stores its messages in clear text at rest.

Set encryption to an encrypted mode, such as QueueEncryption.KMS_MANAGED, or set kmsMasterKeyId.

The construction new sqs.Queue(this, "Jobs") reports omitted. Use new sqs.Queue(this, "Jobs", { encryption: sqs.QueueEncryption.KMS_MANAGED }).

Finds new s3.Bucket constructions whose blockPublicAccess is BlockPublicAccess.BLOCK_ACLS_ONLY or a new BlockPublicAccess with blockPublicAcls, blockPublicPolicy, ignorePublicAcls, or restrictPublicBuckets set to false.

On in the recommended and all configs.

Without these blocks, an access list or a bucket policy can make the objects of the bucket public.

Use blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, or leave the option at its default.

The construction new s3.Bucket(this, "Data", { blockPublicAccess: s3.BlockPublicAccess.BLOCK_ACLS_ONLY }) reports aclsOnly. Use s3.BlockPublicAccess.BLOCK_ALL.

Finds new sagemaker.CfnNotebookInstance constructions without a kmsKeyId.

On in the recommended and all configs.

Without a KMS key, the storage volume of the notebook instance is not encrypted with a key that you control.

Set kmsKeyId to a KMS key.

The construction new sagemaker.CfnNotebookInstance(this, "Notebook", { instanceType, roleArn }) reports omitted. Add kmsKeyId: key.keyId.

Finds new ec2.Volume constructions that leave out encrypted or set it to false.

On in the recommended and all configs.

An unencrypted volume exposes its data to anyone who gets a copy of the disk or of its snapshots.

Set encrypted: true on the volume.

The construction new ec2.Volume(this, "Data", { availabilityZone, size }) reports omitted. Add encrypted: true.