Skip to content

Commit

Permalink
fix(kuma-cp): deep copy tags when gen. outbounds (backport #5070) (#5090
Browse files Browse the repository at this point in the history
)

* fix(kuma-cp): deep copy tags when gen. outbounds (#5070)

It fixes potential data race (iterating and writing to tags map)

Signed-off-by: Bart Smykla <[email protected]>

Signed-off-by: Bart Smykla <[email protected]>
(cherry picked from commit 81ccca0)

# Conflicts:
#	pkg/xds/sync/proxy_builder_test.go
#	pkg/xds/topology/outbound.go

* fix: conflicts

Signed-off-by: Bart Smykla <[email protected]>

* chore: bump ubuntu ver. (22.04) for kuma-universal

Signed-off-by: Bart Smykla <[email protected]>

* chore: change apt to abt-get

Signed-off-by: Bart Smykla <[email protected]>

* chore: remove failing apt-get dist-upgrade

Signed-off-by: Bart Smykla <[email protected]>

* chore: remove specifying docker ver. in ci/build

Signed-off-by: Bart Smykla <[email protected]>

* chore: revert setup_remote_docker + bump 20.10.14

Signed-off-by: Bart Smykla <[email protected]>

Signed-off-by: Bart Smykla <[email protected]>
Co-authored-by: Bart Smykla <[email protected]>
  • Loading branch information
mergify[bot] and bartsmykla authored Oct 4, 2022
1 parent 1eceb83 commit 3073060
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ jobs:
name: Build all Kuma binaries (such as, kumactl, kuma-cp, kuma-dp, kuma-prometheus-sd)
command: make build
- setup_remote_docker:
version: 20.10.7
version: 20.10.14
- run:
name: Build Docker images
command: |
Expand Down
22 changes: 17 additions & 5 deletions pkg/xds/topology/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func fillDataplaneOutbounds(
dpNetworking := dpSpec.GetNetworking()

for _, inbound := range dpNetworking.GetHealthyInbounds() {
inboundTags := inbound.GetTags()
inboundTags := cloneTags(inbound.GetTags())
serviceName := inboundTags[mesh_proto.ServiceTag]
inboundInterface := dpNetworking.ToInboundInterface(inbound)
inboundAddress := inboundInterface.DataplaneAdvertisedIP
Expand Down Expand Up @@ -210,7 +210,9 @@ func fillIngressOutbounds(
if service.Mesh != mesh.GetMeta().GetName() {
continue
}
serviceTags := service.GetTags()

// deep copy map to not modify tags in BuildRemoteEndpointMap
serviceTags := cloneTags(service.GetTags())
serviceName := serviceTags[mesh_proto.ServiceTag]
serviceInstances := service.GetInstances()
locality := localityFromTags(mesh, priorityRemote, serviceTags)
Expand All @@ -237,7 +239,7 @@ func fillIngressOutbounds(
}
// this is necessary for correct spiffe generation for dp when
// traffic is routed: egress -> ingress -> egress
if mesh.ZoneEgressEnabled() && service.ExternalService {
if service.ExternalService {
endpoint.ExternalService = &core_xds.ExternalService{}
}

Expand Down Expand Up @@ -312,7 +314,8 @@ func fillExternalServicesOutboundsThroughEgress(
mesh *core_mesh.MeshResource,
) {
for _, externalService := range externalServices {
serviceTags := externalService.Spec.GetTags()
// deep copy map to not modify tags in ExternalService.
serviceTags := cloneTags(externalService.Spec.GetTags())
serviceName := serviceTags[mesh_proto.ServiceTag]
locality := localityFromTags(mesh, priorityRemote, serviceTags)

Expand Down Expand Up @@ -347,7 +350,8 @@ func NewExternalServiceEndpoint(
spec := externalService.Spec
tls := spec.GetNetworking().GetTls()
meshName := mesh.GetMeta().GetName()
tags := spec.GetTags()
// deep copy map to not modify tags in ExternalService.
tags := cloneTags(spec.GetTags())

es := &core_xds.ExternalService{
TLSEnabled: tls.GetEnabled(),
Expand Down Expand Up @@ -380,6 +384,14 @@ func NewExternalServiceEndpoint(
}, nil
}

func cloneTags(tags map[string]string) map[string]string {
result := map[string]string{}
for tag, value := range tags {
result[tag] = value
}
return result
}

func convertToEnvoy(ds *v1alpha1.DataSource, mesh string, loader datasource.Loader) []byte {
if ds == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions test/dockerfiles/Dockerfile.universal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM ubuntu:21.04
FROM ubuntu:22.04

RUN mkdir /kuma
RUN echo "# use this file to override default configuration of \`kuma-cp\`" > /kuma/kuma-cp.conf \
&& chmod a+rw /kuma/kuma-cp.conf

RUN apt update \
&& apt dist-upgrade -y \
RUN apt-get update \
&& apt-get dist-upgrade -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
curl \
dnsutils \
Expand Down

0 comments on commit 3073060

Please sign in to comment.