Add support for NTLM the WinRM communicator.

WinRM exposes an HTTP transport decorator that can be used for different
authentication schemes.  Windows on Azures requires this if one is to use
the out of the box configuration.
This commit is contained in:
Christopher Boumenot 2016-03-10 10:47:30 -08:00
parent cd83c3f2eb
commit b57ed27352
5 changed files with 33 additions and 22 deletions

2
Godeps/Godeps.json generated
View File

@ -329,7 +329,7 @@
}, },
{ {
"ImportPath": "github.com/packer-community/winrmcp/winrmcp", "ImportPath": "github.com/packer-community/winrmcp/winrmcp",
"Rev": "3d184cea22ee1c41ec1697e0d830ff0c78f7ea97" "Rev": "f1bcf36a69fa2945e65dd099eee11b560fbd3346"
}, },
{ {
"ImportPath": "github.com/pierrec/lz4", "ImportPath": "github.com/pierrec/lz4",

View File

@ -41,6 +41,11 @@ func New(config *Config) (*Communicator, error) {
// Create the client // Create the client
params := winrm.DefaultParameters() params := winrm.DefaultParameters()
if config.TransportDecorator != nil {
params.TransportDecorator = config.TransportDecorator
}
params.Timeout = formatDuration(config.Timeout) params.Timeout = formatDuration(config.Timeout)
client, err := winrm.NewClientWithParameters( client, err := winrm.NewClientWithParameters(
endpoint, config.Username, config.Password, params) endpoint, config.Username, config.Password, params)
@ -155,5 +160,6 @@ func (c *Communicator) newCopyClient() (*winrmcp.Winrmcp, error) {
Insecure: c.config.Insecure, Insecure: c.config.Insecure,
OperationTimeout: c.config.Timeout, OperationTimeout: c.config.Timeout,
MaxOperationsPerShell: 15, // lowest common denominator MaxOperationsPerShell: 15, // lowest common denominator
TransportDecorator: c.config.TransportDecorator,
}) })
} }

View File

@ -1,6 +1,7 @@
package winrm package winrm
import ( import (
"net/http"
"time" "time"
) )
@ -13,4 +14,5 @@ type Config struct {
Timeout time.Duration Timeout time.Duration
Https bool Https bool
Insecure bool Insecure bool
TransportDecorator func(*http.Transport) http.RoundTripper
} }

View File

@ -3,6 +3,7 @@ package communicator
import ( import (
"errors" "errors"
"fmt" "fmt"
"net/http"
"os" "os"
"time" "time"
@ -39,6 +40,7 @@ type Config struct {
WinRMTimeout time.Duration `mapstructure:"winrm_timeout"` WinRMTimeout time.Duration `mapstructure:"winrm_timeout"`
WinRMUseSSL bool `mapstructure:"winrm_use_ssl"` WinRMUseSSL bool `mapstructure:"winrm_use_ssl"`
WinRMInsecure bool `mapstructure:"winrm_insecure"` WinRMInsecure bool `mapstructure:"winrm_insecure"`
WinRMTransportDecorator func(*http.Transport) http.RoundTripper
} }
// Port returns the port that will be used for access based on config. // Port returns the port that will be used for access based on config.

View File

@ -131,6 +131,7 @@ func (s *StepConnectWinRM) waitForWinRM(state multistep.StateBag, cancel <-chan
Timeout: s.Config.WinRMTimeout, Timeout: s.Config.WinRMTimeout,
Https: s.Config.WinRMUseSSL, Https: s.Config.WinRMUseSSL,
Insecure: s.Config.WinRMInsecure, Insecure: s.Config.WinRMInsecure,
TransportDecorator: s.Config.WinRMTransportDecorator,
}) })
if err != nil { if err != nil {
log.Printf("[ERROR] WinRM connection err: %s", err) log.Printf("[ERROR] WinRM connection err: %s", err)