Skip to content

Commit

Permalink
Merge pull request #1759 from fangzhengjin/docker_login_escape_specia…
Browse files Browse the repository at this point in the history
…l_characters

fix: docker login escape special characters
  • Loading branch information
ks-ci-bot authored Mar 16, 2023
2 parents aef9f90 + c5af876 commit c6afa38
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmd/kk/pkg/container/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (p *DockerLoginRegistry) Execute(runtime connector.Runtime) error {
if len(entry.Username) == 0 || len(entry.Password) == 0 {
continue
}
cmd := fmt.Sprintf("docker login --username \"%s\" --password \"%s\" %s", entry.Username, entry.Password, repo)
cmd := fmt.Sprintf("docker login --username '%s' --password '%s' %s", escapeSpecialCharacters(entry.Username), escapeSpecialCharacters(entry.Password), repo)
if _, err := runtime.GetRunner().SudoCmd(cmd, false); err != nil {
return errors.Wrapf(err, "login registry failed, cmd: %v, err:%v", cmd, err)
}
Expand Down Expand Up @@ -139,3 +139,10 @@ func (d *DisableDocker) Execute(runtime connector.Runtime) error {
}
return nil
}

func escapeSpecialCharacters(str string) string {
newStr := strings.ReplaceAll(str, "$", "\\$")
newStr = strings.ReplaceAll(newStr, "&", "\\&")
newStr = strings.ReplaceAll(newStr, "*", "\\*")
return newStr
}

0 comments on commit c6afa38

Please sign in to comment.