sous-chefs / ossec

Development repository for the ossec cookbook
https://supermarket.chef.io/cookbooks/ossec
Apache License 2.0
44 stars 65 forks source link

1.2.1 throws RuntimeError #136

Open okdas opened 4 years ago

okdas commented 4 years ago

:ghost: Brief Description

Chef run fails after an upgrade to 1.2.1 version of this cookbook.

:pancakes: Cookbook version

1.2.1

:woman_cook: Chef-Infra Version

15.6.10

:tophat: Platform details

    System Info:
    ------------
    chef_version=15.6.10
    platform=amazon
    platform_version=2
    ruby=ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
    program_name=/usr/bin/chef-client
    executable=/opt/chef/bin/chef-client

:heavy_plus_sign: Additional context

Recipe: ossec::install_server
  * yum_package[ossec] action install (up to date)
Recipe: ossec::common
  * ruby_block[ossec install_type] action run
    - execute the ruby block ossec install_type
  * chef_gem[gyoku] action install (up to date)
  * file[/var/ossec/etc/ossec.conf] action create

    ================================================================================
    Error executing action `create` on resource 'file[/var/ossec/etc/ossec.conf]'
    ================================================================================

    RuntimeError
    ------------
    can't add a new key into hash during iteration

    Cookbook Trace:
    ---------------
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:33:in `block in object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:31:in `each_key'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:31:in `object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:41:in `block in object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:40:in `map!'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:40:in `object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:35:in `block in object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:31:in `each_key'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:31:in `object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:35:in `block in object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:31:in `each_key'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:31:in `object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:35:in `block in object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:31:in `each_key'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:31:in `object_to_ossec'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/libraries/helpers.rb:56:in `ossec_to_xml'
    /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/recipes/common.rb:58:in `block (2 levels) in from_file'

    Resource Declaration:
    ---------------------
    # In /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/recipes/common.rb

     46: file "#{node['ossec']['dir']}/etc/ossec.conf" do
     47:   owner 'root'
     48:   group 'ossec'
     49:   mode '0440'
     50:   manage_symlink_source true
     51:   notifies :restart, 'service[ossec]'
     52:
     53:   content lazy {
     54:     # Merge the "typed" attributes over the "all" attributes.
     55:     all_conf = node['ossec']['conf']['all'].to_hash
     56:     type_conf = node['ossec']['conf'][node['ossec']['install_type']].to_hash
     57:     conf = Chef::Mixin::DeepMerge.deep_merge(type_conf, all_conf)
     58:     Chef::OSSEC::Helpers.ossec_to_xml('ossec_config' => conf)
     59:   }
     60: end
     61:

    Compiled Resource:
    ------------------
    # Declared in /var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/recipes/common.rb:46:in `from_file'

    file("/var/ossec/etc/ossec.conf") do
      action [:create]
      default_guard_interpreter :default
      declared_type :file
      cookbook_name "ossec"
      recipe_name "common"
      content #<Chef::DelayedEvaluator:0x00000000059cfc20@/var/chef/.chef/local-mode-cache/cache/cookbooks/ossec/recipes/common.rb:53>
      owner "root"
      group "ossec"
      mode "0440"
      manage_symlink_source true
      path "/var/ossec/etc/ossec.conf"
      verifications []
    end

    System Info:
    ------------
    chef_version=15.6.10
    platform=amazon
    platform_version=2
    ruby=ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
    program_name=/usr/bin/chef-client
    executable=/opt/chef/bin/chef-client
okdas commented 4 years ago

Seems like related to this commit: https://github.com/sous-chefs/ossec/commit/cda4dd979cc53b8cfe6f44471c58da016e58d469

Ruby 1.9+ only supports read-only operations on hash during iteration. Can we probably revert this commit? I'm pretty sure there are a lot of people who switched to 1.9+.