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

NGINX Ingress Controller Configuration guide update #2864

Merged
Changes from 14 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
cba90f8
Missing_Documentation_for_Use_Cases_for_NAP_within_NIC
rranghar Jul 18, 2022
e678ed3
Missing_Documentation_for_Use_Cases_for_NAP_within_NIC
rranghar Jul 18, 2022
506b5c7
Missing_Documentation_for_Use_Cases_for_NAP_within_NIC
rranghar Jul 18, 2022
e4ca40d
Fixed Lior's comments
rranghar Jul 19, 2022
b73085d
Fixed Lior's comments
rranghar Jul 19, 2022
4bcb30f
Fixed Daniel's and Brian's comments
rranghar Jul 20, 2022
f60bfda
Fixed Daniel's and Brian's comments
rranghar Jul 21, 2022
a8fbd6c
Fixed Lior's comments
rranghar Jul 21, 2022
ee7ec34
Fixed Daniel's and Brian's comments
rranghar Aug 4, 2022
1cb31a9
Fixed Daniel's comments
rranghar Aug 5, 2022
d34f1a5
Fixed Daniel's comments
rranghar Aug 5, 2022
b86bbab
Fixed Brian's comments
rranghar Aug 5, 2022
d8e7370
Fixed Brian's comments
rranghar Aug 5, 2022
9673efa
Fixed Daniel's comments
rranghar Aug 5, 2022
502df41
Fixed Ciara's comments
rranghar Aug 9, 2022
c984ed3
Fixed Ciara's comments
rranghar Aug 11, 2022
baa8413
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
8ddfa21
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
06d83bd
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
002f6fd
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
1df1e4d
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
006cd54
Missing_Documentation_for_Use_Cases_for_NAP_within_NIC
rranghar Jul 18, 2022
cc78251
Missing_Documentation_for_Use_Cases_for_NAP_within_NIC
rranghar Jul 18, 2022
00728ff
Missing_Documentation_for_Use_Cases_for_NAP_within_NIC
rranghar Jul 18, 2022
d6cde76
Fixed Lior's comments
rranghar Jul 19, 2022
284e065
Fixed Lior's comments
rranghar Jul 19, 2022
04fad6b
Fixed Daniel's and Brian's comments
rranghar Jul 20, 2022
aa8cd66
Fixed Daniel's and Brian's comments
rranghar Jul 21, 2022
0ec195a
Fixed Lior's comments
rranghar Jul 21, 2022
ff0b654
Fixed Daniel's and Brian's comments
rranghar Aug 4, 2022
8155bd1
Fixed Daniel's comments
rranghar Aug 5, 2022
341e251
Fixed Daniel's comments
rranghar Aug 5, 2022
1fe969e
Fixed Brian's comments
rranghar Aug 5, 2022
24eb2cf
Fixed Brian's comments
rranghar Aug 5, 2022
0a704c9
Fixed Daniel's comments
rranghar Aug 5, 2022
90a457f
Fixed Ciara's comments
rranghar Aug 9, 2022
212352a
Fixed Ciara's comments
rranghar Aug 11, 2022
960b6c6
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
0f0bd3a
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
55d304d
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
5f5622f
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
6669053
Added Configuration in WAF using Virtual Server Resource
rranghar Aug 12, 2022
2be23ec
Fixed Ciara's comments
rranghar Aug 22, 2022
92a09c2
Merge branch 'Missing_Documentation_for_Use_Cases_for_NAP_within_NIC'…
rranghar Aug 22, 2022
539feab
Fixed Ciara's comments
rranghar Aug 22, 2022
1e68fe6
Fixed Ciara's comments
rranghar Aug 22, 2022
86c7172
Fixed Ciara's comments
rranghar Aug 22, 2022
aca64e9
Fixed Ciara's comments
rranghar Aug 22, 2022
099fe27
Fixed Ciara's comments
rranghar Aug 22, 2022
98d2722
Fixed Ciara's comments
rranghar Aug 22, 2022
53b277b
Fixed Ciara's comments
rranghar Aug 22, 2022
3532248
Fixed Ciara's comments
rranghar Aug 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
186 changes: 181 additions & 5 deletions docs/content/app-protect/configuration.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
---
title: Configuration

description: "This document describes how to configure the NGINX App Protect module"
description: "This document describes how to configure the NGINX App Protect module."
weight: 1900
doctypes: [""]
toc: true
docs: "DOCS-578"
---

This document describes how to configure the NGINX App Protect module
> Check out the complete [NGINX Ingress Controller with App Protect example resources on GitHub](https://github.com/nginxinc/kubernetes-ingress/tree/v2.3.0/examples/appprotect).
> Check out the complete [NGINX Ingress Controller with App Protect example resources on GitHub](https://github.com/nginxinc/kubernetes-ingress/tree/v2.3.0/examples/appprotect).
Refer to [Custom Resource](https://github.com/nginxinc/kubernetes-ingress/tree/main/examples/custom-resources/waf) for Custom Resource sample.
rranghar marked this conversation as resolved.
Show resolved Hide resolved

## Global Configuration

The NGINX Ingress Controller has a set of global configuration parameters that align with those available in the NGINX App Protect module. See [ConfigMap keys](/nginx-ingress-controller/configuration/global-configuration/configmap-resource/#modules) for the complete list. The App Protect parameters use the `app-protect*` prefix.

> Check out the complete [NGINX Ingress Controller with App Protect example resources on GitHub](https://github.com/nginxinc/kubernetes-ingress/tree/v2.3.0/examples/appprotect).

## Enable App Protect for an Ingress Resource
## Enabling App Protect

You can enable and configure NGINX App Protect on the Custom Resources (VirtualServer, VirtualServerRoute) or on the Ingress-resource basis. Refer to [Custom Resource](https://docs.nginx.com/nginx-ingress-controller/configuration/policy-resource/#waf) examples for more details.

Refer to [Custom Resource](https://github.com/nginxinc/kubernetes-ingress/tree/main/examples/custom-resources/waf) for Custom Resource sample.

To configure NGINX App Protect on an Ingress resource, you would apply the [App Protect annotations](/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/#app-protect) to each desired resource.
rranghar marked this conversation as resolved.
Show resolved Hide resolved

brianehlert marked this conversation as resolved.
Show resolved Hide resolved

You can enable and configure NGINX App Protect on a per-Ingress-resource basis. To do so, you can apply the [App Protect annotations](/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/#app-protect) to each desired resource.

## App Protect Policies

rranghar marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -203,3 +209,173 @@ spec:
softwareVersion: 15.1.0
tag: Fruits
```

## OpenAPI Specification in NGINX Ingress Controller

The OpenAPI Specification defines the spec file format needed to describe RESTful APIs. The spec file can be written either in JSON or YAML. Using a spec file simplifies the work of implementing API protection. Refer to the [OpenAPI Specification](#https://github.com/OAI/OpenAPI-Specification) (formerly called Swagger) for details.

NGINX Ingress Controller supports OpenAPI Specification versions 2.0 and 3.0.

The simplest way to create an API protection policy is using an OpenAPI Specification file to import the details of the APIs. If you use an OpenAPI Specification file, NGINX App Protect WAF will automatically create a policy for the following properties (depending on what's included in the spec file):
* Methods
* URLs
* Parameters
* JSON profiles

An OpenAPI-ready policy template is provided with the NGINX App Protect WAF packages and is located in: `/etc/app_protect/conf/NginxApiSecurityPolicy.json`

It contains violations related to OpenAPI set to blocking (enforced).

### Types of OpenAPI References

There are different ways of referencing OpenAPI Specification files. The configuration is similar to [External References](#external-references).

**Note**: Any update of an OpenAPI Specification file referenced in the policy will not trigger a policy compilation. This action needs to be done actively by reloading the NGINX configuration.

#### URL Reference

URL reference is the method of referencing an external source by providing its full URL.

Make sure to configure certificates prior to using the HTTPS protocol - see the [External References](#https-reference) for details.

## Configuration in NGINX Ingress Controller

rranghar marked this conversation as resolved.
Show resolved Hide resolved
These are the typical steps to deploy an OpenAPI protection Policy in NGINX Ingress Controller:

1. Copy the API security policy `/etc/app_protect/conf/NginxApiSecurityPolicy.json` to a different file so that it can be edited.
2. Add the reference to the desired OpenAPI file.
3. Make other custom changes if needed (e.g. enable Data Guard protection).
4. Use a tool to convert the result to YAML. There are many, for example: [`yq` utility](https://github.com/mikefarah/yq).
5. Add the YAML properties to create an `APPolicy` Custom Resource putting the policy itself (as in step 4) within the `spec` property of the Custom Resource. Refer to [App Protect Policies](#app-protect-policies) section above.
6. Create a `Policy` object which references the `APPolicy` Customer Resource as in [this example](https://github.com/nginxinc/kubernetes-ingress/blob/main/examples/custom-resources/waf/waf.yaml).
rranghar marked this conversation as resolved.
Show resolved Hide resolved
7. Finally, attach the `Policy` object to a `VirtualServer` resource as in [this example](https://github.com/nginxinc/kubernetes-ingress/blob/main/examples/custom-resources/waf/virtual-server.yaml).

**Note**: You need to make sure that the server where the resource files are located is always available when you are compiling your policy.

rranghar marked this conversation as resolved.
Show resolved Hide resolved
##### Example Configuration

In this example, we are adding an OpenAPI Specification file reference to `/etc/app_protect/conf/NginxApiSecurityPolicy.yaml` using the link ` :https://raw.githubusercontent.com/aws-samples/api-gateway-secure-pet-store/master/src/main/resources/swagger.yaml`. This will configure allowed data types for `query_int` and `query_str` parameters values.

**Policy configuration:**
rranghar marked this conversation as resolved.
Show resolved Hide resolved

~~~yaml
---
apiVersion: appprotect.f5.com/v1beta1
kind: APPolicy
metadata:
name: petstore_api_security_policy
spec:
policy:
name: petstore_api_security_policy
description: NGINX App Protect WAF API Security Policy for the Petstore API
template:
name: POLICY_TEMPLATE_NGINX_BASE
open-api-files:
- link: https://raw.githubusercontent.com/aws-samples/api-gateway-secure-pet-store/master/src/main/resources/swagger.yaml
blocking-settings:
violations:
- block: true
description: Disallowed file upload content detected in body
name: VIOL_FILE_UPLOAD_IN_BODY
- block: true
description: Mandatory request body is missing
name: VIOL_MANDATORY_REQUEST_BODY
- block: true
description: Illegal parameter location
name: VIOL_PARAMETER_LOCATION
- block: true
description: Mandatory parameter is missing
name: VIOL_MANDATORY_PARAMETER
- block: true
description: JSON data does not comply with JSON schema
name: VIOL_JSON_SCHEMA
- block: true
description: Illegal parameter array value
name: VIOL_PARAMETER_ARRAY_VALUE
- block: true
description: Illegal Base64 value
name: VIOL_PARAMETER_VALUE_BASE64
- block: true
description: Disallowed file upload content detected
name: VIOL_FILE_UPLOAD
- block: true
description: Illegal request content type
name: VIOL_URL_CONTENT_TYPE
- block: true
description: Illegal static parameter value
name: VIOL_PARAMETER_STATIC_VALUE
- block: true
description: Illegal parameter value length
name: VIOL_PARAMETER_VALUE_LENGTH
- block: true
description: Illegal parameter data type
name: VIOL_PARAMETER_DATA_TYPE
- block: true
description: Illegal parameter numeric value
name: VIOL_PARAMETER_NUMERIC_VALUE
- block: true
description: Parameter value does not comply with regular expression
name: VIOL_PARAMETER_VALUE_REGEXP
- block: true
description: Illegal URL
name: VIOL_URL
- block: true
description: Illegal parameter
name: VIOL_PARAMETER
- block: true
description: Illegal empty parameter value
name: VIOL_PARAMETER_EMPTY_VALUE
- block: true
description: Illegal repeated parameter name
name: VIOL_PARAMETER_REPEATED

~~~

Content of the referenced file `myapi.yaml`:

~~~yaml
openapi: 3.0.1
info:
title: 'Primitive data types'
description: 'Primitive data types.'
version: '2.5.0'
servers:
- url: http://localhost
paths:
/query:
get:
tags:
- query_int_str
description: query_int_str
operationId: query_int_str
parameters:
- name: query_int
in: query
required: false
allowEmptyValue: false
schema:
type: integer
- name: query_str
in: query
required: false
allowEmptyValue: true
schema:
type: string
responses:
200:
description: OK
404:
description: NotFound
~~~

In this case, the following request will trigger an `Illegal parameter data type` violation, as we expect to have an integer value in the `query_int` parameter:

```
http://localhost/query?query_int=abc
```

The request will be blocked.

The `link` option is also available in the `openApiFileReference` property and is synonymous with the `open-api-files` property as seen in the App Protect policy example above.

**Note**: `openApiFileReference` is not an array.