winrm 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.rubocop.yml +26 -26
- data/.travis.yml +11 -11
- data/Gemfile +3 -3
- data/README.md +263 -260
- data/Rakefile +34 -34
- data/Vagrantfile +6 -6
- data/WinrmAppveyor.psm1 +31 -31
- data/appveyor.yml +51 -51
- data/changelog.md +107 -104
- data/lib/winrm.rb +39 -39
- data/lib/winrm/connection.rb +83 -83
- data/lib/winrm/connection_opts.rb +91 -91
- data/lib/winrm/exceptions.rb +76 -76
- data/lib/winrm/http/response_handler.rb +96 -96
- data/lib/winrm/http/transport.rb +424 -424
- data/lib/winrm/http/transport_factory.rb +68 -68
- data/lib/winrm/output.rb +59 -59
- data/lib/winrm/psrp/create_pipeline.xml.erb +167 -167
- data/lib/winrm/psrp/fragment.rb +70 -70
- data/lib/winrm/psrp/init_runspace_pool.xml.erb +224 -224
- data/lib/winrm/psrp/message.rb +130 -130
- data/lib/winrm/psrp/message_data.rb +42 -42
- data/lib/winrm/psrp/message_data/base.rb +49 -49
- data/lib/winrm/psrp/message_data/error_record.rb +68 -68
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +32 -32
- data/lib/winrm/psrp/message_data/pipeline_output.rb +54 -49
- data/lib/winrm/psrp/message_data/pipeline_state.rb +40 -40
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +32 -32
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +39 -39
- data/lib/winrm/psrp/message_data/session_capability.rb +36 -36
- data/lib/winrm/psrp/message_defragmenter.rb +62 -62
- data/lib/winrm/psrp/message_factory.rb +75 -75
- data/lib/winrm/psrp/message_fragmenter.rb +60 -60
- data/lib/winrm/psrp/powershell_output_decoder.rb +144 -139
- data/lib/winrm/psrp/receive_response_reader.rb +97 -97
- data/lib/winrm/psrp/session_capability.xml.erb +7 -7
- data/lib/winrm/psrp/uuid.rb +40 -40
- data/lib/winrm/shells/base.rb +180 -180
- data/lib/winrm/shells/cmd.rb +65 -65
- data/lib/winrm/shells/power_shell.rb +202 -202
- data/lib/winrm/shells/retryable.rb +45 -45
- data/lib/winrm/shells/shell_factory.rb +58 -58
- data/lib/winrm/version.rb +7 -7
- data/lib/winrm/wsmv/base.rb +59 -59
- data/lib/winrm/wsmv/cleanup_command.rb +61 -61
- data/lib/winrm/wsmv/close_shell.rb +50 -50
- data/lib/winrm/wsmv/command.rb +101 -101
- data/lib/winrm/wsmv/command_output.rb +76 -76
- data/lib/winrm/wsmv/command_output_decoder.rb +55 -55
- data/lib/winrm/wsmv/configuration.rb +46 -46
- data/lib/winrm/wsmv/create_pipeline.rb +66 -66
- data/lib/winrm/wsmv/create_shell.rb +119 -119
- data/lib/winrm/wsmv/header.rb +203 -203
- data/lib/winrm/wsmv/init_runspace_pool.rb +95 -95
- data/lib/winrm/wsmv/iso8601_duration.rb +60 -60
- data/lib/winrm/wsmv/keep_alive.rb +68 -68
- data/lib/winrm/wsmv/receive_response_reader.rb +126 -126
- data/lib/winrm/wsmv/send_data.rb +68 -68
- data/lib/winrm/wsmv/soap.rb +51 -51
- data/lib/winrm/wsmv/wql_query.rb +79 -79
- data/lib/winrm/wsmv/write_stdin.rb +88 -88
- data/tests/integration/auth_timeout_spec.rb +18 -18
- data/tests/integration/cmd_spec.rb +131 -131
- data/tests/integration/config-example.yml +16 -16
- data/tests/integration/issue_59_spec.rb +26 -26
- data/tests/integration/powershell_spec.rb +165 -165
- data/tests/integration/spec_helper.rb +65 -65
- data/tests/integration/transport_spec.rb +99 -99
- data/tests/integration/wql_spec.rb +16 -16
- data/tests/matchers.rb +60 -60
- data/tests/spec/configuration_spec.rb +184 -184
- data/tests/spec/connection_spec.rb +39 -39
- data/tests/spec/exception_spec.rb +50 -50
- data/tests/spec/http/transport_factory_spec.rb +68 -68
- data/tests/spec/http/transport_spec.rb +44 -44
- data/tests/spec/output_spec.rb +127 -127
- data/tests/spec/psrp/fragment_spec.rb +62 -62
- data/tests/spec/psrp/message_data/base_spec.rb +13 -13
- data/tests/spec/psrp/message_data/error_record_spec.rb +41 -41
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +25 -25
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +32 -32
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +40 -40
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +25 -25
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +16 -16
- data/tests/spec/psrp/message_data/session_capability_spec.rb +30 -30
- data/tests/spec/psrp/message_data_spec.rb +35 -35
- data/tests/spec/psrp/message_defragmenter_spec.rb +47 -47
- data/tests/spec/psrp/message_fragmenter_spec.rb +105 -105
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +100 -100
- data/tests/spec/psrp/psrp_message_spec.rb +70 -70
- data/tests/spec/psrp/recieve_response_reader_spec.rb +172 -172
- data/tests/spec/psrp/uuid_spec.rb +28 -28
- data/tests/spec/response_handler_spec.rb +61 -61
- data/tests/spec/shells/base_spec.rb +202 -202
- data/tests/spec/shells/cmd_spec.rb +75 -75
- data/tests/spec/shells/powershell_spec.rb +175 -175
- data/tests/spec/spec_helper.rb +47 -47
- data/tests/spec/stubs/clixml/error_record.xml.erb +84 -84
- data/tests/spec/stubs/clixml/pipeline_state.xml.erb +88 -88
- data/tests/spec/stubs/responses/get_command_output_response.xml.erb +13 -13
- data/tests/spec/stubs/responses/get_command_output_response_not_done.xml.erb +10 -10
- data/tests/spec/stubs/responses/get_powershell_keepalive_response.xml.erb +10 -10
- data/tests/spec/stubs/responses/get_powershell_output_response.xml.erb +12 -12
- data/tests/spec/stubs/responses/get_powershell_output_response_not_done.xml.erb +9 -9
- data/tests/spec/stubs/responses/open_shell_v1.xml +19 -19
- data/tests/spec/stubs/responses/open_shell_v2.xml +20 -20
- data/tests/spec/stubs/responses/soap_fault_v1.xml +36 -36
- data/tests/spec/stubs/responses/soap_fault_v2.xml +42 -42
- data/tests/spec/stubs/responses/wmi_error_v2.xml +41 -41
- data/tests/spec/wsmv/cleanup_command_spec.rb +22 -22
- data/tests/spec/wsmv/close_shell_spec.rb +17 -17
- data/tests/spec/wsmv/command_output_decoder_spec.rb +37 -37
- data/tests/spec/wsmv/command_output_spec.rb +45 -45
- data/tests/spec/wsmv/command_spec.rb +19 -19
- data/tests/spec/wsmv/configuration_spec.rb +17 -17
- data/tests/spec/wsmv/create_pipeline_spec.rb +31 -31
- data/tests/spec/wsmv/create_shell_spec.rb +38 -38
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +36 -36
- data/tests/spec/wsmv/keep_alive_spec.rb +21 -21
- data/tests/spec/wsmv/receive_response_reader_spec.rb +123 -123
- data/tests/spec/wsmv/send_data_spec.rb +30 -30
- data/tests/spec/wsmv/wql_query_spec.rb +13 -13
- data/tests/spec/wsmv/write_stdin_spec.rb +22 -22
- data/winrm.gemspec +47 -42
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 640699847b134916407b0e18c09c14cc323f0951
|
4
|
+
data.tar.gz: 0129263b31ef9e042dbb7e404e71b56ebcad7f34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71b28f0853aca2274064f14e867f1638a83927ea649df320701c171c58425c1149cc6b0ca36fe11dd34c9df5756117ba92ada06fe4716b5e0f7d9fac8f6ce38e
|
7
|
+
data.tar.gz: e22fa02527fa907bc668fbdead7d0a40f6ad6eeeb1d965064e6266270a173a52a1bd16a8ab9d7e664689f17bbe33c43f5abeee1ab0a4f611a731c59436b10f39
|
data/.gitignore
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
*.swp
|
2
|
-
*.gem
|
3
|
-
pkg/*
|
4
|
-
.rvmrc
|
5
|
-
.idea
|
6
|
-
.bundle
|
7
|
-
tests/integration/config.yml
|
8
|
-
traces/
|
9
|
-
Gemfile.lock
|
10
|
-
.vagrant
|
1
|
+
*.swp
|
2
|
+
*.gem
|
3
|
+
pkg/*
|
4
|
+
.rvmrc
|
5
|
+
.idea
|
6
|
+
.bundle
|
7
|
+
tests/integration/config.yml
|
8
|
+
traces/
|
9
|
+
Gemfile.lock
|
10
|
+
.vagrant
|
data/.rubocop.yml
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
AllCops:
|
2
|
-
Exclude:
|
3
|
-
- 'appveyor.yml'
|
4
|
-
- 'Vagrantfile'
|
5
|
-
- 'scripts/**/*'
|
6
|
-
|
7
|
-
Style/Encoding:
|
8
|
-
Enabled: true
|
9
|
-
|
10
|
-
Style/NumericLiterals:
|
11
|
-
Enabled: false
|
12
|
-
|
13
|
-
Metrics/LineLength:
|
14
|
-
Max: 100
|
15
|
-
|
16
|
-
Metrics/MethodLength:
|
17
|
-
Max: 20
|
18
|
-
|
19
|
-
ModuleLength:
|
20
|
-
Max: 250
|
21
|
-
|
22
|
-
ClassLength:
|
23
|
-
Max: 250
|
24
|
-
|
25
|
-
Metrics/AbcSize:
|
26
|
-
Max: 25
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'appveyor.yml'
|
4
|
+
- 'Vagrantfile'
|
5
|
+
- 'scripts/**/*'
|
6
|
+
|
7
|
+
Style/Encoding:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Style/NumericLiterals:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/LineLength:
|
14
|
+
Max: 100
|
15
|
+
|
16
|
+
Metrics/MethodLength:
|
17
|
+
Max: 20
|
18
|
+
|
19
|
+
ModuleLength:
|
20
|
+
Max: 250
|
21
|
+
|
22
|
+
ClassLength:
|
23
|
+
Max: 250
|
24
|
+
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Max: 25
|
data/.travis.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.0.0
|
4
|
-
- 2.1.0
|
5
|
-
before_install:
|
6
|
-
- gem update bundler
|
7
|
-
|
8
|
-
# This prevents testing branches that are created just for PRs
|
9
|
-
branches:
|
10
|
-
only:
|
11
|
-
- master
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
- 2.1.0
|
5
|
+
before_install:
|
6
|
+
- gem update bundler
|
7
|
+
|
8
|
+
# This prevents testing branches that are created just for PRs
|
9
|
+
branches:
|
10
|
+
only:
|
11
|
+
- master
|
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
source 'https://rubygems.org'
|
3
|
-
gemspec
|
1
|
+
# encoding: UTF-8
|
2
|
+
source 'https://rubygems.org'
|
3
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,260 +1,263 @@
|
|
1
|
-
# Windows Remote Management (WinRM) for Ruby
|
2
|
-
[![Build Status](https://travis-ci.org/WinRb/WinRM.svg?branch=master)](https://travis-ci.org/WinRb/WinRM)
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/winrm.svg)](http://badge.fury.io/rb/winrm)
|
4
|
-
[![Build status](https://ci.appveyor.com/api/projects/status/ods9tvos78k5c15h?svg=true)](https://ci.appveyor.com/project/winrb/winrm)
|
5
|
-
|
6
|
-
This is a SOAP library that uses the functionality in Windows Remote
|
7
|
-
Management(WinRM) to call native object in Windows. This includes, but is
|
8
|
-
not limited to, running batch scripts, powershell scripts and fetching WMI
|
9
|
-
variables. For more information on WinRM, please visit [Microsoft's WinRM
|
10
|
-
site](http://msdn.microsoft.com/en-us/library/aa384426.aspx).
|
11
|
-
|
12
|
-
As of version 2.0, this gem retains the WinRM name but all powershell calls use the more modern [Powershell Remoting Protocol (PSRP)](https://msdn.microsoft.com/en-us/library/dd357801.aspx) for initializing runspace pools as well as creating and processing powershell pipelines.
|
13
|
-
|
14
|
-
## Supported
|
15
|
-
|
16
|
-
|
17
|
-
##
|
18
|
-
|
19
|
-
|
20
|
-
##
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
* `:
|
45
|
-
* `:
|
46
|
-
* `:
|
47
|
-
* `:
|
48
|
-
* `:
|
49
|
-
* `:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
* `:
|
85
|
-
* `:
|
86
|
-
* `:
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
* `:
|
144
|
-
* `:
|
145
|
-
* `:
|
146
|
-
* `:
|
147
|
-
* `:
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
$thumbprint = (
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
conn
|
207
|
-
|
208
|
-
#
|
209
|
-
conn.logger.
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
```
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
##
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
*
|
254
|
-
|
255
|
-
|
256
|
-
*
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
1
|
+
# Windows Remote Management (WinRM) for Ruby
|
2
|
+
[![Build Status](https://travis-ci.org/WinRb/WinRM.svg?branch=master)](https://travis-ci.org/WinRb/WinRM)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/winrm.svg)](http://badge.fury.io/rb/winrm)
|
4
|
+
[![Build status](https://ci.appveyor.com/api/projects/status/ods9tvos78k5c15h?svg=true)](https://ci.appveyor.com/project/winrb/winrm)
|
5
|
+
|
6
|
+
This is a SOAP library that uses the functionality in Windows Remote
|
7
|
+
Management(WinRM) to call native object in Windows. This includes, but is
|
8
|
+
not limited to, running batch scripts, powershell scripts and fetching WMI
|
9
|
+
variables. For more information on WinRM, please visit [Microsoft's WinRM
|
10
|
+
site](http://msdn.microsoft.com/en-us/library/aa384426.aspx).
|
11
|
+
|
12
|
+
As of version 2.0, this gem retains the WinRM name but all powershell calls use the more modern [Powershell Remoting Protocol (PSRP)](https://msdn.microsoft.com/en-us/library/dd357801.aspx) for initializing runspace pools as well as creating and processing powershell pipelines.
|
13
|
+
|
14
|
+
## Supported Ruby Versions
|
15
|
+
Ruby 2.0 or higher is required. If you need to use an older version of Ruby you'll need to use a 1.x version of this gem.
|
16
|
+
|
17
|
+
## Supported WinRM Versions
|
18
|
+
WinRM 1.1 is supported, however 2.0 and higher is recommended. [See MSDN](http://technet.microsoft.com/en-us/library/ff520073.aspx) for information about WinRM versions and supported operating systems.
|
19
|
+
|
20
|
+
## Install
|
21
|
+
`gem install -r winrm` then on the server `Enable-PSRemoting -Force` (already enabled on server operating systems 2012 and above) as admin
|
22
|
+
|
23
|
+
## Example
|
24
|
+
```ruby
|
25
|
+
require 'winrm'
|
26
|
+
opts = {
|
27
|
+
endpoint: 'http://myhost:5985/wsman',
|
28
|
+
user: 'administrator',
|
29
|
+
password: 'Pass@word1'
|
30
|
+
}
|
31
|
+
conn = WinRM::Connection.new(opts)
|
32
|
+
conn.shell(:powershell) do |shell|
|
33
|
+
output = shell.run('$PSVersionTable') do |stdout, stderr|
|
34
|
+
STDOUT.print stdout
|
35
|
+
STDERR.print stderr
|
36
|
+
end
|
37
|
+
puts "The script exited with exit code #{output.exitcode}"
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Connection Options
|
42
|
+
There are various connection options you can specify upon initializing a WinRM connection object:
|
43
|
+
|
44
|
+
* `:transport` - The type of underlying connection transport to use (more on this below). Defaults to `:negotiate`
|
45
|
+
* `:locale` - The locale requested for response text formatting. This is the value sent in the `DataLocale` and `Locale` header values and defaults to `en-us`
|
46
|
+
* `:max_envelope_size` - mazimum number of bytes expected for WinRM responses. This defaults to 153600
|
47
|
+
* `:operation_timeout` - The maximum amount of time to wait for a response from the endpoint. This defaults to 60 seconds. Note that this will not "timeout" commands that exceed this amount of time to process, it just requires the endpoint to report the status of the command before the given amount of time passes.
|
48
|
+
* `:receive_timeout` - The amount of time given to the underlying HTTP connection to respond before timing out. The defaults to 10 seconds longer than the `:operation_timeout`.
|
49
|
+
* `:retry_limit` - the maximum number of times to retry opening a shell after failure. This defaults to 3.
|
50
|
+
* `:retry_delay` - the amount of time to wait between retries and defaults to 10 seconds
|
51
|
+
* `:user` - username used to authenticate over the `:transport`
|
52
|
+
* `:password` - password used to authenticate over the `:transport`
|
53
|
+
|
54
|
+
There are other options that may apply depending on the type of `:transport` used and are discussed below.
|
55
|
+
|
56
|
+
## Transports
|
57
|
+
|
58
|
+
The transport used governs the authentication method used and the encryption level used for the underlying HTTP communication with the endpoint. The WinRM gem supports the following transport types:
|
59
|
+
|
60
|
+
### `:negotiate`
|
61
|
+
```ruby
|
62
|
+
WinRM::Connection.new(
|
63
|
+
endpoint: 'http://myhost:5985/wsman',
|
64
|
+
transport: :negotiate,
|
65
|
+
user: 'administrator',
|
66
|
+
password: 'Pass@word1'
|
67
|
+
)
|
68
|
+
```
|
69
|
+
|
70
|
+
The `:negotiate` transport uses the [rubyntlm gem](https://github.com/WinRb/rubyntlm) to authenticate with the endpoint using the NTLM protocol. This uses an HTTP based connection but the SOAP message payloads are encrypted. If using HTTP (as opposed to HTTPS) this is the recommended transport. This is also the default transport used if none is specified in the connection options.
|
71
|
+
|
72
|
+
### `:ssl`
|
73
|
+
```ruby
|
74
|
+
WinRM::Connection.new(
|
75
|
+
endpoint: 'https://myhost:59856/wsman',
|
76
|
+
transport: :ssl,
|
77
|
+
user: 'administrator',
|
78
|
+
password: 'Pass@word1'
|
79
|
+
)
|
80
|
+
```
|
81
|
+
|
82
|
+
The `:ssl` transport establishes a connection to the winrm endpoint over a secure sockets layer transport encrypting the entire message. Here are some additional connecion options available to `:ssl` connections:
|
83
|
+
|
84
|
+
* `:client_cert` - Either a string path to a certificate `.pem` file or a `X509::Certificate` object. This along with an accompanying `:client_key` can be used in lieu of a `:user` and `:password`.
|
85
|
+
* `:client_key` - the path to the private key file accompanying the above mentioned `:client_cert` or an `PKey::Pkey` object.
|
86
|
+
* `:key_pass` - the optional password if necessary to access the `:client_cert`
|
87
|
+
* `:no_ssl_peer_verification` - when set to `true` ssl certificate validation is not performed. With a self signed cert, its a match made in heaven!
|
88
|
+
* `:ssl_peer_fingerprint` - when this is provided, normal certificate validation is skipped and instead the given fingerprint is matched against the certificate of the endpoint for verification.
|
89
|
+
* `:ca_trust_path` - the path to a certificate `.pem` file to trust. Its similar to the `:ssl_peer_fingerprint` but contains the entire certificate to trust.
|
90
|
+
|
91
|
+
### `:kerberos`
|
92
|
+
```ruby
|
93
|
+
WinRM::Connection.new(
|
94
|
+
endpoint: 'http://myhost:5985/wsman',
|
95
|
+
transport: :kerberos,
|
96
|
+
realm: 'kerberos_realm'
|
97
|
+
)
|
98
|
+
```
|
99
|
+
|
100
|
+
Uses `:kerberos` to authenticate with the endpoint. These additional connection options may be used:
|
101
|
+
|
102
|
+
* `:service` - kerberos service used to authenticate with the endpoint. Defaults to `HTTP`.
|
103
|
+
* `:realm` - Kerberos realm to authenticate against.
|
104
|
+
|
105
|
+
### `:plaintext`
|
106
|
+
Note: It is strongly recommended that you use `:negotiate` instead of `:plaintext`. As the name infers, the `:plaintext` transport includes authentication credentials in plain text.
|
107
|
+
```ruby
|
108
|
+
WinRM::Connection.new(
|
109
|
+
endpoint: 'http://myhost:5985/wsman',
|
110
|
+
transport: :plaintext,
|
111
|
+
user: 'administrator',
|
112
|
+
password: 'Pass@word1',
|
113
|
+
basic_auth_only: true
|
114
|
+
)
|
115
|
+
```
|
116
|
+
|
117
|
+
Additional supported connection options:
|
118
|
+
|
119
|
+
* `:basic_auth_only` - Force basic authentication
|
120
|
+
* `:disable_sspi` - Disable SSPI Negotiation authentication
|
121
|
+
|
122
|
+
## Shells
|
123
|
+
|
124
|
+
As of the WinRM gem version 2, one creates a shell for executing commands by calling the `shell` method of a WinRM connection. There are two types of shells available:
|
125
|
+
|
126
|
+
* `:cmd` - initiates a traditional cmd.exe shell via the WinRM protocol
|
127
|
+
* `:powershell` - initiates a powershell runspace via the PSRP protocol
|
128
|
+
|
129
|
+
Both shells support the same public methods: `:open`, `:close`, and `run`. Note that when given a shell, it is opened automatically upon executing the first command via `:run`. Further, `close` is called automatically when a `shell` is garbage collected or when using a shell from a block. However, it is always a good idea to proactively `close` a shell.
|
130
|
+
|
131
|
+
### Shell options supported by the `:cmd` shell
|
132
|
+
|
133
|
+
```
|
134
|
+
shell_opts = {
|
135
|
+
env_vars: { 'FOO' => 'BAR' }
|
136
|
+
}
|
137
|
+
conn = WinRM::Connection.new(opts)
|
138
|
+
shell = conn.shell(:cmd, shell_opts)
|
139
|
+
```
|
140
|
+
|
141
|
+
The `:cmd` shell supports a number of shell options that you can specify for the shell. There are safe defaults for all shell options and chances are that you will not need to override any of them. The available options are listed below.
|
142
|
+
|
143
|
+
* `:shell_uri` - WSMAN Resource URI. Defaults to `http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd` and you should not change this unless you hold the keys to the portal of eternity.
|
144
|
+
* `:i_stream` - A simple token list of all input streams the client will be using during execution. The only supported stream and the default is `stdin`.
|
145
|
+
* `:o_stream` - A simple token list of all output streams expected by the client. The supported streams and the defaults are `stdout` and `stderr`.
|
146
|
+
* `:codepage` - The `WINRS_CODEPAGE` which is the client's console output code page. The default is 65001 (UTF-8).
|
147
|
+
* `:noprofile` - The `WINRS_NOPROFILE` if set to `TRUE`, this option specifies that the user profile does not exist on the remote system and that the default profile should be used. By default, the value is `FALSE`.
|
148
|
+
* `:working_directory` - the starting directory that the Shell is to use for initialization.
|
149
|
+
* `:idle_timeout` - The remote winrm service will close and terminate the shell instance if it is idle for this many seconds. If the Shell is reused within this time limit, the countdown timer is reset once the command sequence is completed.
|
150
|
+
* `:env_vars` - a hash of EnvironmentVariable key/values, the starting set of environment variables that the Shell will use.
|
151
|
+
|
152
|
+
### `:codepage` and working with legacy Windows versions
|
153
|
+
|
154
|
+
When using the `:cmd` shell, the default codepage used is `65001`. This works best accross locales on "modern" versions of Windows (Windows 7/Server 2008 R2 and later). Older versions may exhibit undesirable behavior under the 65001 codepage. The most common symptom is that commands invoking executables will return immediately with no output or errors.
|
155
|
+
|
156
|
+
When using these older versions of Windows, its best to use the native code page of the server's locale. For example, en-US servers will have a codepage of `437`. The `chcp` command can be used to determine the value of the native codepage.
|
157
|
+
|
158
|
+
## Executing a WQL Query
|
159
|
+
```ruby
|
160
|
+
opts = {
|
161
|
+
endpoint: 'http://myhost:5985/wsman',
|
162
|
+
user: 'administrator',
|
163
|
+
password: 'Pass@word1'
|
164
|
+
}
|
165
|
+
conn = WinRM::Connection.new(opts)
|
166
|
+
|
167
|
+
out = conn.run_wql('select * from Win32_OperatingSystem')
|
168
|
+
output_caption = out[:win32_operating_system][0][:caption]
|
169
|
+
```
|
170
|
+
|
171
|
+
## Create a self signed cert for WinRM
|
172
|
+
You may want to create a self signed certificate for servicing https WinRM connections. You can use the following PowerShell script to create a cert and enable the WinRM HTTPS listener. Unless you are running windows server 2012 R2 or later, you must install makecert.exe from the Windows SDK, otherwise use `New-SelfSignedCertificate`.
|
173
|
+
|
174
|
+
```powershell
|
175
|
+
$hostname = $Env:ComputerName
|
176
|
+
|
177
|
+
C:\"Program Files"\"Microsoft SDKs"\Windows\v7.1\Bin\makecert.exe -r -pe -n "CN=$hostname,O=vagrant" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 "$hostname.cer"
|
178
|
+
|
179
|
+
$thumbprint = (& ls cert:LocalMachine/my).Thumbprint
|
180
|
+
|
181
|
+
# Windows 2012R2 and above can use New-SelfSignedCertificate
|
182
|
+
$thumbprint = (New-SelfSignedCertificate -DnsName $hostname -CertStoreLocation cert:\LocalMachine\my).Thumbprint
|
183
|
+
|
184
|
+
$cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$hostname`";CertificateThumbprint=`"$thumbprint`"}'"
|
185
|
+
iex $cmd
|
186
|
+
```
|
187
|
+
|
188
|
+
## Setting up Certificate based authentication
|
189
|
+
Perform the following steps to authenticate with a certificate instead of a username and password:
|
190
|
+
|
191
|
+
1. Generate a certificate with an Extended Key Usage of Client Authentication and a Subject Alternative Name with the UPN of the user. See this [powershell function](https://github.com/WinRb/WinRM/blob/master/WinrmAppveyor.psm1#L1) as an example of using `openssl` to create a self signed user certificate in `.pem` and `.pfx` formats along with the private key file.
|
192
|
+
|
193
|
+
2. Import the pfx file into the `TrustedPeople` directory of the `LocalMachine` certificate store on the windows endpoint.
|
194
|
+
|
195
|
+
3. Import the issuing certificate authority certificate in the endpoint's `Root` certificates. If your client certificate is self signed, this will be the client certificate.
|
196
|
+
|
197
|
+
4. Enable certificate authentication on the endpoint: `Set-Item -Path WSMan:\localhost\Service\Auth\Certificate -Value $true`
|
198
|
+
|
199
|
+
5. Add a winrm user mapping for the issuing certificate: `New-Item -Path WSMan:\localhost\ClientCertificate -Subject <user UPN> -URI * -Issuer <issuing certificate thumbprint> -Credential (Get-Credential) -Force`
|
200
|
+
|
201
|
+
See [this post](http://www.hurryupandwait.io/blog/certificate-password-less-based-authentication-in-winrm) for more details on certificate authentication.
|
202
|
+
|
203
|
+
## Logging
|
204
|
+
The `WinRM::Connection` exposes a `logger` attribute and uses the [logging](https://rubygems.org/gems/logging) gem to manage logging behavior. By default this appends to `STDOUT` and has a level of `:warn`, but one can adjust the level or add additional appenders.
|
205
|
+
```ruby
|
206
|
+
conn = WinRM::Connection.new(opts)
|
207
|
+
|
208
|
+
# suppress warnings
|
209
|
+
conn.logger.level = :error
|
210
|
+
|
211
|
+
# Log to a file
|
212
|
+
conn.logger.add_appenders(Logging.appenders.file('error.log'))
|
213
|
+
```
|
214
|
+
|
215
|
+
If a consuming application uses its own logger that complies to the logging API, you can simply swap it in:
|
216
|
+
```ruby
|
217
|
+
conn.logger = my_logger
|
218
|
+
```
|
219
|
+
|
220
|
+
## Troubleshooting
|
221
|
+
You may have some errors like ```WinRM::WinRMAuthorizationError```. See [this post](http://www.hurryupandwait.io/blog/understanding-and-troubleshooting-winrm-connection-and-authentication-a-thrill-seekers-guide-to-adventure) for tips and troubleshooting steps related to winrm connection and authentication issues.
|
222
|
+
|
223
|
+
## Contributing
|
224
|
+
|
225
|
+
1. Fork it.
|
226
|
+
2. Create a branch (git checkout -b my_feature_branch)
|
227
|
+
3. Run the unit and integration tests (bundle exec rake integration)
|
228
|
+
4. Commit your changes (git commit -am "Added a sweet feature")
|
229
|
+
5. Push to the branch (git push origin my_feature_branch)
|
230
|
+
6. Create a pull requst from your branch into master (Please be sure to provide enough detail for us to cipher what this change is doing)
|
231
|
+
|
232
|
+
### Running the tests
|
233
|
+
|
234
|
+
We use Bundler to manage dependencies during development.
|
235
|
+
|
236
|
+
```
|
237
|
+
$ bundle install
|
238
|
+
```
|
239
|
+
|
240
|
+
Once you have the dependencies, you can run the unit tests with `rake`:
|
241
|
+
|
242
|
+
```
|
243
|
+
$ bundle exec rake spec
|
244
|
+
```
|
245
|
+
|
246
|
+
To run the integration tests you will need a Windows box with the WinRM service properly configured. Its easiest to use a Vagrant Windows box (mwrock/Windows2012R2 is public on [atlas](https://atlas.hashicorp.com/mwrock/boxes/Windows2012R2) with an evaluation version of Windows 2012 R2). You can also use `mwrock/WindowsNano` provided in this repo's `Vagrantfile`.
|
247
|
+
|
248
|
+
1. Create a Windows VM with WinRM configured (see above).
|
249
|
+
2. Copy the config-example.yml to config.yml - edit this file with your WinRM connection details.
|
250
|
+
3. Run `bundle exec rake integration`
|
251
|
+
|
252
|
+
## WinRM Author
|
253
|
+
* Twitter: [@zentourist](https://twitter.com/zentourist)
|
254
|
+
* BLOG: [http://distributed-frostbite.blogspot.com/](http://distributed-frostbite.blogspot.com/)
|
255
|
+
* Add me in LinkedIn: [http://www.linkedin.com/in/danwanek](http://www.linkedin.com/in/danwanek)
|
256
|
+
* Find me on irc.freenode.net in #ruby-lang (zenChild)
|
257
|
+
|
258
|
+
## Maintainers
|
259
|
+
* Paul Morton (https://github.com/pmorton)
|
260
|
+
* Shawn Neal (https://github.com/sneal)
|
261
|
+
* Matt Wrock (https://github.com/mwrock)
|
262
|
+
|
263
|
+
[Contributors](https://github.com/WinRb/WinRM/graphs/contributors)
|