Skip to content

Commit 4f8afe2

Browse files
authored
only add istio automtls when label has value (#10574)
1 parent 65196f5 commit 4f8afe2

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
changelog:
2+
- type: FIX
3+
issueLink: https://github.com/solo-io/gloo/issues/10575
4+
resolvesIssue: true
5+
description: |
6+
When a workload has the label `security.istio.io/tlsMode: disabled`
7+
we will no longer attempt to send mTLS to that workload.

projects/gateway2/krtcollections/endpoints.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
"google.golang.org/protobuf/types/known/wrapperspb"
1414

1515
ggv2utils "github.com/solo-io/gloo/projects/gateway2/utils"
16-
"github.com/solo-io/gloo/projects/gloo/constants"
1716
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
1817
glookubev1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1/kube/apis/gloo.solo.io/v1"
1918
kubeplugin "github.com/solo-io/gloo/projects/gloo/pkg/api/v1/options/kubernetes"
19+
"github.com/solo-io/gloo/projects/gloo/pkg/plugins/istio_automtls"
2020
"github.com/solo-io/gloo/projects/gloo/pkg/translator"
2121
"github.com/solo-io/go-utils/contextutils"
2222
"istio.io/istio/pkg/kube"
@@ -336,7 +336,7 @@ func CreateLBEndpoint(address string, port uint32, podLabels map[string]string,
336336
metadata := &envoy_config_core_v3.Metadata{
337337
FilterMetadata: map[string]*structpb.Struct{},
338338
}
339-
metadata = addIstioAutomtlsMetadata(metadata, podLabels, enableAutoMtls)
339+
metadata = istio_automtls.AddIstioAutomtlsMetadata(metadata, podLabels, enableAutoMtls)
340340
// Don't add the annotations to the metadata - it's not documented so it's not coming
341341
// metadata = addAnnotations(metadata, addr.GetMetadata().GetAnnotations())
342342

@@ -365,24 +365,6 @@ func CreateLBEndpoint(address string, port uint32, podLabels map[string]string,
365365
}
366366
}
367367

368-
func addIstioAutomtlsMetadata(metadata *envoy_config_core_v3.Metadata, labels map[string]string, enableAutoMtls bool) *envoy_config_core_v3.Metadata {
369-
const EnvoyTransportSocketMatch = "envoy.transport_socket_match"
370-
if enableAutoMtls {
371-
if _, ok := labels[constants.IstioTlsModeLabel]; ok {
372-
metadata.GetFilterMetadata()[EnvoyTransportSocketMatch] = &structpb.Struct{
373-
Fields: map[string]*structpb.Value{
374-
constants.TLSModeLabelShortname: {
375-
Kind: &structpb.Value_StringValue{
376-
StringValue: constants.IstioMutualTLSModeLabel,
377-
},
378-
},
379-
},
380-
}
381-
}
382-
}
383-
return metadata
384-
}
385-
386368
func findPortForService(kctx krt.HandlerContext, services krt.Collection[*corev1.Service], spec *kubeplugin.UpstreamSpec) (*corev1.ServicePort, bool) {
387369
maybeSvc := krt.FetchOne(kctx, services, krt.FilterObjectName(types.NamespacedName{
388370
Namespace: spec.GetServiceNamespace(),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package istio_automtls
2+
3+
import (
4+
"github.com/solo-io/gloo/projects/gloo/constants"
5+
"google.golang.org/protobuf/types/known/structpb"
6+
7+
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
8+
)
9+
10+
const EnvoyTransportSocketMatch = "envoy.transport_socket_match"
11+
12+
// AddIstioAutomtlsMetadata adds metadata used by the transport_socket_match
13+
// to select the mTLS transport socket. The Envoy metadata label is added
14+
// based on the presence of the Istio workload label "security.istio.io/tlsMode=istio".
15+
func AddIstioAutomtlsMetadata(
16+
metadata *envoy_config_core_v3.Metadata,
17+
workloadLabels map[string]string,
18+
enableAutoMtls bool,
19+
) *envoy_config_core_v3.Metadata {
20+
if enableAutoMtls {
21+
// Valid label values are 'istio', 'disabled'
22+
// https://github.com/istio/api/blob/5b3f065ee1c2802fb4bc6010ac847c181caa6cc3/label/labels.gen.go#L285
23+
if value, ok := workloadLabels[constants.IstioTlsModeLabel]; ok && value == constants.IstioMutualTLSModeLabel {
24+
metadata.GetFilterMetadata()[EnvoyTransportSocketMatch] = &structpb.Struct{
25+
Fields: map[string]*structpb.Value{
26+
constants.TLSModeLabelShortname: {
27+
Kind: &structpb.Value_StringValue{
28+
StringValue: constants.IstioMutualTLSModeLabel,
29+
},
30+
},
31+
},
32+
}
33+
}
34+
}
35+
return metadata
36+
}

0 commit comments

Comments
 (0)