foreman icon indicating copy to clipboard operation
foreman copied to clipboard

Fixes #36688 - Provide option to use wget for the new Register Host feature

Open goarsna opened this issue 2 years ago • 34 comments

The Register hosts page uses curl for registering hosts. This seems to be a good approach for EL based systems as most of these come with curl preinstalled. On Debian based systems this is not always the case (at least for recent versions of Debian and Ubuntu).

This feature request aims to provide an option to use wget for registering hosts as wget is as widely used as curl. By this system administrators that only have wget installed are not forced to also install curl anymore.

goarsna avatar Aug 21 '23 11:08 goarsna

Can one of the admins verify this patch?

theforeman-bot avatar Aug 21 '23 11:08 theforeman-bot

Can one of the admins verify this patch?

theforeman-bot avatar Aug 21 '23 11:08 theforeman-bot

Can one of the admins verify this patch?

theforeman-bot avatar Aug 21 '23 11:08 theforeman-bot

Issues: #36688

theforeman-bot avatar Aug 21 '23 11:08 theforeman-bot

I have opened a PR to document this in foreman-documentation: https://github.com/theforeman/foreman-documentation/pull/2376

goarsna avatar Aug 21 '23 15:08 goarsna

Thanks @ekohl. I've incorporated your feedback and rebased my branch.

goarsna avatar Sep 04 '23 14:09 goarsna

ok to test

stejskalleos avatar Sep 19 '23 10:09 stejskalleos

Thanks @stejskalleos for your review, I finally made it to answer / adapt everything.

Please let me know if you would like to see any further changes.

goarsna avatar Oct 02 '23 22:10 goarsna

ok to test

sbernhard avatar Oct 27 '23 08:10 sbernhard

@nofaralfasi can you take a look and do the review?

stejskalleos avatar Oct 30 '23 09:10 stejskalleos

When attempting to preview the 'Global Registration' template from the template edit page, I encounter the following error: There was an error rendering the Global Registration template: undefined method '#[]' for NilClass::Jail (NilClass).

Additionally, could we merge the 16 commits into a single commit?

nofaralfasi avatar Dec 12 '23 10:12 nofaralfasi

Hey @nofaralfasi, thanks for your feedback. I fixed the template, squashed the commits and rebased my branch.

goarsna avatar Jan 08 '24 15:01 goarsna

Hey @nofaralfasi, again some changes. in the first commit I rebased my branch to solve merge conflicts in the global_registration.erb introduced by replacing apt-key for Ubuntu and Debian . Then I've added some tests to cover my changes. And lastly @sbernhard and I discussed moving the dicts holding the curl and wget command patterns to one place.

What I just noticed is that there is still a failing node test. I'll have a look at that.

Just ping me, in case I can / should squash the commits again. :)

goarsna avatar Jan 10 '24 22:01 goarsna

Ok, something weird was happening to my local tests, but now the tests are fixed. :)

goarsna avatar Jan 11 '24 13:01 goarsna

Hey there, I rebased my branch due to merge conflicts and squashed the commits. Now the Jenkins unit tests fail. However the tests are working in my forklift. I tried both, calling bundle exec rake jenkins:unit TESTOPTS="-v" --trace and running the failing test file directly calling bundle exec rake test TEST=test/controllers/unattended_controller_test.rb.

What do you think @nofaralfasi?

goarsna avatar Jan 18 '24 13:01 goarsna

I don't know why the tests are failing. Also, the wget command doesn't work for me, whereas the curl command does.

[root@rhel8-8-testing-machine ~]# set -o pipefail && wget --no-verbose -O- --no-check-certificate 'http://192.168.121.1:3000/register?download_utility=wget&location_id=2&operatingsystem_id=13&organization_id=1&update_packages=false' --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo0LCJpYXQiOjE3MDU5MzQyOTksImp0aSI6IjRkOWJiYmQ4Yzg2OGUyODNlZWE3OGExZmFiMjZiNGZkZmEwNTRiZDAzMGZiOTU1NGNlNGQ2M2U3ZDc0YTEyZDciLCJleHAiOjE3MDU5NDg2OTksInNjb3BlIjoicmVnaXN0cmF0aW9uI2dsb2JhbCByZWdpc3RyYXRpb24jaG9zdCJ9.m_d_whF1xwve7KGDDDbrBRihBJMrAUpu9849ilAWd_M' | bash
2024-01-22 14:38:40 URL:http://192.168.121.1:3000/register?download_utility=wget&location_id=2&operatingsystem_id=13&organization_id=1&update_packages=false [3594] -> "-" [1]
#
# Running registration
#
http://192.168.121.1:3000/register:
2024-01-22 14:38:41 ERROR 422: Unprocessable Entity.

nofaralfasi avatar Jan 22 '24 14:01 nofaralfasi

Hey @nofaralfasi, thanks a lot for your reviews. I'll have a look at the error.

fyi: The docs for this PR got merged yesterday.

goarsna avatar Feb 08 '24 09:02 goarsna

The docs have been reverted. I've created a new PR to include the docs ^^

Lennonka avatar May 22 '24 23:05 Lennonka

Hey there, updated, rebased and did tests with Ubuntu 22.04 and Almalinux 8 that were successful. But I cannot tell atm what is causing the failing test. I can have a look at it again in calendar week 24, when I am back from vacation.

This PR also requires https://github.com/theforeman/foreman/pull/10179 to use wget in the host init config template.

goarsna avatar May 30 '24 21:05 goarsna

After having a look at the failing tests again, I assume they are not related to my PR. :thinking: But I am a little bit clueless what's causing them. Any ideas, suggestions, thoughts or objections?

goarsna avatar Jul 03 '24 19:07 goarsna

Thanks @ofedoren for your review! Again the failing Katello tests...

goarsna avatar Jul 10 '24 12:07 goarsna

Hey @sbernhard, as discussed in our call last week I moved the construction of the "curl" and "wget" commands completely to helper methods. I will also have a look at unifying the two methods in one generic method for creating web requests in templates. But I have to see what the result looks like, considering all the cases and the formatting.

goarsna avatar Jul 22 '24 09:07 goarsna

Hey @ofedoren and @sbernhard, I (hopefully) addressed everything that was requested and fixed the tests again (despite those often failing katello tests... :sweat_smile:). And I again did test some tests: I registered an Ubuntu host using curl and wget and the command in the register host page worked as well as the rendered global_registration template with both, curl and wget.

Is there anything left from your side or are we good to merge this? :)

goarsna avatar Jul 23 '24 11:07 goarsna

I received a good suggestion by @sbernhard: Add tests for the generate_web_request method :grin: => Done

goarsna avatar Jul 23 '24 12:07 goarsna

I did some other end-to-end tests with bash -x and also tested the host_init_config template with the changes from https://github.com/theforeman/foreman/pull/10179. Thereby I noticed that https://github.com/theforeman/foreman/pull/9983 added installation of curl to the global_registration template. => Removed

goarsna avatar Jul 23 '24 13:07 goarsna

In further downstream tests @dosas discovered that wget by default enables HSTS support whereas curl does not. This can lead to errors (for example) in case a repository is added to use during host registration which is secured with a self signed certificate.

To stay consistent accross curl and wget we added the --no-hsts flag to the wget commands. The --no-hsts flag has no effect on https connections.

goarsna avatar Jul 24 '24 13:07 goarsna

The failed tests are not related.

Any objections to get this change in @stejskalleos / @ekohl / @ofedoren ?

sbernhard avatar Jul 25 '24 06:07 sbernhard

Some js tests failed, could you please run npm run test -- -u to regenerate the snapshots?

ofedoren avatar Jul 29 '24 10:07 ofedoren

Hey @ofedoren, thanks again for your review. I left one comment above and added missing Apipie documentation for the download_utility in the registration_controller.rb :see_no_evil:

goarsna avatar Jul 29 '24 11:07 goarsna