Skip to content

Commit 2da870c

Browse files
committed
WAF policy resource, managed WAF rulesets data source, and waf_policy_id in build settings
1 parent 21490a9 commit 2da870c

37 files changed

+5941
-7
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/swagger_go.json
33
/.env
44
*.out
5+
/waf
56

67
*.dll
78
*.exe

Diff for: UPDATING_OPENAPI_JSON.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ This project uses a modified `openapi.json`. Please maintain these instructions
66

77
1. Take the latest `openapi-external.json` from [netlify/bitballoon-openapi](https://github.dev/netlify/bitballoon-openapi/blob/main/openapi-external.json).
88
1. Remove the billing_details property from the `Account` object (also from the `required` array).
9-
1. Fix the type of `Repo.base_rel_dir` to `boolean`.
109
1. Remove all required properties from the `Repo` object (manual builds).
1110
1. Remove the `domain` property from the `required` array of the `DnsZone` object.
1211
1. Remove the `values`, `scopes` and `is_secret` parameters from the `updateEnvVar` operation.
1312
1. Add a request body schema to the `updateEnvVar` operation, by copying it from an earlier version of the `openapi.json`.
1413
1. Remove `scopes` from the `required` array of the `updateEnvVar` operation request body.
1514
1. Remove `scopes` from the `required` array of the `EnvVar` object.
16-
1. Add a `package_path` property of type `string` to the `Repo` object.
17-
1. Add a `branch` property of type `string` to the `Repo` object.
1815
1. Add a `functions_region` property of type `string` to the `Site` object.
1916
1. Add a `cdp_enabled_contexts` property of type `array` of `string`s to the `Site` object.
2017
1. Add a `hud_enabled` property of type `boolean` to the `Site` object.
@@ -23,12 +20,11 @@ This project uses a modified `openapi.json`. Please maintain these instructions
2320
1. Change the type of `LogDrain.id` to `string`.
2421
1. Add the various `log_drains` paths from `bitballoon-openapi`'s `openapi.json` file.
2522
1. Remove the required properties from the `LogDrainServiceConfig` object.
26-
1. Add properties to the `LogDrainServiceConfig` object, by copying it from an earlier version of the `openapi.json`.
2723
1. Change the request body of the `Log Drains-update` operation to use the `LogDrain` object (copy from `Log Drains-create`).
2824
1. Add the various `firewall_rule_set` paths from `bitballoon-openapi`'s `openapi.json` file (NOTE: both site and account level).
2925
1. Replace the response body of the `getAccountFirewallRuleSet` operation to use the `SiteFirewallConfig` object.
3026
1. Replace the request body of the `updateAccountFirewallRuleSet` operation to use the `SiteFirewallConfig` object.
31-
1. Renamed the `unpublished_rules` and `published_rules` properties to `unpublished` and `published` in the `SiteFirewallConfig` object, also in the required properties array.
3227
1. Add a `rum_enabled` property of type `boolean` to the `Site` object.
3328
1. Add a `rum_enabled` property of type `boolean` to the `PartialSite` object.
3429
1. Add an `analytics_instance_id` property of type `string` to the `Site` object.
30+
1. Add the various WAF paths and schemas, by copying them from an earlier version of the `openapi.json`.

Diff for: docs/data-sources/managed_waf_rules.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "netlify_managed_waf_rules Data Source - netlify"
4+
subcategory: ""
5+
description: |-
6+
Netlify managed WAF rule sets. This should be used when defining a WAF policy (netlify_waf_policy).
7+
---
8+
9+
# netlify_managed_waf_rules (Data Source)
10+
11+
Netlify managed WAF rule sets. This should be used when defining a WAF policy (netlify_waf_policy).
12+
13+
## Example Usage
14+
15+
```terraform
16+
# Read-only definitions of all managed WAF rules available in Netlify.
17+
# The team ID is required to query the rules.
18+
data "netlify_managed_waf_rules" "example" {
19+
team_id = "6600abcdef1234567890abcd"
20+
}
21+
```
22+
23+
<!-- schema generated by tfplugindocs -->
24+
## Schema
25+
26+
### Required
27+
28+
- `team_id` (String)
29+
30+
### Read-Only
31+
32+
- `rule_sets` (Attributes Map) (see [below for nested schema](#nestedatt--rule_sets))
33+
34+
<a id="nestedatt--rule_sets"></a>
35+
### Nested Schema for `rule_sets`
36+
37+
Read-Only:
38+
39+
- `definition` (Attributes) (see [below for nested schema](#nestedatt--rule_sets--definition))
40+
- `rules` (Attributes List) (see [below for nested schema](#nestedatt--rule_sets--rules))
41+
42+
<a id="nestedatt--rule_sets--definition"></a>
43+
### Nested Schema for `rule_sets.definition`
44+
45+
Read-Only:
46+
47+
- `id` (String)
48+
- `type` (String)
49+
- `version` (String)
50+
51+
52+
<a id="nestedatt--rule_sets--rules"></a>
53+
### Nested Schema for `rule_sets.rules`
54+
55+
Read-Only:
56+
57+
- `category` (String)
58+
- `description` (String)
59+
- `id` (String)
60+
- `phase` (String)
61+
- `severity` (String) notice, warning, error, critical

Diff for: docs/resources/site_build_settings.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ resource "netlify_site_build_settings" "blog" {
4444
- `package_directory` (String)
4545
- `pretty_urls` (Boolean)
4646
- `stop_builds` (Boolean)
47+
- `waf_policy_id` (String) See more details in the netlify_waf_policy resource.
4748

4849
### Read-Only
4950

Diff for: docs/resources/waf_policy.md

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "netlify_waf_policy Resource - netlify"
4+
subcategory: ""
5+
description: |-
6+
Netlify Web Application Firewall (WAF) policy. Read more https://docs.netlify.com/security/secure-access-to-sites/web-application-firewall/
7+
---
8+
9+
# netlify_waf_policy (Resource)
10+
11+
Netlify Web Application Firewall (WAF) policy. [Read more](https://docs.netlify.com/security/secure-access-to-sites/web-application-firewall/)
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "netlify_waf_policy" "example" {
17+
team_id = data.netlify_team.team.id
18+
name = "Terraform Policy"
19+
description = "This is a test policy through Terraform"
20+
rule_sets = [
21+
{
22+
managed_id = "crs-basic",
23+
passive_mode = true,
24+
overall_threshold = 5,
25+
category_thresholds = {
26+
"fixation" = 8,
27+
},
28+
rule_overrides = {
29+
"920100" = {
30+
action = "log_only"
31+
}
32+
}
33+
}
34+
]
35+
}
36+
37+
# To use this policy in a site, use the netlify_site_build_settings resource:
38+
39+
resource "netlify_site_build_settings" "example" {
40+
# other attributes...
41+
waf_policy_id = netlify_waf_policy.example.id
42+
}
43+
44+
# To dynamically define the rule overrides, you can query netlify_managed_waf_rules to get the rule IDs:
45+
46+
data "netlify_managed_waf_rules" "example" {
47+
team_id = "6600abcdef1234567890abcd"
48+
}
49+
50+
resource "netlify_waf_policy" "example" {
51+
team_id = "66ae34e11a567e9092e3850f"
52+
name = "Terraform Policy"
53+
description = "This is a test policy through Terraform"
54+
rule_sets = [
55+
{
56+
managed_id = "crs-basic",
57+
passive_mode = true,
58+
overall_threshold = 5,
59+
rule_overrides = {
60+
for rule in data.netlify_managed_waf_rules.example.rule_sets["crs-basic"].rules : rule.id => {
61+
action = "log_only"
62+
} if rule.category == "rce"
63+
}
64+
}
65+
]
66+
}
67+
```
68+
69+
<!-- schema generated by tfplugindocs -->
70+
## Schema
71+
72+
### Required
73+
74+
- `description` (String)
75+
- `name` (String)
76+
- `rule_sets` (Attributes List) (see [below for nested schema](#nestedatt--rule_sets))
77+
- `team_id` (String)
78+
79+
### Read-Only
80+
81+
- `id` (String) The ID of this resource.
82+
- `last_updated` (String)
83+
84+
<a id="nestedatt--rule_sets"></a>
85+
### Nested Schema for `rule_sets`
86+
87+
Required:
88+
89+
- `managed_id` (String) The managed ID of the rule set. Currently, only crs-basic is supported.
90+
- `overall_threshold` (Number) Recommended default value is 5
91+
- `passive_mode` (Boolean)
92+
93+
Optional:
94+
95+
- `category_thresholds` (Map of Number) Thresholds for each category, e.g. fixation, injection-generic, injection-java, injection-php, lfi, protocol, rce, reputation-scanner, rfi, sqli, ssrf, xss
96+
- `excluded_patterns` (List of String)
97+
- `rule_overrides` (Attributes Map) (see [below for nested schema](#nestedatt--rule_sets--rule_overrides))
98+
99+
<a id="nestedatt--rule_sets--rule_overrides"></a>
100+
### Nested Schema for `rule_sets.rule_overrides`
101+
102+
Required:
103+
104+
- `action` (String) log_only or none
105+
106+
## Import
107+
108+
Import is supported using the following syntax:
109+
110+
```shell
111+
# Import a WAF policy by its team ID and the policy ID
112+
terraform import netlify_waf_policy.main 6600abcdef1234567890abcd:6600abcdef1234567890abcd
113+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Read-only definitions of all managed WAF rules available in Netlify.
2+
# The team ID is required to query the rules.
3+
data "netlify_managed_waf_rules" "example" {
4+
team_id = "6600abcdef1234567890abcd"
5+
}

Diff for: examples/resources/netlify_waf_policy/import.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Import a WAF policy by its team ID and the policy ID
2+
terraform import netlify_waf_policy.main 6600abcdef1234567890abcd:6600abcdef1234567890abcd

Diff for: examples/resources/netlify_waf_policy/resource.tf

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
resource "netlify_waf_policy" "example" {
2+
team_id = data.netlify_team.team.id
3+
name = "Terraform Policy"
4+
description = "This is a test policy through Terraform"
5+
rule_sets = [
6+
{
7+
managed_id = "crs-basic",
8+
passive_mode = true,
9+
overall_threshold = 5,
10+
category_thresholds = {
11+
"fixation" = 8,
12+
},
13+
rule_overrides = {
14+
"920100" = {
15+
action = "log_only"
16+
}
17+
}
18+
}
19+
]
20+
}
21+
22+
# To use this policy in a site, use the netlify_site_build_settings resource:
23+
24+
resource "netlify_site_build_settings" "example" {
25+
# other attributes...
26+
waf_policy_id = netlify_waf_policy.example.id
27+
}
28+
29+
# To dynamically define the rule overrides, you can query netlify_managed_waf_rules to get the rule IDs:
30+
31+
data "netlify_managed_waf_rules" "example" {
32+
team_id = "6600abcdef1234567890abcd"
33+
}
34+
35+
resource "netlify_waf_policy" "example" {
36+
team_id = "66ae34e11a567e9092e3850f"
37+
name = "Terraform Policy"
38+
description = "This is a test policy through Terraform"
39+
rule_sets = [
40+
{
41+
managed_id = "crs-basic",
42+
passive_mode = true,
43+
overall_threshold = 5,
44+
rule_overrides = {
45+
for rule in data.netlify_managed_waf_rules.example.rule_sets["crs-basic"].rules : rule.id => {
46+
action = "log_only"
47+
} if rule.category == "rce"
48+
}
49+
}
50+
]
51+
}

Diff for: internal/netlifyapi/.openapi-generator/FILES

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ api_sni_certificates.go
3030
api_snippets.go
3131
api_split_tests.go
3232
api_users.go
33+
api_waf_managed_rules.go
34+
api_waf_policies.go
3335
api_work_os_scim.go
3436
client.go
3537
configuration.go
@@ -156,6 +158,10 @@ model_key_value_target_config.go
156158
model_log_drain.go
157159
model_log_drain_service_config.go
158160
model_log_drains_verify_request.go
161+
model_managed_waf_rule_set.go
162+
model_managed_waf_rule_set_definition.go
163+
model_managed_waf_rule_set_rules_inner.go
164+
model_managed_waf_rules.go
159165
model_member.go
160166
model_member_committer_match_method.go
161167
model_mfa_confirmation.go
@@ -228,5 +234,9 @@ model_user_connected_accounts.go
228234
model_user_questionnaire_params.go
229235
model_user_signup.go
230236
model_value_target_config.go
237+
model_waf_policy.go
238+
model_waf_policy_rule_override.go
239+
model_waf_policy_rule_sets_inner.go
240+
model_waf_policy_update.go
231241
response.go
232242
utils.go

0 commit comments

Comments
 (0)