Skip to content

Commit 37be913

Browse files
added ECS rules matching AWS SecurityHub
1 parent 5546916 commit 37be913

10 files changed

Lines changed: 224 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @name ECS clusters should use Container Insights
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/container-insights
6+
* @tags security
7+
* aws/ecs/12
8+
* NIST/800-53/AU-6(3)
9+
* NIST/800-53/AU-6(4)
10+
* NIST/800-53/CA-7
11+
* NIST/800-53/SI-2
12+
*/
13+
14+
import iac
15+
16+
from CloudFormation::ECSCluster cluster
17+
where not cluster.getContainerInsights().toString() = "'enabled'"
18+
select cluster, "ECS Cluster should have cluster settings enabled"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @name ECS Fargate services should run on the latest Fargate platform version
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/latest-version
6+
* @tags security
7+
* experimental
8+
* aws/ecs/10
9+
* NIST/800-53/SI-2
10+
* NIST/800-53/SI-2(2)
11+
* NIST/800-53/SI-2(4)
12+
* NIST/800-53/SI-2(5)
13+
* PCI-DSS/4.0.1
14+
* PCI-DSS/6.3.3
15+
*
16+
*/
17+
18+
// need to figure out how to make !Ref to be recognized, then and this should be possible to be used properly, used as "Experimental for now
19+
import iac
20+
from CloudFormation::ECSService ecs, CloudFormation::TaskDefinition td
21+
//where ecs.getPlatformVersion().toString() = ["'LATEST'", "'1.4.0'"] or ecs.getPlatformVersion().toString() = ["'LATEST'", "'1.0.0'"]
22+
//where td.getRuntimePlatform().toString() = "'LINUX'" or td.getRuntimePlatform().toString() = "'WINDOWS'"
23+
where
24+
((ecs.getPlatformVersion().toString() = ["'LATEST'", "'1.4.0'"] or not exists(ecs.getPlatformVersion()))
25+
and
26+
(td.getRuntimePlatform().toString() ="'LINUX'" or not exists(td.getRuntimePlatform())) )
27+
or
28+
((ecs.getPlatformVersion().toString() = ["'LATEST'", "'1.0.0'"] or not exists(ecs.getPlatformVersion()))
29+
and
30+
(exists(td.getRuntimePlatform()) and td.getRuntimePlatform().toString() !="'LINUX'"))
31+
32+
select td, "ContainerDefinitions must have a log configuration"
33+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @name ECS task definitions should have a logging configuration
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/log-configuration
6+
* @tags security
7+
* aws/ecs/9
8+
* NIST/800-53/AC-4(26)
9+
* NIST/800-53/AU-10
10+
* NIST/800-53/AU-12
11+
* NIST/800-53/AU-2
12+
* NIST/800-53/AU-3
13+
* NIST/800-53/AU-6(3)
14+
* NIST/800-53/AU-6(4)
15+
* NIST/800-53/CA-7
16+
* NIST/800-53/SC-7(9)
17+
* NIST/800-53/SI-7(8)
18+
*/
19+
20+
import iac
21+
22+
from CloudFormation::ContainerDefinition cd
23+
where not exists(cd.getLogConfiguration())
24+
select cd, "ContainerDefinitions must have a log configuration"
25+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @name Amazon ECS task definitions should have secure networking modes and user definitions.
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/networkmode
6+
* @tags security
7+
* experimental
8+
* /aws/config/ecs/1
9+
* /NIST/800-53/AC-2(1)
10+
* /NIST/800-53/AC-3
11+
* /NIST/800-53/AC-3(15)
12+
* /NIST/800-53/AC-3(7)
13+
* /NIST/800-53/AC-5
14+
* /NIST/800-53/AC-6
15+
*/
16+
17+
import iac
18+
19+
//Check for NetworkMode to not be host in taskdefinition, this is very much experimental -> Experimental
20+
from CloudFormation::ContainerDefinition cd, CloudFormation::TaskDefinition td
21+
where
22+
(cd.getUser().toString() = "'root'" or cd.getPrivileged() = "true") and
23+
td.getNetworkMode().toString() = "'host'"
24+
select td,
25+
"ContainerDefinitions must not run as root or be privileged when networkmode Host is used"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name ECS containers should run as non-privileged
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/non-priv
6+
* @tags security
7+
* aws/ecs/4
8+
* NIST/800-53/AC-2(1)
9+
* NIST/800-53/AC-3
10+
* NIST/800-53/AC-3(15)
11+
* NIST/800-53/AC-3(7)
12+
* NIST/800-53/AC-5
13+
* NIST/800-53/AC-6
14+
*/
15+
16+
import iac
17+
18+
from CloudFormation::ContainerDefinition cd
19+
where not cd.getPrivileged() = "false"
20+
select cd, "ContainerDefinitions must be explictly configured privileged mode to false"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @name ECS task definitions should not share the host's process namespace
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/pidmode
6+
* @tags security
7+
* aws/ecs/3
8+
* NIST/800-53/CA-9(1)
9+
* NIST/800-53/CM-2
10+
*/
11+
12+
import iac
13+
14+
from CloudFormation::TaskDefinition td
15+
where not td.getPidMode().toString() = "task"
16+
select td, "PidMode should be \"task\" for ECS tasks"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @name ECS task sets should not automatically assign public IP addresses
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/assignpublicip
6+
* @tags security
7+
* aws/ecs/2
8+
* NIST/800-53/AC-21
9+
* NIST/800-53/AC-3
10+
* NIST/800-53/AC-3(7)
11+
* NIST/800-53/AC-4
12+
* NIST/800-53/AC-4(21)
13+
* NIST/800-53/AC-6
14+
* NIST/800-53/SC-7
15+
* NIST/800-53/SC-7(11)
16+
* NIST/800-53/SC-7(16)
17+
* NIST/800-53/SC-7(20)
18+
* NIST/800-53/SC-7(21)
19+
* NIST/800-53/SC-7(3)
20+
* NIST/800-53/SC-7(4)
21+
* NIST/800-53/SC-7(9)
22+
* PCI-DSS/4.0.1
23+
* PCI-DSS/1.4.4
24+
*/
25+
26+
import iac
27+
28+
from CloudFormation::ECSNetworkConfiguration ecsnetwork
29+
where not ecsnetwork.getAssignPublicIp().toString() = ["'DISABLED'","DISABLED"]
30+
select ecsnetwork.getAssignPublicIp(), "AssignPublicIp should be \"DISABLED\" for ECS tasks"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @name ECS task sets should not automatically assign public IP addresses
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/assign-publicip-taskset
6+
* @tags security
7+
* cloudformation
8+
* aws/ecs/16
9+
* PCI-DSS/4.0.1
10+
* PCI-DSS/1.4.4
11+
*/
12+
13+
import iac
14+
15+
from CloudFormation::ECSTaskSet ts
16+
//where not ts.getAssignPublicIp().toString() = ["'DISABLED'","DISABLED"]
17+
select ts, "AssignPublicIp must be \"DISABLED\" for ECS tasks"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name ECS containers should be limited to read-only access to root filesystems
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/read-only-root-filesystem
6+
* @tags security
7+
* aws/ecs/5
8+
* NIST/800-53/AC-2(1)
9+
* NIST/800-53/AC-3
10+
* NIST/800-53/AC-3(15)
11+
* NIST/800-53/AC-3(7)
12+
* NIST/800-53/AC-5
13+
* NIST/800-53/AC-6
14+
*/
15+
16+
import iac
17+
18+
from CloudFormation::ContainerDefinition cd
19+
where not cd.getReadOnlyRootFilesystem() = "true"
20+
select cd, "Containers must have explictly only read only root filesystem"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Secrets should not be passed as container environment variables
3+
* @kind problem
4+
* @problem.severity warning
5+
* @id iac/ecs/secrets
6+
* @tags security
7+
* aws/ecs/8
8+
* NIST/800-53/AC-2(1)
9+
* NIST/800-53/AC-3
10+
* NIST/800-53/AC-3(15)
11+
* NIST/800-53/AC-3(7)
12+
* NIST/800-53/AC-5
13+
* NIST/800-53/AC-6
14+
*/
15+
16+
import iac
17+
18+
from CloudFormation::ContainerDefinition cd
19+
//where cd.getSecrets().getAChild().getAChild().toString() = ["'AWS_ACCESS_KEY_ID'", "'AWS_SECRET_ACCESS_KEY'", "'ECS_ENGINE_AUTH_DATA'"]
20+
select cd.getSecrets(), "Containers must not pass secret thorugh environment variables"

0 commit comments

Comments
 (0)