Skip to content

Commit 37ab8d6

Browse files
authored
Dos access log dest (#4187)
1 parent b44efbb commit 37ab8d6

File tree

5 files changed

+14
-31
lines changed

5 files changed

+14
-31
lines changed

docs/content/app-protect-dos/dos-protected.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ spec:
3232
{{% table %}}
3333
|Field | Description | Type | Required |
3434
| ---| ---| ---| --- |
35-
|``enable`` | Enables NGINX App Protect DoS. | ``bool`` | No |
36-
|``name`` | Name of the protected object, max of 63 characters. | ``string`` | No |
35+
|``enable`` | Enables NGINX App Protect DoS, Default value: false. | ``bool`` | No |
36+
|``name`` | Name of the protected object, max of 63 characters. | ``string`` | Yes |
37+
|``dosAccessLogDest`` | The log destination for the access log with dos log format. Accepted variables are ``syslog:server=<ip-address &#124; localhost &#124; dns-name>:<port>``, ``stderr``, ``<absolute path to file>``. | ``string`` | No |
3738
|``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 |
3839
|``apDosMonitor.protocol`` | Determines if the server listens on http1 / http2 / grpc / websocket. [App Protect DoS monitor](#dosprotectedresourceapdosmonitor) Default value: http1. | ``enum`` | No |
3940
|``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 |
4041
|``apDosPolicy`` | The [App Protect DoS policy](#dosprotectedresourceapdospolicy) of the dos. Accepts an optional namespace. | ``string`` | No |
4142
|``dosSecurityLog.enable`` | Enables security log. | ``bool`` | No |
4243
|``dosSecurityLog.apDosLogConf`` | The [App Protect DoS log conf](/nginx-ingress-controller/app-protect-dos/configuration/#app-protect-dos-logs) resource. Accepts an optional namespace. | ``string`` | No |
43-
|``dosSecurityLog.dosLogDest`` | The log destination for the security log. Accepted variables are ``syslog:server=<ip-address | localhost | dns-name>:<port>``,``stderr``,``<absolute path to file>``. Default is``"syslog:server=127.0.0.1:514"``. | ``string`` | No |
44+
|``dosSecurityLog.dosLogDest`` | The log destination for the security log. Accepted variables are ``syslog:server=<ip-address &#124; localhost &#124; dns-name>:<port>``, ``stderr``, ``<absolute path to file>``. Default is ``"syslog:server=127.0.0.1:514"``. | ``string`` | No |
4445
{{% /table %}}
4546

4647
### DosProtectedResource.apDosPolicy

internal/configs/dos.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func getAppProtectDosResource(dosEx *DosEx) *appProtectDosResource {
3232
dosResource.AppProtectDosMonitorTimeout = protected.Spec.ApDosMonitor.Timeout
3333
}
3434

35-
dosResource.AppProtectDosAccessLogDst = generateDosLogDest(protected.Spec.DosAccessLogDest)
35+
if protected.Spec.DosAccessLogDest != "" {
36+
dosResource.AppProtectDosAccessLogDst = generateDosLogDest(protected.Spec.DosAccessLogDest)
37+
}
3638

3739
if dosEx.DosPolicy != nil {
3840
dosResource.AppProtectDosPolicyFile = appProtectDosPolicyFileName(dosEx.DosPolicy.GetNamespace(), dosEx.DosPolicy.GetName())

pkg/apis/dos/validation/dos.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ func ValidateDosProtectedResource(protected *v1beta1.DosProtectedResource) error
4444
}
4545

4646
// dosAccessLogDest
47-
if protected.Spec.DosAccessLogDest == "" {
48-
return fmt.Errorf("error validating DosProtectedResource: %v missing value for field: %v", protected.Name, "dosAccessLogDest")
49-
}
50-
err = validateAppProtectDosLogDest(protected.Spec.DosAccessLogDest)
51-
if err != nil {
52-
return fmt.Errorf("error validating DosProtectedResource: %v invalid field: %v err: %w", protected.Name, "dosAccessLogDest", err)
47+
if protected.Spec.DosAccessLogDest != "" {
48+
err = validateAppProtectDosLogDest(protected.Spec.DosAccessLogDest)
49+
if err != nil {
50+
return fmt.Errorf("error validating DosProtectedResource: %v invalid field: %v err: %w", protected.Name, "dosAccessLogDest", err)
51+
}
5352
}
5453

5554
// apDosPolicy

pkg/apis/dos/validation/dos_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ func TestValidateDosProtectedResource(t *testing.T) {
2929
expectErr: "error validating DosProtectedResource: missing value for field: name",
3030
msg: "empty spec",
3131
},
32-
{
33-
protected: &v1beta1.DosProtectedResource{
34-
Spec: v1beta1.DosProtectedResourceSpec{
35-
Name: "name",
36-
},
37-
},
38-
expectErr: "error validating DosProtectedResource: missing value for field: dosAccessLogDest",
39-
msg: "only name specified",
40-
},
41-
{
42-
protected: &v1beta1.DosProtectedResource{
43-
Spec: v1beta1.DosProtectedResourceSpec{
44-
Name: "name",
45-
ApDosMonitor: &v1beta1.ApDosMonitor{
46-
URI: "example.com",
47-
},
48-
},
49-
},
50-
expectErr: "error validating DosProtectedResource: missing value for field: dosAccessLogDest",
51-
msg: "name and apDosMonitor specified",
52-
},
5332
{
5433
protected: &v1beta1.DosProtectedResource{
5534
Spec: v1beta1.DosProtectedResourceSpec{

tests/suite/test_dos.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def test_ap_nginx_config_entries(
177177
f"app_protect_dos_policy_file /etc/nginx/dos/policies/{test_namespace}_{dos_setup.pol_name}.json;",
178178
f"app_protect_dos_security_log_enable on;",
179179
f"app_protect_dos_security_log /etc/nginx/dos/logconfs/{test_namespace}_{dos_setup.log_name}.json syslog:server=syslog-svc.{ingress_controller_prerequisites.namespace}.svc.cluster.local:514;",
180+
f"set $loggable '0';",
181+
f"access_log syslog:server=127.0.0.1:5561 log_dos if=$loggable;",
180182
]
181183

182184
conf_nginx_directive = ["app_protect_dos_api on;", "location = /dashboard-dos.html"]

0 commit comments

Comments
 (0)