Merge pull request #4123 from rickard-von-essen/issue-4117
provisioner/ansible: Move info messages to log
This commit is contained in:
commit
5114b66bab
|
@ -37,7 +37,7 @@ func newAdapter(done <-chan struct{}, l net.Listener, config *ssh.ServerConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *adapter) Serve() {
|
func (c *adapter) Serve() {
|
||||||
c.ui.Say(fmt.Sprintf("SSH proxy: serving on %s", c.l.Addr()))
|
log.Printf("SSH proxy: serving on %s", c.l.Addr())
|
||||||
|
|
||||||
for {
|
for {
|
||||||
// Accept will return if either the underlying connection is closed or if a connection is made.
|
// Accept will return if either the underlying connection is closed or if a connection is made.
|
||||||
|
@ -62,7 +62,7 @@ func (c *adapter) Serve() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *adapter) Handle(conn net.Conn, ui packer.Ui) error {
|
func (c *adapter) Handle(conn net.Conn, ui packer.Ui) error {
|
||||||
c.ui.Message("SSH proxy: accepted connection")
|
log.Print("SSH proxy: accepted connection")
|
||||||
_, chans, reqs, err := ssh.NewServerConn(conn, c.config)
|
_, chans, reqs, err := ssh.NewServerConn(conn, c.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("failed to handshake")
|
return errors.New("failed to handshake")
|
||||||
|
@ -160,7 +160,7 @@ func (c *adapter) handleSession(newChannel ssh.NewChannel) error {
|
||||||
sftpCmd = "/usr/lib/sftp-server -e"
|
sftpCmd = "/usr/lib/sftp-server -e"
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ui.Say("starting sftp subsystem")
|
log.Print("starting sftp subsystem")
|
||||||
go func() {
|
go func() {
|
||||||
_ = c.remoteExec(sftpCmd, channel, channel, channel.Stderr())
|
_ = c.remoteExec(sftpCmd, channel, channel, channel.Stderr())
|
||||||
close(done)
|
close(done)
|
||||||
|
@ -171,7 +171,7 @@ func (c *adapter) handleSession(newChannel ssh.NewChannel) error {
|
||||||
req.Reply(false, nil)
|
req.Reply(false, nil)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
c.ui.Message(fmt.Sprintf("rejecting %s request", req.Type))
|
log.Printf("rejecting %s request", req.Type)
|
||||||
req.Reply(false, nil)
|
req.Reply(false, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,13 +184,11 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
keyChecker := ssh.CertChecker{
|
keyChecker := ssh.CertChecker{
|
||||||
UserKeyFallback: func(conn ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) {
|
UserKeyFallback: func(conn ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) {
|
||||||
if user := conn.User(); user != p.config.User {
|
if user := conn.User(); user != p.config.User {
|
||||||
ui.Say(fmt.Sprintf("%s is not a valid user", user))
|
return nil, errors.New(fmt.Sprintf("authentication failed: %s is not a valid user", user))
|
||||||
return nil, errors.New("authentication failed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(k.Marshal(), pubKey.Marshal()) {
|
if !bytes.Equal(k.Marshal(), pubKey.Marshal()) {
|
||||||
ui.Say("unauthorized key")
|
return nil, errors.New("authentication failed: unauthorized key")
|
||||||
return nil, errors.New("authentication failed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -199,7 +197,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
|
|
||||||
config := &ssh.ServerConfig{
|
config := &ssh.ServerConfig{
|
||||||
AuthLogCallback: func(conn ssh.ConnMetadata, method string, err error) {
|
AuthLogCallback: func(conn ssh.ConnMetadata, method string, err error) {
|
||||||
ui.Say(fmt.Sprintf("authentication attempt from %s to %s as %s using %s", conn.RemoteAddr(), conn.LocalAddr(), conn.User(), method))
|
log.Printf("authentication attempt from %s to %s as %s using %s", conn.RemoteAddr(), conn.LocalAddr(), conn.User(), method)
|
||||||
},
|
},
|
||||||
PublicKeyCallback: keyChecker.Authenticate,
|
PublicKeyCallback: keyChecker.Authenticate,
|
||||||
//NoClientAuth: true,
|
//NoClientAuth: true,
|
||||||
|
@ -242,7 +240,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
p.adapter = newAdapter(p.done, localListener, config, p.config.SFTPCmd, ui, comm)
|
p.adapter = newAdapter(p.done, localListener, config, p.config.SFTPCmd, ui, comm)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
ui.Say("shutting down the SSH proxy")
|
log.Print("shutting down the SSH proxy")
|
||||||
close(p.done)
|
close(p.done)
|
||||||
p.adapter.Shutdown()
|
p.adapter.Shutdown()
|
||||||
}()
|
}()
|
||||||
|
@ -355,7 +353,7 @@ func (p *Provisioner) executeAnsible(ui packer.Ui, comm packer.Communicator, pri
|
||||||
go repeat(stdout)
|
go repeat(stdout)
|
||||||
go repeat(stderr)
|
go repeat(stderr)
|
||||||
|
|
||||||
ui.Say(fmt.Sprintf("Executing Ansible: %s", strings.Join(cmd.Args, " ")))
|
log.Printf("Executing Ansible: %s", strings.Join(cmd.Args, " "))
|
||||||
cmd.Start()
|
cmd.Start()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
|
|
Loading…
Reference in New Issue