Skip to content

Commit 015e856

Browse files
authored
fix: Fixed DLP Web Rule validation (#369)
* fix: Fixed DLP Web Rule validation
1 parent 4656294 commit 015e856

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## 3.0.4 (September, 6 2024)
4+
5+
### Notes
6+
7+
- Release date: **(September, 6 2024)**
8+
- Supported Terraform version: **v1.x**
9+
10+
### Bug Fixes
11+
12+
- [PR #369](https://github.com/zscaler/terraform-provider-zia/pull/369) - Fixed `zia_dlp_web_rules` validation function for the attribute `file_types`.
13+
314
## 3.0.3 (August, 26 2024)
415

516
### Notes

GNUmakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ test\:integration\:zscalertwo:
196196
build13: GOOS=$(shell go env GOOS)
197197
build13: GOARCH=$(shell go env GOARCH)
198198
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
199-
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/3.0.3/$(GOOS)_$(GOARCH)
199+
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/3.0.4/$(GOOS)_$(GOARCH)
200200
else
201-
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/3.0.3/$(GOOS)_$(GOARCH)
201+
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/3.0.4/$(GOOS)_$(GOARCH)
202202
endif
203203
build13: fmtcheck
204204
@echo "==> Installing plugin to $(DESTINATION)"
205205
@mkdir -p $(DESTINATION)
206-
go build -o $(DESTINATION)/terraform-provider-zia_v3.0.3
206+
go build -o $(DESTINATION)/terraform-provider-zia_v3.0.4
207207

208208
coverage: test
209209
@echo "✓ Opening coverage for unit tests ..."

docs/guides/release-notes.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ description: |-
1212
Track all ZIA Terraform provider's releases. New resources, features, and bug fixes will be tracked here.
1313

1414
---
15-
``Last updated: v3.0.3``
15+
``Last updated: v3.0.4``
1616

1717
---
1818

19+
## 3.0.4 (September, 6 2024)
20+
21+
### Notes
22+
23+
- Release date: **(September, 6 2024)**
24+
- Supported Terraform version: **v1.x**
25+
26+
### Bug Fixes
27+
28+
- [PR #369](https://github.com/zscaler/terraform-provider-zia/pull/369) - Fixed `zia_dlp_web_rules` validation function for the attribute `file_types`.
29+
1930
## 3.0.3 (August, 26 2024)
2031

2132
### Notes

docs/resources/zia_dlp_web_rules.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ The following arguments are supported:
179179

180180
* ~> Note: `ALL_OUTBOUND` file type is applicable only when the predefined DLP engine called `EXTERNAL` is used and when the attribute `without_content_inspection` is set to `false`.
181181

182-
* ~> Note: `ALL_OUTBOUND` file type cannot be used alongside any any other file type.
182+
* ~> Note: `ALL_OUTBOUND` file type cannot be used alongside any other file type.
183183

184-
* `severity` - (String) Indicates the severity selected for the DLP rule violation: Returned values are: `RULE_SEVERITY_HIGH`, `RULE_SEVERITY_MEDIUM`, `RULE_SEVERITY_LOW`, `RULE_SEVERITY_INFO`
184+
* `cloud_applications` - (Optional) The list of cloud applications to which the DLP policy rule must be applied.. For the complete list of supported file types refer to the [ZIA API documentation](https://help.zscaler.com/zia/data-loss-prevention#/webDlpRules-post)
185+
186+
* `severity` - (Optional) Indicates the severity selected for the DLP rule violation: Returned values are: `RULE_SEVERITY_HIGH`, `RULE_SEVERITY_MEDIUM`, `RULE_SEVERITY_LOW`, `RULE_SEVERITY_INFO`
185187

186188
* `user_risk_score_levels` (Optional) - Indicates the user risk score level selectedd for the DLP rule violation: Returned values are: `LOW`, `MEDIUM`, `HIGH`, `CRITICAL`
187189

zia/validator.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,64 @@ func validateOCRDlpWebRules(dlp dlp_web_rules.WebDLPRules) error {
570570
return nil
571571
}
572572

573+
func validateDLPRuleFileTypes(dlp dlp_web_rules.WebDLPRules) error {
574+
// Define allowed file types for both true and false states of `withoutContentInspection`
575+
allowedFileTypesWithoutInspection := []string{
576+
"FORM_DATA_POST", "DB", "JAVASCRIPT", "FOR", "MS_POWERPOINT", "TMP", "MATLAB_FILES", "NATVIS", "PNG", "SC", "RUBY_FILES",
577+
"CAB", "PERL_FILES", "APPLE_DOCUMENTS", "CSX", "POSTSCRIPT", "ZIP", "CATALOG", "BITMAP", "SCZIP", "BORLAND_CPP_FILES",
578+
"RAR", "SQL", "APPX", "NETMON", "MS_RTF", "PARASOLID", "INF", "ACCDB", "IGS", "HIGH_EFFICIENCY_IMAGE_FILES", "RPY",
579+
"OAB", "CER", "ENCRYPT", "MM", "DSP", "YAML_FILES", "CHEMDRAW_FILES", "HBS", "SCT", "PS2", "INI", "CERT", "SLDPRT",
580+
"ICS", "MS_EXCEL", "MS_MSG", "QLIKVIEW_FILES", "MS_MDB", "VISUAL_BASIC_SCRIPT", "MAKE_FILES", "BCP", "MS_CPP_FILES",
581+
"AAC", "COMPILED_HTML_HELP", "DB2", "SDB", "MS_PST", "JAVA_APPLET", "ADE", "COBOL", "AUTOCAD", "VSDX", "MS_WORD", "CP",
582+
"BGI", "DAT", "DER", "ASM", "TAR", "BASH_SCRIPTS", "MUI", "PYTHON", "TLB", "HIVE", "KEY", "IMG", "GIF", "STL", "STUFFIT",
583+
"INCLUDE_FILES", "TABLEAU_FILES", "XZ", "AU3", "PCAP", "DELPHI", "P12", "PHOTOSHOP", "TIFF", "FLASH", "TLI", "VISUAL_CPP_FILES",
584+
"EML_FILES", "GREENSHOT", "C_FILES", "JAVA_FILES", "MANIFEST", "NFM", "IFC", "VIRTUAL_HARD_DISK", "ISO", "LOG_FILES", "GZIP",
585+
"EXP", "FCL", "BZIP2", "DMD", "P7Z", "PRT", "NCB", "X1B", "DRAWIO", "XAML", "CML", "ASHX", "PGP", "PS3", "ACIS", "VISUAL_BASIC_FILES",
586+
"TXT", "DRV", "NLS", "F_FILES", "P7B", "JPEG", "TLH", "CSV", "POD", "SAS", "WINDOWS_META_FORMAT", "RSP", "KDBX", "WINDOWS_SCRIPT_FILES",
587+
"SCALA", "ONENOTE", "CGR", "BASIC_SOURCE_CODE", "MSC", "POWERSHELL", "PEM", "INTEGRATED_CIRCUIT_FILES", "GO_FILES", "PDF_DOCUMENT",
588+
"DBF", "JKS", "VDA", "RES_FILES", "A_FILE", "SHELL_SCRAP", "ALL_OUTBOUND",
589+
}
590+
591+
allowedFileTypesWithInspection := []string{
592+
"BASH_SCRIPTS", "FORM_DATA_POST", "PYTHON", "INCLUDE_FILES", "TABLEAU_FILES", "JAVASCRIPT", "AU3", "DELPHI", "FOR", "TIFF",
593+
"MS_POWERPOINT", "TLI", "MATLAB_FILES", "NATVIS", "PNG", "SC", "RUBY_FILES", "VISUAL_CPP_FILES", "EML_FILES", "PERL_FILES",
594+
"APPLE_DOCUMENTS", "CSX", "C_FILES", "JAVA_FILES", "BITMAP", "IFC", "LOG_FILES", "SCZIP", "BORLAND_CPP_FILES", "SQL",
595+
"MS_RTF", "INF", "ACCDB", "X1B", "XAML", "RPY", "VISUAL_BASIC_FILES", "DSP", "TXT", "F_FILES", "YAML_FILES", "JPEG", "TLH",
596+
"CSV", "POD", "SCT", "SAS", "RSP", "WINDOWS_SCRIPT_FILES", "SCALA", "MS_EXCEL", "MS_MSG", "MS_MDB", "BASIC_SOURCE_CODE",
597+
"MSC", "VISUAL_BASIC_SCRIPT", "POWERSHELL", "GO_FILES", "MAKE_FILES", "BCP", "PDF_DOCUMENT", "MS_CPP_FILES", "RES_FILES",
598+
"SHELL_SCRAP", "JAVA_APPLET", "COBOL", "VSDX", "MS_WORD", "DAT", "ASM", "ALL_OUTBOUND",
599+
}
600+
601+
// Check if `ALL_OUTBOUND` is selected and `withoutContentInspection` is false
602+
allOutboundSelected := contains(dlp.FileTypes, "ALL_OUTBOUND")
603+
if allOutboundSelected && !dlp.WithoutContentInspection {
604+
return fmt.Errorf("when file_type ALL_OUTBOUND is present, without_content_inspection must be true")
605+
}
606+
607+
// If ALL_OUTBOUND is selected and no other file types are present, allow it
608+
if allOutboundSelected && len(dlp.FileTypes) > 1 {
609+
return fmt.Errorf("cannot have other file types when ALL_OUTBOUND is selected")
610+
}
611+
612+
// Validate file types based on the `withoutContentInspection` flag
613+
var allowedFileTypes []string
614+
if dlp.WithoutContentInspection {
615+
allowedFileTypes = allowedFileTypesWithoutInspection
616+
} else {
617+
allowedFileTypes = allowedFileTypesWithInspection
618+
}
619+
620+
// Ensure all selected file types are in the allowed list
621+
for _, fileType := range dlp.FileTypes {
622+
if !contains(allowedFileTypes, fileType) {
623+
return fmt.Errorf("the file_type '%s' is not accepted when without_content_inspection is %v", fileType, dlp.WithoutContentInspection)
624+
}
625+
}
626+
627+
return nil
628+
}
629+
630+
/*
573631
func validateDLPRuleFileTypes(dlp dlp_web_rules.WebDLPRules) error {
574632
// New check: If FileTypes is not defined, WithoutContentInspection must be false
575633
if len(dlp.FileTypes) == 0 && dlp.WithoutContentInspection {
@@ -608,6 +666,7 @@ func validateDLPRuleFileTypes(dlp dlp_web_rules.WebDLPRules) error {
608666
609667
return nil
610668
}
669+
*/
611670

612671
func validateDeviceTrustLevels() schema.SchemaValidateDiagFunc {
613672
return func(i interface{}, path cty.Path) diag.Diagnostics {

0 commit comments

Comments
 (0)