Project

General

Profile

Actions

Bug #28960

closed

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

Added by Emil Dragu about 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Users, Roles and Permissions
Target version:
-
Difficulty:
Triaged:
No
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)).

Actions #1

Updated by The Foreman Bot about 4 years ago

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

Updated by The Foreman Bot about 4 years ago

  • Fixed in Releases 2.1.0 added
Actions #3

Updated by Anonymous about 4 years ago

  • Status changed from Ready For Testing to Closed
Actions #4

Updated by Amit Upadhye almost 4 years ago

  • Category set to 218
Actions #5

Updated by Tomer Brisker almost 4 years ago

  • Category changed from 218 to Users, Roles and Permissions
Actions #6

Updated by Ewoud Kohl van Wijngaarden over 3 years ago

  • Subject changed from Error "Couldn't find Host::Managed with 'id'=" when sending Configuration Errror Reports to Error "Couldn't find Host::Managed with 'id'=" when sending Configuration Error Reports
  • Assignee set to Emil Dragu
Actions

Also available in: Atom PDF