Skip to content

Commit

Permalink
When policies are attached to a gateway and mergeGateways is set to
Browse files Browse the repository at this point in the history
true, don't apply policies to routes from other gateways.

Signed-off-by: Lior Okman <lior.okman@sap.com>
  • Loading branch information
liorokman committed Feb 22, 2024
1 parent 4c79ef9 commit 99a7fdf
Show file tree
Hide file tree
Showing 165 changed files with 233 additions and 5 deletions.
7 changes: 7 additions & 0 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,14 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
// Should exist since we've validated this
ir := xdsIR[irKey]

policyTarget := irStringKey(
string(ptr.Deref(policy.Spec.TargetRef.Namespace, gwv1a2.Namespace(policy.Namespace))),
string(policy.Spec.TargetRef.Name),
)
for _, http := range ir.HTTP {
if t.MergeGateways && http.GatewayName != policyTarget {
continue
}
for _, r := range http.Routes {
// Apply if not already set
if r.RateLimit == nil {
Expand Down
9 changes: 5 additions & 4 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap
switch listener.Protocol {
case gwapiv1.HTTPProtocolType, gwapiv1.HTTPSProtocolType:
irListener := &ir.HTTPListener{
Name: irHTTPListenerName(listener),
Address: "0.0.0.0",
Port: uint32(containerPort),
TLS: irTLSConfigs(listener.tlsSecrets),
GatewayName: irStringKey(gateway.Namespace, gateway.Name),
Name: irHTTPListenerName(listener),
Address: "0.0.0.0",
Port: uint32(containerPort),
TLS: irTLSConfigs(listener.tlsSecrets),
Path: ir.PathSettings{
MergeSlashes: true,
EscapedSlashesAction: ir.UnescapeAndRedirect,
Expand Down
10 changes: 9 additions & 1 deletion internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ func (t *Translator) translateSecurityPolicyForGateway(
}
}

// Apply IR to all the routes within the specific Gateway
// Apply IR to all the routes within the specific Gateway that originated
// from the gateway to which this security policy was attached.
// If the feature is already set, then skip it, since it must have be
// set by a policy attaching to the route
//
Expand All @@ -372,7 +373,14 @@ func (t *Translator) translateSecurityPolicyForGateway(
// Should exist since we've validated this
ir := xdsIR[irKey]

policyTarget := irStringKey(
string(ptr.Deref(policy.Spec.TargetRef.Namespace, gwv1a2.Namespace(policy.Namespace))),
string(policy.Spec.TargetRef.Name),
)
for _, http := range ir.HTTP {
if t.MergeGateways && http.GatewayName != policyTarget {
continue
}
for _, r := range http.Routes {
// Apply if not already set
if r.CORS == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand All @@ -374,6 +375,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down Expand Up @@ -343,6 +344,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down Expand Up @@ -275,6 +276,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down Expand Up @@ -469,6 +470,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down Expand Up @@ -353,6 +354,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down Expand Up @@ -267,6 +268,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down Expand Up @@ -297,6 +298,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: default/gateway-1
name: default/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: true
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down Expand Up @@ -279,6 +280,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-1
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-1
path:
escapedSlashesAction: UnescapeAndRedirect
Expand All @@ -136,6 +137,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-2
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ xdsIR:
http1:
http10: {}
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-1
path:
escapedSlashesAction: UnescapeAndRedirect
Expand All @@ -221,6 +222,7 @@ xdsIR:
http10:
defaultHost: www.example.com
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-2
path:
escapedSlashesAction: UnescapeAndRedirect
Expand All @@ -231,6 +233,7 @@ xdsIR:
- '*'
http1: {}
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-3
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ xdsIR:
- '*'
http3: {}
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/tls
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-1
path:
escapedSlashesAction: KeepUnchanged
Expand All @@ -133,6 +134,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-2
path:
escapedSlashesAction: KeepUnchanged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ xdsIR:
enableTrailers: true
preserveHeaderCase: true
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-1
path:
escapedSlashesAction: UnescapeAndRedirect
Expand All @@ -139,6 +140,7 @@ xdsIR:
enableTrailers: true
preserveHeaderCase: true
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-2
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-1
path:
escapedSlashesAction: UnescapeAndRedirect
Expand All @@ -133,6 +134,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-2
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand All @@ -318,6 +319,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-2
name: envoy-gateway/gateway-2/http
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-1
path:
escapedSlashesAction: UnescapeAndRedirect
Expand All @@ -165,6 +166,7 @@ xdsIR:
hostnames:
- '*'
isHTTP2: false
gatewayName: envoy-gateway/gateway-1
name: envoy-gateway/gateway-1/http-2
path:
escapedSlashesAction: UnescapeAndRedirect
Expand Down
Loading

0 comments on commit 99a7fdf

Please sign in to comment.