Skip to content

Commit 6151ae0

Browse files
fix(query): adding missing function_app resources to terraform/azure queries (#7744)
* added new resources to all 6 "function_app" queries * removed unnecessary '' and 'none' values from various queries
1 parent 4e29dca commit 6151ae0

File tree

54 files changed

+1160
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1160
-226
lines changed

assets/queries/cloudFormation/aws/iam_policy_allows_for_data_exfiltration/query.rego

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ CxPolicy[result] {
1717

1818
common_lib.is_allow_effect(statement)
1919
ilegal_action := is_ilegal(statement.Action)
20-
ilegal_action != "none"
2120

2221
result := {
2322
"documentId": input.document[i].id,
@@ -42,7 +41,6 @@ CxPolicy[result] {
4241

4342
common_lib.is_allow_effect(statement)
4443
ilegal_action := is_ilegal(statement.Action)
45-
ilegal_action != "none"
4644

4745
result := {
4846
"documentId": input.document[i].id,
@@ -67,4 +65,4 @@ is_ilegal(Action) = Action {
6765
]
6866
res := concat(", ", illegal_actions_list)
6967
res != ""
70-
} else = "none"
68+
}

assets/queries/terraform/aws/api_gateway_with_cloudwatch_logging_disabled/query.rego

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ get_results(resource,doc,name) = results {
2626
results := does_not_have_valid_stage_name(resource,doc,name)
2727
} else = results {
2828
r2 := does_not_have_valid_stage_name(resource,doc,name)
29-
r2 != ""
3029
results := does_not_have_valid_destination_arn(resource,doc,name)
3130
}
3231

assets/queries/terraform/aws/elb_v2_lb_access_log_disabled/query.rego

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import data.generic.terraform as tf_lib
55

66
CxPolicy[result] {
77
load_balancer := get_load_balancer(input.document[i].resource)
8-
load_balancer != ""
98
resource := input.document[i].resource[load_balancer][name]
109

1110
not common_lib.valid_key(resource, "access_logs")

assets/queries/terraform/aws/iam_policy_allows_for_data_exfiltration/query.rego

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ CxPolicy[result] { # resources
1414
statement := st[st_index]
1515
common_lib.is_allow_effect(statement)
1616
illegal_action := is_illegal(statement.Action)
17-
illegal_action != "none"
1817

1918
result := {
2019
"documentId": input.document[i].id,
@@ -38,7 +37,6 @@ CxPolicy[result] { # modules
3837
statement := st[st_index]
3938
common_lib.is_allow_effect(statement)
4039
illegal_action := is_illegal(statement.Action)
41-
illegal_action != "none"
4240

4341
result := {
4442
"documentId": input.document[i].id,
@@ -76,7 +74,6 @@ prepare_issue_data_source(statement, name, index, is_unique_element) = res {
7674
not is_unique_element
7775
common_lib.is_allow_effect(statement)
7876
illegal_action := is_illegal(statement.actions)
79-
illegal_action != "none"
8077

8178
res := {
8279
"sk": sprintf("aws_iam_policy_document[%s].statement[%d].actions", [name, index]),
@@ -89,7 +86,6 @@ prepare_issue_data_source(statement, name, index, is_unique_element) = res {
8986
is_unique_element
9087
common_lib.is_allow_effect(statement)
9188
illegal_action := is_illegal(statement.actions)
92-
illegal_action != "none"
9389

9490
res := {
9591
"sk": sprintf("aws_iam_policy_document[%s].statement.actions", [name]),
@@ -124,4 +120,4 @@ is_illegal(Action) = Action {
124120
]
125121
res := concat(", ", illegal_actions_list)
126122
res != ""
127-
} else = "none"
123+
}

assets/queries/terraform/aws/postgres_rds_logging_disabled/query.rego

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ CxPolicy[result] {
88
resource := input.document[i].resource.aws_db_parameter_group[name]
99

1010
undefined_parameters_message = get_undefined_parameters(resource)
11-
undefined_parameters_message != "none"
1211

1312
result := {
1413
"documentId": input.document[i].id,
@@ -70,7 +69,7 @@ get_undefined_parameters(resource) = "log_statement and log_min_duration_stateme
7069
not log_statement_defined(resource.parameter)
7170
} else = "log_min_duration_statement is" {
7271
not log_min_duration_statement_defined(resource.parameter)
73-
} else = "none"
72+
}
7473

7574
log_statement_defined(parameters) {
7675
parameters[_].name == "log_statement"
@@ -92,7 +91,7 @@ get_wrong_values(parameters) = "both"{
9291
} else = "log_min_duration_statement has" {
9392
parameters[i2].name == "log_min_duration_statement"
9493
parameters[i2].value != "1"
95-
} else = "none"
94+
}
9695

9796

9897
get_extra_path(statement,parameters) = path {

assets/queries/terraform/azure/app_service_not_using_latest_tls_encryption_version/query.rego

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ CxPolicy[result] { # 1.3 is the latest tls
3131
app := input.document[i].resource[types[t]][name]
3232

3333
results := minimum_tls_undefined_or_not_latest(app,types[t],name)
34-
results != ""
3534

3635
result := {
3736
"documentId": input.document[i].id,
@@ -87,4 +86,4 @@ minimum_tls_undefined_or_not_latest(app,type,name) = results {
8786
}),
8887
"remediationType" : "replacement",
8988
}
90-
} else = ""
89+
}

assets/queries/terraform/azure/azure_app_service_client_certificate_disabled/query.rego

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ CxPolicy[result] {
1010

1111
not resource.site_config.http2_enabled
1212
results := client_certificate_is_undefined_or_false(resource,name,types[t])
13-
results != ""
1413

1514
result := {
1615
"documentId": input.document[i].id,
@@ -74,7 +73,7 @@ client_certificate_is_undefined_or_false(resource,name,type) = results { # case
7473
}),
7574
"remediationType": "replacement",
7675
}
77-
} else = ""
76+
}
7877

7978
get_field("azurerm_app_service") = "client_cert_enabled"
8079
get_field("azurerm_linux_web_app") = "client_certificate_enabled"

assets/queries/terraform/azure/function_app_authentication_disabled/query.rego

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,94 @@ package Cx
33
import data.generic.common as common_lib
44
import data.generic.terraform as tf_lib
55

6+
types := {"azurerm_function_app", "azurerm_linux_function_app", "azurerm_windows_function_app"}
7+
68
CxPolicy[result] {
7-
function := input.document[i].resource.azurerm_function_app[name]
9+
doc := input.document[i]
10+
resource := doc.resource[types[t]][name]
811

9-
not common_lib.valid_key(function, "auth_settings")
12+
res := prepare_issues(resource, types[t], name)
1013

1114
result := {
12-
"documentId": input.document[i].id,
13-
"resourceType": "azurerm_function_app",
14-
"resourceName": tf_lib.get_resource_name(function, name),
15-
"searchKey": sprintf("azurerm_function_app[%s]", [name]),
16-
"issueType": "MissingAttribute",
17-
"keyExpectedValue": sprintf("'azurerm_function_app[%s].auth_settings' should be defined and not null", [name]),
18-
"keyActualValue": sprintf("'azurerm_function_app[%s].auth_settings' is undefined or null", [name]),
19-
"searchLine": common_lib.build_search_line(["resource", "azurerm_function_app", name], []),
20-
"remediation": "\nauth_settings {\n\t\tenabled = true\n\t}\n",
21-
"remediationType": "addition",
15+
"documentId": doc.id,
16+
"resourceType": types[t],
17+
"resourceName": tf_lib.get_resource_name(resource, name),
18+
"searchKey": res["sk"],
19+
"searchLine": res["sl"],
20+
"issueType": res["it"],
21+
"keyExpectedValue": res["kev"],
22+
"keyActualValue": res["kav"],
23+
"remediation": res["rem"],
24+
"remediationType": res["rt"],
2225
}
2326
}
2427

25-
CxPolicy[result] {
26-
function := input.document[i].resource.azurerm_function_app[name]
27-
28-
function.auth_settings.enabled != true
29-
30-
result := {
31-
"documentId": input.document[i].id,
32-
"resourceType": "azurerm_function_app",
33-
"resourceName": tf_lib.get_resource_name(function, name),
34-
"searchKey": sprintf("azurerm_function_app[%s].auth_settings.enabled", [name]),
35-
"issueType": "IncorrectValue",
36-
"keyExpectedValue": sprintf("'azurerm_function_app[%s].auth_settings.enabled' should be set to true", [name]),
37-
"keyActualValue": sprintf("'azurerm_function_app[%s].auth_settings.enabled' is not set to true", [name]),
38-
"searchLine": common_lib.build_search_line(["resource", "azurerm_function_app", name, "auth_settings", "enabled"], []),
39-
"remediation": json.marshal({
28+
prepare_issues(resource, type, name) = res { # auth_settings not defined for azurerm_function_app (legacy)
29+
not common_lib.valid_key(resource, "auth_settings")
30+
type == "azurerm_function_app"
31+
res := {
32+
"sk": sprintf("%s[%s]", [type, name]),
33+
"sl": common_lib.build_search_line(["resource", type, name], []),
34+
"it": "MissingAttribute",
35+
"kev": sprintf("'%s[%s].auth_settings' should be defined", [type, name]),
36+
"kav": sprintf("'%s[%s].auth_settings' is not defined", [type, name]),
37+
"rem": "auth_settings {\n\t\tenabled = true\n\t}",
38+
"rt": "addition",
39+
}
40+
} else = res{ # auth_settings and auth_settings_v2 not defined
41+
not common_lib.valid_key(resource, "auth_settings")
42+
not common_lib.valid_key(resource, "auth_settings_v2")
43+
res := {
44+
"sk": sprintf("%s[%s]", [type, name]),
45+
"sl": common_lib.build_search_line(["resource", type, name], []),
46+
"it": "MissingAttribute",
47+
"kev": sprintf("'%s[%s].auth_settings' or '%s[%s].auth_settings_v2' should be defined", [type, name, type, name]),
48+
"kav": sprintf("'%s[%s].auth_settings' and '%s[%s].auth_settings_v2' are not defined", [type, name, type, name]),
49+
"rem": "auth_settings {\n\t\tenabled = true\n\t}",
50+
"rt": "addition",
51+
}
52+
} else = res { # auth_settings field defined and auth_settings.enabled defined to false
53+
not common_lib.valid_key(resource, "auth_settings_v2")
54+
common_lib.valid_key(resource, "auth_settings")
55+
resource.auth_settings.enabled == false
56+
res := {
57+
"sk": sprintf("'%s[%s].auth_settings.enabled'", [type, name]),
58+
"sl": common_lib.build_search_line(["resource", type, name, "auth_settings", "enabled"], []),
59+
"it": "IncorrectValue",
60+
"kev": sprintf("'%s[%s].auth_settings.enabled' should be defined to 'true'", [type, name]),
61+
"kav": sprintf("'%s[%s].auth_settings.enabled' is defined to 'false'", [type, name]),
62+
"rem": json.marshal({
4063
"before": "false",
4164
"after": "true"
4265
}),
43-
"remediationType": "replacement",
66+
"rt": "replacement",
4467
}
45-
}
68+
} else = res { # auth_settings_v2 field defined with the field auth_enabled defined to false
69+
common_lib.valid_key(resource, "auth_settings_v2")
70+
common_lib.valid_key(resource.auth_settings_v2, "auth_enabled")
71+
resource.auth_settings_v2.auth_enabled == false
72+
res := {
73+
"sk": sprintf("%s[%s].auth_settings_v2.auth_enabled", [type, name]),
74+
"sl": common_lib.build_search_line(["resource", type, name, "auth_settings_v2", "auth_enabled"], []),
75+
"it": "IncorrectValue",
76+
"kev": sprintf("'%s[%s].auth_settings_v2.auth_enabled' should be defined to 'true'", [type, name]),
77+
"kav": sprintf("'%s[%s].auth_settings_v2.auth_enabled' is defined to 'false'", [type, name]),
78+
"rem": json.marshal({
79+
"before": "false",
80+
"after": "true"
81+
}),
82+
"rt": "replacement",
83+
}
84+
} else = res { # auth_settings_v2 field defined but without the field auth_enabled defined
85+
common_lib.valid_key(resource, "auth_settings_v2")
86+
not common_lib.valid_key(resource.auth_settings_v2, "auth_enabled")
87+
res := {
88+
"sk": sprintf("%s[%s].auth_settings_v2", [type, name]),
89+
"sl": common_lib.build_search_line(["resource", type, name, "auth_settings_v2"], []),
90+
"it": "MissingAttribute",
91+
"kev": sprintf("'%s[%s].auth_settings_v2.auth_enabled' should be defined (default value is 'false')", [type, name]),
92+
"kav": sprintf("'%s[%s].auth_settings_v2.auth_enabled' is not defined", [type, name]),
93+
"rem": "auth_enabled = true",
94+
"rt": "addition",
95+
}
96+
}

assets/queries/terraform/azure/function_app_authentication_disabled/test/negative.tf

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
resource "azurerm_function_app" "negative1" {
2+
name = "example-app-service"
3+
location = azurerm_resource_group.example.location
4+
resource_group_name = azurerm_resource_group.example.name
5+
app_service_plan_id = azurerm_app_service_plan.example.id
6+
7+
auth_settings {
8+
enabled = true
9+
}
10+
}
11+

0 commit comments

Comments
 (0)