Skip to content

Commit 59ea39a

Browse files
API v5.1 (#67)
* 20240701 - dev NGINX App Protect 5 compiler * 20240701 - dev NGINX App Protect 5 compiler * 20240730 - v5.1 dev * 2024073002 - v5.1 dev * 2024073003 dev 5.1 * 20240731 - 5.1 dev * 2024080201 - 5.1 dev * 20240806 - 5.1 dev Moved resolvers config to include files Added per-upstream resolver support FEATURES updated * 2024080602 - 5.1 dev Moved HTTP upstreams to separate include files Bugfixes Updated postman collection * 20240807 - 5.1 dev Moved HTTP and Stream upstream to separated include config file Added DNS resolver support for stream servers and stream upstreams Moved .declaration.http.resolvers[] to .declaration.resolvers[] Postman collection updated for v5.1 * 2024080801 - 5.1 dev Postman collection updated NGINX One REST API endpoints updated * 2024080809 - 5.1 dev FEATURES updated Postman collection README updated API v5.1 USAGE updated * 2024080902 - 5.1 dev FEATURES updated * 2024080903 - 5.1 dev
1 parent 181c7b4 commit 59ea39a

30 files changed

+1029
-607
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ Thumbs.db
2424
/src/v5_0/__pycache__/
2525
/src/v5_1/__pycache__/
2626
/contrib/devportal/redocly/src/__pycache__/
27+
/contrib/app-protect/src/__pycache__/
2728
/venv/

FEATURES.md

+134-58
Large diffs are not rendered by default.

README.md

+11-24
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22

33
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
44

5-
This project provides a set of declarative REST API for [NGINX Instance Manager](https://docs.nginx.com/nginx-management-suite/nim/) and [NGINX One Cloud Console](https://docs.nginx.com/nginx-one/) (currently in early stage).
5+
This project provides a set of declarative REST API for [NGINX Instance Manager](https://docs.nginx.com/nginx-management-suite/nim/) and [NGINX One Cloud Console](https://docs.nginx.com/nginx-one/) (currently in early stage / unstable).
66

77
It can be used to manage NGINX Plus configuration lifecycle and to create NGINX Plus configurations using JSON service definitions.
88

99
GitOps integration is supported: source of truth is checked for updates (NGINX App Protect policies, TLS certificates, keys and chains/bundles, Swagger/OpenAPI definitions, snippets) and NGINX configurations are automatically kept in sync.
1010

1111
Use cases include:
1212

13-
- Rapid configuration generation and templating
14-
- CI/CD integration with NGINX Instance Manager (instance groups and staged configs) and NGINX One Cloud Console (clusters)
13+
- Integration with NGINX Instance Manager (instance group) and NGINX One Cloud Console (config sync group)
1514
- NGINX App Protect DevSecOps integration (NGINX Instance Manager only)
1615
- API Gateway deployments with automated Swagger / OpenAPI schema import
17-
- API Developer portals zero-touch deployment
16+
- API Developer portals zero-touch deployment (redocly and backstage supported)
1817
- GitOps integration with source of truth support for
1918
- NGINX App Protect WAF policies
2019
- TLS certificates, keys and chains/bundles
@@ -29,9 +28,9 @@ A **blog article** to automate NGINX API Gateway management from OpenAPI schemas
2928
## Supported releases
3029

3130
- NGINX Instance Manager 2.14+
32-
- NGINX One Cloud Console
31+
- NGINX One Cloud Console (early stage / unstable)
3332
- NGINX Plus R30+
34-
- NGINX App Protect WAF 4.8+
33+
- NGINX App Protect WAF 4
3534

3635
## Architecture
3736

@@ -55,10 +54,6 @@ stateDiagram-v2
5554
DEVP: Developer Portal Service
5655
OUTPUT: Output
5756
REDIS: Redis
58-
POST: Generic POST endpoint
59-
CONFIGMAP: Kubernetes ConfigMap
60-
PLAINTEXT: Plaintext
61-
BASE64: Base64-encoded
6257
6358
DevOps --> Pipeline
6459
Pipeline --> INPUT
@@ -69,10 +64,6 @@ stateDiagram-v2
6964
SOT --> NDAPI
7065
NDAPI --> REDIS
7166
REDIS --> NDAPI
72-
OUTPUT --> BASE64
73-
OUTPUT --> POST
74-
OUTPUT --> CONFIGMAP
75-
OUTPUT --> PLAINTEXT
7667
OUTPUT --> NIM
7768
OUTPUT --> N1
7869
NDAPI --> DEVP
@@ -124,7 +115,7 @@ critical If Developer Portal enabled
124115
end
125116
end
126117
127-
NGINX Declarative API Core ->>+ NGINX Instance Manager / NGINX One: Publish staged config to instance group / cluster
118+
NGINX Declarative API Core ->>+ NGINX Instance Manager / NGINX One: Publish staged config to instance group / config sync group
128119
NGINX Instance Manager / NGINX One ->> NGINX: Publish config to NGINX instances
129120
NGINX Instance Manager / NGINX One ->>- NGINX Declarative API Core: Publish outcome
130121
@@ -139,12 +130,8 @@ end
139130

140131
## Output formats
141132

142-
- [X] Plaintext
143-
- [X] JSON-wrapped Base64-encoded
144-
- [X] Kubernetes Configmap
145-
- [X] POST to Generic REST API endpoint
146-
- [X] Output to NGINX Instance Manager 2.14+ imperative REST API (NGINX instance groups)
147-
- [X] Output to NGINX One Cloud Console REST API (NGINX clusters)
133+
- [X] Output to NGINX Instance Manager 2.14+ imperative REST API (instance group)
134+
- [X] Output to NGINX One Cloud Console REST API (config sync group)
148135

149136
## Supported features
150137

@@ -154,9 +141,9 @@ See the [features list](/FEATURES.md)
154141

155142
Usage details and JSON schema are available here:
156143

157-
- [API v5.1](/USAGE-v5.1.md) - development
158-
- [API v5.0](/USAGE-v5.0.md) - latest
159-
- [API v4.2](/USAGE-v4.2.md)
144+
- [API v5.1](/USAGE-v5.1.md) - latest
145+
- [API v5.0](/USAGE-v5.0.md)
146+
- [API v4.2](/USAGE-v4.2.md) - deprecated
160147

161148
A sample Postman collection and usage instructions can be found [here](/contrib/postman)
162149

USAGE-v5.1.md

+11-165
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,13 @@
33
Version 5.1 supports:
44

55
- [NGINX Instance Manager](https://docs.nginx.com/nginx-management-suite/nim/) 2.14+
6-
- [NGINX One Cloud Console](https://docs.nginx.com/nginx-one/)
6+
- [NGINX One Cloud Console](https://docs.nginx.com/nginx-one/) - early stage / unstable
77
- [NGINX Plus](https://docs.nginx.com/nginx/) R30+
8-
- [NGINX App Protect WAF](https://docs.nginx.com/nginx-app-protect-waf/) 4.2.0+ with compiled [policy bundles](https://docs.nginx.com/nginx-app-protect-waf/v5/admin-guide/compiler/)
8+
- [NGINX App Protect WAF](https://docs.nginx.com/nginx-app-protect-waf/) 4 with precompiled [policy bundles](https://docs.nginx.com/nginx-app-protect-waf/v5/admin-guide/compiler/)
99

10-
The JSON schema is self explanatory. See also the [sample Postman collection](/contrib/postman)
10+
The JSON schema is self explanatory. See also the [sample Postman collection](/contrib/postman) for usage examples
1111

1212
- `.output.type` defines how NGINX configuration will be returned:
13-
- *plaintext* - plaintext format
14-
- *json* - JSON-wrapped, base64-encoded
15-
- *configmap* - Kubernetes Configmap in YAML format.
16-
- `.output.configmap.name` must be set to the ConfigMap name
17-
- `.output.configmap.filename` must be set to the NGINX configuration filename
18-
- `.output.configmap.namespace` the optional namespace for the ConfigMap
19-
- *http* - NGINX configuration is POSTed to custom url
20-
- `.output.http.url` the URL to POST the configuration to
2113
- *nms* - NGINX configuration is published as a Staged Config to NGINX Instance Manager
2214
- `.output.nms.url` the NGINX Instance Manager URL
2315
- `.output.nms.username` the NGINX Instance Manager authentication username
@@ -38,165 +30,23 @@ The JSON schema is self explanatory. See also the [sample Postman collection](/c
3830
- `.output.nms.policies[].versions[].displayName` the policy version's display name
3931
- `.output.nms.policies[].versions[].description` the policy version's description
4032
- `.output.nms.policies[].versions[].contents` this can be either base64-encoded or be a HTTP(S) URL that will be fetched dynamically from a source of truth
41-
- *nginxone* - NGINX configuration is published to a NGINX One Cloud Console cluster
33+
- *nginxone* - NGINX configuration is published to a NGINX One Cloud Console config sync group
4234
- `.output.nginxone.url` the NGINX One Cloud Console URL
4335
- `.output.nginxone.namespace` the NGINX One Cloud Console namespace
4436
- `.output.nginxone.token` the authentication token
45-
- `.output.nginxone.cluster` the cluster name
37+
- `.output.nginxone.configsyncgroup` the NGINX One Cloud Console config sync group name
4638
- `.output.nginxone.synctime` **optional**, used for GitOps autosync. When specified and the declaration includes HTTP(S) references to NGINX App Protect policies, TLS certificates/keys/chains, the HTTP(S) endpoints will be checked every `synctime` seconds and if external contents have changed, the updated configuration will automatically be published to NGINX One Cloud Console
4739
- `.output.nginxone.modules` an optional array of NGINX module names (ie. 'ngx_http_app_protect_module', 'ngx_http_js_module','ngx_stream_js_module')
4840
- `.output.nginxone.certificates` an optional array of TLS certificates/keys/chains to be published
4941
- `.output.nginxone.certificates[].type` the item type ('certificate', 'key', 'chain')
5042
- `.output.nginxone.certificates[].name` the certificate/key/chain name with no path/extension (ie. 'test-application')
5143
- `.output.nginxone.certificates[].contents` the content: this can be either base64-encoded or be a HTTP(S) URL that will be fetched dynamically from a source of truth
52-
- `.declaration` describes the NGINX configuration to be created.
44+
- `.declaration` describes the NGINX configuration to be created
45+
- `.declaration.http[]` NGINX HTTP definitions
46+
- `.declaration.layer4[]` NGINX TCP/UDP definitions
47+
- `.declaration.resolvers[]` DNS resolvers definitions
5348

54-
### Locations ###
55-
56-
Locations `.declaration.http.servers[].locations[].uri` match modifiers in `.declaration.http.servers[].locations[].urimatch` can be:
57-
58-
- *prefix* - prefix URI matching
59-
- *exact* - exact URI matching
60-
- *regex* - case sensitive regex matching
61-
- *iregex* - case insensitive regex matching
62-
- *best* - case sensitive regex matching that halts any other location matching once a match is made
63-
64-
### Javascript profiles ###
65-
66-
NGINX Javascript profiles are defined in `.declaration.http.njs[]`:
67-
68-
- `name` - the NJS profile name
69-
- `file.content` - the base64-encoded njs source code or the `http(s)://` URL of the file
70-
- `file.authentication.server[0].profile` - authentication profile name if `file.content` is a URL and the request must be authenticated
71-
72-
### Javascript hooks ###
73-
74-
NGINX Javascript hooks can be used in:
75-
76-
- `.declaration.http.njs`
77-
- Supported hooks:
78-
- `js_preload_object'
79-
- 'js_set`
80-
- `.declaration.http.server[].njs`
81-
- Supported hooks:
82-
- `js_preload_object'
83-
- 'js_set`
84-
- `.declaration.http.server[].location[].njs`
85-
- Supported hooks:
86-
- `js_body_filter'
87-
- 'js_content'
88-
- 'js_header_filter'
89-
- 'js_periodic'
90-
- 'js_preload_object'
91-
- 'js_set`
92-
93-
Hooks invocation is:
94-
95-
```
96-
"njs": [
97-
{
98-
"hook": {
99-
"name": "<HOOK_NAME>",
100-
"parameters": [
101-
{
102-
"name": "<HOOK_PARAMETER_NAME>",
103-
"value": "<HOOK_PARAMETER_VALUE>"
104-
}
105-
]
106-
},
107-
"profile": "<NGINX_JAVASCRIPT_PROFILE>",
108-
"function": "<JAVASCRIPT_FUNCTION_NAME>"
109-
}
110-
]
111-
```
112-
113-
For detailed examples see the [Postman collection](/contrib/postman)
114-
115-
### API Gateway ###
116-
117-
Swagger files and OpenAPI schemas can be used to automatically configure NGINX as an API Gateway. Developer portal creation is supported through [Redocly](https://redocly.com/)
118-
119-
Declaration path `.declaration.http.servers[].locations[].apigateway` defines the API Gateway configuration:
120-
121-
- `openapi_schema` - the base64-encoded schema, or the schema URL. YAML and JSON are supported
122-
- `api_gateway.enabled` - enable/disable API Gateway provisioning
123-
- `api_gateway.strip_uri` - removes the `.declaration.http.servers[].locations[].uri` part of the URI before forwarding requests to the upstream
124-
- `api_gateway.server_url` - the base URL of the upstream server
125-
- `developer_portal.enabled` - enable/disable Developer portal provisioning
126-
- `developer_portal.type` - developer portal type. Currently supported are: `redocly`, `backstage`
127-
- `developer_portal.redocly.*` - Redocly-based developer portal parameters. See the [Postman collection](/contrib/postman)
128-
- `developer_portal.backstage.*` - Backstage-based developer portal parameters. See the [Postman collection](/contrib/postman)
129-
- `authentication` - optional, used to enforce authentication at the API Gateway level
130-
- `authentication.client[]` - authentication profile names
131-
- `authentication.enforceOnPaths` - if set to `true` authentication is enforced on all API endpoints listed under `authentication.paths`. if set to `false` authentication is enforced on all API endpoints but those listed under `authentication.paths`
132-
- `authentication.paths` - paths to enforce authentication
133-
- `authorization[]` - optional, used to enforce authorization
134-
- `authorization[].profile` - authorization profile name
135-
- `authorization[].enforceOnPaths` - if set to `true` authorization is enforced on all API endpoints listed under `authorization.paths`. if set to `false` authorization is enforced on all API endpoints but those listed under `authorization[].paths`
136-
- `authorization[].paths` - paths to enforce authorization
137-
- `rate_limit` - optional, used to enforce rate limiting at the API Gateway level
138-
- `rate_limit.enforceOnPaths` - if set to `true` rate limiting is enforced on all API endpoints listed under `rate_limit.paths`. if set to `false` rate limiting is enforced on all API endpoints but those listed under `rate_limit.paths`
139-
140-
A sample API Gateway declaration to publish the `https://petstore.swagger.io` REST API using:
141-
142-
- REST API endpoint URIs
143-
- HTTP Methods
144-
- Rate limiting on `/user/login`, `/usr/logout` and `/pet/{petId}/uploadImage`
145-
- JWT authentication on `/user/login`, `/usr/logout` and `/pet/{petId}/uploadImage`
146-
- JWT claim-based authorization on `/user/login`, `/usr/logout` and `/pet/{petId}/uploadImage`
147-
- Redocly-based developer portal
148-
- NGINX App Protect WAF security
149-
150-
can be found in the [Postman collection](/contrib/)
151-
152-
### Maps ###
153-
154-
Map entries `.declaration.maps[].entries.keymatch` can be:
155-
156-
- *exact* - exact variable matching
157-
- *regex* - case sensitive regex matching
158-
- *iregex* - case insensitive regex matching
159-
160-
### Snippets ###
161-
162-
Snippets for `http`, `upstream`, `server` and `location` can be specified as:
163-
- base64-encoded content
164-
- HTTP(S) URL of a source of truth to fetch snippet content from. Content on the source of truth must be plaintext
165-
- source of truth authentication is supported through authentication profiles
166-
167-
### Authentication profiles ###
168-
169-
Client and Server authentication profiles can be defined in the declarative json at `.declaration.http.authentication`
170-
171-
```commandline
172-
"authentication": {
173-
"client": [
174-
{
175-
"name": "<PROFILE_NAME>",
176-
"type": "<PROFILE_TYPE>",
177-
"<PROFILE_TYPE>": {
178-
"<PROFILE_KEY>": "<VALUE>",
179-
[...]
180-
}
181-
},
182-
[...]
183-
],
184-
"server": [
185-
{
186-
"name": "<PROFILE_NAME>",
187-
"type": "<PROFILE_TYPE>",
188-
"<PROFILE_TYPE>": {
189-
"<PROFILE_KEY>": "<VALUE>",
190-
[...]
191-
}
192-
},
193-
[...]
194-
]
195-
```
196-
197-
For a list of all supported authentication profile types see the [feature matrix](/FEATURES.md)
198-
199-
### API endpoints ###
49+
### API endpoints
20050

20151
- `POST /v5.1/config/` - Publish a new declaration
20252
- `PATCH /v5.1/config/{config_uid}` - Update an existing declaration
@@ -206,8 +56,4 @@ For a list of all supported authentication profile types see the [feature matrix
20656
- Per-Stream upstream CRUD
20757
- Per-NGINX App Protect WAF policy CRUD
20858
- `GET /v5.1/config/{config_uid}` - Retrieve an existing declaration
209-
- `DELETE /v5.1/config/{config_uid}` - Delete an existing declaration
210-
211-
### Usage Examples ###
212-
213-
A sample Postman collection is available [here](/contrib/postman)
59+
- `DELETE /v5.1/config/{config_uid}` - Delete an existing declaration

contrib/app-protect/Dockerfile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# syntax=docker/dockerfile:1
2+
ARG VERSION_TAG
3+
ARG BASE_IMAGE=private-registry.nginx.com/nap/waf-compiler:${VERSION_TAG}
4+
FROM ${BASE_IMAGE}
5+
6+
# Installing packages as root
7+
USER root
8+
9+
ENV DEBIAN_FRONTEND="noninteractive"
10+
11+
# REST API wrapper
12+
WORKDIR /compiler
13+
COPY src src/
14+
# REST API wrapper
15+
16+
RUN --mount=type=secret,id=nginx-crt,dst=/etc/ssl/nginx/nginx-repo.crt,mode=0644 \
17+
--mount=type=secret,id=nginx-key,dst=/etc/ssl/nginx/nginx-repo.key,mode=0644 \
18+
apt-get update \
19+
&& apt-get install -y \
20+
apt-transport-https \
21+
lsb-release \
22+
ca-certificates \
23+
wget \
24+
gnupg2 \
25+
ubuntu-keyring \
26+
&& wget -qO - https://cs.nginx.com/static/keys/app-protect-security-updates.key | gpg --dearmor | \
27+
tee /usr/share/keyrings/app-protect-security-updates.gpg >/dev/null \
28+
&& printf "deb [signed-by=/usr/share/keyrings/app-protect-security-updates.gpg] \
29+
https://pkgs.nginx.com/app-protect-security-updates/ubuntu `lsb_release -cs` nginx-plus\n" | \
30+
tee /etc/apt/sources.list.d/nginx-app-protect.list \
31+
&& wget -P /etc/apt/apt.conf.d https://cs.nginx.com/static/files/90pkgs-nginx \
32+
&& apt-get update \
33+
&& apt-get install -y \
34+
app-protect-attack-signatures \
35+
app-protect-bot-signatures \
36+
app-protect-threat-campaigns \
37+
# REST API wrapper
38+
&& apt-get -y install python3 python3-venv \
39+
&& python3 -m venv /compiler/env/ \
40+
&& . /compiler/env/bin/activate \
41+
&& pip3 install --no-cache --upgrade pip setuptools virtualenv \
42+
&& python3 -m pip install --upgrade pip \
43+
&& pip3 install -r /compiler/src/requirements.txt \
44+
# REST API wrapper
45+
&& apt-get clean \
46+
&& rm -rf /var/lib/apt/lists/*
47+
48+
# non-root default user (UID 101)
49+
USER nginx
50+
51+
# REST API wrapper
52+
ENTRYPOINT [ "/compiler/src/start.sh" ]
53+
# REST API wrapper

contrib/app-protect/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# REST API for NGINX App Protect WAF Compiler
2+
3+
This contrib provides a set of REST API to use the NGINX App Protect 5 policy compiler
4+
5+
## REST API Endpoints
6+
7+
- `/v1/compile/policy` - compiles a JSON policy into a bundle
8+
- Method: `POST`
9+
- Payload: `{"global-settings": "<BASE64_ENCODED_GLOBAL_SETTINGS_JSON>", "policy": "<BASE64_ENCODED_POLICY_JSON>", "cookie-protection-seed": "<SEED_VALUE>"}`
10+
- `/v1/compile/logprofile` - compiles a log profile JSON into a bundle
11+
- Method: `POST`
12+
- Payload: `{"logprofile": "<BASE64_ENCODED_LOG_PROFILE_JSON>"}`
13+
- `/v1/bundle/info` - returns details on a compiled bundle
14+
- Method: `POST`
15+
- Payload: `{"bundle": "<BASE64_ENCODED_TGZ_BUNDLE>"}`
16+
17+
Headers required for all endpoints:
18+
19+
```
20+
Content-Type: application/json
21+
```
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
typing
2+
uvicorn
3+
fastapi
4+
uuid
5+
pyyaml

0 commit comments

Comments
 (0)