Skip to content

Fixes #39220 - Exclude host taxonomies that don't match the capsule t…#10952

Open
pondrejk wants to merge 2 commits intotheforeman:developfrom
pondrejk:proxy-capsules
Open

Fixes #39220 - Exclude host taxonomies that don't match the capsule t…#10952
pondrejk wants to merge 2 commits intotheforeman:developfrom
pondrejk:proxy-capsules

Conversation

@pondrejk
Copy link
Copy Markdown
Contributor

@pondrejk pondrejk commented Apr 8, 2026

…axonomies from used_taxonomy_ids

SAT-35949 - the the taxonomies listed in the smart proxy edit dialog could exceed the actual taxonomies assigned to proxy

Copy link
Copy Markdown
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Thanks, @pondrejk, some minor notes:

Comment thread app/models/smart_proxy.rb Outdated
@@ -78,7 +78,14 @@ def used_taxonomy_ids(type)
return [] if new_record? || !respond_to?(:hosts)

conditions = "#{id} IN (#{Host::Managed.proxy_column_list})"
::Host::Managed.with_smart_proxies.where(conditions).distinct.pluck(type).compact
host_ids = ::Host::Managed.with_smart_proxies.where(conditions).distinct.pluck(type).compact
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A bit misleading name, consider host_taxonomy_ids?

Comment thread app/models/smart_proxy.rb Outdated
when :location_id then location_ids
when :organization_id then organization_ids
else
[]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even though we're dealing with a bug already, and the current implementation takes whatever is provided as type (even though we only expect :<location|organization>_id), maybe it's worth to raise an error since it's something not expected?

@@ -38,6 +38,41 @@ class SmartProxyTest < ActiveSupport::TestCase
assert_equal [taxonomies(:location1).id], smart_proxies(:puppetmaster).used_or_selected_location_ids
end

describe '#used_taxonomy_ids' do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it's also worth to add a test which doesn't test only for emptiness? Something like proxy has orgs [A, B], host references orgs [B, C] => should return only [B].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I added test on line 62

Copy link
Copy Markdown
Member

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Thanks, @pondrejk, code-wise LGTM.

Although, I'm not sure about the actual idea of the fix. The issue seems more like a data mismatch caused by something, since it seems to be fixed by explicit Fix mismatches button. I'm afraid the underlying issue is more complex, this fix would just mask it (although correctly). E.g. the link between a host in orgC and a proxy that is in orgA + orgB will still be there, we would just not show it.

Also, I've tried to reproduce it naively: assign orgA, orgB to the proxyA, create a host in orgC using proxyA and it just didn't allow me. What are your reproduction steps that show current state and the fixed state?

@pondrejk
Copy link
Copy Markdown
Contributor Author

pondrejk commented Apr 10, 2026

Thanks, @pondrejk, code-wise LGTM.

Although, I'm not sure about the actual idea of the fix. The issue seems more like a data mismatch caused by something, since it seems to be fixed by explicit Fix mismatches button. I'm afraid the underlying issue is more complex, this fix would just mask it (although correctly). E.g. the link between a host in orgC and a proxy that is in orgA + orgB will still be there, we would just not show it.

That is true, from what I can tell the situation is a result of data mismatch. What about I'd add some explicit warning somewhere to the proxy details UI, that would show up only when this occurs?

Also, I've tried to reproduce it naively: assign orgA, orgB to the proxyA, create a host in orgC using proxyA and it just didn't allow me. What are your reproduction steps that show current state and the fixed state?

I could reproduce trough downstream automation, though I think you could create the situation it by creating host-capsule relationsips with matching orgs, and then dropping the orgs from the capsule via cli (which is allowed -- maybe another item to improve)

@ofedoren
Copy link
Copy Markdown
Member

That is true, from what I can tell the situation is a result of data mismatch. What about I'd add some explicit warning somewhere to the proxy details UI, that would show up only when this occurs?

Hmm, might be a good idea. Although, I'd like to get rid of the possibility of mismatching, stating on the proxy details page that it's being used by something from a different org/loc with a potential fix could help users a bit.

Copy link
Copy Markdown
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

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

Looking at some other methods in taxonomix (like used_or_selected_location_ids) it seems that the sets of directly assigned taxonomies and used (aka indirectly assigned) taxonomies are expected to possibly be disjoint.

If I'm reading it correctly then in the edit form the used taxonomies should be disabled (you can't toggle them). What if we went the other direction and instead of showing directly assigned taxonomies everywhere, we displayed the used ones so that instead of masking the issue we force the user to reconcile it?

@github-actions github-actions Bot added the Legacy JS PRs making changes in the legacy Javascript stack label May 4, 2026
@pondrejk
Copy link
Copy Markdown
Contributor Author

pondrejk commented May 4, 2026

@ofedoren @adamruzicka to sum up findings since the last time:

  • in case the capsule has: used taxonomies > assigned taxonomies, user can resolve this either by adding the missing taxonomies to the assigned ones, or by removing the host association if possible
  • prior to this fix the first solution was possible to do only by running fix mismatches in the taxonomies section, but not in the proxy edit dialog -- the taxonomy appeared as already included and disabled

My proposal is to not include the taxonomy if its not assigned, but mark it as used, so users find out about it and can select what to do about it, the current form

image

once you include the offending org and submit, on the next visit it shows up as included and associated with a host

image

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

Labels

Legacy JS PRs making changes in the legacy Javascript stack Needs re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants