Skip to content

Commit

Permalink
fix(meshservice): permissive mTLS of synced services (#11749)
Browse files Browse the repository at this point in the history
## Motivation

We want to use permissive mTLS with MeshServices. It turned out that
synced services are not marked as TLS ready in this case, but actually
it's the only way to access them (through Zone Ingress)

## Implementation information

Always mark synced MeshService as TLS ready

## Supporting documentation

No issue created. Reported by Baptiste

Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
  • Loading branch information
jakubdyszkiewicz authored Oct 18, 2024
1 parent 1b6afe9 commit 948e6a4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/core/resources/apis/meshservice/api/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func (m *MeshServiceResource) FindPortByName(name string) (Port, bool) {
return Port{}, false
}

func (m *MeshServiceResource) IsLocalMeshService(localZone string) bool {
func (m *MeshServiceResource) IsLocalMeshService() bool {
if len(m.GetMeta().GetLabels()) == 0 {
return true // no labels mean that it's a local resource
}
resZone, ok := m.GetMeta().GetLabels()[mesh_proto.ZoneTag]
origin, ok := m.GetMeta().GetLabels()[mesh_proto.ResourceOriginLabel]
if !ok {
return true // no zone label mean that it's a local resource
}
return resZone == localZone
return origin == string(mesh_proto.ZoneResourceOrigin)
}

var _ core_vip.ResourceHoldingVIPs = &MeshServiceResource{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/resources/apis/meshservice/status/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *StatusUpdater) updateStatus(ctx context.Context) error {
dppsForMs := meshservice.MatchDataplanesWithMeshServices(dpList.Items, msList.Items, false)

for ms, dpps := range dppsForMs {
if !ms.IsLocalMeshService(s.localZone) {
if !ms.IsLocalMeshService() {
// identities are already computed by the other zone
continue
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/core/resources/apis/meshservice/status/updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ var _ = Describe("Updater", func() {
// when
Expect(samples.MeshServiceBackendBuilder().
WithLabels(map[string]string{
v1alpha1.ZoneTag: "west",
v1alpha1.ZoneTag: "west",
v1alpha1.ResourceOriginLabel: string(v1alpha1.GlobalResourceOrigin),
}).
AddServiceTagIdentity("backend").
Create(resManager)).To(Succeed())
Expand Down
5 changes: 4 additions & 1 deletion pkg/plugins/policies/core/xds/meshroute/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ func GenerateClusters(
}
} else {
if realResourceRef := service.BackendRef().RealResourceBackendRef(); realResourceRef != nil {
tlsReady = true // tls readiness is only relevant for MeshService
if common_api.TargetRefKind(realResourceRef.Resource.ResourceType) == common_api.MeshService {
if ms := meshCtx.MeshServiceByIdentifier[pointer.Deref(realResourceRef.Resource).ResourceIdentifier]; ms != nil {
tlsReady = ms.Status.TLS.Status == meshservice_api.TLSReady
// we only check TLS status for local service
// services that are synced can be accessed only with TLS through ZoneIngress
tlsReady = !ms.IsLocalMeshService() || ms.Status.TLS.Status == meshservice_api.TLSReady
}
}
edsClusterBuilder.Configure(envoy_clusters.ClientSideMultiIdentitiesMTLS(
Expand Down
9 changes: 4 additions & 5 deletions pkg/xds/topology/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func BuildEdsEndpointMap(
fillExternalServicesOutboundsThroughEgress(outbound, externalServices, meshExternalServices, zoneEgresses, mesh, localZone)

// it has to be last because it reuses endpoints for other cases
fillMeshMultiZoneServices(outbound, meshServicesByName, meshMultiZoneServices, localZone)
fillMeshMultiZoneServices(outbound, meshServicesByName, meshMultiZoneServices)

return outbound
}
Expand All @@ -139,7 +139,6 @@ func fillMeshMultiZoneServices(
outbound core_xds.EndpointMap,
meshServicesByName map[model.ResourceIdentifier]*meshservice_api.MeshServiceResource,
meshMultiZoneServices []*meshmzservice_api.MeshMultiZoneServiceResource,
localZone string,
) {
for _, mzSvc := range meshMultiZoneServices {
for _, matchedMs := range mzSvc.Status.MeshServices {
Expand All @@ -153,7 +152,7 @@ func fillMeshMultiZoneServices(
if !ok {
continue
}
if !ms.IsLocalMeshService(localZone) && ms.Spec.State != meshservice_api.StateAvailable {
if !ms.IsLocalMeshService() && ms.Spec.State != meshservice_api.StateAvailable {
// we don't want to load balance to zones that has no available endpoints.
// we check this only for non-local services, because if service is unavailable in the local zone it has no endpoints.
// if a new local endpoint just become healthy, we can add it immediately without waiting for state to be reconciled.
Expand Down Expand Up @@ -215,7 +214,7 @@ func fillRemoteMeshServices(
}

for _, ms := range services {
if ms.IsLocalMeshService(localZone) {
if ms.IsLocalMeshService() {
continue
}
msZone := ms.GetMeta().GetLabels()[mesh_proto.ZoneTag]
Expand Down Expand Up @@ -328,7 +327,7 @@ func fillLocalMeshServices(
) {
dppsForMs := meshservice.MatchDataplanesWithMeshServices(dataplanes, meshServices, true)
for meshSvc, dpps := range dppsForMs {
if !meshSvc.IsLocalMeshService(localZone) {
if !meshSvc.IsLocalMeshService() {
continue
}

Expand Down
8 changes: 7 additions & 1 deletion test/e2e_env/multizone/meshservice/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/onsi/gomega/types"
kube_meta "k8s.io/apimachinery/pkg/apis/meta/v1"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/pkg/config/core"
"github.com/kumahq/kuma/pkg/test/resources/samples"
"github.com/kumahq/kuma/test/e2e_env/kubernetes/gateway"
. "github.com/kumahq/kuma/test/framework"
"github.com/kumahq/kuma/test/framework/client"
Expand All @@ -29,7 +31,11 @@ func Connectivity() {
var testServerPodNames []string
BeforeAll(func() {
Expect(NewClusterSetup().
Install(MTLSMeshWithMeshServicesUniversal(meshName, "Everywhere")).
Install(Yaml(samples.MeshMTLSBuilder().
WithName(meshName).
WithMeshServicesEnabled(mesh_proto.Mesh_MeshServices_Everywhere).
WithPermissiveMTLSBackends(),
)).
Install(MeshTrafficPermissionAllowAllUniversal(meshName)).
Install(YamlUniversal(fmt.Sprintf(`
type: HostnameGenerator
Expand Down

0 comments on commit 948e6a4

Please sign in to comment.