Skip to content

Commit bbc5c68

Browse files
committed
OCPBUGS-27965: escape '%' in proxy settings
The 'DefaultEnvironment' config from systemd accepts some % specifiers for expansion [1]. Because of that, proxy configurations that make use of that character need to be escaped with another '%'. However, during proxy validation, the Installer parses the URI and fails when it encounters a "%%" with an `invalid URL escape` error. To mitigate the problem, we introduce a new `replace` function to the templating system and use it to substitute "%" with "%%" causing the following config: ``` proxy: httpProxy: http://user%40test:[email protected]:3128 httpsProxy: http://user%40test:[email protected]:3128 ``` to become the `10-default-env.conf`: ``` [Manager] DefaultEnvironment=HTTP_PROXY="http://user%%40test:[email protected]:3128" DefaultEnvironment=HTTPS_PROXY="http://user%%40test:[email protected]:3128" ``` [1] https://man7.org/linux/man-pages/man5/systemd-system.conf.5.html
1 parent 514c886 commit bbc5c68

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{{if .Proxy -}}
22
[Manager]
33
{{if .Proxy.HTTPProxy -}}
4-
DefaultEnvironment=HTTP_PROXY="{{.Proxy.HTTPProxy}}"
4+
DefaultEnvironment=HTTP_PROXY="{{replace .Proxy.HTTPProxy "%" "%%"}}"
55
{{end -}}
66
{{if .Proxy.HTTPSProxy -}}
7-
DefaultEnvironment=HTTPS_PROXY="{{.Proxy.HTTPSProxy}}"
7+
DefaultEnvironment=HTTPS_PROXY="{{replace .Proxy.HTTPSProxy "%" "%%"}}"
88
{{end -}}
99
{{if .Proxy.NoProxy -}}
1010
DefaultEnvironment=NO_PROXY="{{.Proxy.NoProxy}}"
1111
{{end -}}
12-
{{end -}}
12+
{{end -}}

pkg/asset/ignition/bootstrap/common.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ func AddSystemdUnits(config *igntypes.Config, uri string, templateData interface
518518
return nil
519519
}
520520

521+
// replace is an utilitary function to do string replacement in templates.
522+
func replace(input, from, to string) string {
523+
return strings.ReplaceAll(input, from, to)
524+
}
525+
521526
// Read data from the string reader, and, if the name ends with
522527
// '.template', strip that extension from the name and render the
523528
// template.
@@ -529,7 +534,7 @@ func readFile(name string, reader io.Reader, templateData interface{}) (finalNam
529534

530535
if filepath.Ext(name) == ".template" {
531536
name = strings.TrimSuffix(name, ".template")
532-
tmpl := template.New(name)
537+
tmpl := template.New(name).Funcs(template.FuncMap{"replace": replace})
533538
tmpl, err := tmpl.Parse(string(data))
534539
if err != nil {
535540
return name, data, err

0 commit comments

Comments
 (0)