Skip to content

Commit

Permalink
Merge branch 'main' into NET-5272/add-docs-team-for-code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
JadhavPoonam authored Aug 15, 2024
2 parents 14a5b77 + a7479a9 commit bc1c1f9
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/4247.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api-gateway: fix nil pointer deref bug when the section name in a gateway policy is not specified
```
3 changes: 3 additions & 0 deletions acceptance/tests/consul-dns/coredns-original.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

apiVersion: v1
data:
Corefile: |
Expand Down
3 changes: 3 additions & 0 deletions acceptance/tests/consul-dns/coredns-template.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

apiVersion: v1
data:
Corefile: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

apiVersion: consul.hashicorp.com/v1alpha1
kind: TerminatingGateway
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

apiVersion: consul.hashicorp.com/v1alpha1
kind: Registration
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

apiVersion: consul.hashicorp.com/v1alpha1
kind: TerminatingGateway
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

apiVersion: consul.hashicorp.com/v1alpha1
kind: Registration
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

apiVersion: consul.hashicorp.com/v1alpha1
kind: TerminatingGateway
metadata:
Expand Down
13 changes: 12 additions & 1 deletion control-plane/api-gateway/binding/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ func validateGateway(gateway gwv1beta1.Gateway, pods []corev1.Pod, consulGateway
return result
}

func stringOrEmtpy(s *gwv1beta1.SectionName) string {
if s == nil {
return ""
}
return string(*s)
}

func validateGatewayPolicies(gateway gwv1beta1.Gateway, policies []v1alpha1.GatewayPolicy, resources *common.ResourceMap) gatewayPolicyValidationResults {
results := make(gatewayPolicyValidationResults, 0, len(policies))

Expand All @@ -176,7 +183,7 @@ func validateGatewayPolicies(gateway gwv1beta1.Gateway, policies []v1alpha1.Gate

exists := listenerExistsForPolicy(gateway, policy)
if !exists {
result.resolvedRefsErrs = append(result.resolvedRefsErrs, errorForMissingListener(policy.Spec.TargetRef.Name, string(*policy.Spec.TargetRef.SectionName)))
result.resolvedRefsErrs = append(result.resolvedRefsErrs, errorForMissingListener(policy.Spec.TargetRef.Name, stringOrEmtpy(policy.Spec.TargetRef.SectionName)))
}

missingJWTProviders := make(map[string]struct{})
Expand Down Expand Up @@ -212,6 +219,10 @@ func validateGatewayPolicies(gateway gwv1beta1.Gateway, policies []v1alpha1.Gate
}

func listenerExistsForPolicy(gateway gwv1beta1.Gateway, policy v1alpha1.GatewayPolicy) bool {
if policy.Spec.TargetRef.SectionName == nil {
return false
}

return gateway.Name == policy.Spec.TargetRef.Name &&
slices.ContainsFunc(gateway.Spec.Listeners, func(l gwv1beta1.Listener) bool { return l.Name == *policy.Spec.TargetRef.SectionName })
}
Expand Down
7 changes: 6 additions & 1 deletion hack/copy-crds-to-chart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ func realMain(helmPath string) error {
// Add {{- if and .Values.connectInject.enabled .Values.global.peering.enabled }} {{- end }} wrapper.
contents = fmt.Sprintf("{{- if and .Values.connectInject.enabled .Values.global.peering.enabled }}\n%s{{- end }}\n", contents)
} else if dir == "external" {
contents = fmt.Sprintf("{{- if and .Values.connectInject.enabled .Values.connectInject.apiGateway.manageExternalCRDs }}\n%s{{- end }}\n", contents)
// TCP Route is special, as it isn't installed onto GKE Autopilot, so it needs to have the option for `manageNonStandardCRDs`.
if info.Name() == "tcproutes.gateway.networking.k8s.io.yaml" {
contents = fmt.Sprintf("{{- if and .Values.connectInject.enabled (or .Values.connectInject.apiGateway.manageExternalCRDs .Values.connectInject.apiGateway.manageNonStandardCRDs ) }}\n%s{{- end }}\n", contents)
} else {
contents = fmt.Sprintf("{{- if and .Values.connectInject.enabled .Values.connectInject.apiGateway.manageExternalCRDs }}\n%s{{- end }}\n", contents)
}
} else {
// Add {{- if .Values.connectInject.enabled }} {{- end }} wrapper.
contents = fmt.Sprintf("{{- if .Values.connectInject.enabled }}\n%s{{- end }}\n", contents)
Expand Down

0 comments on commit bc1c1f9

Please sign in to comment.