Skip to content

Commit

Permalink
Add websocket protocol option to monitor directive (#3442)
Browse files Browse the repository at this point in the history
* Add websocket protocol option to monitor directive

* fix golint

Co-authored-by: Venktesh Shivam Patel <[email protected]>
  • Loading branch information
pasmant and vepatel authored Jan 19, 2023
1 parent d51a554 commit b92ac45
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ spec:
type: object
properties:
protocol:
description: Protocol determines if the server listens on http1 / http2 / grpc. The default is http1.
description: Protocol determines if the server listens on http1 / http2 / grpc / websocket. The default is http1.
type: string
enum:
- http1
- http2
- grpc
- websocket
timeout:
description: Timeout determines how long (in seconds) should NGINX App Protect DoS wait for a response. Default is 10 seconds for http1/http2 and 5 seconds for grpc.
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ spec:
type: object
properties:
protocol:
description: Protocol determines if the server listens on http1 / http2 / grpc. The default is http1.
description: Protocol determines if the server listens on http1 / http2 / grpc / websocket. The default is http1.
type: string
enum:
- http1
- http2
- grpc
- websocket
timeout:
description: Timeout determines how long (in seconds) should NGINX App Protect DoS wait for a response. Default is 10 seconds for http1/http2 and 5 seconds for grpc.
type: integer
Expand Down
2 changes: 1 addition & 1 deletion docs/content/app-protect-dos/dos-protected.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec:
|``enable`` | Enables NGINX App Protect DoS. | ``bool`` | No |
|``name`` | Name of the protected object, max of 63 characters. | ``string`` | No |
|``apDosMonitor.uri`` | The destination to the desired protected object. [App Protect DoS monitor](#dosprotectedresourceapdosmonitor) Default value: None, URL will be extracted from the first request which arrives and taken from "Host" header or from destination ip+port. | ``string`` | No |
|``apDosMonitor.protocol`` | Determines if the server listens on http1 / http2 / grpc. [App Protect DoS monitor](#dosprotectedresourceapdosmonitor) Default value: http1. | ``enum`` | No |
|``apDosMonitor.protocol`` | Determines if the server listens on http1 / http2 / grpc / websocket. [App Protect DoS monitor](#dosprotectedresourceapdosmonitor) Default value: http1. | ``enum`` | No |
|``apDosMonitor.timeout`` | Determines how long (in seconds) should NGINX App Protect DoS wait for a response. [App Protect DoS monitor](#dosprotectedresourceapdosmonitor) Default value: 10 seconds for http1/http2 and 5 seconds for grpc. | ``int64`` | No |
|``apDosPolicy`` | The [App Protect DoS policy](#dosprotectedresourceapdospolicy) of the dos. Accepts an optional namespace. | ``string`` | No |
|``dosSecurityLog.enable`` | Enables security log. | ``bool`` | No |
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/dos/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ type DosProtectedResourceSpec struct {
type ApDosMonitor struct {
// URI is the destination to the desired protected object in the nginx.conf:
URI string `json:"uri"`
// +kubebuilder:validation:Enum=http1;http2;grpc
// Protocol determines if the server listens on http1 / http2 / grpc. The default is http1.
// +kubebuilder:validation:Enum=http1;http2;grpc;websocket
// Protocol determines if the server listens on http1 / http2 / grpc / websocket. The default is http1.
Protocol string `json:"protocol"`
// Timeout determines how long (in seconds) should NGINX App Protect DoS wait for a response. Default is 10 seconds for http1/http2 and 5 seconds for grpc.
Timeout uint64 `json:"timeout"`
Expand Down
7 changes: 4 additions & 3 deletions pkg/apis/dos/validation/dos.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ func validateAppProtectDosName(name string) error {
}

var validMonitorProtocol = map[string]bool{
"http1": true,
"http2": true,
"grpc": true,
"http1": true,
"http2": true,
"grpc": true,
"websocket": true,
}

func validateAppProtectDosMonitor(apDosMonitor v1beta1.ApDosMonitor) error {
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/dos/validation/dos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ func TestValidateAppProtectDosMonitor(t *testing.T) {
Protocol: "grpc",
Timeout: 10,
},
{
URI: "https://example.com/good_path",
Protocol: "websocket",
Timeout: 10,
},
}
negDstAntns := []struct {
apDosMonitor v1beta1.ApDosMonitor
Expand Down

0 comments on commit b92ac45

Please sign in to comment.