Need help with mixing Facets in an Auth query

I am trying to fix the following issue Bug #24056: Permissions fail when connected to Facets - Foreman . Was wondering if y’all had any suggestions on how to fix this. Main issue is this foreman/authorizer.rb at develop · theforeman/foreman · GitHub . The code does the equivalent of
“”"

FactValue.joins(:host => :content_facet).to_sql
ActiveRecord::ConfigurationError: Can’t join ‘Host::Base’ to association named ‘content_facet’; perhaps you misspelled it?
“”"

Let me know how I can join Host and Content Facet or any facets for that matter to FactValue so that I dont have to do this join.

I wonder if it could be due to the fact, that Katello is extending the Host::Managed, not Host::Base with the facet https://github.com/Katello/katello/blob/KATELLO-3.7/lib/katello/engine.rb#L203

Needed more than that :slight_smile: . Here is the corresponding PR I created connected to this -> Fixes #24056 - Authorizes perms on associations by parthaa · Pull Request #5739 · theforeman/foreman · GitHub

Hmm I am not able to figure this out

console > Report.joins(:host => [:content_facet]).to_sql
=> “SELECT “reports”.* FROM “reports” INNER JOIN “hosts” ON “hosts”.“id” = “reports”.“host_id” AND “hosts”.“type” IN (‘Host::Managed’) AND “hosts”.“organization_id” = 1 AND “hosts”.“location_id” = 2 INNER JOIN “katello_content_facets” ON “katello_content_facets”.“host_id” = “hosts”.“id””

While

console > FactValue.joins(:host => [:content_facet]).to_sql
=> ActiveRecord::ConfigurationError: Can’t join ‘Host::Base’ to association named ‘content_facet’; perhaps you misspelled it?
from /home/vagrant/.rvm/gems/ruby-2.4.1/gems/activerecord-5.1.6/lib/active_record/associations/join_dependency.rb:233:in `find_reflection’

I am not sure what is special in Reports (which is not in base but is in managed only). More over the host joins content)facets works fine from Reports but not from FactValue.

Any thougts?

Without looking at the models, I would check definition of :hosts on both models. My guess would be connection to Host::Base in facts and Host::Managed in reports.

Hey Shimon,
Was discussing this issue with stbenjam and jsherrill on irc. I notice that only fact_value hard codes its host class association to to “Host::Base” (foreman/fact_value.rb at develop · theforeman/foreman · GitHub) while there rest tie to “Host::Managed”. It used to be managed but got changed here ? (Fixes #16082 - Associate FactValues with Host::Base · theforeman/foreman@9ba40b5 · GitHub)

Anyway question is can we just move facets stuff from Host::Managed to Host::Base ? That would probably be a lower risk and more straight forward change than the perms change we have right now.

Short answer: It should be possible.
TLDR: I remember finding some methods that are defined only on Host::Managed, so I will need to try and do it in order to say something definitive. Key file would be app/models/concerns/facets/managed_host_extensions.rb.