diff --git a/app/controllers/api/v2/registration_commands_controller.rb b/app/controllers/api/v2/registration_commands_controller.rb index 8c8bb6984a9e..5e5886caf15a 100644 --- a/app/controllers/api/v2/registration_commands_controller.rb +++ b/app/controllers/api/v2/registration_commands_controller.rb @@ -21,6 +21,7 @@ class RegistrationCommandsController < V2::BaseController param :update_packages, :bool, desc: N_("Update all packages on the host") param :repo, String, desc: N_("Repository URL / details, for example for Debian OS family: 'deb http://deb.example.com/ buster 1.0', for Red Hat and SUSE OS family: 'http://yum.theforeman.org/client/latest/el8/x86_64/'") param :repo_gpg_key_url, String, desc: N_("URL of the GPG key for the repository") + param :use_wget, :bool, desc: N_("Use wget instead of curl") end def create unless os_with_template? diff --git a/app/controllers/concerns/foreman/controller/registration.rb b/app/controllers/concerns/foreman/controller/registration.rb index 18f213bcf896..f3494c9e65eb 100644 --- a/app/controllers/concerns/foreman/controller/registration.rb +++ b/app/controllers/concerns/foreman/controller/registration.rb @@ -32,6 +32,7 @@ def global_registration_vars update_packages: params['update_packages'], repo: params['repo'], repo_gpg_key_url: params['repo_gpg_key_url'], + use_wget: params['use_wget'], } params.permit(permitted) diff --git a/app/controllers/concerns/foreman/controller/registration_commands.rb b/app/controllers/concerns/foreman/controller/registration_commands.rb index 6db3b94a31ab..9ed8328b0028 100644 --- a/app/controllers/concerns/foreman/controller/registration_commands.rb +++ b/app/controllers/concerns/foreman/controller/registration_commands.rb @@ -5,7 +5,7 @@ module Foreman::Controller::RegistrationCommands def command args_query = "?#{registration_args.to_query}" - "curl -sS #{insecure} '#{registration_url(@smart_proxy)}#{args_query if args_query != '?'}' #{command_headers} | bash" + "#{application}#{insecure} '#{registration_url(@smart_proxy)}#{args_query if args_query != '?'}' #{command_headers} | bash" end def registration_args @@ -16,7 +16,19 @@ def registration_args end def insecure - registration_params['insecure'] ? '--insecure' : '' + if useWget + registration_params['insecure'] ? ' --no-check-certificate' : '' + else + registration_params['insecure'] ? ' --insecure' : '' + end + end + + def application + useWget ? 'wget --no-verbose' : 'curl -sS' + end + + def useWget + return registration_params['use_wget'] end def registration_url(proxy = nil) @@ -38,7 +50,7 @@ def command_headers jwt_args[:expiration] = 4.hours.to_i end - "-H 'Authorization: Bearer #{User.current.jwt_token!(**jwt_args)}'" + "--header 'Authorization: Bearer #{User.current.jwt_token!(**jwt_args)}'" end def host_config_params diff --git a/app/views/unattended/provisioning_templates/registration/global_registration.erb b/app/views/unattended/provisioning_templates/registration/global_registration.erb index f9f4af6e2749..7cded513f6a1 100644 --- a/app/views/unattended/provisioning_templates/registration/global_registration.erb +++ b/app/views/unattended/provisioning_templates/registration/global_registration.erb @@ -14,7 +14,7 @@ description: | # Make sure, all command output can be parsed (e.g. from subscription-manager) export LC_ALL=C LANG=C <% - headers = ["-H 'Authorization: Bearer #{@auth_token}'"] + headers = ["--header 'Authorization: Bearer #{@auth_token}'"] activation_keys = [(@hostgroup.params['kt_activation_keys'] if @hostgroup), @activation_keys].compact.join(',') -%> @@ -36,6 +36,7 @@ export LC_ALL=C LANG=C <%= "\n# Ignore subman errors: [#{@ignore_subman_errors}]" unless @ignore_subman_errors.nil? -%> <%= "\n# Lifecycle environment id: [#{@lifecycle_environment_id}]" if @lifecycle_environment_id.present? -%> <%= "\n# Activation keys: [#{activation_keys}]" if activation_keys.present? -%> +<%= "\n# Use wget: [#{@use_wget}]" unless @use_wget.nil? -%> if ! [ $(id -u) = 0 ]; then @@ -84,9 +85,18 @@ EOF fi elif [ -f /etc/debian_version ]; then <%= save_to_file('/etc/apt/sources.list.d/foreman_registration.list', @repo) %> + +<% +if @use_wget + gpg_key_download_command="wget --no-verbose -O-" +else + gpg_key_download_command="curl --silent --show-error" +end +%> + <% if @repo_gpg_key_url.present? -%> apt-get -y install ca-certificates gpg - curl --silent --show-error <%= shell_escape @repo_gpg_key_url %> | apt-key add - + <%= gpg_key_download_command-%> <%= shell_escape @repo_gpg_key_url %> | apt-key add - <% end -%> apt-get update @@ -96,22 +106,36 @@ else fi <% end -%> +<% +if @use_wget + data_keyword = "--post-data" +else + data_keyword = "--data" +end + +if @use_wget + registration_command="wget --no-verbose -O- --ca-certificate=" +else + registration_command="curl --silent --show-error --request POST --cacert " +end +%> + register_host() { - curl --silent --show-error --cacert $SSL_CA_CERT --request POST <%= @registration_url %> \ - <%= headers.join(' ') %> \ - --data "host[name]=$(hostname --fqdn)" \ - --data "host[build]=false" \ - --data "host[managed]=false" \ -<%= " --data 'host[organization_id]=#{@organization.id}' \\\n" if @organization -%> -<%= " --data 'host[location_id]=#{@location.id}' \\\n" if @location -%> -<%= " --data 'host[hostgroup_id]=#{@hostgroup.id}' \\\n" if @hostgroup -%> -<%= " --data 'host[operatingsystem_id]=#{@operatingsystem.id}' \\\n" if @operatingsystem -%> -<%= " --data host[interfaces_attributes][0][identifier]=#{shell_escape(@remote_execution_interface)} \\\n" if @remote_execution_interface.present? -%> -<%= " --data 'setup_insights=#{@setup_insights}' \\\n" unless @setup_insights.nil? -%> -<%= " --data 'setup_remote_execution=#{@setup_remote_execution}' \\\n" unless @setup_remote_execution.nil? -%> -<%= " --data remote_execution_interface=#{shell_escape(@remote_execution_interface)} \\\n" if @remote_execution_interface.present? -%> -<%= " --data packages=#{shell_escape(@packages)} \\\n" if @packages.present? -%> -<%= " --data 'update_packages=#{@update_packages}' \\\n" unless @update_packages.nil? -%> + <%= registration_command-%>$SSL_CA_CERT <%= @registration_url %> \ + <%= headers.join(' ') %> \ +<%= " #{data_keyword} \"host[name]=$(hostname --fqdn)\" \\\n" -%> +<%= " #{data_keyword} \"host[build]=false\" \\\n" -%> +<%= " #{data_keyword} \"host[managed]=false\" \\\n" -%> +<%= " #{data_keyword} 'host[organization_id]=#{@organization.id}' \\\n" if @organization -%> +<%= " #{data_keyword} 'host[location_id]=#{@location.id}' \\\n" if @location -%> +<%= " #{data_keyword} 'host[hostgroup_id]=#{@hostgroup.id}' \\\n" if @hostgroup -%> +<%= " #{data_keyword} 'host[operatingsystem_id]=#{@operatingsystem.id}' \\\n" if @operatingsystem -%> +<%= " #{data_keyword} host[interfaces_attributes][0][identifier]=#{shell_escape(@remote_execution_interface)} \\\n" if @remote_execution_interface.present? -%> +<%= " #{data_keyword} 'setup_insights=#{@setup_insights}' \\\n" unless @setup_insights.nil? -%> +<%= " #{data_keyword} 'setup_remote_execution=#{@setup_remote_execution}' \\\n" unless @setup_remote_execution.nil? -%> +<%= " #{data_keyword} remote_execution_interface=#{shell_escape(@remote_execution_interface)} \\\n" if @remote_execution_interface.present? -%> +<%= " #{data_keyword} packages=#{shell_escape(@packages)} \\\n" if @packages.present? -%> +<%= " #{data_keyword} 'update_packages=#{@update_packages}' \\\n" unless @update_packages.nil? -%> } @@ -121,21 +145,21 @@ echo "#" <% if plugin_present?('katello') && activation_keys.present? -%> register_katello_host(){ - UUID=$(subscription-manager identity | grep --max-count 1 --only-matching '\([[:xdigit:]]\{8\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{12\}\)') - curl --silent --show-error --cacert $KATELLO_SERVER_CA_CERT --request POST "<%= @registration_url %>" \ - <%= headers.join(' ') %> \ - --data "uuid=$UUID" \ - --data "host[build]=false" \ -<%= " --data 'host[organization_id]=#{@organization.id}' \\\n" if @organization -%> -<%= " --data 'host[location_id]=#{@location.id}' \\\n" if @location -%> -<%= " --data 'host[hostgroup_id]=#{@hostgroup.id}' \\\n" if @hostgroup -%> -<%= " --data 'host[lifecycle_environment_id]=#{@lifecycle_environment_id}' \\\n" if @lifecycle_environment_id.present? -%> -<%= " --data 'setup_insights=#{@setup_insights}' \\\n" unless @setup_insights.nil? -%> -<%= " --data 'setup_remote_execution=#{@setup_remote_execution}' \\\n" unless @setup_remote_execution.nil? -%> -<%= " --data remote_execution_interface=#{shell_escape(@remote_execution_interface)} \\\n" if @remote_execution_interface.present? -%> -<%= " --data 'setup_remote_execution_pull=#{@setup_remote_execution_pull}' \\\n" unless @setup_remote_execution_pull.nil? -%> -<%= " --data packages=#{shell_escape(@packages)} \\\n" if @packages.present? -%> -<%= " --data 'update_packages=#{@update_packages}' \\\n" unless @update_packages.nil? -%> + UUID=$(subscription-manager identity | grep --max-count 1 --only-matching '\([[:xdigit:]]\{8\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{4\}-[[:xdigit:]]\{12\}\)') + <%= registration_command-%>$KATELLO_SERVER_CA_CERT "<%= @registration_url %>"" \ + <%= headers.join(' ') %> \ +<%= " #{data_keyword} \"uuid=$UUID\" \\\n" -%> +<%= " #{data_keyword} \"host[build]=false\" \\\n" -%> +<%= " #{data_keyword} 'host[organization_id]=#{@organization.id}' \\\n" if @organization -%> +<%= " #{data_keyword} 'host[location_id]=#{@location.id}' \\\n" if @location -%> +<%= " #{data_keyword} 'host[hostgroup_id]=#{@hostgroup.id}' \\\n" if @hostgroup -%> +<%= " #{data_keyword} 'host[lifecycle_environment_id]=#{@lifecycle_environment_id}' \\\n" if @lifecycle_environment_id.present? -%> +<%= " #{data_keyword} 'setup_insights=#{@setup_insights}' \\\n" unless @setup_insights.nil? -%> +<%= " #{data_keyword} 'setup_remote_execution=#{@setup_remote_execution}' \\\n" unless @setup_remote_execution.nil? -%> +<%= " #{data_keyword} remote_execution_interface=#{shell_escape(@remote_execution_interface)} \\\n" if @remote_execution_interface.present? -%> +<%= " #{data_keyword} 'setup_remote_execution_pull=#{@setup_remote_execution_pull}' \\\n" unless @setup_remote_execution_pull.nil? -%> +<%= " #{data_keyword} packages=#{shell_escape(@packages)} \\\n" if @packages.present? -%> +<%= " #{data_keyword} 'update_packages=#{@update_packages}' \\\n" unless @update_packages.nil? -%> } diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js index 4e5c51b6f363..273b745f2797 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js @@ -21,6 +21,8 @@ export const generalComponentProps = { handleInsecure: () => {}, handleInvalidField: () => {}, isLoading: false, + useWget: false, + handleUseWget: () => {}, }; export const advancedComponentProps = { configParams: {}, @@ -100,6 +102,12 @@ export const updatePackagesProps = { isLoading: false, }; +export const useWgetProps = { + useWget: false, + handleUseWget: () => {}, + isLoading: false, +}; + export const repositoryProps = { repo: '', handleRepo: () => {}, diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/General.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/General.js index 146ba504e32c..c6a2e9e59d1d 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/General.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/General.js @@ -6,6 +6,7 @@ import HostGroup from './fields/HostGroup'; import OperatingSystem from './fields/OperatingSystem'; import SmartProxy from './fields/SmartProxy'; import Insecure from './fields/Insecure'; +import UseWget from './fields/UseWget'; const General = ({ organizationId, @@ -28,6 +29,8 @@ const General = ({ handleInsecure, handleInvalidField, isLoading, + useWget, + handleUseWget, }) => ( <> + + ( + + + {__('Use wget')}{' '} + + + } + id="reg_use_wget" + onChange={() => handleUseWget(!useWget)} + isDisabled={isLoading} + isChecked={useWget} + /> + +); + +UseWget.propTypes = { + useWget: PropTypes.bool.isRequired, + handleUseWget: PropTypes.func.isRequired, + isLoading: PropTypes.bool.isRequired, +}; + +export default UseWget; diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js index 3fd94feb132c..7197533fa05f 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js @@ -91,6 +91,7 @@ const RegistrationCommandsPage = () => { const [repo, setRepo] = useState(''); const [repoGpgKeyUrl, setRepoGpgKeyUrl] = useState(''); const [invalidFields, setInvalidFields] = useState([]); + const [useWget, setUseWget] = useState(false); // Command const command = useSelector(selectCommand); @@ -132,6 +133,7 @@ const RegistrationCommandsPage = () => { repo, repoGpgKeyUrl, updatePackages, + useWget, ...pluginValues, }; @@ -265,6 +267,8 @@ const RegistrationCommandsPage = () => { handleInvalidField={handleInvalidField} invalidFields={invalidFields} isLoading={isLoading} + useWget={useWget} + handleUseWget={setUseWget} />