func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData map[string]interface{}) error {
	ui.Say("Provisioning with Puppet Bolt...")

	k, err := newUserKey(p.config.SSHAuthorizedKeyFile)
	if err != nil {
		return err
	}

	hostSigner, err := newSigner(p.config.SSHHostKeyFile)
	// Remove the private key file
	if len(k.privKeyFile) > 0 {
		defer os.Remove(k.privKeyFile)
	}

	keyChecker := ssh.CertChecker{
		UserKeyFallback: func(conn ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) {
			if user := conn.User(); user != p.config.User {
				return nil, errors.New(fmt.Sprintf("authentication failed: %s is not a valid user", user))
			}

			if !bytes.Equal(k.Marshal(), pubKey.Marshal()) {
				return nil, errors.New("authentication failed: unauthorized key")
			}

			return nil, nil
		},
	}

	config := &ssh.ServerConfig{
		AuthLogCallback: func(conn ssh.ConnMetadata, method string, err error) {
			log.Printf("authentication attempt from %s to %s as %s using %s", conn.RemoteAddr(), conn.LocalAddr(), conn.User(), method)
		},
		PublicKeyCallback: keyChecker.Authenticate,
		//NoClientAuth:      true,
	}

	config.AddHostKey(hostSigner)

	localListener, err := func() (net.Listener, error) {

		port := p.config.LocalPort
		tries := 1
		if port != 0 {
			tries = 10
		}
		for i := 0; i < tries; i++ {
			l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))
			port++
			if err != nil {
				ui.Say(err.Error())
				continue
			}
			_, portStr, err := net.SplitHostPort(l.Addr().String())
			if err != nil {
				ui.Say(err.Error())
				continue
			}
			p.config.LocalPort, err = strconv.Atoi(portStr)
			if err != nil {
				ui.Say(err.Error())
				continue
			}
			return l, nil
		}
		return nil, errors.New("Error setting up SSH proxy connection")
	}()

	if err != nil {
		return err
	}

	ui = &packer.SafeUi{
		Sem: make(chan int, 1),
		Ui:  ui,
	}
	p.adapter = adapter.NewAdapter(p.done, localListener, config, "", ui, comm)

	defer func() {
		log.Print("shutting down the SSH proxy")
		close(p.done)
		p.adapter.Shutdown()
	}()

	go p.adapter.Serve()

	if err := p.executeBolt(ui, comm, k.privKeyFile); err != nil {
		return fmt.Errorf("Error executing Bolt: %s", err)
	}

	return nil

}
// Provision using the Puppet Bolt provisioner
Provision using the Puppet Bolt provisioner
// Provision using the Puppet Bolt provisioner
func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData map[string]interface{}) error {
	ui.Say("Provisioning with Puppet Bolt...")
	k, err := newUserKey(p.config.SSHAuthorizedKeyFile)
	if err != nil {
		return err
	}
	hostSigner, err := newSigner(p.config.SSHHostKeyFile)
	if len(k.privKeyFile) > 0 {
		defer os.Remove(k.privKeyFile)
	}
	keyChecker := ssh.CertChecker{
		UserKeyFallback: func(conn ssh.ConnMetadata, pubKey ssh.PublicKey) (*ssh.Permissions, error) {
			if user := conn.User(); user != p.config.User {
				return nil, errors.New(fmt.Sprintf("authentication failed: %s is not a valid user", user))
			}
			if !bytes.Equal(k.Marshal(), pubKey.Marshal()) {
				return nil, errors.New("authentication failed: unauthorized key")
			}
			return nil, nil
		},
	}
	config := &ssh.ServerConfig{
		AuthLogCallback: func(conn ssh.ConnMetadata, method string, err error) {
			log.Printf("authentication attempt from %s to %s as %s using %s", conn.RemoteAddr(), conn.LocalAddr(), conn.User(), method)
		},
		PublicKeyCallback: keyChecker.Authenticate,
	}
	config.AddHostKey(hostSigner)
	localListener, err := func() (net.Listener, error) {
		port := p.config.LocalPort
		tries := 1
		if port != 0 {
			tries = 10
		}
		for i := 0; i < tries; i++ {
			l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))
			port++
			if err != nil {
				ui.Say(err.Error())
				continue
			}
			_, portStr, err := net.SplitHostPort(l.Addr().String())
			if err != nil {
				ui.Say(err.Error())
				continue
			}
			p.config.LocalPort, err = strconv.Atoi(portStr)
			if err != nil {
				ui.Say(err.Error())
				continue
			}
			return l, nil
		}
		return nil, errors.New("Error setting up SSH proxy connection")
	}()
	if err != nil {
		return err
	}
	ui = &packer.SafeUi{
		Sem: make(chan int, 1),
		Ui:  ui,
	}
	p.adapter = adapter.NewAdapter(p.done, localListener, config, "", ui, comm)
	defer func() {
		log.Print("shutting down the SSH proxy")
		close(p.done)
		p.adapter.Shutdown()
	}()
	go p.adapter.Serve()
	if err := p.executeBolt(ui, comm, k.privKeyFile); err != nil {
		return fmt.Errorf("Error executing Bolt: %s", err)
	}
	return nil
}
func ( p * Provisioner ) Provision ( ctx context . Context , ui packer . Ui , comm packer . Communicator , generatedData map [ string ] interface { } ) error { ui . Say ( " " ) k , err := newUserKey ( p . config . SSHAuthorizedKeyFile ) if err != nil { return err } hostSigner , err := newSigner ( p . config . SSHHostKeyFile ) if len ( k . privKeyFile ) > 0 { defer os . Remove ( k . privKeyFile ) } keyChecker := ssh . CertChecker { UserKeyFallback : func ( conn ssh . ConnMetadata , pubKey ssh . PublicKey ) ( * ssh . Permissions , error ) { if user := conn . User ( ) ; user != p . config . User { return nil , errors . New ( fmt . Sprintf ( " " , user ) ) } if ! bytes . Equal ( k . Marshal ( ) , pubKey . Marshal ( ) ) { return nil , errors . New ( " " ) } return nil , nil } , } config := & ssh . ServerConfig { AuthLogCallback : func ( conn ssh . ConnMetadata , method string , err error ) { log . Printf ( " " , conn . RemoteAddr ( ) , conn . LocalAddr ( ) , conn . User ( ) , method ) } , PublicKeyCallback : keyChecker . Authenticate , } config . AddHostKey ( hostSigner ) localListener , err := func ( ) ( net . Listener , error ) { port := p . config . LocalPort tries := 1 if port != 0 { tries = 10 } for i := 0 ; i < tries ; i ++ { l , err := net . Listen ( " " , fmt . Sprintf ( " " , port ) ) port ++ if err != nil { ui . Say ( err . Error ( ) ) continue } _ , portStr , err := net . SplitHostPort ( l . Addr ( ) . String ( ) ) if err != nil { ui . Say ( err . Error ( ) ) continue } p . config . LocalPort , err = strconv . Atoi ( portStr ) if err != nil { ui . Say ( err . Error ( ) ) continue } return l , nil } return nil , errors . New ( " " ) } ( ) if err != nil { return err } ui = & packer . SafeUi { Sem : make ( chan int , 1 ) , Ui : ui , } p . adapter = adapter . NewAdapter ( p . done , localListener , config , " " , ui , comm ) defer func ( ) { log . Print ( " " ) close ( p . done ) p . adapter . Shutdown ( ) } ( ) go p . adapter . Serve ( ) if err := p . executeBolt ( ui , comm , k . privKeyFile ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil }
Provision using the Puppet Bolt provisioner
Provision using the Puppet Bolt provisioner
// Remove the private key file //NoClientAuth:      true,