Skip to content

Commit ad644e1

Browse files
committed
feat: update rego controls to policy format
1 parent a409b5c commit ad644e1

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

compliance/controls/aws/aws_ec2_ami_not_older_than_90_days_rego.yaml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,42 @@ integration_type:
55
- aws_cloud_account
66
parameters: []
77
policy:
8-
language: sql
8+
language: rego
99
primary_resource: aws_ec2_ami
10+
rego_policies:
11+
- |
12+
package aws_ec2_ami_not_older_than_90_days_rego
13+
import future.keywords.in
14+
15+
# Define the result rule
16+
result[obj] {
17+
some ami in opencomply.aws_ec2_ami({})
18+
19+
# Populate the fields in the result object
20+
obj := {
21+
"resource": ami.image_id,
22+
"platform_integration_id": ami.platform_integration_id,
23+
"platform_resource_id": ami.platform_resource_id,
24+
"status": status(ami.creation_date),
25+
"reason": sprintf("%s created %s (%d days).", [
26+
ami.title,
27+
time.format(ami.creation_date),
28+
days_since_creation(ami.creation_date)
29+
])
30+
}
31+
}
32+
33+
# Determine the status based on the creation_date
34+
status(creation_date) = "ok" {
35+
creation_date >= time.now_ns() - (90 * 24 * 60 * 60 * 1e9) # 90 days in nanoseconds
36+
}
37+
status(creation_date) = "alarm" {
38+
creation_date < time.now_ns() - (90 * 24 * 60 * 60 * 1e9)
39+
}
40+
days_since_creation(creation_date) = days {
41+
now := time.now_ns()
42+
days := floor((now - creation_date) / (24 * 60 * 60 * 1e9)) # Convert nanoseconds to days
43+
}
1044
definition: |
1145
data.aws_ec2_ami_not_older_than_90_days_rego.result
1246
severity: low

compliance/controls/aws/aws_ec2_classic_lb_connection_draining_enabled_rego.yaml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
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:
1+
id: aws_ec2_classic_lb_connection_draining_enabled_rego
2+
title: Classic Load Balancers should have connection draining enabled
3+
description: This control checks whether Classic Load Balancers have connection draining enabled.
4+
integration_type:
45
- 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:
6+
parameters: []
7+
policy:
8+
language: rego
9+
primary_resource: aws_ec2_classic_load_balancer
10+
rego_policies:
1211
- |
1312
package aws_ec2_classic_lb_connection_draining_enabled_rego
1413
import future.keywords.in
@@ -40,10 +39,10 @@ Query:
4039
"account_id": lb.account_id,
4140
}
4241
}
43-
QueryToExecute: |
42+
definition: |
4443
data.aws_ec2_classic_lb_connection_draining_enabled_rego.result
45-
Severity: medium
46-
Tags:
44+
severity: medium
45+
tags:
4746
aws_foundational_security:
4847
- "true"
4948
category:
@@ -56,4 +55,3 @@ Tags:
5655
- aws
5756
service:
5857
- AWS/ELB
59-
Title: Classic Load Balancers should have connection draining enabled

0 commit comments

Comments
 (0)