Skip to content

Commit 10a31f1

Browse files
authored
fix: nil pointer error (envoyproxy#5000)
* fix: nil pointer error Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
1 parent f71fa99 commit 10a31f1

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

internal/gatewayapi/securitypolicy.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,16 @@ func backendRefAuthority(resources *resource.Resources, backendRef *gwapiv1.Back
962962
}
963963
}
964964

965-
return net.JoinHostPort(
966-
fmt.Sprintf("%s.%s", backendRef.Name, backendNamespace),
967-
strconv.Itoa(int(*backendRef.Port)),
968-
)
965+
// Port is mandatory for Kubernetes services
966+
if backendKind == resource.KindService {
967+
return net.JoinHostPort(
968+
fmt.Sprintf("%s.%s", backendRef.Name, backendNamespace),
969+
strconv.Itoa(int(*backendRef.Port)),
970+
)
971+
}
972+
973+
// Fallback to the backendRef name, normally it's a unix domain socket in this case
974+
return fmt.Sprintf("%s.%s", backendRef.Name, backendNamespace)
969975
}
970976

971977
func (t *Translator) buildAuthorization(policy *egv1a1.SecurityPolicy) (*ir.Authorization, error) {

internal/gatewayapi/testdata/securitypolicy-with-extauth-backend.in.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ backends:
107107
- fqdn:
108108
hostname: 'primary.foo.com'
109109
port: 3000
110+
- apiVersion: gateway.envoyproxy.io/v1alpha1
111+
kind: Backend
112+
metadata:
113+
name: backend-uds
114+
namespace: default
115+
spec:
116+
endpoints:
117+
- unix:
118+
path: '/var/run/uds.sock'
110119
referenceGrants:
111120
- apiVersion: gateway.networking.k8s.io/v1alpha2
112121
kind: ReferenceGrant
@@ -179,7 +188,6 @@ securityPolicies:
179188
extAuth:
180189
http:
181190
backendRef:
182-
name: backend-fqdn
191+
name: backend-uds
183192
kind: Backend
184193
group: gateway.envoyproxy.io
185-
port: 3000

internal/gatewayapi/testdata/securitypolicy-with-extauth-backend.out.yaml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ backends:
1717
reason: Accepted
1818
status: "True"
1919
type: Accepted
20+
- apiVersion: gateway.envoyproxy.io/v1alpha1
21+
kind: Backend
22+
metadata:
23+
creationTimestamp: null
24+
name: backend-uds
25+
namespace: default
26+
spec:
27+
endpoints:
28+
- unix:
29+
path: /var/run/uds.sock
30+
status:
31+
conditions:
32+
- lastTransitionTime: null
33+
message: The Backend was accepted
34+
reason: Accepted
35+
status: "True"
36+
type: Accepted
2037
gateways:
2138
- apiVersion: gateway.networking.k8s.io/v1
2239
kind: Gateway
@@ -322,8 +339,7 @@ securityPolicies:
322339
backendRef:
323340
group: gateway.envoyproxy.io
324341
kind: Backend
325-
name: backend-fqdn
326-
port: 3000
342+
name: backend-uds
327343
targetRef:
328344
group: gateway.networking.k8s.io
329345
kind: HTTPRoute
@@ -526,14 +542,15 @@ xdsIR:
526542
security:
527543
extAuth:
528544
http:
529-
authority: primary.foo.com:3000
545+
authority: backend-uds.default
530546
destination:
531547
name: securitypolicy/default/policy-for-http-route-3-http-backendref/extauth/0
532548
settings:
533-
- addressType: FQDN
549+
- addressType: IP
534550
endpoints:
535-
- host: primary.foo.com
536-
port: 3000
551+
- host: ""
552+
path: /var/run/uds.sock
553+
port: 0
537554
protocol: HTTP
538555
weight: 1
539556
path: ""

release-notes/current.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ new features: |
2020
2121
# Fixes for bugs identified in previous versions.
2222
bug fixes: |
23+
Fixed a nil pointer error that occurs when a SecurityPolicy refers to a UDS backend
2324
2425
# Enhancements that improve performance.
2526
performance improvements: |

0 commit comments

Comments
 (0)