Bug #28960
closedError "Couldn't find Host::Managed with 'id'=" when sending Configuration Error Reports
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)).
Updated by The Foreman Bot over 4 years ago
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/7422 added
Updated by Anonymous over 4 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset 10d6debad60138a1bf7b0f59fcab4ec40e79e61c.
Updated by Tomer Brisker about 4 years ago
- Category changed from 218 to Users, Roles and Permissions
Updated by Ewoud Kohl van Wijngaarden about 4 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