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

Setup proxy environment variables from system settings #266

Merged
merged 1 commit into from
Sep 29, 2021

Conversation

jandubois
Copy link
Member

@jandubois jandubois commented Sep 23, 2021

Implement the changes suggested in #189 (comment).

env.* settings from lima.yaml will override system settings.

Process environment during instance creation override all.

Fixes #189 (comment)

@jandubois
Copy link
Member Author

This change is fully functional (afaict), but I'm still thinking about it's limitations: environment settings are "baked in" to the instance at the time it is created.

So how do we deal with e.g. a laptop that is moving between a company office requiring certain proxies and a public Wifi setup, using a VPN?

There is no way to update proxy settings even by stopping and restarting the instance, so maybe we need a different mechanism.

@jandubois
Copy link
Member Author

There is no way to update proxy settings even by stopping and restarting the instance

One way to deal with this would be to re-create the cidata volume on each instance start. This would also allow you to e.g. edit the provisioning scripts, or the dns and env settings without having to destroy and recreate the instance.

@AkihiroSuda what do you think?

@AkihiroSuda
Copy link
Member

Aren’t we already always recreating cidata.iso ?

@jandubois
Copy link
Member Author

Aren’t we already always recreating cidata.iso ?

Looks like it. When I tested last night, I didn't see changes to proxy settings after a restart. The only explanation I can come up with is that I ran make all instead of make all install before doing my tests (I was testing with an older pre-existing instance).

But that's good, so maybe this PR is sufficient then.

@jandubois
Copy link
Member Author

Given that we recreate cidata on each instance start, I think the PR is good as-is.

Interface string `json:"interface"`
DNS DNS `json:"DNS"`
Interface string `json:"interface"`
Proxies Proxies `json:"proxies"`
Copy link
Member

Choose a reason for hiding this comment

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

nit: json:”Proxies” for consistency with other json fields

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting! I didn't know that JSON marshalling will use a case-insensitive match if it can't find an exact match, which is why this still worked despite not having the right capitalization. Fixed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've left interface lowercase because that is how it comes in from system_profiler:

$ system_profiler SPNetworkDataType -json | jq -r '.SPNetworkDataType[0]|keys[]' | sort
DNS
Ethernet
IPv4
IPv6
Proxies
_name
dhcp
hardware
interface
ip_address
sleep_proxies
spnetwork_service_order
type

env.* settings from lima.yaml will override system settings.

Process environment during instance creation override all.

Signed-off-by: Jan Dubois <[email protected]>
PortForwards []PortForward `yaml:"portForwards,omitempty"`
Networks []Network `yaml:"networks,omitempty"`
Network NetworkDeprecated `yaml:"network,omitempty"` // DEPRECATED, use `networks` instead
Env map[string]string `yaml:"env,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Why was *string changed to string?

Copy link
Member Author

Choose a reason for hiding this comment

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

There was some reason, but I don't remember, and it no longer applies; I can easily change it back. Please confirm if you want me to do that!

I asked back in #195 (comment) why it was a *string to begin with because I was having issues with them in templates elsewhere, but didn't receive a response.

So I'm still curious why it should be a *string. Theoretically we could use nil vs "" to "unset" an environment variable, but that doesn't make much sense in /etc/environment, so I still have no idea...

Copy link
Member Author

Choose a reason for hiding this comment

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

So it doesn't matter because (1) we no longer pass y.Env directly to the template, and (2) because we don't use printf on the values, but if we did, here is the difference (using this template):

#LIMA-START
{{- range $key, $val := .Env}}
{{$key}}={{$val}}
{{printf "%s=%q" $key $val}}
{{- end}}
#LIMA-END

produces this output:

#LIMA-START
KEY=value"value
KEY=%!q(*string=0xc0001bb2a0)
#LIMA-END

which is what prejudices me against the *string. 😸

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

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.

Add support for HTTP Proxy or any generic environment variables
2 participants