ssh and git: a user, host or URL starting with - isn't taken as an option
An answers file passed with --config (or an imported one) could set the SSH user to -oProxyCommand=... and run it on this machine. '--' before the destination and the repository stops ssh and git reading them as options. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
704cd39bb1
commit
06dbed58b9
6 files changed
+7
-7
No files matched your search
@@ -227,7 +227,7 @@ func FetchPlaybook(ctx context.Context, c *config.Config) error {
|
||||
if err := os.MkdirAll(filepath.Dir(c.PlaybookDir), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "git", "clone", "--depth", "1", c.Sources.PlaybookGit, c.PlaybookDir)
|
||||
cmd := exec.CommandContext(ctx, "git", "clone", "--depth", "1", "--", c.Sources.PlaybookGit, c.PlaybookDir)
|
||||
cmd.Env = Env(c)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
|
||||
@@ -88,7 +88,7 @@ func Preflight(c *config.Config) []Check {
|
||||
}
|
||||
|
||||
func gitReachable(ctx context.Context, url string) (string, error) {
|
||||
cmd := exec.CommandContext(ctx, "git", "ls-remote", url, "HEAD")
|
||||
cmd := exec.CommandContext(ctx, "git", "ls-remote", "--", url, "HEAD")
|
||||
cmd.Env = append(cmd.Environ(), "GIT_TERMINAL_PROMPT=0")
|
||||
b, err := cmd.Output()
|
||||
if err != nil {
|
||||
|
||||
@@ -391,7 +391,7 @@ func (r *Runner) playbook(ctx context.Context) error {
|
||||
dir := r.cfg.PlaybookDir
|
||||
if _, err := os.Stat(filepath.Join(dir, ".git")); err == nil {
|
||||
before := r.gitHead(dir)
|
||||
err := r.exec(ctx, StepPlaybook, dir, "git", "remote", "set-url", "origin", r.cfg.Sources.PlaybookGit)
|
||||
err := r.exec(ctx, StepPlaybook, dir, "git", "remote", "set-url", "--", "origin", r.cfg.Sources.PlaybookGit)
|
||||
if pin := r.cfg.PinnedCommit; err == nil && pin != "" {
|
||||
err = r.checkout(ctx, dir, pin)
|
||||
r.playbookUpdated = before != r.gitHead(dir)
|
||||
@@ -419,7 +419,7 @@ func (r *Runner) playbook(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
r.playbookUpdated = true
|
||||
if err := r.exec(ctx, StepPlaybook, "", "git", "clone", "--depth", "1", r.cfg.Sources.PlaybookGit, dir); err != nil {
|
||||
if err := r.exec(ctx, StepPlaybook, "", "git", "clone", "--depth", "1", "--", r.cfg.Sources.PlaybookGit, dir); err != nil {
|
||||
return err
|
||||
}
|
||||
if pin := r.cfg.PinnedCommit; pin != "" {
|
||||
|
||||
@@ -29,7 +29,7 @@ func (r *Runner) dryPlaybook(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := r.exec(ctx, StepDryPlaybook, dir, "git", "fetch", "--quiet", r.cfg.Sources.PlaybookGit, defaultBranch(dir)); err != nil {
|
||||
if err := r.exec(ctx, StepDryPlaybook, dir, "git", "fetch", "--quiet", "--", r.cfg.Sources.PlaybookGit, defaultBranch(dir)); err != nil {
|
||||
return err
|
||||
}
|
||||
return r.exec(ctx, StepDryPlaybook, dir, "git", "checkout", "--quiet", "--force", "--detach", "FETCH_HEAD")
|
||||
|
||||
@@ -31,7 +31,7 @@ func sshArgs(t config.Target) []string {
|
||||
if t.SSHKey != "" {
|
||||
args = append(args, "-i", config.ExpandHome(t.SSHKey))
|
||||
}
|
||||
return append(args, t.User+"@"+t.Host)
|
||||
return append(args, "--", t.User+"@"+t.Host) // --: a user or host starting with - isn't an option
|
||||
}
|
||||
|
||||
// sshReuse keeps one connection per server open for a while and shares it
|
||||
|
||||
@@ -107,7 +107,7 @@ func gitHasVersion(ctx context.Context, url, version string) (string, error) {
|
||||
}
|
||||
return d, err
|
||||
}
|
||||
cmd := exec.CommandContext(ctx, "git", "ls-remote", url, "refs/tags/"+version, "refs/heads/"+version)
|
||||
cmd := exec.CommandContext(ctx, "git", "ls-remote", "--", url, "refs/tags/"+version, "refs/heads/"+version)
|
||||
cmd.Env = append(cmd.Environ(), "GIT_TERMINAL_PROMPT=0")
|
||||
b, err := cmd.Output()
|
||||
switch {
|
||||
|
||||
Reference in new issue
Block a user