ssh: Renamed ssh_disable_agent to ssh_disable_agent_forwarding
Closes: #4941
This commit is contained in:
parent
aa7ef7a4e3
commit
4f6010aa26
|
@ -46,8 +46,8 @@ type Config struct {
|
|||
// Pty, if true, will request a pty from the remote end.
|
||||
Pty bool
|
||||
|
||||
// DisableAgent, if true, will not forward the SSH agent.
|
||||
DisableAgent bool
|
||||
// DisableAgentForwarding, if true, will not forward the SSH agent.
|
||||
DisableAgentForwarding bool
|
||||
|
||||
// HandshakeTimeout limits the amount of time we'll wait to handshake before
|
||||
// saying the connection failed.
|
||||
|
@ -327,7 +327,7 @@ func (c *comm) connectToAgent() {
|
|||
return
|
||||
}
|
||||
|
||||
if c.config.DisableAgent {
|
||||
if c.config.DisableAgentForwarding {
|
||||
log.Printf("[INFO] SSH agent forwarding is disabled.")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ func init() {
|
|||
"parallels-headless": new(FixerParallelsHeadless),
|
||||
"parallels-deprecations": new(FixerParallelsDeprecations),
|
||||
"sshkeypath": new(FixerSSHKeyPath),
|
||||
"sshdisableagent": new(FixerSSHDisableAgent),
|
||||
"manifest-filename": new(FixerManifestFilename),
|
||||
"amazon-shutdown_behavior": new(FixerAmazonShutdownBehavior),
|
||||
}
|
||||
|
@ -43,6 +44,7 @@ func init() {
|
|||
"parallels-headless",
|
||||
"parallels-deprecations",
|
||||
"sshkeypath",
|
||||
"sshdisableagent",
|
||||
"manifest-filename",
|
||||
"amazon-shutdown_behavior",
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// FixerSSHDisableAgent changes the "ssh_disable_agent" of a template
|
||||
// to "ssh_disable_agent_forwarding".
|
||||
type FixerSSHDisableAgent struct{}
|
||||
|
||||
func (FixerSSHDisableAgent) Fix(input map[string]interface{}) (map[string]interface{}, error) {
|
||||
// The type we'll decode into; we only care about builders
|
||||
type template struct {
|
||||
Builders []map[string]interface{}
|
||||
}
|
||||
|
||||
// Decode the input into our structure, if we can
|
||||
var tpl template
|
||||
if err := mapstructure.Decode(input, &tpl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, builder := range tpl.Builders {
|
||||
sshDisableAgentRaw, ok := builder["ssh_disable_agent"]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
sshDisableAgent, ok := sshDisableAgentRaw.(bool)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
// only assign to ssh_disable_agent_forwarding if it doesn't
|
||||
// already exist; otherwise we'll just ignore ssh_disable_agent
|
||||
_, sshDisableAgentIncluded := builder["ssh_disable_agent_forwarding"]
|
||||
if !sshDisableAgentIncluded {
|
||||
builder["ssh_disable_agent_forwarding"] = sshDisableAgent
|
||||
}
|
||||
|
||||
delete(builder, "ssh_disable_agent")
|
||||
}
|
||||
|
||||
input["builders"] = tpl.Builders
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func (FixerSSHDisableAgent) Synopsis() string {
|
||||
return `Updates builders using "ssh_disable_agent" to use "ssh_disable_agent_forwarding"`
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package fix
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFixerSSHDisableAgent_Impl(t *testing.T) {
|
||||
var _ Fixer = new(FixerSSHDisableAgent)
|
||||
}
|
||||
|
||||
func TestFixerSSHDisableAgent_Fix(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input map[string]interface{}
|
||||
Expected map[string]interface{}
|
||||
}{
|
||||
// No disable_agent field
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"type": "virtualbox",
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"type": "virtualbox",
|
||||
},
|
||||
},
|
||||
|
||||
// disable_agent_forwarding without disable_agent
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"ssh_disable_agent_forwarding": true,
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"ssh_disable_agent_forwarding": true,
|
||||
},
|
||||
},
|
||||
|
||||
// disable_agent without disable_agent_forwarding
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"ssh_disable_agent": true,
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"ssh_disable_agent_forwarding": true,
|
||||
},
|
||||
},
|
||||
|
||||
// disable_agent and disable_agent_forwarding
|
||||
{
|
||||
Input: map[string]interface{}{
|
||||
"ssh_disable_agent": true,
|
||||
"ssh_disable_agent_forwarding": false,
|
||||
},
|
||||
|
||||
Expected: map[string]interface{}{
|
||||
"ssh_disable_agent_forwarding": false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
var f FixerSSHDisableAgent
|
||||
|
||||
input := map[string]interface{}{
|
||||
"builders": []map[string]interface{}{tc.Input},
|
||||
}
|
||||
|
||||
expected := map[string]interface{}{
|
||||
"builders": []map[string]interface{}{tc.Expected},
|
||||
}
|
||||
|
||||
output, err := f.Fix(input)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(output, expected) {
|
||||
t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ type Config struct {
|
|||
SSHPty bool `mapstructure:"ssh_pty"`
|
||||
SSHTimeout time.Duration `mapstructure:"ssh_timeout"`
|
||||
SSHAgentAuth bool `mapstructure:"ssh_agent_auth"`
|
||||
SSHDisableAgent bool `mapstructure:"ssh_disable_agent"`
|
||||
SSHDisableAgentForwarding bool `mapstructure:"ssh_disable_agent_forwarding"`
|
||||
SSHHandshakeAttempts int `mapstructure:"ssh_handshake_attempts"`
|
||||
SSHBastionHost string `mapstructure:"ssh_bastion_host"`
|
||||
SSHBastionPort int `mapstructure:"ssh_bastion_port"`
|
||||
|
|
|
@ -163,7 +163,7 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
|
|||
Connection: connFunc,
|
||||
SSHConfig: sshConfig,
|
||||
Pty: s.Config.SSHPty,
|
||||
DisableAgent: s.Config.SSHDisableAgent,
|
||||
DisableAgentForwarding: s.Config.SSHDisableAgentForwarding,
|
||||
UseSftp: s.Config.SSHFileTransferMethod == "sftp",
|
||||
}
|
||||
|
||||
|
|
|
@ -76,8 +76,8 @@ The SSH communicator has the following options:
|
|||
- `ssh_bastion_username` (string) - The username to connect to the bastion
|
||||
host.
|
||||
|
||||
- `ssh_disable_agent` (boolean) - If true, SSH agent forwarding will be
|
||||
disabled. Defaults to false.
|
||||
- `ssh_disable_agent_forwarding` (boolean) - If true, SSH agent forwarding
|
||||
will be disabled. Defaults to false.
|
||||
|
||||
- `ssh_file_transfer_method` (`scp` or `sftp`) - How to transfer files, Secure
|
||||
copy (default) or SSH File Transfer Protocol.
|
||||
|
|
Loading…
Reference in New Issue