Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Writing proxy.sh from environment character escape errors #2785

Closed
k00p opened this issue May 22, 2019 · 2 comments
Closed

Writing proxy.sh from environment character escape errors #2785

k00p opened this issue May 22, 2019 · 2 comments

Comments

@k00p
Copy link

k00p commented May 22, 2019

proxyLines = append(proxyLines, fmt.Sprintf("export %s=%s", k, v))

Presence of special characters (i.e. &) in proxy environment values causes generation of an invalid /etc/profile.d/proxy.sh file. This is a problem due to the common inclusion of special characters in passwords and proxy strings of the format htt[p|s]://user:pass@url:port.

Not sure what the appropriate fix would be - wrapping the proxy strings in double quotes works in my case (with the & issue), but that would be problematic if the special character in question was a double quote.

Possibly changing the line from:

proxyLines = append(proxyLines, fmt.Sprintf("export %s=%s", k, v))

To:

proxyLines = append(proxyLines, fmt.Sprintf("export %s=%q", k, v))

With the %q providing string escaping would work, but I don't have the experience with Go to be confidant with that solution.

@niusmallnan
Copy link
Contributor

Here is my test case after building with the latest commit.

I use this cloud-config:

#cloud-config
rancher:
  network:
    http_proxy: https://myproxy.example.com
    https_proxy: https://user:xx&xx@myproxy.example.com
    no_proxy: localhost,127.0.0.1

Then check the proxy after reboot:

$ env
...
https_proxy=https://user:xx&xx@myproxy.example.com
http_proxy=https://myproxy.example.com
no_proxy=localhost,127.0.0.1
NO_PROXY=localhost,127.0.0.1
HTTPS_PROXY=https://user:xx&xx@myproxy.example.com
...

[rancher@rancher-dev ~]$ cat /etc/profile.d/proxy.sh
#!/bin/sh
export http_proxy="https://myproxy.example.com"
export HTTP_PROXY="https://myproxy.example.com"
export https_proxy="https://user:xx&xx@myproxy.example.com"
export HTTPS_PROXY="https://user:xx&xx@myproxy.example.com"
export no_proxy="localhost,127.0.0.1"
export NO_PROXY="localhost,127.0.0.1"

@kingsd041
Copy link
Contributor

Fixed in ros v1.5.2-rc2
I also verified other special characters, such as:

https_proxy=https://u1s&er:password!#$%^&*()_+@myproxy.example.com
http_proxy=https://user:password!#$%^&*()_+@myproxy.example.com

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants