knife-windows 0.8.6 → 1.0.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +17 -3
  4. data/CHANGELOG.md +25 -6
  5. data/DOC_CHANGES.md +323 -0
  6. data/Gemfile +2 -1
  7. data/README.md +160 -29
  8. data/RELEASE_NOTES.md +59 -6
  9. data/appveyor.yml +42 -0
  10. data/ci.gemfile +15 -0
  11. data/knife-windows.gemspec +4 -2
  12. data/lib/chef/knife/bootstrap/windows-chef-client-msi.erb +35 -21
  13. data/lib/chef/knife/bootstrap_windows_base.rb +155 -31
  14. data/lib/chef/knife/bootstrap_windows_ssh.rb +1 -1
  15. data/lib/chef/knife/bootstrap_windows_winrm.rb +17 -10
  16. data/lib/chef/knife/core/windows_bootstrap_context.rb +67 -16
  17. data/lib/chef/knife/windows_cert_generate.rb +155 -0
  18. data/lib/chef/knife/windows_cert_install.rb +62 -0
  19. data/lib/chef/knife/windows_helper.rb +3 -1
  20. data/lib/chef/knife/windows_listener_create.rb +100 -0
  21. data/lib/chef/knife/winrm.rb +84 -208
  22. data/lib/chef/knife/winrm_base.rb +36 -10
  23. data/lib/chef/knife/winrm_knife_base.rb +201 -0
  24. data/lib/chef/knife/winrm_session.rb +72 -0
  25. data/lib/chef/knife/winrm_shared_options.rb +47 -0
  26. data/lib/chef/knife/wsman_endpoint.rb +44 -0
  27. data/lib/chef/knife/wsman_test.rb +96 -0
  28. data/lib/knife-windows/path_helper.rb +77 -0
  29. data/lib/knife-windows/version.rb +1 -1
  30. data/spec/functional/bootstrap_download_spec.rb +41 -23
  31. data/spec/spec_helper.rb +11 -1
  32. data/spec/unit/knife/bootstrap_template_spec.rb +27 -27
  33. data/spec/unit/knife/bootstrap_windows_winrm_spec.rb +67 -23
  34. data/spec/unit/knife/core/windows_bootstrap_context_spec.rb +47 -0
  35. data/spec/unit/knife/windows_cert_generate_spec.rb +90 -0
  36. data/spec/unit/knife/windows_cert_install_spec.rb +35 -0
  37. data/spec/unit/knife/windows_listener_create_spec.rb +61 -0
  38. data/spec/unit/knife/winrm_session_spec.rb +47 -0
  39. data/spec/unit/knife/winrm_spec.rb +222 -56
  40. data/spec/unit/knife/wsman_test_spec.rb +176 -0
  41. metadata +51 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1ec9c8dd7c8a66f06b72b2e46bc3e172477bd7a
4
- data.tar.gz: 2a07331546fc140023af2b6e4ef8bb3abb174f24
3
+ metadata.gz: e51a14571a819d9ff57f8ff5c1f9be04e45645a0
4
+ data.tar.gz: fd8710840fd171781b95ed291b2c2926aa503fdf
5
5
  SHA512:
6
- metadata.gz: 9f287cd625f4b21850b54293cb2c7b8cf104c35f06d966ad3e319d4da258fad285870b3b07d668e554b3d2761c877e2092f2db279dcadb98db8d454dd02f1ea6
7
- data.tar.gz: b5a6ef473ba830356a6aafa6295a6732f837ea618542750cf077d6d3d3dbc99167d755ce1aa940b3f84ba4fac8b7b72edb2a53bfdfa855438661ca944835d337
6
+ metadata.gz: f7e087bfadbb0825a9a3a27388df0e4262642b39aaa839eb9d7396dd1a83d8bf92d4f454881a979c938fbff7c12c9f7104b6f5ae38aabbab3759487fc5ec5888
7
+ data.tar.gz: 7cdddbaa21aff487fc7a2c4db10e26b52d8929a4c06d4b74db252ac1fbe2e6b38fdf94359ea3d10c490718d0c11917c08fbf96b488043771d276865ce82557e4
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ ci.gemfile.lock
4
5
  pkg/*
data/.travis.yml CHANGED
@@ -1,6 +1,20 @@
1
+ language: ruby
2
+
1
3
  rvm:
4
+ - 1.9.3
2
5
  - 2.0.0
3
- - 2.1.5
4
- - 2.2.0
5
6
 
6
- script: bundle exec rake spec
7
+ gemfile: ci.gemfile
8
+
9
+ env:
10
+ - CHEF_VERSION="master"
11
+ - CHEF_VERSION="~> 12.0"
12
+ - CHEF_VERSION="< 12"
13
+
14
+ matrix:
15
+ exclude:
16
+ - rvm: 1.9.3
17
+ env: CHEF_VERSION="master"
18
+ - rvm: 1.9.3
19
+ env: CHEF_VERSION="~> 12.0"
20
+
data/CHANGELOG.md CHANGED
@@ -1,23 +1,42 @@
1
1
  # knife-windows Change Log
2
2
 
3
- ## Latest release: 0.8.6
4
- * [knife-windows #268](https://github.com/chef/knife-windows/issues/268) Use winrm 1.3.x in 0.8-stable
3
+ ## Unreleased changes
4
+
5
+ * [knife-windows #240](https://github.com/chef/knife-windows/pull/240) Change kerberos keytab short option to -T to resolve conflict
6
+ * [knife-windows #232](https://github.com/chef/knife-windows/pull/232) Adding --hint option to bootstrap
7
+ * [knife-windows #227](https://github.com/chef/knife-windows/issues/227) Exception: NoMethodError: undefined method 'gsub' for false:FalseClass
8
+ * [knife-windows #222](https://github.com/chef/knife-windows/issues/222) Validatorless bootstrap support
9
+ * [knife-windows #202](https://github.com/chef/knife-windows/issues/202) knife windows bootstrap should support enabling the service
10
+ * [knife-windows #213](https://github.com/chef/knife-windows/pull/213) Search possibilities of HOME for bootstrap templates
11
+ * [knife-windows #206](https://github.com/chef/knife-windows/pull/206) Add a flag msi_url that allows one to fetch the Chef client msi from a non-chef.io path
12
+ * [knife-windows #192](https://github.com/chef/knife-windows/issues/192) deprecate knife bootstrap --distro
13
+ * [knife-windows #159](https://github.com/opscode/knife-windows/issues/159) `winrm_port` option should default to 5986 if `winrm_transport` option is `ssl`
14
+ * [knife-windows #149](https://github.com/chef/knife-windows/pull/149) Adding knife wsman test to validate WSMAN/WinRM availability
15
+ * [knife-windows #139](https://github.com/opscode/knife-windows/issues/139) Force dev dependency on Chef 11 for test scenarios to avoid Ohai 8 conflict on Ruby 1.9.x
16
+ * [knife-windows #126](https://github.com/opscode/knife-windows/pull/126) Allow disabling of SSL peer verification in knife-windows for testing
17
+ * [knife-windows #154](https://github.com/opscode/knife-windows/issues/154) Unreleased regression in master: NameError: undefined local variable or method `path_separator
18
+ * [knife-windows #143](https://github.com/opscode/knife-windows/issues/143) Unreleased regression in master: WinRM::WinRMHTTPTransportError: Bad HTTP response returned from server (503) in the middle of bootstrap
19
+ * [knife-windows #133](https://github.com/opscode/knife-windows/issues/133) Bootstrap failure -- unable to validate SSL chef server endpoints
20
+ * [knife-windows #132](https://github.com/opscode/knife-windows/issues/132) New subcommands for WinRM: windows listener create, cert generate, and cert install
21
+ * [knife-windows #129](https://github.com/opscode/knife-windows/issues/129) New --winrm-authentication-protocol option for explicit control of authentication
22
+ * [knife-windows #125](https://github.com/opscode/knife-windows/issues/125) knife-windows should use PowerShell first before cscript to download the Chef Client msi
23
+ * [knife-windows #92](https://github.com/opscode/knife-windows/issues/92) EventMachine issue: knife bootstrap windows winrm error
24
+ * [knife-windows #94](https://github.com/opscode/knife-windows/issues/94) Remove Eventmachine dependency
5
25
 
6
26
  ## Release: 0.8.5
7
- * [knife-windows #228](https://github.com/chef/knife-windows/issues/228) make winrm-s dep more strict on knife-windows 0.8.x
27
+ * [knife-windows #228](https://github.com/chef/knife-windows/pull/228) make winrm-s dep more strict on knife-windows 0.8.x
8
28
 
9
29
  ## Release: 0.8.4
10
30
  * [knife-windows #133](https://github.com/opscode/knife-windows/issues/133) Bootstrap failure -- unable to validate SSL chef server endpoints
11
31
 
12
32
  ## Release: 0.8.3
13
- * [knife-windows #131](https://github.com/opscode/knife-windows/issues/108): Windows should be bootstrapped using latest Chef Client version compatible with knife's version just like non-Windows systems
14
- * [knife-windows #162](https://github.com/chef/knife-windows/issues/162): fixes "uninitialized constant Chef::Knife::Bootstrap (NameError)"
33
+ * [knife-windows #131](https://github.com/opscode/knife-windows/issues/108) Issue #131: Windows should be bootstrapped using latest Chef Client version compatible with knife's version just like non-Windows systems
34
+ * [knife-windows #139](https://github.com/opscode/knife-windows/issues/139) Force dev dependency on Chef 11 for test scenarios to avoid Ohai 8 conflict on Ruby 1.9.x
15
35
 
16
36
  ## Release: 0.8.2
17
37
  * [knife-windows #108](https://github.com/opscode/knife-windows/issues/108) Error: Unencrypted communication not supported if remote server does not require encryption
18
38
 
19
39
  ## Release: 0.8.0
20
-
21
40
  * [knife-windows #98](https://github.com/opscode/knife-windows/issues/98) Get winrm command exit code if it is not expected
22
41
  * [knife-windows #96](https://github.com/opscode/knife-windows/issues/96) Fix break from OS patch KB2918614
23
42
  * Remove the 'instance data' method of creating EC2 servers
data/DOC_CHANGES.md ADDED
@@ -0,0 +1,323 @@
1
+ <!---
2
+ This file is reset every time a new release is done. This file describes changes that have not yet been released.
3
+
4
+ Example Doc Change:
5
+ ### Headline for the required change
6
+ Description of the required change.
7
+ -->
8
+ # knife-windows 1.0.0 doc changes
9
+
10
+ ### WinRM default port default change
11
+ The `winrm_port` option specifies the TCP port on the remote system to which
12
+ to connect for WinRM communication for `knife-windows` commands that use
13
+ WinRM. The default value of this option is **5986** if the WinRM transport
14
+ (configured by the `winrm_transport` option) is SSL, otherwise it is **5985**.
15
+ These defaults correspond to the port assignment conventions for the WinRM
16
+ protocol, which is also honored by WinRM tools built-in to Windows such as the
17
+ `winrs` tool.
18
+
19
+ In previous releases, the default port was always 5985, regardless of the
20
+ transport being used. To override the default, specify the `winrm_port`
21
+ (`-p`) option and specify the desired port as the option's value.
22
+
23
+ ### WinRM authentication protocol defaults to `negotiate` regardless of name formats
24
+ Unless explicitly overridden using the new `winrm_authentication_protocol`
25
+ option, `knife-windows` subcommands that use WinRM will authenticate using the
26
+ negotiate protocol, just as the tools built-in to the Windows operating
27
+ system would do.
28
+
29
+ Previously, `knife-windows` would use basic authentication, unless the
30
+ username specified to the `winrm_user` option had the format `domain\user`,
31
+ and in that case `knife-windows` would use negotiate authentication.
32
+
33
+ To override the new behavior, specify the `winrm_authentication_protocol`
34
+ option with a value of either the `basic` or `kerberos` to choose a different
35
+ authentication protocol.
36
+
37
+ ### New `:winrm_authentication_protocol` option
38
+
39
+ This option allows the authentication protocol used for WinRM communication to
40
+ be explicitly specified. The supported protocol values are `kerberos`, `negotiate`,
41
+ and `basic`, each of which directs `knife-windows` to use the respective authentication protocols.
42
+
43
+ If the option is not specified, `knife-windows` treats this as a default value
44
+ of `negotiate` and the tool uses negotiate authentication for WinRM.
45
+
46
+ ### New `:winrm_ssl_verify_mode` option
47
+ When running the `winrm` and `bootstrap windows` subcommands with the
48
+ `winrm_transport` option set to `ssl` to communicate with a remote Windows system using
49
+ the WinRM protocol via the SSL transport, you may disable `knife`'s verification of
50
+ the remote system's SSL certificate. This is useful for testing or
51
+ troubleshooting SSL connectivity before you've verified the certificate of the remote system's SSL WinRM listener.
52
+
53
+ The option that controls whether the server is validated is the
54
+ `knife[:winrm_verify_ssl_mode]` option, which has the same values as Chef's
55
+ [`:ssl_verify_mode`](https://docs.getchef.com/config_rb_client.html#settings) option. By default, the option is set to `:verify_peer`,
56
+ which means that SSL communication must be verified using a certificate file
57
+ specified by the `:ca_trust_file` option. To avoid the need to have this file available
58
+ during testing, you can specify the `knife[:winrm_ssl_verify_mode]` option in
59
+ `knife.rb` OR specify it directly on the `knife` command line as
60
+ `--winrm-ssl-verify-mode` and set its value to `:verify_none`, which will
61
+ override the default behavior and skip the verification of the remote system
62
+ -- there is no need to specify the `:ca_trust_file` option in this case.
63
+
64
+ Here's an example that disables peer verification:
65
+
66
+ knife winrm -m 192.168.0.6 -x 'mydomain\myuser' -P "$PASSWORDVAR" -t ssl --winrm-ssl-verify-mode verify_none ipconfig
67
+
68
+ This option should be used carefully since disabling the verification of the
69
+ remote system's certificate can subject knife commands to spoofing attacks.
70
+
71
+ ### New subcommands to automate WinRM SSL listener configuration
72
+ The WinRM protocol may be encapsulated by SSL, but the configuration of such
73
+ connections can be difficult, particularly when the WinRM client is a
74
+ non-Windows system. Three new knife subcommands have been implemented in
75
+ knife-windows 1.0.0.rc.0 to simplify and automate this configuration:
76
+
77
+ * `knife windows cert generate` subcommand:
78
+ Generates certificates in formats useful for creating WinRM SSL listeners.
79
+ It also generates a related public key file in .pem format to validating
80
+ communication involving listeners configured with the generated certificate.
81
+ * `knife windows cert install` subcommand:
82
+ Installs a certificate such as one generated by the `cert generate`
83
+ subcommand into the Windows certificate store so that it can be used as the
84
+ SSL certificate for a WinRM listener. This command will only function on the
85
+ Windows operating system. Certificates are always installed in the
86
+ computer's personal store, i.e. the store that can be viewed via the
87
+ PowerShell command `ls Cert:\LocalMachine\My`.
88
+ * `knife windows listener create` subcommand:
89
+ Creates a WinRM listener on a Windows system. This command functions only on
90
+ the Windows operating system.
91
+
92
+ #### Example WinRM listener configuration workflows
93
+
94
+ The subcommands are used in the following scenarios
95
+
96
+ ##### Creation of a new listener with a new SSL certificate
97
+
98
+ This workflow assumes that WinRM is enabled on the system, which can be
99
+ accomplished with the command
100
+
101
+ winrm quickconfig
102
+
103
+ If you're creating a listener and don't already have an SSL certificate with
104
+ which to configure it, you can quickly create an enabled listener with a short
105
+ sequence of commands. The example below assumes that the `knife-windows`
106
+ plugin is being executed on a Windows system via the PowerShell command shell,
107
+ and that the system is registered with the relevant DNS with the name
108
+ `mysystem.myorg.org` and that this is the name with which the user would like
109
+ to remotely access this system.
110
+
111
+ This sequence of commands creates a listener -- it assumes the existence of the directory `winrmcerts`
112
+ under the user's profile directory:
113
+
114
+ knife windows cert generate --domain myorg.org --output-file $env:userprofile/winrmcerts/winrm-ssl
115
+ knife windows listener create --hostname *.myorg.org --cert-install $env:userprofile/winrmcerts/winrm-ssl.pfx
116
+
117
+ The first command, `cert generate`, may be executed on any computer (even one not running the
118
+ Windows operating system) and produces three files. The first two are certificates containing
119
+ private keys that should be stored securely. The 3rd is a `.pem` file
120
+ containing the public key required to validate the server. This file may be
121
+ shared. The command also outputs the thumbprint of the generated certificate,
122
+ which is useful for finding the certificate in a certificate store or using
123
+ with other commands that require the thumbprint.
124
+
125
+ The next command, `listener create`, creates the SSL listener -- if it is executed on a different
126
+ system than that which generated the certificates, the required certificate
127
+ file **must** be transferred securely to the system on which the listener will
128
+ be created. It requires a PKCS12 `.pfx` file for the `--cert-install` argument
129
+ which is one of the files generated by the previous `cert generate` command.
130
+
131
+ After these commands are executed, an SSL listener will be created listening
132
+ on TCP port 5986, the default WinRM SSL port. Using PowerShell, the following
133
+ command will show this and other listeners on the system:
134
+
135
+ ls wsman:\localhost\listener
136
+
137
+ As an alternative to the command sequence above, the `cert install` command could be used to install the
138
+ certificate in a separate step, i which case the `--cert-install` option must
139
+ be replaced with the `--cert-thumbprint` option to use the generated
140
+ certificate's thumbprint to identify the certificate with which the listener
141
+ should be configured:
142
+
143
+ knife windows cert generate --domain myorg.org --output-file $env:userprofile/winrmcerts/winrm-ssl
144
+ knife windows cert install $env:userprofile/winrmcerts/winrm-ssl
145
+ knife windows listener create --hostname *.myorg.org --cert-thumbprint 1F3A70E2601FA1576BC4850ED2D7EF6587076423
146
+
147
+ The system would then be in the same state as that after the original shorter
148
+ command sequence.
149
+
150
+ Note that the `cert install` command could be skipped if the certificate
151
+ already exists in the personal certificate store of the computer. To view that store and
152
+ see the thumbprints of certificates that could be used with the `listener
153
+ create` command to create an SSL listener, the following PowerShell command
154
+ may be executed:
155
+
156
+ ls Cert:\LocalMachine\My
157
+
158
+ ##### Connecting to a configured SSL listener
159
+
160
+ In order to connect securely to the configured SSL listener via the `knife
161
+ winrm` or `knife bootstrap windows winrm` subcommands, the workstation running
162
+ `knife` must have a `.pem` file that contains the listener's public key, such
163
+ as the one generated by `knife windows cert generate`. If the file was
164
+ generated from a different system than the one initiating the connection with
165
+ the listener, it must be transferred securely to the initiating system.
166
+
167
+ For example, assume the file `./winrmcerts/myserver.pem` was securely
168
+ copied from another system on which the `cert generate` command originally
169
+ produced the file. Now it can be used against a system with the appropriately
170
+ configured listener as follows:
171
+
172
+ knife winrm -f ./winrmcerts/myserver.pem -m myserver.myorg.com -t ssl ipconfig -x 'my_ad_domain\myuser' -P "$PASSWORDVAR"
173
+
174
+ This will send the output of the Windows command `ipconfig` on the remote
175
+ system. The argument to the `-f` option is the public key for the listener so
176
+ that the listener's authenticity can be validated. The specified key
177
+ can simply be a copy of the `.pem` file generated by the `cert generate` subcommand if
178
+ that was used to create the certificates for the listener. The user
179
+ `my_ad_domain\myuser` in the example is a user in the Windows Active Directory
180
+ domain `my_ad_domain`.
181
+
182
+ Alternatively, the [`knife ssl fetch`](https://docs.chef.io/knife_ssl_fetch.html) command can be used to retrieve the
183
+ public key for the listener by simply reading it from the listener, though this command *must* be executed under
184
+ conditions where the connection to the server is considered secure:
185
+
186
+ knife ssl fetch https://myserver.myorg.org:5986/wsman
187
+ knife winrm -f ./.chef/trusted_certs/wildcard_myorg_org.crt -m myserver.myorg.com -t ssl ipconfig -x 'my_ad_domain\myuser' -P "$PASSWORDVAR"
188
+
189
+ In the `fetch` subcommand, the URL specified for testing WinRM connectivity to
190
+ a given server SERVER on port PORT takes the form `https://SERVER:PORT/wsman`,
191
+ hence the url specified above to retrieve the key for `myserver.myorg.org`.
192
+ The command also outputs the location to which the key was retrieved, which
193
+ can then be used as input to a subsequent `knife winrm` command.
194
+
195
+ For that `knife winrm` command in the example, the argument to the `-f` option is again the public key -- this time its value
196
+ of `./.chef/trusted_certs/wildcard_myorg_org.crt` is the file system location to which
197
+ `knife ssl fetch` retrieved the public key.
198
+
199
+ #### Testing WinRM SSL configuration
200
+
201
+ The techniques below are useful for validating a WinRM listener's configuration -- all
202
+ examples below assume there is a WinRM SSL listener configured on a remote Windows
203
+ system `winserver.myoffice.com` on the default WinRM port of 5986 and this is
204
+ the server being tested.
205
+
206
+ ##### PowerShell's `test-wsman` cmdlet
207
+ If you have access to a workstation running
208
+ the Windows 8 or Windows Server 2012 or later versions of the Windows
209
+ operating systems, you can use the `test-wsman` command to validate the
210
+ configuration of a listener on a remote system `winserver.myoffice.com`:
211
+
212
+ 1. On the Windows workstation client (not the system with the listener),
213
+ install the .pfx public key certificate for the listener using
214
+ certmgr.msc. This should be installed in the personal store under *"Trusted
215
+ Root Certification Authorities"*.
216
+ 2. Start PowerShell, and use it to run this command:
217
+ `test-wsman -ComputerName winserver.myoffice.com -UseSSL`
218
+
219
+ If the command executes without error, the ssl configuration is correct.
220
+
221
+ ##### End to end SSL testing with `knife winrm`
222
+
223
+ To validate that SSL is enabled for the listener without validating the
224
+ server's certificate, the `--winrm-ssl-verify-mode` option of the `winrm`
225
+ subcommand can be used:
226
+
227
+ knife winrm -m winserver.myoffice.com -t ssl --winrm-ssl-verify-mode verify_none ipconfig -x 'my_ad_domain\myuser' -P "$PASSWORDVAR"
228
+
229
+ If this succeeds, then any failures to execute the command when correctly
230
+ validating the server, i.e. when specifying the `-f` parameter, are due to
231
+ certificate configuration issues, not other connectivity or authentication
232
+ problems.
233
+
234
+ ##### The winrs tool
235
+
236
+ The `winrs` tool is built into Windows, so if a Windows system is available,
237
+ `winrs` may be used to troubleshoot. It takes parameters analogous to those of
238
+ `knife winrm` and differences in success and failure between the two tools may
239
+ indicate areas to investigate.
240
+
241
+ Visit Microsoft's documentation for [`winrs`](https://technet.microsoft.com/en-us/library/hh875630.aspx) to learn more about the tool.
242
+
243
+ ### Troubleshooting WinRM authentication issues
244
+
245
+ Authentication issues can be debugged by loosening the authentication
246
+ requirements on the server and explicitly using
247
+ `--winrm-authentication-protocol` option for `knife winrm` to attempt to
248
+ connect. As an example, the following PowerShell commands on the server will allow basic authentication
249
+ and unencrypted communication:
250
+
251
+ si wsman:\localhost\service\allowunencrypted $true
252
+ # Don't set the following if attempting domain authentication
253
+ si wsman:\localhost\service\auth\basic $true
254
+
255
+ From the client, `knife winrm` can be instructed to explicitly allow basic
256
+ authentication when validating authentication using a non-domain (i.e. local)
257
+ account:
258
+
259
+ # For testing a local account
260
+ knife winrm -m winserver.myoffice.com --winrm-authentication-protocol basic ipconfig -x 'localuser' -P "$PASSWORDVAR" -VV
261
+
262
+ # For testing a domain account
263
+ knife winrm -m winserver.myoffice.com --winrm-authentication-protocol negotiate ipconfig -x 'localuser' -P "$PASSWORDVAR" -VV
264
+
265
+ If the listener is an SSL listener, the additional arguments `-t ssl
266
+ --winrm-ssl-verify-mode verify_none` should be supplied to enable SSL
267
+ communication and disable peer verification for testing. The specification of
268
+ `-VV` enables additional detailed debug output that can provide clues to the
269
+ root cause of any failures.
270
+
271
+ If the command fails, there is either a connectivity issue or a problem with
272
+ an incorrect or expired password or disabled account.
273
+
274
+ If the command succeeds, try the following
275
+
276
+ si wsman:\localhost\service\allowunencrypted $false
277
+
278
+ Then retry the earlier `knife winrm` command. If it fails, this may indicate
279
+ an issue with your operating system's ability to encrypt traffic, particularly
280
+ when using the `plaintext` transport, i.e. when not using the `SSL` transport.
281
+ In that case, the Windows platform supports encryption of plaintext traffic
282
+ through native Windows authentication protocols, but such support is often incomplete on other platforms.
283
+
284
+ If the command succeeds, then there may be a more subtle issue with negotiate
285
+ authentication. It may be necessary to explicitly specify a domain in the user
286
+ name parameter (e.g. `mydomain\myuser` rather than just `user`) for instance,
287
+ or a specified domain may actually be incorrect and something that should be omitted.
288
+
289
+ ### Platform WinRM authentication support
290
+
291
+ `knife-windows` supports `Kerberos`, `Negotiate`, and `Basic` authentication
292
+ for WinRM communication. However, some of these protocols
293
+ may not work with `knife-windows` on non-Windows systems because
294
+ `knife-windows` relies on operating system libraries such as GSSAPI to implement
295
+ Windows authentication, and some versions of these libraries do not
296
+ fully implement the protocols.
297
+
298
+ The following table shows the authentication protocols that can be used with
299
+ `knife-windows` depending on whether the knife workstation is a Windows
300
+ system, the transport, and whether or not the target user is a domain user or
301
+ local to the target Windows system.
302
+
303
+ | Workstation OS / Account Scope | SSL | Plaintext |
304
+ |--------------------------------|------------------------------|----------------------------|
305
+ | Windows / Local | Kerberos, Negotiate* , Basic | Kerberos, Negotiate, Basic |
306
+ | Windows / Domain | Kerberos, Negotiate | Kerberos, Negotiate |
307
+ | Non-Windows / Local | Kerberos, [Negotiate*](https://github.com/chef/knife-windows/issues/176) Basic | Kerberos, Basic |
308
+ | Non-Windows / Domain | Kerberos, Negotiate | Kerberos |
309
+
310
+ > \* There is a known defect in the `knife winrm` and `knife bootstrap windows
311
+ > winrm` subcommands invoked on any OS platform when authenticating with the Negotiate protocol over
312
+ > the SSL transport. The defect is tracked by
313
+ > [knife-windows issue #176](https://github.com/chef/knife-windows/issues/176): If the remote system is
314
+ > domain-joined, local accounts may not be used to authenticate via Negotiate
315
+ > over SSL -- only domain accounts will work. Local accounts will only
316
+ > successfully authenticate if the system is not joined to a domain.
317
+ >
318
+ > This is generally not an issue for bootstrap scenarios, where the
319
+ > system has yet to be joined to any domain, but can be a problem for remote
320
+ > management cases after the system is domain joined. Workarounds include using
321
+ > a domain account instead, or enabling Basic authentication on the remote
322
+ > system (unencrypted communication **does not** need to be enabled to make
323
+ > Basic authentication function over SSL).
data/Gemfile CHANGED
@@ -4,8 +4,9 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :test do
7
+ gem "chef"
7
8
  gem "rspec", '~> 3.0'
8
9
  gem "ruby-wmi"
9
- gem "chef"
10
+ gem "httpclient"
10
11
  gem 'rake'
11
12
  end
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  Knife Windows Plugin
2
2
  ====================
3
+ [![Build Status Master](https://travis-ci.org/chef/knife-windows.svg?branch=master)](https://travis-ci.org/chef/knife-windows)
4
+ [![Build Status Master](https://ci.appveyor.com/api/projects/status/github/chef/knife-windows?branch=master&svg=true&passingText=master%20-%20Ok&pendingText=master%20-%20Pending&failingText=master%20-%20Failing)](https://ci.appveyor.com/project/Chef/knife-windows/branch/master)
3
5
 
4
6
  This plugin adds additional functionality to the Chef Knife CLI tool for
5
7
  configuring/interacting with nodes running Microsoft Windows. The subcommands
6
- should function on any system running Ruby 1.9.1+ but nodes being configured
8
+ should function on any system running Ruby 1.9.3+ but nodes being configured
7
9
  via these subcommands require Windows Remote Management (WinRM) 1.0+.WinRM
8
10
  allows you to call native objects in Windows. This includes, but is not
9
- limited to, running batch scripts, powershell scripts and fetching WMI
11
+ limited to, running PowerShell scripts, batch scripts, and fetching WMI
10
12
  variables. For more information on WinRM, please visit
11
13
  [Microsoft's WinRM site](http://msdn.microsoft.com/en-us/library/aa384426(v=VS.85).aspx).
12
14
  You will want to familiarize yourself with (certain key aspects) of WinRM
@@ -26,7 +28,7 @@ This plugin provides the following Knife subcommands. Specific command options c
26
28
 
27
29
  ### knife winrm
28
30
 
29
- The `winrm` subcommand allows you to invoke commands in parallel on a subset of the nodes in your infrastructure. The `winrm` subcommand uses the same syntax as the [search subcommand](http://wiki.opscode.com/display/chef/Search); you could could find the uptime of all your web servers using the command:
31
+ The `winrm` subcommand allows you to invoke commands in parallel on a subset of the nodes in your infrastructure. The `winrm` subcommand uses the same syntax as the [search subcommand](https://docs.chef.io/knife_search.html); you could could find the uptime of all your web servers using the command:
30
32
 
31
33
  knife winrm "role:web" "net stats srv" -x Administrator -P 'super_secret_password'
32
34
 
@@ -40,16 +42,48 @@ Or force a chef run:
40
42
  ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Running report handlers
41
43
  ec2-50-xx-xx-124.compute-1.amazonaws.com [Fri, 04 Mar 2011 22:00:53 +0000] INFO: Report handlers complete
42
44
 
43
- This subcommand operates in a manner similar to [knife ssh](http://wiki.opscode.com/display/chef/Knife#Knife-SSHSubcommand)...just leveraging the WinRM protocol for communication. It also include's `knife ssh`'s "[interactive session mode](http://wiki.opscode.com/display/chef/Knife#Knife-InteractiveMode)"
45
+ This subcommand operates in a manner similar to [knife ssh](https://docs.chef.io/knife_ssh.html)...just leveraging the WinRM protocol for communication. It also include's `knife ssh`'s "[interactive session mode](https://docs.chef.io/knife_ssh.html#options)"
46
+
47
+ ### knife wsman test
48
+
49
+ Connects to the remote WSMan/WinRM endpoint and verifies the remote node is listening. This is the equivalent of running Test-Wsman from PowerShell. Endpoints to test can be specified manually, or be driven by search and use many of the same connection options as knife winrm.
50
+ To test a single node using the default WinRM port (5985)
51
+
52
+ knife wsman test 192.168.1.10 -m
53
+
54
+ or to test a single node with SSL enabled on the default port (5986)
55
+
56
+ knife wsman test 192.168.1.10 -m --winrm-transport ssl
57
+
58
+ or to test all windows nodes registered with your Chef Server organization
59
+
60
+ knife wsman test platform:windows
61
+
44
62
 
45
63
  ### knife bootstrap windows winrm
46
64
 
47
65
  Performs a Chef Bootstrap (via the WinRM protocol) on the target node. The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists. It is primarily intended for Chef Client systems that talk to a Chef server.
48
66
 
49
- This subcommand operates in a manner similar to [knife bootstrap](http://wiki.opscode.com/display/chef/Knife+Bootstrap)...just leveraging the WinRM protocol for communication. An initial run_list for the node can also be passed to the subcommand. Example usage:
67
+ This subcommand operates in a manner similar to [knife bootstrap](https://docs.chef.io/knife_bootstrap.html)...just leveraging the WinRM protocol for communication. An initial run_list for the node can also be passed to the subcommand. Example usage:
50
68
 
51
69
  knife bootstrap windows winrm ec2-50-xx-xx-124.compute-1.amazonaws.com -r 'role[webserver],role[production]' -x Administrator -P 'super_secret_password'
52
70
 
71
+ ### Use SSL for WinRM communication
72
+
73
+ By default, the `knife winrm` and `knife bootstrap windows winrm` subcommands use a plaintext transport,
74
+ but they support an option `--winrm-transport` (or `-t`) with the argument
75
+ `ssl` that allows the SSL to secure the WinRM payload. Here's an example:
76
+
77
+ knife winrm -t ssl "role:web" "net stats srv" -x Administrator -P 'super_secret_password'
78
+
79
+ Use of SSL is strongly recommended, particularly when invoking `knife-windows` on non-Windows platforms, since
80
+ without SSL there are limited options for ensuring the privacy of the
81
+ plaintext transport. See the section on [Platform authentication
82
+ support](#platform-winrm-authentication-support).
83
+
84
+ SSL will become the default transport in future revisions of
85
+ `knife-windows`.
86
+
53
87
  ### knife bootstrap windows ssh
54
88
 
55
89
  Performs a Chef Bootstrap (via the SSH protocol) on the target node. The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists. It is primarily intended for Chef Client systems that talk to a Chef server.
@@ -60,6 +94,39 @@ An initial run_list for the node can also be passed to the subcommand. Example u
60
94
 
61
95
  knife bootstrap windows ssh ec2-50-xx-xx-124.compute-1.amazonaws.com -r 'role[webserver],role[production]' -x Administrator -i ~/.ssh/id_rsa
62
96
 
97
+ ### knife windows cert generate
98
+
99
+ Generates a certificate(x509) containing a public / private key pair for WinRM 'SSL' communication.
100
+ The certificate will be generated in three different formats *.pfx, *.b64 and *.pem.
101
+ The PKCS12(i.e *.pfx) contains both the public and private keys, usually used on the server. This will be added to WinRM Server's Certificate Store.
102
+ The *.b64 is Base64 PKCS12 key pair. Contains both the public and private keys, for upload to the Cloud REST API. e.g. Azure.
103
+ The *.pem is Base64 encoded public certificate only. Required by the client to connect to the server.
104
+ This command also displays the thumbprint of the generated certificate.
105
+
106
+ knife windows cert generate --cert-passphrase "strong_passphrase" --domain "cloudapp.net" --output-file "~/server_cert.pfx"
107
+ # This command will generate certificates at user's home directory with names server_cert.b64, server_cert.pfx and server_cert.pem.
108
+
109
+ ### knife windows cert install
110
+
111
+ This command only functions on Windows. It adds the specified certificate to its certificate store. This command must include a valid PKCS12(i.e *.pfx) certificate file path.
112
+
113
+ knife windows cert install "~/server_cert.pfx" --cert-passphrase "strong_passphrase"
114
+
115
+ ### knife windows listener create
116
+ This command only functions on Windows. It creates the winrm listener for SSL communication(i.e HTTPS).
117
+ This command can also install certificate which is specified using --cert-install option and use the installed certificate thumbprint to create winrm listener.
118
+ --hostname option is optional. Default value for hostname is *.
119
+
120
+ knife windows listener create --cert-passphrase "strong_passphrase" --hostname "*.cloudapp.net" --cert-install "~/server_cert.pfx"
121
+
122
+ The command also allows you to use existing certificates from local store to create winrm listener. Use --cert-thumbprint option to specify the certificate thumbprint.
123
+
124
+ knife windows listener create --cert-passphrase "strong_passphrase" --hostname "*.cloudapp.net" --cert-thumbprint "bf0fef0bb41be40ceb66a3b38813ca489fe99746"
125
+
126
+ You can get the thumbprint for existing certificates in local store using the following PowerShell command:
127
+
128
+ Get-ChildItem -path cert:\LocalMachine\My
129
+
63
130
  ## BOOTSTRAP TEMPLATES:
64
131
 
65
132
  This gem provides the bootstrap template `windows-chef-client-msi`.
@@ -73,17 +140,18 @@ This bootstrap template does the following:
73
140
  * Writes a default config file for Chef (`C:\chef\client.rb`) using values from the `knife.rb`.
74
141
  * Creates a JSON attributes file containing the specified run list and run Chef.
75
142
 
76
- This is the default bootstrap template used by both the `windows bootstrap` subcommands.
143
+ This is the default bootstrap template used by both of the `windows bootstrap` subcommands.
77
144
 
78
145
  ## REQUIREMENTS/SETUP:
79
146
 
80
147
  ### Ruby
81
148
 
82
- Ruby 1.9.1+ is needed.
149
+ Ruby 1.9.3+ is needed.
83
150
 
84
151
  ### Chef Version
85
152
 
86
- Knife plugins require >= Chef 0.10. More details about Knife plugins can be [found on the Chef wiki](http://wiki.opscode.com/display/chef/Knife+Plugins).
153
+ This knife plugins requires >= Chef 11.0.0. More details about Knife plugins can be
154
+ [found in the Chef documentation](https://docs.chef.io/plugin_knife.html).
87
155
 
88
156
  ## Nodes
89
157
 
@@ -94,7 +162,8 @@ A server running WinRM must also be configured properly to allow outside connect
94
162
  winrm quickconfig -q
95
163
 
96
164
  The Chef and Ohai gem installations (that occur during bootstrap) take more
97
- memory than the default 150MB WinRM allocates per shell -- this can slow down
165
+ memory than the default 150MB WinRM allocates per shell on older versions of
166
+ Windows (prior to Windows Server 2012) -- this can slow down
98
167
  bootstrap. Optionally increase the memory limit to 300MB with the following command:
99
168
 
100
169
  winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
@@ -105,47 +174,109 @@ complete, optionally increase to 30 minutes if bootstrap terminates a command pr
105
174
  winrm set winrm/config @{MaxTimeoutms="1800000"}
106
175
 
107
176
  WinRM supports both the HTTP and HTTPS transports and the following
108
- authentication schemes: Kerberos, Digest, Certificate and Basic. The details
177
+ authentication schemes: Kerberos, Digest, Certificate and Basic. The details
109
178
  of these authentication transports are outside of the scope of this README but
110
179
  details can be found on the
111
180
  [WinRM configuration guide](http://msdn.microsoft.com/en-us/library/aa384372(v=vs.85).aspx).
112
- Currently, this plugin support Kerberos and Basic authentication schemes on
113
- all platform versions. The negotiate protocol which allows NTLM is fully
114
- supported when `knife windows bootstrap` is executed on a Windows system; if
115
- it is executed on a non-Windows system, certificate authentication or Kerberos
116
- should be used instead via the `:kerberos_service` and related options of the subcommands.
117
-
118
- **NOTE**: In order to use NTLM / Negotiate to authenticate as the user
119
- specified by the `--winrm-user` (`-x`) option, you must include the user's
120
- Windows domain when specifying the user name using the format `domain\user`
121
- where the backslash ('`\`') character separates the user from the domain. If
122
- an account local to the node is being used to access, `.` may be used as the domain:
181
+
182
+ ## WinRM authentication
183
+
184
+ The default authentication protocol for `knife-windows` subcommands that use
185
+ WinRM is the Negotiate protocol. The following commands when executed on a
186
+ Windows system show authentication for domain and local accounts respectively:
123
187
 
124
188
  knife bootstrap windows winrm web1.cloudapp.net -r 'server::web' -x 'proddomain\webuser' -P 'super_secret_password'
125
- knife bootstrap windows winrm db1.cloudapp.net -r 'server::db' -x '.\localadmin' -P 'super_secret_password'
189
+ knife bootstrap windows winrm db1.cloudapp.net -r 'server::db' -x 'localadmin' -P 'super_secret_password'
190
+
191
+ The commands above are using the default plaintext transport for WinRM --
192
+ the default of Negotiate authentication may not be fully supported on
193
+ non-Windows systems using the plaintext transport. To work around this, the
194
+ remote system can be configured with an SSL WinRM listener instead of a
195
+ plaintext listener. Then the above commands should be modified to use the SSL
196
+ transport as follows using the `-t` (or `--winrm-transport`) option with the
197
+ `ssl` argument:
198
+
199
+ knife bootstrap windows winrm -t ssl web1.cloudapp.net -r 'server::web' -x 'proddomain\webuser' -P 'super_secret_password'
200
+ knife bootstrap windows winrm -t ssl db1.cloudapp.net -r 'server::db' -x 'localadmin' -P 'super_secret_password'
126
201
 
127
- For development and testing purposes, unencrypted traffic with Basic authentication can make it easier to test connectivity:
202
+ The commands using SSL above will work from any operating system, not just Windows.
203
+
204
+ ### Troubleshooting authentication
205
+
206
+ For development and testing purposes, unencrypted traffic with Basic
207
+ authentication can make it easier to test connectivity. The configuration for
208
+ the remote system may be accomplished with the following commands:
128
209
 
129
210
  winrm set winrm/config/service @{AllowUnencrypted="true"}
130
211
  winrm set winrm/config/service/auth @{Basic="true"}
131
212
 
132
- ## Troubleshooting
213
+ To test connectivity via `knife-windows` from another system, the default
214
+ authentication protocol of Negotiate must be overridden using the
215
+ `--winrm-authentication-protocol` option with the desired protocol, in this
216
+ case Basic:
217
+
218
+ knife winrm -m web1.cloudapp.net --winrm-authentication-protocol basic ipconfig -x 'localadmin' -P 'super_secret_password'
219
+
220
+ Note that when using Basic authentication, domain accounts may not be used for
221
+ authentication; an account local to the remote system must be used.
222
+
223
+ ### Platform WinRM authentication support
224
+
225
+ `knife-windows` supports `Kerberos`, `Negotiate`, and `Basic` authentication
226
+ for WinRM communication. However, some of these protocols
227
+ may not work with `knife-windows` on non-Windows systems because
228
+ `knife-windows` relies on operating system libraries such as GSSAPI to implement
229
+ Windows authentication, and some versions of these libraries do not
230
+ fully implement the protocols.
231
+
232
+ The following table shows the authentication protocols that can be used with
233
+ `knife-windows` depending on whether the knife workstation is a Windows
234
+ system, the transport, and whether or not the target user is a domain user or
235
+ local to the target Windows system.
236
+
237
+ | Workstation OS / Account Scope | SSL | Plaintext |
238
+ |--------------------------------|------------------------------|----------------------------|
239
+ | Windows / Local | Kerberos, Negotiate* , Basic | Kerberos, Negotiate, Basic |
240
+ | Windows / Domain | Kerberos, Negotiate | Kerberos, Negotiate |
241
+ | Non-Windows / Local | Kerberos, [Negotiate*](https://github.com/chef/knife-windows/issues/176) Basic | Kerberos, Basic |
242
+ | Non-Windows / Domain | Kerberos, Negotiate | Kerberos |
243
+
244
+ > \* There is a known defect in the `knife winrm` and `knife bootstrap windows
245
+ > winrm` subcommands invoked on any OS platform when authenticating with the Negotiate protocol over
246
+ > the SSL transport. The defect is tracked by
247
+ > [knife-windows issue #176](https://github.com/chef/knife-windows/issues/176): If the remote system is
248
+ > domain-joined, local accounts may not be used to authenticate via Negotiate
249
+ > over SSL -- only domain accounts will work. Local accounts will only
250
+ > successfully authenticate if the system is not joined to a domain.
251
+ >
252
+ > This is generally not an issue for bootstrap scenarios, where the
253
+ > system has yet to be joined to any domain, but can be a problem for remote
254
+ > management cases after the system is domain joined. Workarounds include using
255
+ > a domain account instead, or enabling Basic authentication on the remote
256
+ > system (unencrypted communication **does not** need to be enabled to make
257
+ > Basic authentication function over SSL).
258
+
259
+ ## General troubleshooting
133
260
 
134
261
  * When I run the winrm command I get: "Error: Invalid use of command line. Type "winrm -?" for help."
135
262
  You're running the winrm command from PowerShell and you need to put the key/value pair in single quotes. For example:
136
263
 
137
- winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="512"}'
264
+ `winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="512"}'`
265
+
266
+ * Windows 2008R2 and earlier versions require an extra configuration for MaxTimeoutms to avoid WinRM::WinRMHTTPTransportError: Bad HTTP response error while bootstrapping. It should be atleast 300000.
267
+
268
+ `winrm set winrm/config @{MaxTimeoutms="300000"}`
138
269
 
139
270
  ## CONTRIBUTING:
140
271
 
141
- Please file bugs against the KNIFE_WINDOWS project at https://github.com/opscode/knife-windows/issues.
272
+ Please file bugs against the KNIFE_WINDOWS project at https://github.com/chef/knife-windows/issues.
142
273
 
143
- More information on the contribution process for Opscode projects can be found in the [Chef Contributions document](http://docs.opscode.com/community_contributions.html).
274
+ More information on the contribution process for Chef projects can be found in the [Chef Contributions document](http://docs.chef.io/community_contributions.html).
144
275
 
145
276
  # LICENSE:
146
277
 
147
- Author:: Seth Chisamore (<schisamo@opscode.com>)
148
- Copyright:: Copyright (c) 2014 Opscode, Inc.
278
+ Author:: Seth Chisamore (<schisamo@chef.io>)
279
+ Copyright:: Copyright (c) 2015 Chef Software, Inc.
149
280
  License:: Apache License, Version 2.0
150
281
 
151
282
  Licensed under the Apache License, Version 2.0 (the "License");