Bug 2211484

Summary: Global Registration using an user with "Register Hosts" role ignores all the setup options.
Product: Red Hat Satellite Reporter: Manu Sunil <msunil>
Component: RegistrationAssignee: Leos Stejskal <lstejska>
Status: CLOSED ERRATA QA Contact: Shweta Singh <shwsingh>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.13.0CC: amolpati, gtalreja, jentrena, lstejska, nalfassi, pcreech, rlavi, shwsingh, svigan
Target Milestone: 6.14.0Keywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-11-08 14:19:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Manu Sunil 2023-05-31 18:24:32 UTC
Description of problem:

Global Registration using an user with "Register Hosts" role ignores all the setup options.

Version-Release number of selected component (if applicable):

- Satellite 6.13.0

How reproducible:

- Everytime

Steps to Reproduce:

1. Create a user on the Satellite with Register Hosts role.

2. Using the new user, generate a global registration command with all the Setup options set to No.

3. Execute the command on the client.

Actual results:

- The parameters in the script. 

  ~~~
  # Rendered with following template parameters:
  # User: [reg-user]
  # Organization: [RedHat]
  # Location: [Pune]
  # Setup Insights: [false]
  # Setup remote execution: [false]
  # Setup remote execution pull: [false]
  # Update packages: [false]
  # Activation keys: [GENERAL]
  ~~~

- The register command in the script.

  ~~~
  curl --silent --show-error --cacert $KATELLO_SERVER_CA_CERT --request POST "https://satellite.example.com/register" \
       --data "uuid=$UUID" \
       -H 'Authorization: Bearer XYZ \
    --data 'host[organization_id]=1' \
    --data 'host[location_id]=2' \
    --data 'setup_insights=false' \
    --data 'setup_remote_execution=false' \
    --data 'setup_remote_execution_pull=false' \
    --data 'update_packages=false'
  ~~~

- The script generated by this command still performs the setups that are set to No.

  ~~~
  #!/bin/bash
  set -e
  
  echo "# Running [client-1.example.com] host initial configuration"
  
  foreman_curl() {
    curl --silent --show-error  -o /dev/null --noproxy \* "$@"
  }
  
  exit_and_cancel_build() {
    echo 'Host [client-1.example.com] initial configuration failed'
    foreman_curl --request POST 'http://satellite.example.com/unattended/failed?token=XYZ' \
         --data 'Host initial configuration failed, please see the registration log for more details.'
    exit 1
  }
  
  set +e
  trap 'exit_and_cancel_build' ERR
  
  user_exists=false
  getent passwd root >/dev/null 2>&1 && user_exists=true
  
  if $user_exists; then
  
    mkdir -p ~root/.ssh
  
    cat << EOF >> ~root/.ssh/authorized_keys
  ssh-rsa XYZ foreman-proxy.com
  EOF
  
    chmod 0700 ~root/.ssh
    chmod 0600 ~root/.ssh/authorized_keys
    chown -R root: ~root/.ssh
  
    # Restore SELinux context with restorecon, if it's available:
    command -v restorecon && restorecon -RvF ~root/.ssh || true
  
  else
    echo 'The remote_execution_ssh_user does not exist and remote_execution_create_user is not set to true.  remote_execution_ssh_keys snippet will not install keys'
  fi
  
  echo '#'
  echo '# Installing Insights client'
  echo '#'
  
  yum install -y insights-client
  insights-client --register
  
  if command -v subscription-manager &>/dev/null; then
    echo "Refreshing subscription data"
    subscription-manager refresh
  fi
  
  # Call home to exit build mode
  
  trap - ERR
  foreman_curl 'http://satellite.example.com/unattended/built?token=b91a860e-3a68-43f4-b345-95ca7ff41307'
  
  if [[ $? == 0 ]] ; then
    echo "Host [client-1.example.com] successfully configured."
  else
    echo "Host [client-1.example.com] successfully configured, but failed to set built status."
  fi
  
  subscription-manager facts --update
  
  exit 0
  ~~~

- Here is the same script from the admin user.

  ~~~
  # Rendered with following template parameters:
  # User: [admin]
  # Organization: [RedHat]
  # Location: [Pune]
  # Setup Insights: [false]
  # Setup remote execution: [false]
  # Setup remote execution pull: [false]
  # Update packages: [false]
  # Activation keys: [GENERAL]
  ~~~

  ~~~
  #!/bin/bash
  set -e
  
  echo "# Running [client-2.example.com] host initial configuration"
  
  foreman_curl() {
    curl --silent --show-error  -o /dev/null --noproxy \* "$@"
  }
  
  exit_and_cancel_build() {
    echo 'Host [client-2.example.com] initial configuration failed'
    foreman_curl --request POST 'http://satellite.example.com/unattended/failed?token=XYZ' \
         --data 'Host initial configuration failed, please see the registration log for more details.'
    exit 1
  }
  
  set +e
  trap 'exit_and_cancel_build' ERR
  
  if command -v subscription-manager &>/dev/null; then
    echo "Refreshing subscription data"
    subscription-manager refresh
  fi
  
  # Call home to exit build mode
  
  trap - ERR
  foreman_curl 'http://satellite.example.com/unattended/built?token=XYZ'
  
  if [[ $? == 0 ]] ; then
    echo "Host [client-2.example.com] successfully configured."
  else
    echo "Host [client-2.example.com] successfully configured, but failed to set built status."
  fi
  
  subscription-manager facts --update
  
  exit 0
  ~~~

  This excludes all the setups that are set to No.

Expected results:

- Script should not perform the setups that are set to No.

Comment 1 Leos Stejskal 2023-06-07 08:29:12 UTC
The issue is reproducible on the latest foreman develop, looking into the solution.

Comment 2 Leos Stejskal 2023-06-07 10:32:24 UTC
Created redmine issue https://projects.theforeman.org/issues/36484 from this bug

Comment 3 Bryan Kearney 2023-06-12 16:03:19 UTC
Moving this bug to POST for triage into Satellite since the upstream issue https://projects.theforeman.org/issues/36484 has been resolved.

Comment 4 Shweta Singh 2023-07-20 10:49:13 UTC
Verified.

Version Tested: Satellite 6.14 Snap 7.0

Verification Steps:
1. Enable the required repositories on the satellite and get a host(RHEL7/RHEL8/RHEL9)
2. Create a non-admin user and assign "Register Hosts" role to it.
3. Create an activation key and assign CV and LCE to it.
4. Login Satellite with new user and generate curl command to register host with all setup options set to NO.
5. Run the curl command on the host.

Result:
The script generated by this command skips the setups that are set to No.

Comment 7 errata-xmlrpc 2023-11-08 14:19:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Important: Satellite 6.14 security and bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2023:6818