foreman
foreman copied to clipboard
Fixes #36646 - compare remote address against correct IP address family
So far, the find_host_by_ip_or_mac function in the HostFinder class was unable to identify a host if the remote address (e.g. in a user-data query) was an IPv6 address because the address was not checked for whether it was an IPv6 address and always compared to the ip field of the NICs.
This PR contains a minimal change that checks whether the remote address is an IPv6 address and in that case checks the ip6 field instead of the ip field. In all other cases, it defaults to the previous behaviour.
To test this, an IPv6-enabled Foreman installation or at least a capsule server is required.
I tested the change against a dual-stacked capsule server which is connected to an IPv4-only Redhat Satellite server with properly configured trusted-proxies setting. Without the change, a request for endpoint /userdata/user-data via IPv6 to the capsule server would fail (but give the correct result via IPv4), after applying the change, the result was the same for IPv4 and IPv6.
Can one of the admins verify this patch?
Can one of the admins verify this patch?
Can one of the admins verify this patch?
Fixed Rubocop complaints
ok to test
Fixed indentation
The change is breaking something in the unattended controller, unit test failed. I will have a look at this tomorrow.
I would like to add a unit test for template retrieval via IPv6 too, but I am not sure if I understand the test suite correctly. Here is a change that to my understanding would add such a test, but I'd like to have this reviewed by someone with a better understanding:
diff --git a/test/controllers/unattended_controller_test.rb b/test/controllers/unattended_controller_test.rb
index 077e8e973..28a521ea5 100644
--- a/test/controllers/unattended_controller_test.rb
+++ b/test/controllers/unattended_controller_test.rb
@@ -18,7 +18,7 @@ class UnattendedControllerTest < ActionController::TestCase
media(:one).locations << @loc
media(:ubuntu).organizations << @org
media(:ubuntu).locations << @loc
- @rh_host = FactoryBot.create(:host, :managed, :with_dhcp_orchestration, :build => true,
+ @rh_host = FactoryBot.create(:host, :managed, :with_dhcp_orchestration, :with_ipv6, :build => true,
:operatingsystem => operatingsystems(:redhat),
:ptable => ptable,
:medium => media(:one),
@@ -65,6 +65,13 @@ class UnattendedControllerTest < ActionController::TestCase
assert_response :success
end
+ test "should get a kickstart over IPv6" do
+ @request.env["HTTP_X_FORWARDED_FOR"] = @rh_host.ip6
+ @request.env["REMOTE_ADDR"] = "127.0.0.1"
+ get :host_template, params: { :kind => 'provision' }
+ assert_response :success
+ end
+
test "should set @static when requested" do
Setting[:safemode_render] = false
@request.env["HTTP_X_RHN_PROVISIONING_MAC_0"] = "eth0 #{@rh_host.mac}"
Added a unit test for template retrieval over IPv6, tested locally; test passes with the applied change, but fails against the old version Patch posted above almost correct, had to replace :with_ipv6 with :dualstack
@ekohl Could you maybe approve the workflows to see if all the checks pass? Thanks!