Fix definition order of modsecurity directives
This commit is contained in:
parent
b33c9a21a5
commit
5390ce4879
3 changed files with 85 additions and 11 deletions
|
|
@ -1360,12 +1360,6 @@ func buildModSecurityForLocation(cfg config.Configuration, location *ingress.Loc
|
|||
|
||||
if !isMSEnabled {
|
||||
buffer.WriteString(`modsecurity on;
|
||||
modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf;
|
||||
`)
|
||||
}
|
||||
|
||||
if !cfg.EnableOWASPCoreRules && location.ModSecurity.OWASPRules {
|
||||
buffer.WriteString(`modsecurity_rules_file /etc/nginx/owasp-modsecurity-crs/nginx-modsecurity.conf;
|
||||
`)
|
||||
}
|
||||
|
||||
|
|
@ -1381,6 +1375,16 @@ modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf;
|
|||
`, location.ModSecurity.TransactionID))
|
||||
}
|
||||
|
||||
if !isMSEnabled {
|
||||
buffer.WriteString(`modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf;
|
||||
`)
|
||||
}
|
||||
|
||||
if !cfg.EnableOWASPCoreRules && location.ModSecurity.OWASPRules {
|
||||
buffer.WriteString(`modsecurity_rules_file /etc/nginx/owasp-modsecurity-crs/nginx-modsecurity.conf;
|
||||
`)
|
||||
}
|
||||
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1373,7 +1373,9 @@ func TestShouldLoadOpentracingModule(t *testing.T) {
|
|||
|
||||
func TestModSecurityForLocation(t *testing.T) {
|
||||
loadModule := `modsecurity on;
|
||||
modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf;
|
||||
`
|
||||
|
||||
modSecCfg := `modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf;
|
||||
`
|
||||
|
||||
modsecOff := "modsecurity off;"
|
||||
|
|
@ -1411,12 +1413,12 @@ modsecurity_rules_file /etc/nginx/modsecurity/modsecurity.conf;
|
|||
{"configmap enabled, configmap OWASP disabled, annotation enabled, OWASP enabled, no snippet and no transaction ID", true, false, true, true, true, "", "", owaspRules},
|
||||
{"configmap enabled, configmap OWASP disabled, annotation disabled, OWASP disabled, no snippet and no transaction ID", true, false, false, true, false, "", "", modsecOff},
|
||||
{"configmap enabled, configmap OWASP disabled, annotation enabled, OWASP enabled, with snippet and no transaction ID", true, false, true, true, true, "", "", owaspRules},
|
||||
{"configmap enabled, configmap OWASP disabled, annotation enabled, OWASP enabled, with snippet and transaction ID", true, false, true, true, true, "", transactionID, fmt.Sprintf("%v%v", owaspRules, transactionCfg)},
|
||||
{"configmap enabled, configmap OWASP disabled, annotation enabled, OWASP enabled, with snippet and transaction ID", true, false, true, true, true, "", transactionID, fmt.Sprintf("%v%v", transactionCfg, owaspRules)},
|
||||
{"configmap enabled, configmap OWASP enabled, annotation enabled, OWASP disabled", true, true, true, true, false, "", "", ""},
|
||||
{"configmap disabled, annotation enabled, OWASP disabled", false, false, true, true, false, "", "", loadModule},
|
||||
{"configmap disabled, annotation enabled, OWASP disabled", false, false, true, true, false, "", "", fmt.Sprintf("%v%v", loadModule, modSecCfg)},
|
||||
{"configmap disabled, annotation disabled, OWASP disabled", false, false, false, true, false, "", "", ""},
|
||||
{"configmap disabled, annotation enabled, OWASP disabled", false, false, true, true, false, testRule, "", fmt.Sprintf("%v%v", loadModule, modsecRule)},
|
||||
{"configmap disabled, annotation enabled, OWASP enabled", false, false, true, true, false, testRule, "", fmt.Sprintf("%v%v", loadModule, modsecRule)},
|
||||
{"configmap disabled, annotation enabled, OWASP disabled", false, false, true, true, false, testRule, "", fmt.Sprintf("%v%v%v", loadModule, modsecRule, modSecCfg)},
|
||||
{"configmap disabled, annotation enabled, OWASP enabled", false, false, true, true, false, testRule, "", fmt.Sprintf("%v%v%v", loadModule, modsecRule, modSecCfg)},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue