UPT: align waf options
This commit is contained in:
parent
04a89ce234
commit
bab521e81a
5 changed files with 48 additions and 59 deletions
|
|
@ -31,13 +31,13 @@ var luaRestyWAFModes = map[string]bool{"ACTIVE": true, "INACTIVE": true, "SIMULA
|
|||
|
||||
// Config returns lua-resty-waf configuration for an Ingress rule
|
||||
type Config struct {
|
||||
Mode string `json:"mode"`
|
||||
Debug bool `json:"debug"`
|
||||
IgnoredRuleSets []string `json:"ignored-rulesets"`
|
||||
ExtraRulesetString string `json:"extra-ruleset-string"`
|
||||
Score int `json:"score"`
|
||||
AllowUnknownContent bool `json:"allow-unknown-content"`
|
||||
DisableMultipartBody bool `json:"disable-multipart-body"`
|
||||
Mode string `json:"mode"`
|
||||
Debug bool `json:"debug"`
|
||||
IgnoredRuleSets []string `json:"ignored-rulesets"`
|
||||
ExtraRulesetString string `json:"extra-ruleset-string"`
|
||||
ScoreThreshold int `json:"score-threshold"`
|
||||
AllowUnknownContentTypes bool `json:"allow-unknown-content-types"`
|
||||
ProcessMultipartBody bool `json:"process-multipart-body"`
|
||||
}
|
||||
|
||||
// Equal tests for equality between two Config types
|
||||
|
|
@ -60,13 +60,13 @@ func (e1 *Config) Equal(e2 *Config) bool {
|
|||
if e1.ExtraRulesetString != e2.ExtraRulesetString {
|
||||
return false
|
||||
}
|
||||
if e1.Score != e2.Score {
|
||||
if e1.ScoreThreshold != e2.ScoreThreshold {
|
||||
return false
|
||||
}
|
||||
if e1.AllowUnknownContent != e2.AllowUnknownContent {
|
||||
if e1.AllowUnknownContentTypes != e2.AllowUnknownContentTypes {
|
||||
return false
|
||||
}
|
||||
if e1.DisableMultipartBody != e2.DisableMultipartBody {
|
||||
if e1.ProcessMultipartBody != e2.ProcessMultipartBody {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -107,19 +107,19 @@ func (a luarestywaf) Parse(ing *extensions.Ingress) (interface{}, error) {
|
|||
// TODO(elvinefendi) maybe validate the ruleset string here
|
||||
extraRulesetString, _ := parser.GetStringAnnotation("lua-resty-waf-extra-rules", ing)
|
||||
|
||||
score, _ := parser.GetIntAnnotation("lua-resty-waf-score", ing)
|
||||
scoreThreshold, _ := parser.GetIntAnnotation("lua-resty-waf-score-threshold", ing)
|
||||
|
||||
allowUnknownContent, _ := parser.GetBoolAnnotation("lua-resty-waf-allow-unknown-content", ing)
|
||||
allowUnknownContentTypes, _ := parser.GetBoolAnnotation("lua-resty-waf-allow-unknown-content-types", ing)
|
||||
|
||||
disableMultipartBody, _ := parser.GetBoolAnnotation("lua-resty-waf-disable-multipart-body", ing)
|
||||
processMultipartBody, _ := parser.GetBoolAnnotation("lua-resty-waf-process-multipart-body", ing)
|
||||
|
||||
return &Config{
|
||||
Mode: mode,
|
||||
Debug: debug,
|
||||
IgnoredRuleSets: ignoredRuleSets,
|
||||
ExtraRulesetString: extraRulesetString,
|
||||
Score: score,
|
||||
AllowUnknownContent: allowUnknownContent,
|
||||
DisableMultipartBody: disableMultipartBody,
|
||||
Mode: mode,
|
||||
Debug: debug,
|
||||
IgnoredRuleSets: ignoredRuleSets,
|
||||
ExtraRulesetString: extraRulesetString,
|
||||
ScoreThreshold: scoreThreshold,
|
||||
AllowUnknownContentTypes: allowUnknownContentTypes,
|
||||
ProcessMultipartBody: processMultipartBody,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ func TestParse(t *testing.T) {
|
|||
luaRestyWAFAnnotation := parser.GetAnnotationWithPrefix("lua-resty-waf")
|
||||
luaRestyWAFDebugAnnotation := parser.GetAnnotationWithPrefix("lua-resty-waf-debug")
|
||||
luaRestyWAFIgnoredRuleSetsAnnotation := parser.GetAnnotationWithPrefix("lua-resty-waf-ignore-rulesets")
|
||||
luaRestyWAFScoreAnnotation := parser.GetAnnotationWithPrefix("lua-resty-waf-score")
|
||||
luaRestyWAFAllowUnknownAnnotation := parser.GetAnnotationWithPrefix("lua-resty-waf-allow-unknown-content")
|
||||
luaRestyWAFDisableMultipartBody := parser.GetAnnotationWithPrefix("lua-resty-waf-disable-multipart-body")
|
||||
luaRestyWAFScoreThresholdAnnotation := parser.GetAnnotationWithPrefix("lua-resty-waf-score-threshold")
|
||||
luaRestyWAFAllowUnknownContentTypesAnnotation := parser.GetAnnotationWithPrefix("lua-resty-waf-allow-unknown-content-types")
|
||||
luaRestyWAFProcessMultipartBody := parser.GetAnnotationWithPrefix("lua-resty-waf-process-multipart-body")
|
||||
|
||||
ap := NewParser(&resolver.Mock{})
|
||||
if ap == nil {
|
||||
|
|
@ -54,17 +54,17 @@ func TestParse(t *testing.T) {
|
|||
{map[string]string{luaRestyWAFAnnotation: "inactive", luaRestyWAFDebugAnnotation: "true"}, &Config{Mode: "INACTIVE", Debug: true, IgnoredRuleSets: []string{}}},
|
||||
|
||||
{map[string]string{
|
||||
luaRestyWAFAnnotation: "active",
|
||||
luaRestyWAFDebugAnnotation: "true",
|
||||
luaRestyWAFIgnoredRuleSetsAnnotation: "ruleset1, ruleset2 ruleset3, another.ruleset",
|
||||
luaRestyWAFScoreAnnotation: "10",
|
||||
luaRestyWAFAllowUnknownAnnotation: "true"},
|
||||
&Config{Mode: "ACTIVE", Debug: true, IgnoredRuleSets: []string{"ruleset1", "ruleset2", "ruleset3", "another.ruleset"}, Score: 10, AllowUnknownContent: true}},
|
||||
luaRestyWAFAnnotation: "active",
|
||||
luaRestyWAFDebugAnnotation: "true",
|
||||
luaRestyWAFIgnoredRuleSetsAnnotation: "ruleset1, ruleset2 ruleset3, another.ruleset",
|
||||
luaRestyWAFScoreThresholdAnnotation: "10",
|
||||
luaRestyWAFAllowUnknownContentTypesAnnotation: "true"},
|
||||
&Config{Mode: "ACTIVE", Debug: true, IgnoredRuleSets: []string{"ruleset1", "ruleset2", "ruleset3", "another.ruleset"}, ScoreThreshold: 10, AllowUnknownContentTypes: true}},
|
||||
|
||||
{map[string]string{luaRestyWAFAnnotation: "siMulate", luaRestyWAFDebugAnnotation: "true"}, &Config{Mode: "SIMULATE", Debug: true, IgnoredRuleSets: []string{}}},
|
||||
{map[string]string{luaRestyWAFAnnotation: "siMulateX", luaRestyWAFDebugAnnotation: "true"}, &Config{Debug: false}},
|
||||
|
||||
{map[string]string{luaRestyWAFAnnotation: "active", luaRestyWAFDisableMultipartBody: "false"}, &Config{Mode: "ACTIVE", DisableMultipartBody: false, IgnoredRuleSets: []string{}}},
|
||||
{map[string]string{luaRestyWAFAnnotation: "active", luaRestyWAFProcessMultipartBody: "false"}, &Config{Mode: "ACTIVE", ProcessMultipartBody: false, IgnoredRuleSets: []string{}}},
|
||||
}
|
||||
|
||||
ing := &extensions.Ingress{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue