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

Replace localhost in proxy settings with the gateway address #351

Merged
merged 1 commit into from
Oct 20, 2021

Conversation

jandubois
Copy link
Member

Lima uses process environment settings to override system proxy settings, and settings from the env key in lima.yaml.

This does not work when the proxy is running on a localhost address, so this commit replaces localhost with the slirp gateway address.

The new useProcessProxies setting can also be used to disable using the process environment variables to override proxy settings completely.

Motivation: rancher-sandbox/rancher-desktop#431 (comment)

@jandubois jandubois added the enhancement New feature or request label Oct 19, 2021
@jandubois jandubois added this to the v0.7.2 milestone Oct 19, 2021
@jandubois jandubois requested a review from AkihiroSuda October 20, 2021 03:48
# the VM, so it stays routable. Use of the process environment can be disabled by setting
# useProcessProxies to false.
# Default: true
useProcessProxies: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"replaceLocalhostProxies" might be more descriptive

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. If this option is false, then Lima will ignore the process environment. If it is true, then the process environment variables will override the proxy settings.

Lima will always replace "localhost" with the gateway address in proxy values from the environment, so this is not really what you control with this setting.

Now that I write this, I wonder if we should do the replacement in a final pass at the end, so proxys from the system settings are also processed. Except I wouldn't want to modify settings from lima.yaml, as those are obviously meant to be relative to the VM itself. So maybe the current PR implementation is good enough?

I don't really see any point in making the substitution configurable, as the variables will simply not work inside the VM otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All that being said, I would welcome a better name than useProcessProxies, which is hard to understand unless you read the whole paragraph above. The problem is that "host" refers also to the system settings, so I wanted a term that just refers to the environment variables of the limactl process when it is starting the VM...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about propagateProxyEnv ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, better.

Copy link

@dragosh dragosh Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @jandubois @AkihiroSuda thanks for a quick fix, just a small comment as I did give a test to the new version and looks like it ("sort of") works :)
By "sort of" I mean that in the initial limactl start the http(s)_proxy are propagated and replace with the GW IP.
The downside is the new environment vars are only available after another reboot l limactl stop/start since they are written in the /etc/environment file

  1. Initial start
...
INFO[0000] [hostagent] Replacing "http_proxy" value "http://localhost:3128" with "http://192.168.5.2:3128"
INFO[0000] [hostagent] Replacing "https_proxy" value "http://localhost:3128" with "http://192.168.5.2:3128"
...
lima
printenv | grep  https*_proxy
  1. Restart
printenv | grep  https*_proxy

https_proxy=http://192.168.5.2:3128
http_proxy=http://192.168.5.2:3128

Is maybe a way to inject that in a /etc/profile that is read after the initial login? so we can avoid extra provisioning scripts to reload the /etc/environment on user login, or if there is a better way for this, let me know!

Lima uses process environment settings to override system proxy
settings, and settings from the `env` key in lima.yaml.

This does not work when the proxy is running on a localhost address,
so this commit replaces localhost with the slirp gateway address.

The new `useProcessProxies` setting can also be used to disable using
the process environment variables to override proxy settings completely.

Signed-off-by: Jan Dubois <[email protected]>
@jandubois jandubois merged commit 9ca11fc into lima-vm:master Oct 20, 2021
@jandubois jandubois deleted the localhost-proxies branch October 20, 2021 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants