Plugin breaking change: Safemode jail extensions


when new instance or class method needs to be added into safemode jail from plugins, a Ruby reopening is performed:

class Host::Managed::Jail < Safemode::Jail
  allow :bootdisk_build?

There is a new patch for Foreman core pending review to change superclass of all Jail classes from Safemode::Jail to ApplicationRecord::Jail because that’s the correct way to do it. Foreman defines ApplicationRecord::Jail but in reality it is unused for this abstract class. Unfortunately, the change will break all plugins which are reopening the classes - the error is: superclass mismatch for class Jail (TypeError)

Quick search in my working directory reveals the following plugins are affected:

  • Ansible
  • Bootdisk
  • Chef
  • OpenSCAP
  • ReX
  • Salt

The proposed solution is to end this class reopening and introduce a cleaner way via plugin API. The change for plugins would be very simple:

diff --git a/app/models/concerns/foreman_bootdisk/host_ext.rb b/app/models/concerns/foreman_bootdisk/host_ext.rb
index 19103d7..f6b3058 100644
--- a/app/models/concerns/foreman_bootdisk/host_ext.rb
+++ b/app/models/concerns/foreman_bootdisk/host_ext.rb
@@ -44,7 +44,3 @@ module ForemanBootdisk
-class Host::Managed::Jail < Safemode::Jail
-  allow :bootdisk_build?
diff --git a/lib/foreman_bootdisk/engine.rb b/lib/foreman_bootdisk/engine.rb
index 84f8e43..b20f7d3 100644
--- a/lib/foreman_bootdisk/engine.rb
+++ b/lib/foreman_bootdisk/engine.rb
@@ -58,6 +58,7 @@ module ForemanBootdisk
         provision_method 'bootdisk', N_('Boot disk based')
         template_labels 'Bootdisk' => N_('Boot disk embedded template')
         allowed_template_helpers :bootdisk_chain_url, :bootdisk_raise
+        extend_allowed_instance_methods_for_jail ::Host::Managed, :bootdisk_build?

         extend_page "subnets/index" do |cx|
           cx.add_pagelet :subnet_index_action_buttons, name: 'Bootdisk', partial: 'subnets/bootdisk_action_buttons'

When the patch is ready to merge, I will go ahead and make PRs into all plugins. I am sending this as a warning in case you run into the exception after we merge the patch.