-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Leak the HTTP*PROXY environment variables into the VM when doing a podman machine start. #13168
Comments
The goal here is if you are sitting on a MAC and have these settings set, you want your Podman within the VM to follow them also. |
Hey @rhatdan |
Go for it. |
@baude thinks this could be done via qemu. |
Please use the latest Edit: |
I see we would also need them to be in |
Got it. Thanks! Will do it |
@esendjer Something similar on the lines of following diff should be enough. diff --git a/pkg/machine/ignition.go b/pkg/machine/ignition.go
index 206c9144f..89c5f515a 100644
--- a/pkg/machine/ignition.go
+++ b/pkg/machine/ignition.go
@@ -363,7 +363,7 @@ Delegate=memory pids cpu io
},
})
- setProxyOpts := getProxyVariables()
+ setProxyOpts := getProxyVariables(false)
if setProxyOpts != "" {
files = append(files, File{
Node: Node{
@@ -381,9 +381,26 @@ Delegate=memory pids cpu io
})
}
+ setProxyOpts = getProxyVariables(true)
+ if setProxyOpts != "" {
+ files = append(files, File{
+ Node: Node{
+ Group: getNodeGrp("root"),
+ Path: "/etc/systemd/system/system.conf.d/http-proxy.conf",
+ User: getNodeUsr("root"),
+ },
+ FileEmbedded1: FileEmbedded1{
+ Append: nil,
+ Contents: Resource{
+ Source: encodeDataURLPtr(setProxyOpts),
+ },
+ Mode: intToPtr(0644),
+ },
+ })
+ }
+
setDockerHost := `export DOCKER_HOST="unix://$(podman info -f "{{.Host.RemoteSocket.Path}}")"
`
-
files = append(files, File{
Node: Node{
Group: getNodeGrp("root"),
@@ -506,11 +523,18 @@ func prepareCertFile(path string, name string) (File, error) {
return file, nil
}
-func getProxyVariables() string {
+func getProxyVariables(systemd bool) string {
proxyOpts := ""
+ if systemd {
+ proxyOpts = "[Service]\n"
+ }
for _, variable := range config.ProxyEnv {
if value, ok := os.LookupEnv(variable); ok {
- proxyOpts += fmt.Sprintf("\n export %s=%s", variable, value)
+ if !systemd {
+ proxyOpts += fmt.Sprintf("\n export %s=%s", variable, value)
+ } else {
+ proxyOpts += fmt.Sprintf("Environment=\"%s=%s\"\n", variable, value)
+ }
}
}
return proxyOpts |
Hey folks! |
The research has been done. Smal outcomes are below.
So it will be done with the last option UPD |
If this is done in ignition, then it will only happen once correct, not every time the machine is started? |
Unfortunately, it's true for now, but at the same time, the current state doesn't allow propagating anything on a start too, because there are no mechanisms for this here now. Let me dive deeper into the question about how it might be done on a start. Also, I would ask you about embedding bash/python code in ignition is ok? I'm not sure that this way will be used, but it's important to me to know this before. |
I have no idea, best idea is to try it out and see if it works. |
@rhatdan @esendjer I think it will happen everytime when we do The only drawback is that it will keep the environment variable exactly as it was on |
Correct, I am fine with this improvement but this is not really fixed if I do podman macine init Will not work. |
I hope, in the last commit I found a good way to provide and propagate environment variables related to proxy settings on a start |
Sorry, but unfortunately, it's still is not good enough WIP |
This would be an excellent candidate for a cabal, where all the community experts can contribute. What say you? |
@baude sorry, I don't understand what for a cabal means. Is it an offer to attract the attention of the community experts and ask them for help and advice? So, maybe it is so. But I've managed to deal with the issue, just take a look at the latest commit. In that commit, all settings are propagated on a start successfully without a need to re-init and restart VM twice. |
Set proxy settings (such as `HTTP_PROXY`, and others) for the whole guest OS with setting up `DefaultEnvironment` with a `systemd` configuration file `default-env.conf`, a `profile.d` scenario file - `default-env.sh` and a `environment.d` configuration file `default-env.conf` The **actual** environment variables are read by podman at a start, then they are encrypted with base64 into a single string and after are provided into a VM through QEMU Firmware Configuration (fw_cfg) Device Inside a VM a systemd service `envset-fwcfg.service` reads the providead encrypted string from fw_cfg, decrypts and then adds to the files - `/etc/systemd/system.conf.d/default-env.conf` - `/etc/profile.d/default-env.sh` - `/etc/environment.d/default-env.conf` At the end this service execute `systemctl daemon-reload` to propagate new variables for systemd manager [NO NEW TESTS NEEDED] Closes containers#13168 Signed-off-by: esendjer <[email protected]>
Set proxy settings (such as `HTTP_PROXY`, and others) for the whole guest OS with setting up `DefaultEnvironment` with a `systemd` configuration file `default-env.conf`, a `profile.d` scenario file - `default-env.sh` and a `environment.d` configuration file `default-env.conf` The **actual** environment variables are read by podman at a start, then they are encrypted with base64 into a single string and after are provided into a VM through QEMU Firmware Configuration (fw_cfg) Device Inside a VM a systemd service `envset-fwcfg.service` reads the providead encrypted string from fw_cfg, decrypts and then adds to the files - `/etc/systemd/system.conf.d/default-env.conf` - `/etc/profile.d/default-env.sh` - `/etc/environment.d/default-env.conf` At the end this service execute `systemctl daemon-reload` to propagate new variables for systemd manager [NO NEW TESTS NEEDED] Closes containers#13168 Signed-off-by: esendjer <[email protected]>
Leak the following environment variables
Into the VM at start time.
<@cyberpear> systemd will set them if you pass on the kernel CMDLINE
systemd.setenv=VARIABLE=VALUE
at bootThe text was updated successfully, but these errors were encountered: