Skip to content

Commit eeaa409

Browse files
authored
SONARPY-1416: Modify S6330: Default Queue encryption is now SSE-SQS (#1546)
1 parent 49ef15b commit eeaa409

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

python-checks/src/main/java/org/sonar/python/checks/cdk/UnencryptedSqsQueueCheck.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,22 @@
2323
import org.sonar.plugins.python.api.SubscriptionContext;
2424
import org.sonar.plugins.python.api.tree.CallExpression;
2525

26-
import static org.sonar.python.checks.cdk.CdkPredicate.isFqn;
26+
import static org.sonar.python.checks.cdk.CdkPredicate.isFalse;
2727
import static org.sonar.python.checks.cdk.CdkPredicate.isNone;
2828
import static org.sonar.python.checks.cdk.CdkUtils.getArgument;
2929

3030
@Rule(key = "S6330")
3131
public class UnencryptedSqsQueueCheck extends AbstractCdkResourceCheck {
32-
private static final String UNENCRYPTED_MESSAGE = "Setting \"encryption\" to \"QueueEncryption.UNENCRYPTED\" disables SQS queues encryption. Make sure it is safe here.";
33-
private static final String NONE_MESSAGE = "Setting \"encryption\" to \"None\" disables SQS queues encryption. Make sure it is safe here.";
34-
private static final String OMITTING_MESSAGE = "Omitting \"encryption\" disables SQS queues encryption. Make sure it is safe here.";
32+
private static final String SQS_MANAGED_DISABLED_MESSAGE = "Setting \"sqs_managed_sse_enabled\" to \"false\" disables SQS queues encryption. Make sure it is safe here.";
3533
private static final String CFN_NONE_MESSAGE = "Setting \"kms_master_key_id\" to \"None\" disables SQS queues encryption. Make sure it is safe here.";
36-
private static final String CFN_OMITTING_MESSAGE = "Omitting \"kms_master_key_id\" disables SQS queues encryption. Make sure it is safe here.";
3734

3835
@Override
3936
protected void registerFqnConsumer() {
40-
checkFqn("aws_cdk.aws_sqs.Queue", this::checkQueue);
4137
checkFqn("aws_cdk.aws_sqs.CfnQueue", this::checkCfnQueue);
4238
}
4339

44-
protected void checkQueue(SubscriptionContext ctx, CallExpression resourceConstructor) {
45-
getArgument(ctx, resourceConstructor, "encryption").ifPresentOrElse(
46-
flow -> {
47-
flow.addIssueIf(isFqn("aws_cdk.aws_sqs.QueueEncryption.UNENCRYPTED"), UNENCRYPTED_MESSAGE);
48-
flow.addIssueIf(isNone(), NONE_MESSAGE);
49-
},
50-
() -> ctx.addIssue(resourceConstructor.callee(), OMITTING_MESSAGE)
51-
);
52-
}
53-
5440
protected void checkCfnQueue(SubscriptionContext ctx, CallExpression resourceConstructor) {
55-
getArgument(ctx, resourceConstructor, "kms_master_key_id").ifPresentOrElse(
56-
flow -> flow.addIssueIf(isNone(), CFN_NONE_MESSAGE),
57-
() -> ctx.addIssue(resourceConstructor.callee(), CFN_OMITTING_MESSAGE)
58-
);
41+
getArgument(ctx, resourceConstructor, "sqs_managed_sse_enabled")
42+
.ifPresent(flow -> flow.addIssueIf(isFalse(), SQS_MANAGED_DISABLED_MESSAGE));
5943
}
6044
}

python-checks/src/test/resources/checks/cdk/unencryptedSqsQueueCheck.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
22

33
# Success
44
customKey = my_key.key_id
5+
enabled_sqs = True
56
sqs.CfnQueue(self, "encrypted-selfmanaged", kms_master_key_id=my_key.key_id)
67
sqs.CfnQueue(self, "encrypted-selfmanaged", kms_master_key_id=customKey)
8+
sqs.CfnQueue(self, "encrypted", sqs_managed_sse_enabled=True)
9+
sqs.CfnQueue(self, "encrypted", sqs_managed_sse_enabled=enabled_sqs)
710

11+
sqs.CfnQueue(self, "unencrypted") # Compliant ref: SONARPY-1416
12+
13+
noneKey = None
14+
sqs.CfnQueue(self, "encrypted-selfmanaged", kms_master_key_id=None) # Compliant ref: SONARPY-1416
15+
sqs.CfnQueue(self, "encrypted-selfmanaged", kms_master_key_id=noneKey) # Compliant ref: SONARPY-1416
16+
817
encryptionParam = sqs.QueueEncryption.KMS
918
sqs.Queue(self, "encrypted-managed", encryption=sqs.QueueEncryption.KMS_MANAGED)
1019
sqs.Queue(self, "encrypted-managed", encryption=sqs.QueueEncryption.KMS)
1120
sqs.Queue(self, "encrypted-managed", encryption=encryptionParam)
1221

13-
# Failing cases
14-
noneKey = None
15-
sqs.CfnQueue(self, "unencrypted") # NonCompliant{{Omitting "kms_master_key_id" disables SQS queues encryption. Make sure it is safe here.}}
16-
sqs.CfnQueue(self, "encrypted-selfmanaged", kms_master_key_id=None) # NonCompliant{{Setting "kms_master_key_id" to "None" disables SQS queues encryption. Make sure it is safe here.}}
17-
sqs.CfnQueue(self, "encrypted-selfmanaged", kms_master_key_id=noneKey) # NonCompliant{{Setting "kms_master_key_id" to "None" disables SQS queues encryption. Make sure it is safe here.}}
18-
1922
encryptionNone = None
20-
sqs.Queue(self, "unencrypted-explicit") # NonCompliant {{Omitting "encryption" disables SQS queues encryption. Make sure it is safe here.}}
21-
sqs.Queue(self, "unencrypted-explicit", encryption=sqs.QueueEncryption.UNENCRYPTED) # NonCompliant {{Setting "encryption" to "QueueEncryption.UNENCRYPTED" disables SQS queues encryption. Make sure it is safe here.}}
22-
sqs.Queue(self, "unencrypted-explicit", encryption=None) # NonCompliant {{Setting "encryption" to "None" disables SQS queues encryption. Make sure it is safe here.}}
23-
sqs.Queue(self, "unencrypted-explicit", encryption=encryptionNone) # NonCompliant {{Setting "encryption" to "None" disables SQS queues encryption. Make sure it is safe here.}}
23+
sqs.Queue(self, "unencrypted-explicit") # Compliant ref: SONARPY-1416
24+
sqs.Queue(self, "unencrypted-explicit", encryption=sqs.QueueEncryption.UNENCRYPTED) # Compliant ref: SONARPY-1416
25+
sqs.Queue(self, "unencrypted-explicit", encryption=None) # Compliant ref: SONARPY-1416
26+
sqs.Queue(self, "unencrypted-explicit", encryption=encryptionNone) # Compliant ref: SONARPY-1416
27+
28+
# Failing cases
29+
not_enabled_sqs = False
30+
sqs.CfnQueue(self, "unencrypted", sqs_managed_sse_enabled=False) # NonCompliant{{Setting "sqs_managed_sse_enabled" to "false" disables SQS queues encryption. Make sure it is safe here.}}
31+
sqs.CfnQueue(self, "unencrypted", sqs_managed_sse_enabled=not_enabled_sqs) # NonCompliant{{Setting "sqs_managed_sse_enabled" to "false" disables SQS queues encryption. Make sure it is safe here.}}

0 commit comments

Comments
 (0)