Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(*): localhost exposed application shouldn't be reachable #4750

Merged
merged 21 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"net"
"os"
"path/filepath"
"time"
Expand All @@ -26,6 +25,7 @@ import (
"github.com/kumahq/kuma/pkg/util/proto"
kuma_version "github.com/kumahq/kuma/pkg/version"
"github.com/kumahq/kuma/pkg/xds/bootstrap/types"
xds_generator "github.com/kumahq/kuma/pkg/xds/generator"
)

var runLog = dataplaneLog.WithName("run")
Expand Down Expand Up @@ -300,7 +300,7 @@ func getApplicationsToScrape(kumaSidecarConfiguration *types.KumaSidecarConfigur
Name: item.Name,
Path: item.Path,
Port: item.Port,
IsIPv6: isIPv6(item.Address),
IsIPv6: xds_generator.IsAddressIPv6(item.Address),
QueryModifier: metrics.RemoveQueryParameters,
})
}
Expand All @@ -324,15 +324,3 @@ func writeFile(filename string, data []byte, perm os.FileMode) error {
}
return os.WriteFile(filename, data, perm)
}

func isIPv6(address string) bool {
if address == "" {
return false
}
ip := net.ParseIP(address)
if ip == nil {
return false
}

return ip.To4() == nil
}
4 changes: 0 additions & 4 deletions pkg/xds/bootstrap/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,9 @@ func (b *bootstrapGenerator) getMetricsConfig(
}

var address string
var isIPv6 bool
if b.enableLocalhostInboundCluster {
isIPv6 = false
address = core_mesh.IPv4Loopback.String()
} else {
isIPv6 = dataplane.IsIPv6()
address = dataplane.Spec.GetNetworking().GetAddress()
}

Expand All @@ -228,7 +225,6 @@ func (b *bootstrapGenerator) getMetricsConfig(
Name: config.Name,
Port: config.Port,
Path: config.Path,
IsIPv6: isIPv6,
})
}
kumaDpBootstrap.AggregateMetricsConfig = aggregateConfig
Expand Down
1 change: 0 additions & 1 deletion pkg/xds/bootstrap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func createBootstrapResponse(bootstrap []byte, config *KumaDpBootstrap) *types.B
Name: value.Name,
Port: value.Port,
Path: value.Path,
IsIPv6: value.IsIPv6,
})
}
bootstrapConfig.KumaSidecarConfiguration = types.KumaSidecarConfiguration{
Expand Down
1 change: 0 additions & 1 deletion pkg/xds/bootstrap/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type AggregateMetricsConfig struct {
Path string
Address string
Port uint32
IsIPv6 bool
}

type configParameters struct {
Expand Down
1 change: 0 additions & 1 deletion pkg/xds/bootstrap/types/bootstrap_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ type Aggregate struct {
Address string `json:"address"`
Port uint32 `json:"port"`
Path string `json:"path"`
IsIPv6 bool `json:"isIPv6"`
}
2 changes: 1 addition & 1 deletion pkg/xds/generator/inbound_proxy_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (g InboundProxyGenerator) Generate(ctx xds_context.Context, proxy *core_xds
// localhost traffic is routed dirrectly to the application, in case of other interface we are going to set source address to
// 127.0.0.6 to avoid redirections and thanks to first iptables rule just return fast
michaelbeaumont marked this conversation as resolved.
Show resolved Hide resolved
if endpoint.WorkloadIP != core_mesh.IPv4Loopback.String() || endpoint.WorkloadIP != core_mesh.IPv6Loopback.String() {
switch proxy.Dataplane.IsIPv6() {
switch IsAddressIPv6(endpoint.WorkloadIP) {
case true:
clusterBuilder.Configure(envoy_clusters.UpstreamBindConfig(inPassThroughIPv6, 0))
case false:
Expand Down
16 changes: 16 additions & 0 deletions pkg/xds/generator/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package generator

import "net"

func IsAddressIPv6(address string) bool {
lukidzi marked this conversation as resolved.
Show resolved Hide resolved
if address == "" {
return false
}

ip := net.ParseIP(address)
if ip == nil {
return false
}

return ip.To4() == nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func InboundPassthroughDisabled() {
localhostAddress := "127.0.0.1"
wildcardAddress := "0.0.0.0"
if Config.IPV6 {
localhostAddress = "::1"
wildcardAddress = "::"
}

Expand Down