Skip to content

Commit 721b712

Browse files
committed
Add sequence diagram and more detail on status conditions
1 parent b91f8f4 commit 721b712

File tree

1 file changed

+69
-14
lines changed

1 file changed

+69
-14
lines changed

docs/proposals/nap-waf.md

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,20 @@ A key design principle is seamless GitOps workflow support through automatic cha
5050
- **Efficient Updates**: Only downloads policy bundles when content actually changes
5151
- **CI/CD Friendly**: Teams can update policies without modifying Kubernetes resources
5252

53+
**Polling Mechanism:**
54+
55+
- Configurable polling interval (default: 5 minutes)
56+
- Checksum-based change detection for efficiency
57+
- Only downloads policy bundles when content changes
58+
- New policies applied immediately upon detection
59+
5360
### Policy Attachment Strategy
5461

5562
The design uses **inherited policy attachment** following Gateway API best practices:
5663

5764
- **Gateway-level policies** provide default protection for all routes attached to the Gateway
5865
- **Route-level policies** can override Gateway-level policies for specific routes requiring different protection
66+
- NB: cannot _disable_ WAF protection on a per route level, but the Route level WAFPolicy configuration will completely override the Gateway level WAFPolicy configuration
5967
- **Policy precedence**: More specific policies (Route-level) override less specific policies (Gateway-level)
6068
- **Automatic inheritance**: New routes automatically receive Gateway-level protection without explicit configuration
6169

@@ -246,8 +254,6 @@ spec:
246254
247255
### Policy Development Workflow
248256
249-
Given NAP v5 constraints, users must follow this workflow:
250-
251257
1. **Policy Development**: Write WAF policies using NAP v5 JSON schema
252258
2. **Log Profile Development**: Create custom logging profiles or use built-in profiles (log_all, log_blocked, etc.)
253259
3. **Compilation**: Use NAP v5 compiler tools to create policy and logging profile bundles
@@ -257,6 +263,24 @@ Given NAP v5 constraints, users must follow this workflow:
257263
258264
**Note**: Policy enforcement mode and behavior are defined within the compiled NAP policy itself. Security logging profiles can be either built-in names or custom compiled bundles.
259265
266+
```mermaid
267+
sequenceDiagram
268+
participant SecTeam as Security Team
269+
participant Compiler as Policy Compiler
270+
participant Store as Policy Store
271+
participant NGF as NGF Control Plane
272+
participant NGINX as NGINX Data Plane
273+
274+
SecTeam->>Compiler: Develop WAF Policies
275+
Compiler->>Store: Publish Compiled Policies
276+
NGF->>Store: Fetch Policies (Periodic Polling)
277+
NGF->>NGF: Validate Policies (Checksum Verification)
278+
NGF->>NGINX: Push Policies to Shared Volume
279+
NGINX->>NGINX: Apply Policies
280+
Client->>NGINX: Send HTTP/gRPC Requests
281+
NGINX->>Client: Respond with Filtered Traffic
282+
```
283+
260284
Example CI/CD integration for manual updates:
261285
262286
```bash
@@ -275,17 +299,6 @@ aws s3 cp compiled-policy.tgz.sha256 s3://company-policies/prod-policy.tgz.sha25
275299
echo "Policy updated. NGF will detect changes within polling interval."
276300
```
277301

278-
### Policy Polling and Change Detection
279-
280-
NGF supports automatic policy change detection to support GitOps workflows:
281-
282-
**Polling Mechanism:**
283-
284-
- Configurable polling interval (default: 5 minutes)
285-
- Checksum-based change detection for efficiency
286-
- Only downloads policy bundles when content changes
287-
- New policies applied immediately upon detection
288-
289302
### Security Logging Configuration
290303

291304
The securityLogs section supports multiple logging configurations, each generating an `app_protect_security_log` directive:
@@ -700,7 +713,45 @@ This label will help with discoverability and will be used by the planned Gatewa
700713

701714
According to the [Policy and Metaresources GEP](https://gateway-api.sigs.k8s.io/geps/gep-713/), the `WafPolicy` CRD must include a `status` stanza with a slice of Conditions.
702715

703-
The `Accepted` Condition must be populated on the `WafPolicy` CRD using the reasons defined in the [PolicyCondition API](https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1alpha2/policy_types.go). If these reasons are not sufficient, we can add implementation-specific reasons.
716+
The `Accepted` Condition must be populated on the `WafPolicy` CRD using the reasons defined in the [PolicyCondition API](https://github.com/kubernetes-sigs/gateway-api/blob/main/apis/v1alpha2/policy_types.go). Below are example implementation-specific reasons that describe the lifecycle phases and potential issues encountered while processing the policy:
717+
718+
| **Reason** | **Description** | **Example Message** |
719+
|---------------------------|---------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
720+
| **PolicySourceInvalid** | The `policySource` contains invalid or incomplete information. | "The policy source is invalid. Ensure fileLocation is correct." |
721+
| **PolicyFetchError** | Failed to fetch the policy due to network issues, authentication problems, or source misconfiguration. | "Failed to fetch policy bundle due to a network issue or invalid credentials." |
722+
| **PolicyIntegrityInvalid**| Checksum verification failed for the fetched policy bundle. | "Policy integrity check failed because of a checksum mismatch." |
723+
| **PolicyValidationError** | The WAF policy bundle failed schema or format validation for NGINX App Protect WAF. | "The policy bundle did not pass schema validation. Update the policy and retry compilation." |
724+
| **PolicyDeployed** | The policy was successfully deployed to the NGINX Data Plane (Pods). | "The policy has been successfully deployed and is now protecting the targeted resources." |
725+
| **PolicyDeployedUpdate** | An updated version of the policy was successfully deployed to the NGINX Data Plane (Pods) after polling or change detection. | "The policy has been updated and successfully redeployed to the targeted resources." |
726+
| **PolicyDeploymentError** | The data plane (NGINX Pods) failed to apply the policy. | "Failed to deploy the WAF policy to the NGINX Pods." |
727+
| **AuthenticationError** | Authentication to the external store (e.g., S3, HTTP) failed. | "Authentication error while trying to fetch the policy bundle." |
728+
| **PolicyConfigError** | The policy configuration prevents proper processing. | "The policy configuration is incomplete or incorrectly formatted. Correct the configuration and retry." |
729+
730+
### Example Status Conditions in `WafPolicy`
731+
732+
```yaml
733+
status:
734+
conditions:
735+
- type: Accepted
736+
status: "True"
737+
reason: PolicyDeployedUpdate
738+
message: "The policy has been updated and successfully redeployed to the Gateway."
739+
740+
- type: Accepted
741+
status: "False"
742+
reason: PolicyFetchError
743+
message: "Failed to fetch policy bundle due to a network issue or invalid credentials."
744+
745+
- type: Accepted
746+
status: "True"
747+
reason: PolicyDeployed
748+
message: "The policy has been successfully deployed and is now protecting the targeted resources."
749+
750+
- type: Accepted
751+
status: "False"
752+
reason: PolicyIntegrityInvalid
753+
message: "Policy integrity check failed because of a checksum mismatch."
754+
```
704755

705756
#### Setting Status on Objects Affected by a Policy
706757

@@ -1111,3 +1162,7 @@ This complete example demonstrates:
11111162
- **Native cloud authentication** with fallback secret support
11121163
- **Flexible logging configuration** per policy level
11131164
- **Automatic change detection** through configurable polling intervals
1165+
1166+
## Open questions
1167+
1168+
- Will NAP automatically pick up policy changes when the bundle is changed on disk? Do we need to reload NGINX?

0 commit comments

Comments
 (0)