Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing ap tests validation DOS override #2292

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions pkg/apis/configuration/validation/appprotect_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,29 @@ func ValidateRequiredFields(obj *unstructured.Unstructured, fieldsList [][]strin
return nil
}

var logDstEx = regexp.MustCompile(`(?:syslog:server=((?:\d{1,3}\.){3}\d{1,3}|localhost):\d{1,5})|stderr`)
var (
logDstEx = regexp.MustCompile(`(?:syslog:server=((?:\d{1,3}\.){3}\d{1,3}|localhost|[a-zA-Z0-9._-]+):\d{1,5})|stderr|(?:\/[\S]+)+`)
logDstFileEx = regexp.MustCompile(`(?:\/[\S]+)+`)
logDstFQDNEx = regexp.MustCompile(`(?:[a-zA-Z0-9_-]+\.)+[a-zA-Z0-9_-]+`)
)

// ValidateAppProtectLogDestination validates destination for log configuration
func ValidateAppProtectLogDestination(dstAntn string) error {
errormsg := "Error parsing App Protect Log config: Destination must follow format: syslog:server=<ip-address | localhost>:<port> or stderr"
errormsg := "Error parsing App Protect Log config: Destination must follow format: syslog:server=<ip-address | localhost>:<port> or fqdn or stderr or absolute path to file"
if !logDstEx.MatchString(dstAntn) {
return fmt.Errorf("%s Log Destination did not follow format", errormsg)
}
if dstAntn == "stderr" {
return nil
}

if logDstFileEx.MatchString(dstAntn) {
return nil
}

dstchunks := strings.Split(dstAntn, ":")

// // This error can be ignored since the regex check ensures this string will be parsable
// This error can be ignored since the regex check ensures this string will be parsable
port, _ := strconv.Atoi(dstchunks[2])

if port > 65535 || port < 1 {
Expand All @@ -64,8 +72,12 @@ func ValidateAppProtectLogDestination(dstAntn string) error {
return nil
}

if logDstFQDNEx.MatchString(ipstr) {
return nil
}

if net.ParseIP(ipstr) == nil {
return fmt.Errorf("Error parsing host: %v is not a valid ip address", ipstr)
return fmt.Errorf("Error parsing host: %v is not a valid ip address or host name", ipstr)
}

return nil
Expand Down
5 changes: 2 additions & 3 deletions pkg/apis/configuration/validation/appprotect_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,13 @@ func TestValidateRequiredSlices(t *testing.T) {

func TestValidateAppProtectLogDestinationAnnotation(t *testing.T) {
// Positive test cases
posDstAntns := []string{"stderr", "syslog:server=localhost:9000", "syslog:server=10.1.1.2:9000"}
posDstAntns := []string{"stderr", "syslog:server=localhost:9000", "syslog:server=10.1.1.2:9000", "/var/log/ap.log", "syslog:server=my-syslog-server.my-namespace:515"}

// Negative test cases item, expected error message
negDstAntns := [][]string{
{"stdout", "Log Destination did not follow format"},
{"syslog:server=localhost:99999", "not a valid port number"},
{"syslog:server=999.99.99.99:5678", "is not a valid ip address"},
{"/var/log/ap.log", "Error parsing App Protect Log config: Destination must follow format: syslog:server=<ip-address | localhost>:<port> or stderr"},
{"syslog:server=mysyslog-server:999", "not a valid ip address"},
}

for _, tCase := range posDstAntns {
Expand Down
6 changes: 3 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
CONTEXT =
BUILD_IMAGE = nginx/nginx-ingress:2.0.3-SNAPSHOT-61b2a91-dos
BUILD_IMAGE = nginx/nginx-ingress:edge
PULL_POLICY = IfNotPresent
DEPLOYMENT_TYPE = deployment
IC_TYPE = nginx-plus-ingress
IC_TYPE = nginx-ingress
SERVICE = nodeport
NODE_IP =
TAG = latest
PREFIX = test-runner
KUBE_CONFIG_FOLDER = $${HOME}/.kube
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
SHOW_IC_LOGS = no
PYTEST_ARGS = -m dos -v -s
PYTEST_ARGS =
DOCKERFILEPATH = docker/Dockerfile

.PHONY: build
Expand Down