Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NTLM authentication support #56

Merged
merged 10 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ad/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ProviderConfig struct {
WinRMPort int
WinRMProto string
WinRMInsecure bool
WinRMUseNTLM bool
}

// NewConfig returns a new Config struct populated with Resource Data.
Expand All @@ -28,6 +29,7 @@ func NewConfig(d *schema.ResourceData) ProviderConfig {
winRMPort := d.Get("winrm_port").(int)
winRMProto := d.Get("winrm_proto").(string)
winRMInsecure := d.Get("winrm_insecure").(bool)
winRMUseNTLM := d.Get("winrm_use_ntlm").(bool)

cfg := ProviderConfig{
WinRMHost: winRMHost,
Expand All @@ -36,6 +38,7 @@ func NewConfig(d *schema.ResourceData) ProviderConfig {
WinRMUsername: winRMUsername,
WinRMPassword: winRMPassword,
WinRMInsecure: winRMInsecure,
WinRMUseNTLM: winRMUseNTLM,
}

return cfg
Expand All @@ -50,7 +53,14 @@ func GetWinRMConnection(config ProviderConfig) (*winrm.Client, error) {

endpoint := winrm.NewEndpoint(config.WinRMHost, config.WinRMPort, useHTTPS,
config.WinRMInsecure, nil, nil, nil, 0)
client, err := winrm.NewClient(endpoint, config.WinRMUsername, config.WinRMPassword)

params := winrm.DefaultParameters

if config.WinRMUseNTLM {
params.TransportDecorator = func() winrm.Transporter { return &winrm.ClientNTLM{} }
}

client, err := winrm.NewClientWithParameters(endpoint, config.WinRMUsername, config.WinRMPassword, params)
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions ad/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func Provider() *schema.Provider {
DefaultFunc: schema.EnvDefaultFunc("AD_WINRM_INSECURE", false),
Description: "Trust unknown certificates. (default: false, environment variable: AD_WINRM_INSECURE)",
},
"winrm_use_ntlm": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("AD_WINRM_USE_NTLM", false),
Description: "Use NTLM authentication. (default: false, environment variable: AD_WINRM_USE_NTLM)",
},
},
DataSourcesMap: map[string]*schema.Resource{
"ad_user": dataSourceADUser(),
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ resource "ad_gplink" "og" {
### Optional

- **winrm_insecure** (Boolean, Optional) Trust unknown certificates. (default: false, environment variable: AD_WINRM_INSECURE)
- **winrm_use_ntlm** (Boolean, Optional) Use NTLM security. (default: false, environment variable: AD_WINRM_USE_NTLM)
czeumer marked this conversation as resolved.
Show resolved Hide resolved
- **winrm_port** (Number, Optional) The port WinRM is listening for connections. (default: 5985, environment variable: AD_PORT)
- **winrm_proto** (String, Optional) The WinRM protocol we will use. (default: http, environment variable: AD_PROTO)