Skip to content

Fixes #34026 - authorize puppet reports via Proxy#8958

Merged
ezr-ondrej merged 1 commit intotheforeman:developfrom
lzap:config-report-import-feat-34026
Dec 15, 2021
Merged

Fixes #34026 - authorize puppet reports via Proxy#8958
ezr-ondrej merged 1 commit intotheforeman:developfrom
lzap:config-report-import-feat-34026

Conversation

@lzap
Copy link
Member

@lzap lzap commented Nov 29, 2021

The patch #5010 changed how fact importer features are registered, the change was made in the host controller but not in the API controller. Therefore uploading reports via host controller works fine, however, using the API endpoint does not authorize automatically as the feature is not found.

@theforeman-bot
Copy link
Member

Issues: #34026

@lzap
Copy link
Member Author

lzap commented Nov 30, 2021

@ezr-ondrej ezr-ondrej self-assigned this Dec 1, 2021
before_action :compatibility, :only => :create

add_smart_proxy_filters :create, :features => proc { ConfigReportImporter.authorized_smart_proxy_features }
add_smart_proxy_filters :facts, :features => proc { Foreman::Plugin.fact_importer_registry.fact_features }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the endpoint here is called :create, not :facts. Also i'm not sure if there are plugins that import reports but don't have a fact importer, especially now that all fact importers are in core?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh copy and paste error. Good find.

I do not understand why this endpoint is used, normally /v2/host/xxx/facts should be used. But it should save the same purpose I guess and the change I refer to should should change both.

@lzap lzap force-pushed the config-report-import-feat-34026 branch from f70778d to 310d21e Compare December 2, 2021 13:25
@lzap
Copy link
Member Author

lzap commented Dec 3, 2021

I asked gvde to try again, it could not work since I had the typo there.

@gvde
Copy link

gvde commented Dec 3, 2021

I asked gvde to try again, it could not work since I had the typo there.

Yes. Works for me now. Applied the patch, then restarted

# foreman-maintain service stop
# foreman-maintain service stop

Config reports still coming in from my puppet only smart proxy...

before_action :compatibility, :only => :create

add_smart_proxy_filters :create, :features => proc { ConfigReportImporter.authorized_smart_proxy_features }
add_smart_proxy_filters :create, :features => proc { Foreman::Plugin.fact_importer_registry.fact_features }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use fact features to allow config reports?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I accidentally mis-read the #5010 patch I thought it was about reports while it was about facts. This is wrong, need to dig deeper.

@lzap
Copy link
Member Author

lzap commented Dec 6, 2021

DO NOT MERGE

@lzap
Copy link
Member Author

lzap commented Dec 6, 2021

This appears like some issue with class overriding after we pulled all report importers into core. Without Ansible:

[1] pry(main)> ConfigReportImporter.authorized_smart_proxy_features
=> ["Puppet"]

With Ansible plugin:

[4] pry(main)> ConfigReportImporter.authorized_smart_proxy_features
=> ["Ansible"]

@ekohl ekohl marked this pull request as draft December 6, 2021 11:56
@ekohl
Copy link
Member

ekohl commented Dec 6, 2021

DO NOT MERGE

I've marked it as a draft to make that clear. You can do the same thing: there's a well hidden link in the Reviewers block on the top right.

@lzap lzap force-pushed the config-report-import-feat-34026 branch from 310d21e to 5b1e10e Compare December 6, 2021 12:19
@lzap lzap marked this pull request as ready for review December 6, 2021 12:19
@lzap
Copy link
Member Author

lzap commented Dec 6, 2021

Thanks, I figured it out. The problem was that Ansible plugin simply includes module into ConfigReportImporter and overrides the authorized_smart_proxy_features in a way that it would never return what was previously defined there. A registry similar to facts could be a good solution, however, since we are currently rewriting reports completely and they will all reside in a new Foreman plugin, implementing registry is overkill since we are throwing away the code soon.

So the fix is to remove overriding of the authorized_smart_proxy_features method and start relying on the ReportImporter.register_smart_proxy_feature. It looks like we have introduced this kind of registry, the problem is only chef plugin is using that:

foreman_chef/lib/foreman_chef/engine.rb
92:      ::ConfigReportImporter.register_smart_proxy_feature('Chef')

Puppet and Ansible are both overriding the authorized_smart_proxy_features instead. There is actually another problem, if plugins use ConfigReportImporter.register_smart_proxy_feature instead of ReportImporter.register_smart_proxy_feature it won't work as ReportImporter and ConfigReportImporter are two separate classes with two separate class variables for the array holding the registry.

This have never worked, the moment you installed either Chef or Ansible (Salt does appear to implement reports differently), Puppet feature was always removed from the list. Weird that we only got this reported recently, looks like not many people are using more than one configuration management. Or I dunno why we see it now.

So with this patch in core, the following changes needs to be done in order to fully fix this:

  • Ansible: remove overriding of authorized_smart_proxy_features and use ReportImporter.register_smart_proxy_feature("Ansible") instead
  • Chef: use ReportImporter.register_smart_proxy_feature("Chef") instead of ConfigReportImporter.register_smart_proxy_feature("Chef")
  • Salt: should work as the whole importer is reimplemented from scratch there

@ekohl
Copy link
Member

ekohl commented Dec 6, 2021

It sounds like we have a regression and shortest term fix is to use ConfigReportImporter.register_smart_proxy_feature in Ansible now. Then the follow up patch would move things over to ReportImporter, correct?

@lzap
Copy link
Member Author

lzap commented Dec 6, 2021

It sounds like we have a regression and shortest term fix is to use ConfigReportImporter.register_smart_proxy_feature in Ansible now. Then the follow up patch would move things over to ReportImporter, correct?

Yes but I prefer to change Chef to use ReportImporter instead since the registry (the class variable) is actually defined there and not in the child class. Here is the patch for Ansible: theforeman/foreman_ansible#491

Going to do Chef one as well.

@lzap
Copy link
Member Author

lzap commented Dec 6, 2021

Here is the chef PR: theforeman/foreman_chef#98

I am going to deprecate the ConfigReportImporter register method just in case there is something still utilizing it.

@lzap lzap force-pushed the config-report-import-feat-34026 branch from 5b1e10e to 3ac7e06 Compare December 6, 2021 12:42
@ekohl
Copy link
Member

ekohl commented Dec 6, 2021

I was mostly concerned with cherry picks and compatibility. I haven't looked at the exact details since I just came back from PTO.

@lzap
Copy link
Member Author

lzap commented Dec 6, 2021

Hmm I could actually call class methods from one of the classes so it is always stored just once:

  def self.authorized_smart_proxy_features
    ReportImporter.authorized_smart_proxy_features
  end

  def self.register_smart_proxy_feature(feature)
    ReportImporter.register_smart_proxy_feature(feature)
  end

  def self.unregister_smart_proxy_feature(feature)
    ReportImporter.unregister_smart_proxy_feature(feature)
  end

This is backport-friendly, however, Ansible still needs a patch because currently it overrides the self.authorized_smart_proxy_features so it returns irrelevant result.

@lzap lzap force-pushed the config-report-import-feat-34026 branch from 3ac7e06 to 1712b92 Compare December 6, 2021 12:49
end
end

ReportImporter.register_smart_proxy_feature("Puppet")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in an initializer? I wonder how it would deal with code reloads.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should behave fine, but it is ugly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed that manually

Comment on lines +10 to 16
def self.register_smart_proxy_feature(feature)
ReportImporter.register_smart_proxy_feature(feature)
end

def self.unregister_smart_proxy_feature(feature)
ReportImporter.unregister_smart_proxy_feature(feature)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm missing something, but ConfigReportImporter inherits from ReportImporter so isn't this redundant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not actually, because the definition of the parent method means it's defined on class, so you'd define another array on ConfigReportImporter tho this issue would appear in any of the descendants. That is one of the reasons to not have registries in a parent classes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lzap could we deprecate these then and disable it's usage through ConfigReportImporter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, that's why I dislike static methods with state.


def self.register_smart_proxy_feature(feature)
@authorized_smart_proxy_features = (authorized_smart_proxy_features + [feature]).uniq
@authorized_smart_proxy_features = (authorized_smart_proxy_features + [feature.freeze]).uniq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't you want to freeze the array instead? You're creating new one here, so it would be fine and it would not allow touching the array anywhere else, then through this method. But freezing the strings sounds weird, are we worried someone is changing the actual strings?

Signed-off-by: Lukas Zapletal <lzap+git@redhat.com>
@ezr-ondrej ezr-ondrej force-pushed the config-report-import-feat-34026 branch from 1712b92 to 67fbecc Compare December 10, 2021 11:28
Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not totally agree with this solution, but as a temporary workaround untill we have the new sollution for Reports, I'm ok 👍

@ezr-ondrej
Copy link
Member

[test foreman][test katello]

@ezr-ondrej
Copy link
Member

Thanks @lzap 👍

@ezr-ondrej ezr-ondrej merged commit 9c94e1a into theforeman:develop Dec 15, 2021
@ezr-ondrej
Copy link
Member

Shall this be cherry-picked into 3.1?

@loopway
Copy link

loopway commented Jan 10, 2022

Just run into the issue myself with 3.1. Would be nice if it could be included in the next release. Just a friendly reminder. :)

@ezr-ondrej
Copy link
Member

CP 3.1: 24d9df7

I've checked and old Ansible code should work just fine with this (so hopefully this won't break 3.1 🤷 )
Thanks for the reminder @loopway! 👍

@lzap lzap deleted the config-report-import-feat-34026 branch January 12, 2022 08:48
@lzap
Copy link
Member Author

lzap commented Jan 12, 2022

Thanks, sorry late on my GH inbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants