Project

General

Profile

Bug #28960

Error "Couldn't find Host::Managed with 'id'=" when sending Configuration Errror Reports

Added by Emil Dragu 6 months ago. Updated 29 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Users, Roles and Permissions
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

A while ago we stopped getting Error Reports, and the logs show an error like below:

Couldn't find Host::Managed with 'id'=2088 [WHERE "hosts"."type" IN ('Host::Managed') AND (((( hosts.owner_id IS NOT NULL
AND
(
(
hosts.owner_type = 'User'
AND
hosts.owner_id IN (2)
)
OR
(
hosts.owner_type = 'Usergroup'
AND
hosts.owner_id IN (NULL)
)
)
) AND ("hosts"."organization_id" = '2') AND ("hosts"."location_id" = '1')) OR (( hosts.owner_id IS NOT NULL
AND
(
(
hosts.owner_type = 'User'
AND
hosts.owner_id IN (2)
)
OR
(
hosts.owner_type = 'Usergroup'
AND
hosts.owner_id IN (NULL)
)
)
) AND ("hosts"."organization_id" = '2') AND ("hosts"."location_id" = '1')) OR (("hostgroups"."name" = 'Default') AND ("hosts"."organization_id" = '2') AND ("hosts"."location_id" = '1'))))] (ActiveRecord::RecordN
otFound)

Steps to reproduce this(I got this from a production environment so I might miss something):
1. Create a user that is not allowed to view all the hosts.
2. Set Email Preferences -> Config error state to Subscribe to my hosts(Although Subscribe to all hosts might also work)
3. Generate configuration error on a host that above user is not allowed to view.
What happens under the hood,

users = ConfigManagementError.all_hosts.flat_map(&:users)
- this returns the user that is not subscribed to all hosts, I don't know it it's intended, but getting to the following line throws the error in the description:

users.select { |user| Host.authorized_as(user, :view_hosts).find(host.id).present? }
This throws the error as the user is not allowed to see the host.

Also the last line might suffer from the same problem described here in : https://projects.theforeman.org/issues/28093, where the user does not get his hosts but the hosts of foreman_api_admin which has id=2, as you can see in the query (hosts.owner_id IN (2)).

Associated revisions

Revision 10d6deba (diff)
Added by Emil DRAGU 5 months ago

Fixes #28960 - Configuration Error Reports not sent

Place the Host.authorized search in a begin block so when it fails it does not
brake sending emails for other users.
Also, place it in an User.as block so it executes in the contex of the user being
checked

Revision 1e40a052 (diff)
Added by Emil DRAGU 5 months ago

Fixes #28960 - assign filtered users list to original variable

Fix detected coding standard violations

Revision 80c7ab0b (diff)
Added by Emil DRAGU 5 months ago

Fixes #28960 - Remove redundant begin block

History

#1 Updated by The Foreman Bot 6 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/7422 added

#2 Updated by The Foreman Bot 5 months ago

  • Fixed in Releases 2.1.0 added

#3 Updated by Anonymous 5 months ago

  • Status changed from Ready For Testing to Closed

#4 Updated by Amit Upadhye 3 months ago

  • Category set to 218

#5 Updated by Tomer Brisker 29 days ago

  • Category changed from 218 to Users, Roles and Permissions

Also available in: Atom PDF