Skip to content

Commit 0ef85c6

Browse files
authored
make host_groups & ioa_rule_groups required for prevention policies (#53)
* make host_groups and ioa_rule_groups required * update examples
1 parent 08864d1 commit 0ef85c6

File tree

11 files changed

+42
-31
lines changed

11 files changed

+42
-31
lines changed

docs/resources/prevention_policy_linux.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ resource "crowdstrike_prevention_policy_linux" "example" {
4040
enabled = true
4141
description = "made with terraform"
4242
host_groups = ["d6e3c1e1b3d0467da0fowc96a5e6ecb5"]
43-
ioa_rule_groups = ["ed334b3243bc4b6bb8e7d40a2ecd86fa"]
43+
ioa_rule_groups = []
4444
cloud_anti_malware = {
4545
"detection" = "MODERATE"
4646
"prevention" = "CAUTIOUS"
@@ -74,6 +74,8 @@ output "prevention_policy_linux" {
7474

7575
### Required
7676

77+
- `host_groups` (Set of String) Host Group ids to attach to the prevention policy.
78+
- `ioa_rule_groups` (Set of String) IOA Rule Group to attach to the prevention policy.
7779
- `name` (String) Name of the prevention policy.
7880

7981
### Optional
@@ -86,9 +88,7 @@ output "prevention_policy_linux" {
8688
- `enabled` (Boolean) Enable the prevention policy.
8789
- `filesystem_visibility` (Boolean) Whether to enable the setting. Allows the sensor to monitor filesystem activity for additional telemetry and improved detections.
8890
- `ftp_visibility` (Boolean) Whether to enable the setting. Allows the sensor to monitor unencrypted FTP traffic for malicious patterns and improved detections.
89-
- `host_groups` (Set of String) Host Group ids to attach to the prevention policy.
9091
- `http_visibility` (Boolean) Whether to enable the setting. Allows the sensor to monitor unencrypted HTTP traffic for malicious patterns and improved detections.
91-
- `ioa_rule_groups` (Set of String) IOA Rule Group to attach to the prevention policy.
9292
- `network_visibility` (Boolean) Whether to enable the setting. Allows the sensor to monitor network activity for additional telemetry and improved detections.
9393
- `prevent_suspicious_processes` (Boolean) Whether to enable the setting. Block processes that CrowdStrike analysts classify as suspicious. These are focused on dynamic IOAs, such as malware, exploits and other threats.
9494
- `quarantine` (Boolean) Whether to enable the setting. Quarantine executable files after they’re prevented by NGAV. When this is enabled, we recommend setting anti-malware prevention levels to Moderate or higher and not using other antivirus solutions.

docs/resources/prevention_policy_mac.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ resource "crowdstrike_prevention_policy_mac" "example" {
4040
enabled = false
4141
description = "made with terraform"
4242
host_groups = ["d6e3c1e1b3d0467da0fowc96a5e6ecb5"]
43-
ioa_rule_groups = ["ed334b3243bc4b6bb8e7d40a2ecd86fa"]
43+
ioa_rule_groups = []
4444
cloud_adware_and_pup = {
4545
"detection" = "MODERATE"
4646
"prevention" = "CAUTIOUS"
@@ -85,6 +85,8 @@ output "prevention_policy_mac" {
8585

8686
### Required
8787

88+
- `host_groups` (Set of String) Host Group ids to attach to the prevention policy.
89+
- `ioa_rule_groups` (Set of String) IOA Rule Group to attach to the prevention policy.
8890
- `name` (String) Name of the prevention policy.
8991

9092
### Optional
@@ -98,9 +100,7 @@ output "prevention_policy_mac" {
98100
- `empyre_backdoor` (Boolean) Whether to enable the setting. A process with behaviors indicative of the Empyre Backdoor was terminated.
99101
- `enabled` (Boolean) Enable the prevention policy.
100102
- `hash_collector` (Boolean) Whether to enable the setting. An attempt to dump a user’s hashed password was blocked.
101-
- `host_groups` (Set of String) Host Group ids to attach to the prevention policy.
102103
- `intelligence_sourced_threats` (Boolean) Whether to enable the setting. Block processes that CrowdStrike Intelligence analysts classify as malicious. These are focused on static hash-based IOCs.
103-
- `ioa_rule_groups` (Set of String) IOA Rule Group to attach to the prevention policy.
104104
- `kc_password_decoded` (Boolean) Whether to enable the setting. An attempt to recover a plaintext password via the kcpassword file was blocked.
105105
- `notify_end_users` (Boolean) Whether to enable the setting. Show a pop-up notification to the end user when the Falcon sensor blocks, kills, or quarantines. See these messages in Console.app by searching for Process: Falcon Notifications.
106106
- `prevent_suspicious_processes` (Boolean) Whether to enable the setting. Block processes that CrowdStrike analysts classify as suspicious. These are focused on dynamic IOAs, such as malware, exploits and other threats.

docs/resources/prevention_policy_windows.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ resource "crowdstrike_prevention_policy_windows" "example" {
4040
enabled = false
4141
description = "made with terraform"
4242
host_groups = ["d6e3c1e1b3d0467da0fowc96a5e6ecb5"]
43-
ioa_rule_groups = ["ed334b3243bc4b6bb8e7d40a2ecd86fa"]
43+
ioa_rule_groups = []
4444
adware_and_pup = {
4545
"detection" = "MODERATE"
4646
"prevention" = "CAUTIOUS"
@@ -130,6 +130,8 @@ output "prevention_policy_windows" {
130130

131131
### Required
132132

133+
- `host_groups` (Set of String) Host Group ids to attach to the prevention policy.
134+
- `ioa_rule_groups` (Set of String) IOA Rule Group to attach to the prevention policy.
133135
- `name` (String) Name of the prevention policy.
134136

135137
### Optional
@@ -163,11 +165,9 @@ output "prevention_policy_windows" {
163165
- `force_dep` (Boolean) Whether to enable the setting. A process that had Force Data Execution Prevention (Force DEP) applied tried to execute non-executable memory and was blocked. Requires additional_user_mode_data to be enabled.
164166
- `hardware_enhanced_exploit_detection` (Boolean) Whether to enable the setting. Provides additional visibility into application exploits by using CPU hardware features that detect suspicious control flows. Available only for hosts running Windows 10 (RS4) or Windows Server 2016 Version 1803 or later and Skylake or later CPU.
165167
- `heap_spray_preallocation` (Boolean) Whether to enable the setting. A heap spray attempt was detected and blocked. This may have been part of an attempted exploit. Requires additional_user_mode_data to be enabled.
166-
- `host_groups` (Set of String) Host Group ids to attach to the prevention policy.
167168
- `http_detections` (Boolean) Whether to enable the setting. Allows the sensor to monitor unencrypted HTTP traffic and certain encrypted HTTPS traffic on the sensor for malicious patterns and generate detection events on non-Server systems.
168169
- `intelligence_sourced_threats` (Boolean) Whether to enable the setting. Block processes that CrowdStrike Intelligence analysts classify as malicious. These are focused on static hash-based IOCs.
169170
- `interpreter_only` (Boolean) Whether to enable the setting. Provides visibility into malicious PowerShell interpreter usage. For hosts running Windows 10, Script-Based Execution Monitoring may be used instead.
170-
- `ioa_rule_groups` (Set of String) IOA Rule Group to attach to the prevention policy.
171171
- `javascript_via_rundll32` (Boolean) Whether to enable the setting. JavaScript executing from a command line via rundll32.exe was prevented.
172172
- `locky` (Boolean) Whether to enable the setting. A process determined to be associated with Locky was blocked.
173173
- `memory_scanning` (Boolean) Whether to enable the setting. Provides visibility into in-memory attacks by scanning for suspicious artifacts on hosts with the following: an integrated GPU and supporting OS libraries, Windows 10 v1607 (RS1) or later, and a Skylake or newer Intel CPU.

examples/resources/crowdstrike_prevention_policy_linux/resource.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resource "crowdstrike_prevention_policy_linux" "example" {
1616
enabled = true
1717
description = "made with terraform"
1818
host_groups = ["d6e3c1e1b3d0467da0fowc96a5e6ecb5"]
19-
ioa_rule_groups = ["ed334b3243bc4b6bb8e7d40a2ecd86fa"]
19+
ioa_rule_groups = []
2020
cloud_anti_malware = {
2121
"detection" = "MODERATE"
2222
"prevention" = "CAUTIOUS"

examples/resources/crowdstrike_prevention_policy_mac/resource.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resource "crowdstrike_prevention_policy_mac" "example" {
1616
enabled = false
1717
description = "made with terraform"
1818
host_groups = ["d6e3c1e1b3d0467da0fowc96a5e6ecb5"]
19-
ioa_rule_groups = ["ed334b3243bc4b6bb8e7d40a2ecd86fa"]
19+
ioa_rule_groups = []
2020
cloud_adware_and_pup = {
2121
"detection" = "MODERATE"
2222
"prevention" = "CAUTIOUS"

examples/resources/crowdstrike_prevention_policy_windows/resource.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resource "crowdstrike_prevention_policy_windows" "example" {
1616
enabled = false
1717
description = "made with terraform"
1818
host_groups = ["d6e3c1e1b3d0467da0fowc96a5e6ecb5"]
19-
ioa_rule_groups = ["ed334b3243bc4b6bb8e7d40a2ecd86fa"]
19+
ioa_rule_groups = []
2020
adware_and_pup = {
2121
"detection" = "MODERATE"
2222
"prevention" = "CAUTIOUS"

internal/prevention_policy/linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ func (r *preventionPolicyLinuxResource) Schema(
132132
Default: booldefault.StaticBool(true),
133133
},
134134
"host_groups": schema.SetAttribute{
135-
Optional: true,
135+
Required: true,
136136
ElementType: types.StringType,
137137
Description: "Host Group ids to attach to the prevention policy.",
138138
},
139139
"ioa_rule_groups": schema.SetAttribute{
140-
Optional: true,
140+
Required: true,
141141
ElementType: types.StringType,
142142
Description: "IOA Rule Group to attach to the prevention policy.",
143143
},

internal/prevention_policy/mac.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ func (r *preventionPolicyMacResource) Schema(
137137
Default: booldefault.StaticBool(true),
138138
},
139139
"host_groups": schema.SetAttribute{
140-
Optional: true,
140+
Required: true,
141141
ElementType: types.StringType,
142142
Description: "Host Group ids to attach to the prevention policy.",
143143
},
144144
"ioa_rule_groups": schema.SetAttribute{
145-
Optional: true,
145+
Required: true,
146146
ElementType: types.StringType,
147147
Description: "IOA Rule Group to attach to the prevention policy.",
148148
},

internal/prevention_policy/windows.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ func (r *preventionPolicyWindowsResource) Schema(
174174
Default: booldefault.StaticBool(true),
175175
},
176176
"host_groups": schema.SetAttribute{
177-
Optional: true,
177+
Required: true,
178178
ElementType: types.StringType,
179179
Description: "Host Group ids to attach to the prevention policy.",
180180
},
181181
"ioa_rule_groups": schema.SetAttribute{
182-
Optional: true,
182+
Required: true,
183183
ElementType: types.StringType,
184184
Description: "IOA Rule Group to attach to the prevention policy.",
185185
},

internal/prevention_policy/windows_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ func testAccPreventionPolicyWindowsConfig_basic(rName string, enabled bool) stri
1515
resource "crowdstrike_prevention_policy_windows" "test" {
1616
name = "%s"
1717
enabled = %t
18+
host_groups = []
19+
ioa_rule_groups = []
1820
description = "made with terraform"
1921
additional_user_mode_data = true
2022
cloud_anti_malware_microsoft_office_files = {

internal/utils/utils.go

+22-13
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,45 @@ func SetIDsToModify(
1515
ctx context.Context,
1616
plan, state types.Set,
1717
) (idsToAdd []string, idsToRemove []string, diags diag.Diagnostics) {
18-
var planIDs, stateIDs []string
18+
var planIDs, stateIDs []types.String
1919
planMap := make(map[string]bool)
2020
stateMap := make(map[string]bool)
2121

22-
diags.Append(plan.ElementsAs(ctx, &planIDs, false)...)
23-
if diags.HasError() {
24-
return
22+
if !plan.IsUnknown() && !plan.IsNull() {
23+
diags.Append(plan.ElementsAs(ctx, &planIDs, false)...)
24+
if diags.HasError() {
25+
return
26+
}
2527
}
26-
diags.Append(state.ElementsAs(ctx, &stateIDs, false)...)
27-
if diags.HasError() {
28-
return
28+
29+
if !state.IsUnknown() && !state.IsNull() {
30+
diags.Append(state.ElementsAs(ctx, &stateIDs, false)...)
31+
if diags.HasError() {
32+
return
33+
}
2934
}
3035

3136
for _, id := range planIDs {
32-
planMap[id] = true
37+
if !id.IsUnknown() && !id.IsNull() {
38+
planMap[id.ValueString()] = true
39+
}
3340
}
3441

3542
for _, id := range stateIDs {
36-
stateMap[id] = true
43+
if !id.IsUnknown() && !id.IsNull() {
44+
stateMap[id.ValueString()] = true
45+
}
3746
}
3847

3948
for _, id := range planIDs {
40-
if !stateMap[id] {
41-
idsToAdd = append(idsToAdd, id)
49+
if !stateMap[id.ValueString()] {
50+
idsToAdd = append(idsToAdd, id.ValueString())
4251
}
4352
}
4453

4554
for _, id := range stateIDs {
46-
if !planMap[id] {
47-
idsToRemove = append(idsToRemove, id)
55+
if !planMap[id.ValueString()] {
56+
idsToRemove = append(idsToRemove, id.ValueString())
4857
}
4958
}
5059

0 commit comments

Comments
 (0)