Chef InSpec with Puppeteer

We are trying to test redirection of URLs to our federation page for MFA. The inspec HTTP resource can be used for verification with SAML protected URLs. However, it falls short when it comes to OAuth related redirection. Therefore, we were attempting to use a headless browser via Puppeteer. If we simply run the control we CAN make it work. However, if we try to run the profile, we get the following stack trace.

jo314774@C02FK46DMD6R tests % inspec exec ../profiles/core --controls=^/profile-control-/

Traceback (most recent call last):

23: from /usr/local/bin/inspec:255:in `'

22: from /usr/local/bin/inspec:255:in `load'

21: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-bin-4.37.20/bin/inspec:11:in `<top (required)>'

20: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/base_cli.rb:35:in `start'

19: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/base.rb:485:in `start'

18: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'

17: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'

16: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'

15: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/cli.rb:285:in `exec'

14: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/runner.rb:135:in `run'

13: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/runner.rb:101:in `load'

12: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/runner.rb:101:in `each'

11: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/runner.rb:107:in `block in load'

10: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/profile.rb:285:in `load_libraries'

9: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/profile_context.rb:143:in `load_libraries'

8: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/profile_context.rb:143:in `each'

7: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/profile_context.rb:144:in `block in load_libraries'

6: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/profile_context.rb:159:in `load_library_file'

5: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/profile_context.rb:170:in `load_with_context'

4: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/profile_context.rb:170:in `instance_eval'

3: from libraries/multifactor_page_redirect.rb:1:in `load_with_context'

2: from /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/inspec-core-4.37.20/lib/inspec/dsl_shared.rb:33:in `require'

1: from /opt/inspec/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'

/opt/inspec/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- puppeteer ( LoadError )

Can you please provide guidance.

@bobchaos , @Tensibai ... are either of you able to help with this question? If not, can you guide me towards someone who can? Thank you!

@ramereth , @Dan_Webb ... are any of you able to help with this question? If not, can you guide me towards someone who can? Thank you!

Are you sure that gem is installed in the InSpec environment?

@ramereth thank you so much for responding. We've tried both "puppeteer" and or "puppeteer-ruby" in our Gemfile and if I do a gem list I see puppeteer-ruby (0.32.3, 0.32.2). Is there something different you mean by "installed in the InSpec environment"?

Forgive me if it's a silly question. I'm fairly new to InSpec.

InSpec has it's own ruby environment. You need to use /opt/inspec/embedded/bin/gem to install/check if the gem is in the correct environment.

1 Like

Thank you! This is so helpful. However, I'll have to research errors I'm getting when I try to install...

jo314774@C02FK46DMD6R authentication_policy % sudo /opt/inspec/embedded/bin/gem install puppeteer-ruby

Password:

Building native extensions. This could take a while...

ERROR: Error installing puppeteer-ruby:

ERROR: Failed to build gem native extension.

current directory: /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/websocket-driver-0.7.4/ext/websocket-driver

/opt/inspec/embedded/bin/ruby -I /opt/inspec/embedded/lib/ruby/2.7.0 -r ./siteconf20210611-8404-1tnjr2g.rb extconf.rb

creating Makefile

current directory: /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/websocket-driver-0.7.4/ext/websocket-driver

make "DESTDIR=" clean

current directory: /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/websocket-driver-0.7.4/ext/websocket-driver

make "DESTDIR="

compiling websocket_mask.c

linking shared-object websocket_mask.bundle

current directory: /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/websocket-driver-0.7.4/ext/websocket-driver

make "DESTDIR=" install

make: /usr/local/bin/gmkdir: No such file or directory

make: *** [.sitearchdir.time] Error 1

make install failed, exit code 2

Gem files will remain installed in /opt/inspec/embedded/lib/ruby/gems/2.7.0/gems/websocket-driver-0.7.4 for inspection.

Results logged to /opt/inspec/embedded/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-18/2.7.0/websocket-driver-0.7.4/gem_make.out

@ramereth ... Fixed via ... brew install coreutils.

This sure looks like at least a partial solution as puppeteer is NOW able to be loaded. Thank you SOOO much!

1 Like

Glad that helped!

Is there some documentation I missed somewhere that would would have taught me about ... /opt/inspec/embedded/bin/gem