Skip to content

Commit 512d81b

Browse files
committed
feat: add rego policies
1 parent 8c96d7f commit 512d81b

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Description: Ensure that your AMIs are not older than 90 days.
2+
ID: aws_ec2_ami_not_older_than_90_days_rego
3+
IntegrationType:
4+
- aws_cloud_account
5+
Query:
6+
Engine: cloudql-rego
7+
ListOfTables:
8+
- aws_ec2_ami
9+
Parameters: []
10+
PrimaryTable: aws_ec2_ami
11+
RegoPolicies:
12+
- |
13+
package aws_ec2_ami_not_older_than_90_days_rego
14+
import future.keywords.in
15+
16+
# Define the result rule
17+
result[obj] {
18+
some ami in opencomply.aws_ec2_ami({})
19+
20+
# Populate the fields in the result object
21+
obj := {
22+
"resource": ami.image_id,
23+
"platform_integration_id": ami.platform_integration_id,
24+
"platform_resource_id": ami.platform_resource_id,
25+
"status": status(ami.creation_date),
26+
"reason": sprintf("%s created %s (%d days).", [
27+
ami.title,
28+
time.format(ami.creation_date),
29+
days_since_creation(ami.creation_date)
30+
])
31+
}
32+
}
33+
34+
# Determine the status based on the creation_date
35+
status(creation_date) = "ok" {
36+
creation_date >= time.now_ns() - (90 * 24 * 60 * 60 * 1e9) # 90 days in nanoseconds
37+
}
38+
status(creation_date) = "alarm" {
39+
creation_date < time.now_ns() - (90 * 24 * 60 * 60 * 1e9)
40+
}
41+
days_since_creation(creation_date) = days {
42+
now := time.now_ns()
43+
days := floor((now - creation_date) / (24 * 60 * 60 * 1e9)) # Convert nanoseconds to days
44+
}
45+
QueryToExecute: |
46+
data.aws_ec2_ami_not_older_than_90_days_rego.result
47+
Severity: low
48+
Tags: {}
49+
Title: Ensure Images (AMI) are not older than 90 days
50+
51+
52+
53+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Description: This control checks whether Classic Load Balancers have connection draining enabled.
2+
ID: aws_ec2_classic_lb_connection_draining_enabled_rego
3+
IntegrationType:
4+
- aws_cloud_account
5+
Query:
6+
Engine: cloudql-rego
7+
ListOfTables:
8+
- aws_ec2_classic_load_balancer
9+
Parameters: []
10+
PrimaryTable: aws_ec2_classic_load_balancer
11+
RegoPolicies:
12+
- |
13+
package aws_ec2_classic_lb_connection_draining_enabled_rego
14+
import future.keywords.in
15+
16+
status(lb) = "ok" {
17+
lb.connection_draining_enabled == true
18+
}
19+
status(lb) = "alarm" {
20+
lb.connection_draining_enabled == false
21+
}
22+
23+
reason(lb) = sprintf("%s connection draining enabled.", [lb.title]) {
24+
lb.connection_draining_enabled == true
25+
}
26+
reason(lb) = sprintf("%s connection draining disabled.", [lb.title]) {
27+
lb.connection_draining_enabled == false
28+
}
29+
30+
result[obj] {
31+
some lb in opencomply.aws_ec2_classic_load_balancer({})
32+
33+
obj = {
34+
"resource": lb.arn,
35+
"platform_integration_id": lb.platform_integration_id,
36+
"platform_resource_id": lb.platform_resource_id,
37+
"status": status(lb),
38+
"reason": reason(lb),
39+
"region": lb.region,
40+
"account_id": lb.account_id,
41+
}
42+
}
43+
QueryToExecute: |
44+
data.aws_ec2_classic_lb_connection_draining_enabled_rego.result
45+
Severity: medium
46+
Tags:
47+
aws_foundational_security:
48+
- "true"
49+
category:
50+
- Compliance
51+
foundational_security_category:
52+
- resilience
53+
foundational_security_item_id:
54+
- elb_7
55+
plugin:
56+
- aws
57+
service:
58+
- AWS/ELB
59+
Title: Classic Load Balancers should have connection draining enabled

0 commit comments

Comments
 (0)