Skip to content

Commit a6cf62b

Browse files
committed
add rule and files for aws db snapshots should not be public
1 parent a6b4952 commit a6cf62b

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"id": "f0d8781f-1991-4958-9917-d39283b168a0",
3+
"queryName": "DB Snapshot Is Public",
4+
"severity": "HIGH",
5+
"category": "Access Control",
6+
"descriptionText": "The DB snapshot is public. This means that anyone can access the snapshot and restore the database. This can lead to unauthorized access to sensitive data.",
7+
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_snapshot#shared_accounts-1",
8+
"platform": "Terraform",
9+
"descriptionID": "f0d8781f",
10+
"cloudProvider": "aws",
11+
"cwe": "200"
12+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package Cx
2+
3+
import data.generic.terraform as tf_lib
4+
import data.generic.common as common_lib
5+
6+
CxPolicy[result] {
7+
resource := input.document[i].resource.aws_db_snapshot[name]
8+
common_lib.valid_key(resource, "shared_accounts")
9+
resource.shared_accounts[_] == "all"
10+
11+
result := {
12+
"documentId": input.document[i].id,
13+
"resourceType": "aws_db_snapshot",
14+
"resourceName": tf_lib.get_resource_name(resource, name),
15+
"searchKey": sprintf("aws_db_snapshot[{{%s}}].shared_accounts", [name]),
16+
"searchLine": common_lib.build_search_line(["resource", "aws_db_snapshot", name, "shared_accounts"], []),
17+
"issueType": "IncorrectValue",
18+
"keyExpectedValue": "aws_db_snapshot.shared_accounts should not include 'all'",
19+
"keyActualValue": "aws_db_snapshot.shared_accounts includes 'all'",
20+
"remediation": json.marshal({
21+
"before": "shared_accounts = [\"all\"]",
22+
"after": "shared_accounts = []"
23+
}),
24+
"remediationType": "replacement",
25+
}
26+
}
27+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "aws_db_snapshot" "private_snapshot" {
2+
db_snapshot_identifier = "private-db-snapshot"
3+
db_instance_identifier = "my-db-instance"
4+
shared_accounts = []
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resource "aws_db_snapshot" "private_snapshot" {
2+
db_snapshot_identifier = "private-db-snapshot"
3+
db_instance_identifier = "my-db-instance"
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "aws_db_snapshot" "public_snapshot" {
2+
db_snapshot_identifier = "public-db-snapshot"
3+
db_instance_identifier = "my-db-instance"
4+
shared_accounts = ["all"]
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"queryName": "DB Snapshot Is Public",
4+
"severity": "HIGH",
5+
"line": 4
6+
}
7+
]

0 commit comments

Comments
 (0)