inspec / train

Transport Interface to unify communication over SSH, WinRM, and friends.
Apache License 2.0
119 stars 87 forks source link

InSpec breaks with ActiveSupport 7.1.0 #750

Open evandam opened 11 months ago

evandam commented 11 months ago

Version:

Train 3.10.8

Environment:

MacOS Sonoma, InSpec 5.22.3, Ruby 3.1.4

InSpec installed and managed via Bundler:

# frozen_string_literal: true

source "https://rubygems.org"

gem "inspec-bin", "~> 5.22.0"

Scenario:

Run a basic profile. I'm seeing the issue against a Kubernetes target, but I don't believe the issue is specific to train-kubernetes, but rather the version of ActiveSupport that Train is using.

I believe it can be resolved by tweaking the dependency version to something like ~> 7.0.0 instead of >= 6.0.3.1. There's some discussion in https://github.com/inspec/inspec/issues/6527

Steps to Reproduce:

Use the Gemfile mentioned above, and a similar inspec.yml for a profile:

name: kubernetes
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: Apache-2.0
summary: An InSpec Compliance Profile
version: 0.1.0
inspec_version: "~> 5.22"
supports:
  platform: k8s
depends:
  - name: inspec-k8s
    git: https://github.com/inspec/inspec-k8s
    branch: main

Run InSpec:

bundle install
bundle exec inspec exec ./kubernetes -t k8s://

Expected Result:

InSpec runs as expected.

Profile:   InSpec Profile (kubernetes)
Version:   0.1.0
Target:    kubernetes://6847289D2FB4BC9AC036293B0EA62ABC.gr7.us-west-2.eks.amazonaws.com:443
Target ID: 15f2b11e-28d1-5111-82f6-1ef5f5095c4c

     No tests executed.

Profile:   InSpec Profile (inspec-k8s)
Version:   0.1.3
Target:    kubernetes://6847289D2FB4BC9AC036293B0EA62ABC.gr7.us-west-2.eks.amazonaws.com:443
Target ID: 15f2b11e-28d1-5111-82f6-1ef5f5095c4c

     No tests executed.

Test Summary: 0 successful, 0 failures, 0 skipped

Actual Result:

/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:108:in `<class:Array>': undefined method `deprecator' for ActiveSupport:Module (NoMethodError)

  deprecate to_default_s: :to_s, deprecator: ActiveSupport.deprecator
                                                          ^^^^^^^^^^^
Did you mean?  deprecate_constant
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-7.1.0/lib/active_support/core_ext/array/conversions.rb:8:in `<top (required)>'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-7.1.0/lib/active_support/duration.rb:3:in `<top (required)>'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-7.1.0/lib/active_support/core_ext/time/calculations.rb:3:in `<top (required)>'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-7.1.0/lib/active_support/core_ext/string/conversions.rb:4:in `<top (required)>'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/activesupport-7.1.0/lib/active_support/core_ext/string.rb:3:in `<top (required)>'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/dsl_shared.rb:33:in `require'
    from libraries/k8sobjects.rb:4:in `create'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/dsl_shared.rb:47:in `eval'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/dsl_shared.rb:47:in `require'
    from libraries/k8s_api_resources.rb:3:in `load_with_context'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile_context.rb:171:in `instance_eval'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile_context.rb:171:in `load_with_context'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile_context.rb:160:in `load_library_file'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile_context.rb:145:in `block in load_libraries'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile_context.rb:144:in `each'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile_context.rb:144:in `load_libraries'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile.rb:381:in `load_libraries'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile.rb:374:in `block in load_libraries'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile.rb:353:in `each'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile.rb:353:in `each_with_index'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/profile.rb:353:in `load_libraries'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/runner.rb:111:in `block in load'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/runner.rb:104:in `each'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/runner.rb:104:in `load'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/runner.rb:163:in `run'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/cli.rb:364:in `exec'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/thor-1.2.2/lib/thor/base.rb:485:in `start'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-core-5.22.3/lib/inspec/base_cli.rb:35:in `start'
    from /Users/evan/.asdf/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/inspec-bin-5.22.3/bin/inspec:11:in `<top (required)>'
    from /Users/evan/.asdf/installs/ruby/3.1.4/bin/inspec:25:in `load'
    from /Users/evan/.asdf/installs/ruby/3.1.4/bin/inspec:25:in `<main>'
Schwad commented 11 months ago

There is a larger discussion around this here on rails/rails: https://github.com/rails/rails/issues/49495#issuecomment-1749085658

There is a related cocoapods issue, so there may be learnings to be gathered here: https://github.com/CocoaPods/CocoaPods/pull/12082

e.g. ensure requires are happening for activesupport when used outside of rails ecosystem

Schwad commented 11 months ago

Ah, I lost my contributor badge! 😔 Maybe it's because my old Chef work email is no longer tied to this account or something

ahasunos commented 11 months ago

@Schwad @evandam https://github.com/inspec/inspec-k8s/pull/37

Schwad commented 11 months ago

@ahasunos nice!