Skip to content

Commit 0017e4b

Browse files
committed
Single targetRef and other clarifications
1 parent a20a4b4 commit 0017e4b

File tree

1 file changed

+15
-52
lines changed

1 file changed

+15
-52
lines changed

docs/proposals/nap-waf.md

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ A key design principle is seamless GitOps workflow support through automatic cha
6161

6262
The design uses **inherited policy attachment** following Gateway API best practices:
6363

64+
- **Single target per policy**: A WafPolicy targets a single resource (either a Gateway or a Route) following [gep-2649 guidelines](https://gateway-api.sigs.k8s.io/geps/gep-2649/#policy-targetref-api).
6465
- **Gateway-level policies** provide default protection for all routes attached to the Gateway
6566
- **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
67+
- NB: Route-level WafPolicies always override Gateway-level WafPolicies for routes they explicitly target. However, it is not possible to completely disable WAF protection for a specific Route when a Gateway-level WafPolicy is active. Instead, the Route-level policy configuration entirely replaces the Gateway-level policy for that route.
6768
- **Policy precedence**: More specific policies (Route-level) override less specific policies (Gateway-level)
6869
- **Automatic inheritance**: New routes automatically receive Gateway-level protection without explicit configuration
6970

@@ -207,7 +208,7 @@ This architecture demonstrates the hierarchical policy attachment system where G
207208

208209
**Application Namespace Resources:** All user-facing resources (Gateway, HTTPRoute, GRPCRoute, WafPolicy, NginxProxy, and optional authentication Secret) reside in application namespaces for proper isolation and RBAC management. The Secret is only required when using fallback authentication methods for accessing external policy storage - native cloud authentication (where available) uses annotations on the NGF service account in the nginx-gateway namespace.
209210

210-
**Policy Attachment Flow (Orange):** WafPolicy resources use targetRefs to attach to Gateways or Routes. Gateway-level policies provide inherited protection for all attached HTTPRoutes and GRPCRoutes. Route-level policies can override Gateway-level policies for specific routes requiring different protection levels.
211+
**Policy Attachment Flow (Orange):** WafPolicy resources use targetRef to attach to Gateways or Routes. Only one resource can be targeted at a time. Gateway-level policies provide inherited protection for all attached HTTPRoutes and GRPCRoutes. Route-level policies can override Gateway-level policies for specific routes requiring different protection levels.
211212

212213
**Traffic Flow (Yellow/Gold):** Client traffic (HTTP, HTTPS, and gRPC) flows through the public load balancer endpoint to the WAF-protected NGINX container, where NAP v5 applies security policies before forwarding filtered traffic to backend applications.
213214

@@ -258,7 +259,7 @@ spec:
258259
2. **Log Profile Development**: Create custom logging profiles or use built-in profiles (log_all, log_blocked, etc.)
259260
3. **Compilation**: Use NAP v5 compiler tools to create policy and logging profile bundles
260261
4. **Distribution**: Publish compiled policies and log profiles to accessible storage (S3, HTTP)
261-
5. **Configuration**: Create WafPolicy CR with targetRefs referencing Gateway or Routes and configuring security logging
262+
5. **Configuration**: Create WafPolicy CR with targetRef referencing a Gateway or a Route and configuring security logging
262263
6. **Automatic Application**: NGF fetches and applies policies when WafPolicy is created or updated, with automatic inheritance. Policies can also be updated by publishing new content to the same configured file path; when polling is enabled, NGF automatically detects and applies changes.
263264
264265
**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.
@@ -434,8 +435,8 @@ metadata:
434435
namespace: applications
435436
spec:
436437
# Policy attachment - targets Gateway for inherited protection
437-
targetRefs:
438-
- group: gateway.networking.k8s.io
438+
targetRef:
439+
group: gateway.networking.k8s.io
439440
kind: Gateway
440441
name: secure-gateway
441442
namespace: applications
@@ -518,8 +519,8 @@ metadata:
518519
namespace: applications
519520
spec:
520521
# Policy attachment - targets specific HTTPRoute to override Gateway policy
521-
targetRefs:
522-
- group: gateway.networking.k8s.io
522+
targetRef:
523+
group: gateway.networking.k8s.io
523524
kind: HTTPRoute
524525
name: admin-route
525526
namespace: applications
@@ -603,7 +604,7 @@ spec:
603604
backendRefs:
604605
- name: admin-service
605606
port: 8080
606-
# Uses admin-strict-policy WafPolicy override via targetRefs
607+
# Uses admin-strict-policy WafPolicy override via targetRef
607608
```
608609

609610
#### GRPCRoute Integration
@@ -802,7 +803,7 @@ Some additional rules:
802803

803804
- **NginxProxy Extensions**: WAF enablement configuration parsing and validation
804805
- **WafPolicy Controller**: CRUD operations, status management, and policy fetching logic
805-
- **Policy Attachment Logic**: targetRefs validation and inheritance resolution
806+
- **Policy Attachment Logic**: targetRef validation and inheritance resolution
806807
- **Multi-container Orchestration**: Container startup sequences and ephemeral volume management
807808
- **Policy Validation**: Compiled policy bundle checksum integrity checking
808809
- **Polling Engine**: Change detection logic and retry mechanisms
@@ -1001,8 +1002,8 @@ metadata:
10011002
namespace: applications
10021003
spec:
10031004
# Policy attachment - protects entire Gateway and inherits to all routes
1004-
targetRefs:
1005-
- group: gateway.networking.k8s.io
1005+
targetRef:
1006+
group: gateway.networking.k8s.io
10061007
kind: Gateway
10071008
name: secure-gateway
10081009
namespace: applications
@@ -1036,8 +1037,8 @@ metadata:
10361037
namespace: applications
10371038
spec:
10381039
# Policy attachment - overrides Gateway policy for specific route
1039-
targetRefs:
1040-
- group: gateway.networking.k8s.io
1040+
targetRef:
1041+
group: gateway.networking.k8s.io
10411042
kind: HTTPRoute
10421043
name: admin-route
10431044
namespace: applications
@@ -1093,7 +1094,7 @@ spec:
10931094
backendRefs:
10941095
- name: admin-service
10951096
port: 8080
1096-
# Uses admin-strict-protection WafPolicy override via targetRefs
1097+
# Uses admin-strict-protection WafPolicy override via targetRef
10971098
10981099
---
10991100
# 8. GRPCRoute inheriting Gateway protection
@@ -1116,48 +1117,10 @@ spec:
11161117
port: 9000
11171118
# Inherits gateway-base-protection WafPolicy automatically
11181119
1119-
---
1120-
# 9. Example showing multiple route targeting
1121-
apiVersion: gateway.nginx.org/v1alpha1
1122-
kind: WafPolicy
1123-
metadata:
1124-
name: api-routes-protection
1125-
namespace: applications
1126-
spec:
1127-
# Policy attachment - targets multiple routes with same policy
1128-
targetRefs:
1129-
- group: gateway.networking.k8s.io
1130-
kind: HTTPRoute
1131-
name: public-api-route
1132-
namespace: applications
1133-
- group: gateway.networking.k8s.io
1134-
kind: HTTPRoute
1135-
name: partner-api-route
1136-
namespace: applications
1137-
- group: gateway.networking.k8s.io
1138-
kind: GRPCRoute
1139-
name: api-grpc-service
1140-
namespace: applications
1141-
1142-
policySource:
1143-
fileLocation: "s3://company-waf-policies/production/api-specific-policy.tgz"
1144-
polling:
1145-
enabled: true
1146-
1147-
securityLogs:
1148-
- name: "api-logging"
1149-
logProfile: "log_blocked"
1150-
destination:
1151-
type: "Syslog"
1152-
syslog:
1153-
server: "syslog-svc.default:514"
1154-
```
1155-
11561120
This complete example demonstrates:
11571121
11581122
- **Gateway-level inherited protection** for all routes by default
11591123
- **Route-level policy overrides** for specific security requirements
1160-
- **Multi-route targeting** for applying the same policy to multiple routes
11611124
- **HTTP and gRPC route support** with seamless policy inheritance
11621125
- **Native cloud authentication** with fallback secret support
11631126
- **Flexible logging configuration** per policy level

0 commit comments

Comments
 (0)