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

Train fails on Windows Subsystem for Linux #520

Open
christian-wtd opened this issue Sep 25, 2019 · 2 comments
Open

Train fails on Windows Subsystem for Linux #520

christian-wtd opened this issue Sep 25, 2019 · 2 comments

Comments

@christian-wtd
Copy link
Contributor

christian-wtd commented Sep 25, 2019

Version:

Inspec: 4.16
Train: 3.0.3 (latest available on rubygems.org)

Environment:

Windows 10, Subsystem for Linux, Debian

Scenario:

Inspec is not working because OS detection detects Windows and fails because it should run linux commands. I already traced the issue down to the train gem.

Steps to Reproduce:

Start Debian for Windows 10, run any inspec cli or any library function which requires OS detection.

Expected Result:

Inspec correctly detects the Windows Subsystem for Linux

Actual Result:

Traceback (most recent call last):
        21: from ./inspec.rb:7:in `<main>'
        20: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/base_cli.rb:33:in `start'
        19: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
        18: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
        17: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        16: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        15: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/cli.rb:307:in `detect'
        14: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/cli.rb:397:in `run_command'
        13: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/cli.rb:397:in `new'
        12: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/runner.rb:71:in `initialize'
        11: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/runner.rb:79:in `configure_transport'
        10: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/backend.rb:52:in `create'
         9: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:17:in `connection'
         8: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:17:in `new'
         7: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:27:in `initialize'
         6: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:52:in `select_runner'
         5: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:52:in `new'
         4: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:145:in `initialize'
         3: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:163:in `acquire_pipe'
         2: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:181:in `start_pipe_server'
         1: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/thl/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- win32/process (LoadError)
        28: from ./inspec.rb:7:in `<main>'
        27: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/base_cli.rb:33:in `start'
        26: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
        25: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
        24: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        23: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        22: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/cli.rb:307:in `detect'
        21: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/cli.rb:397:in `run_command'
        20: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/cli.rb:397:in `new'
        19: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/runner.rb:71:in `initialize'
        18: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/runner.rb:79:in `configure_transport'
        17: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/inspec-4.16.0/lib/inspec/backend.rb:52:in `create'
        16: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:17:in `connection'
        15: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:17:in `new'
        14: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:27:in `initialize'
        13: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:52:in `select_runner'
        12: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:52:in `new'
        11: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:145:in `initialize'
        10: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:163:in `acquire_pipe'
         9: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/train-3.0.3/lib/train/transports/local.rb:181:in `start_pipe_server'
         8: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:34:in `require'
         7: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `rescue in require'
         6: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:130:in `require'
         5: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/win32-process-0.8.3/lib/win32/process.rb:1:in `<top (required)>'
         4: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/win32-process-0.8.3/lib/win32/process.rb:1:in `require_relative'
         3: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/win32-process-0.8.3/lib/win32/process/functions.rb:8:in `<top (required)>'
         2: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/win32-process-0.8.3/lib/win32/process/functions.rb:22:in `<module:Functions>'
         1: from /home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/ffi-1.11.1/lib/ffi/library.rb:444:in `typedef'
/home/thl/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/ffi-1.11.1/lib/ffi/types.rb:69:in `find_type': unable to resolve type 'uintptr_t' (TypeError)
@christian-wtd
Copy link
Contributor Author

I already know whats the root cause and think of a solution:

The root cause is that we at first try to detect windows and this works because of strange behavior of the WIndows Subsystem for Linux.

The issue is located in:
lib/train/platforms/detect/helpers/os_windows.rb

  def detect_windows
      # try to detect windows, use cmd.exe to also support Microsoft OpenSSH
      res = @backend.run_command("cmd.exe /c ver")
      return false if (res.exit_status != 0) || res.stdout.empty?

the run of "cmd.exe" strangely works, resulting in switching context to the windows cmd.exe.
Therefore we get a valid WIndows Like result.

We need some additional check to detect the Windows subsystem for Linux.

@christian-wtd christian-wtd changed the title Inspec fails on Windows Subsystem for Linux Train fails on Windows Subsystem for Linux Sep 25, 2019
christian-wtd added a commit to christian-wtd/train that referenced this issue Sep 25, 2019
Signed-off-by: christian-wtd <[email protected]>
@christian-wtd
Copy link
Contributor Author

christian-wtd commented Oct 18, 2019

For those arguing WSL is not a supported platform, the provide 3 lines of code make inspec working well as far as I can check instead of breaking immediately.
Also WSL is effectively a Linux of the selected Distribution, nontheless of running inside Windows, so effectively it would not make a big difference than a native Linux. Technically the WSL is just a Linux VM running on top of Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants