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

Fix port range validation in cli arguments #1030

Merged
merged 1 commit into from
Jul 2, 2020
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
8 changes: 4 additions & 4 deletions cmd/nginx-ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var (
nginxStatusAllowCIDRs = flag.String("nginx-status-allow-cidrs", "127.0.0.1", `Whitelist IPv4 IP/CIDR blocks to allow access to NGINX stub_status or the NGINX Plus API. Separate multiple IP/CIDR by commas.`)

nginxStatusPort = flag.Int("nginx-status-port", 8080,
"Set the port where the NGINX stub_status or the NGINX Plus API is exposed. [1023 - 65535]")
"Set the port where the NGINX stub_status or the NGINX Plus API is exposed. [1024 - 65535]")

nginxStatus = flag.Bool("nginx-status", true,
"Enable the NGINX stub_status, or the NGINX Plus API.")
Expand All @@ -127,7 +127,7 @@ var (
"Enable exposing NGINX or NGINX Plus metrics in the Prometheus format")

prometheusMetricsListenPort = flag.Int("prometheus-metrics-listen-port", 9113,
"Set the port where the Prometheus metrics are exposed. [1023 - 65535]")
"Set the port where the Prometheus metrics are exposed. [1024 - 65535]")

enableCustomResources = flag.Bool("enable-custom-resources", true,
"Enable custom resources")
Expand Down Expand Up @@ -561,8 +561,8 @@ func validateResourceName(lock string) error {

// validatePort makes sure a given port is inside the valid port range for its usage
func validatePort(port int) error {
if port < 1023 || port > 65535 {
return fmt.Errorf("port outside of valid port range [1023 - 65535]: %v", port)
if port < 1024 || port > 65535 {
return fmt.Errorf("port outside of valid port range [1024 - 65535]: %v", port)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/nginx-ingress/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

func TestValidatePort(t *testing.T) {
badPorts := []int{80, 443, 1, 1022, 65536}
lucacome marked this conversation as resolved.
Show resolved Hide resolved
badPorts := []int{80, 443, 1, 1023, 65536}
for _, badPort := range badPorts {
err := validatePort(badPort)
if err == nil {
t.Errorf("Expected error for port %v\n", badPort)
}
}

goodPorts := []int{8080, 8081, 8082, 1023, 65535}
goodPorts := []int{8080, 8081, 8082, 1024, 65535}
for _, goodPort := range goodPorts {
err := validatePort(goodPort)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Below we describe the available command-line arguments:

Set the port where the NGINX stub_status or the NGINX Plus API is exposed.

Format: ``[1023 - 65535]`` (default 8080)
Format: ``[1024 - 65535]`` (default 8080)

.. option:: -proxy <string>

Expand Down Expand Up @@ -169,7 +169,7 @@ Below we describe the available command-line arguments:

Sets the port where the Prometheus metrics are exposed.

Format: ``[1023 - 65535]`` (default 9113)
Format: ``[1024 - 65535]`` (default 9113)

.. option:: -spire-agent-address <string>

Expand Down