Skip to content

Commit

Permalink
Merge pull request #508 from rancher-sandbox/fix-localhost-proxies
Browse files Browse the repository at this point in the history
Replace localhost in proxy settings with gateway address
  • Loading branch information
AkihiroSuda authored Jan 1, 2022
2 parents 5aabbf6 + bf43edd commit 30e0550
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ func setupEnv(y *limayaml.LimaYAML) (map[string]string, error) {
upperVars[i] = strings.ToUpper(name)
}
if *y.PropagateProxyEnv {
localhostRegexes := []*regexp.Regexp{
regexp.MustCompile(`\blocalhost\b`),
regexp.MustCompile(`\b127.0.0.1\b`),
}
for _, name := range append(lowerVars, upperVars...) {
value, ok := os.LookupEnv(name)
if !ok {
continue
}
// Replace "localhost" in proxy settings with the gateway address
if name != "no_proxy" && name != "NO_PROXY" {
newValue := value
for _, re := range localhostRegexes {
newValue = re.ReplaceAllString(newValue, qemu.SlirpGateway)
}
if value != newValue {
logrus.Infof("Replacing %q value %q with %q", name, value, newValue)
value = newValue
if value, ok := os.LookupEnv(name); ok {
if _, ok := env[name]; ok && value != env[name] {
logrus.Infof("Overriding %q value %q with %q from limactl process environment",
name, env[name], value)
}
env[name] = value
}
}
}
// Replace "localhost" in proxy settings with the gateway address
localhostRegexes := []*regexp.Regexp{
regexp.MustCompile(`\blocalhost\b`),
regexp.MustCompile(`\b127.0.0.1\b`),
}
for _, name := range append(lowerVars, upperVars...) {
value, ok := env[name]
if ok && !strings.EqualFold(name, "no_proxy") {
for _, re := range localhostRegexes {
value = re.ReplaceAllString(value, qemu.SlirpGateway)
}
if _, ok := env[name]; ok && value != env[name] {
logrus.Infof("Overriding %q value %q with %q from limactl process environment",
name, env[name], value)
if value != env[name] {
logrus.Infof("Replacing %q value %q with %q", name, env[name], value)
env[name] = value
}
env[name] = value
}
}
// Make sure uppercase variants have the same value as lowercase ones.
Expand Down

0 comments on commit 30e0550

Please sign in to comment.