Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that base_class of first target is used for RBAC scope #16178

Merged
merged 1 commit into from
Oct 13, 2017

Conversation

gtanzillo
Copy link
Member

When targets are passed and the instances are of different subclasses through STI, the base class needs to be used for building the scope to prevent ActiveRecord from also scoping to the subclass and limiting the results to only instances of that class.

For example - lets say that targets were passed in as instances of these classes that derive from ExtManagementSystem

["ManageIQ::Providers::Redhat::InfraManager",
 "ManageIQ::Providers::Google::CloudManager",
 "ManageIQ::Providers::StorageManager::CinderManager",
 "ManageIQ::Providers::Vmware::InfraManager",
 "ManageIQ::Providers::Openstack::NetworkManager"]

Without this change RBAC would only return the targets of the first class ManageIQ::Providers::Redhat::InfraManager in the results

https://bugzilla.redhat.com/show_bug.cgi?id=1480812
https://bugzilla.redhat.com/show_bug.cgi?id=1467756

/cc @jrafanie, @yrudman

results = described_class.search(:targets => targets, :user => user)
objects = results.first
expect(objects.length).to eq(4)
expect(objects).to eq(targets)
Copy link
Member

@jrafanie jrafanie Oct 11, 2017

Choose a reason for hiding this comment

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

Ugh, sorry I didn't see this when we were writing it. Are these guaranteed to be in the same order? Maybe we should use contain_exactly or it's similar form match_array

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

Looks good other than my comment above

@gtanzillo gtanzillo force-pushed the rbac-sti-base-class branch from 257e1a0 to 80bbc59 Compare October 12, 2017 13:39
@gtanzillo
Copy link
Member Author

@jrafanie I made the change to use match_array. Please take another 👀

@@ -279,6 +280,10 @@ def search(options = {})
return targets, attrs
end

def is_sti?(klass)
klass.respond_to?(:finder_needs_type_condition?) ? klass.finder_needs_type_condition? : false
Copy link
Contributor

Choose a reason for hiding this comment

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

@gtanzillo @jrafanie

I am just thinking if it is covered also behaviour when you will pass objects with resource_type column like

[MetricRollup.first,
VmPerformance.first]

because as

ManageIQ::Providers::Redhat::InfraManager.finder_needs_type_condition? => true is true
the
VmPerformance.finder_needs_type_condition? => false is not true

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @lpichler. Let me make a test for that case and see.

Copy link
Member

Choose a reason for hiding this comment

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

@gtanzillo what did you find? Is this a test case we need to worry about?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jrafanie, I discussed it with @yrudman and we added 2 more tests for this case. It turned out to be the same case that @lpichler previously did for MiqAeDomain.

Like we discussed yesterday, the case where multiple classes are represented in targets, like [MetricRollup, Vmperformance], and they are not STI would not be supported.

/cc @lpichler, @yrudman

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense to me.

@gtanzillo gtanzillo force-pushed the rbac-sti-base-class branch from 80bbc59 to 7cda928 Compare October 12, 2017 20:13
User.with_user(admin_user) do
results = described_class.search(:targets => [miq_ae_domain]).first
expect(results.first).to be_an_instance_of(MiqAeDomain)
expect(results).to match_array [miq_ae_domain]
end
end

it 'returns the same class as input for parents clast that is not STI' do
Copy link
Member

Choose a reason for hiding this comment

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

typo: clast

end
end

it 'returns the same class as input for subclass that is not STI' do
Copy link
Member

Choose a reason for hiding this comment

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

^ what does that mean? Is it returning a base class or subclass?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's returning the subclass. But, the point is that it's returning the same class that was passed to targets.

@@ -830,6 +870,18 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects)
expect(objects).to eq(targets)
end

it "returns the correct results when targets are of different types" do
Copy link
Member

Choose a reason for hiding this comment

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

maybe this should be "returns the correct class for different classes of targets"

@gtanzillo gtanzillo force-pushed the rbac-sti-base-class branch 2 times, most recently from 4d9aaa0 to 3896845 Compare October 12, 2017 21:53
When targets are passed and the instances are of different subclasses through STI, the base class needs
to be used for building the scope to prevent ActiveRecord from also scoping to the subclass and limiting
the results to only instances of that class.

https://bugzilla.redhat.com/show_bug.cgi?id=1480812
https://bugzilla.redhat.com/show_bug.cgi?id=1467756
@gtanzillo gtanzillo force-pushed the rbac-sti-base-class branch from 3896845 to cb3cb72 Compare October 13, 2017 10:58
@miq-bot
Copy link
Member

miq-bot commented Oct 13, 2017

Checked commit gtanzillo@cb3cb72 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 1 offense detected

lib/rbac/filterer.rb

@chessbyte chessbyte self-assigned this Oct 13, 2017
@chessbyte chessbyte merged commit b02bfce into ManageIQ:master Oct 13, 2017
@chessbyte chessbyte added this to the Sprint 71 Ending Oct 16, 2017 milestone Oct 13, 2017
simaishi pushed a commit that referenced this pull request Nov 13, 2017
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 997fa5b8dbf22aab13d327dd0375b40679b5281c
Author: Oleg Barenboim <[email protected]>
Date:   Fri Oct 13 09:46:11 2017 -0400

    Merge pull request #16178 from gtanzillo/rbac-sti-base-class
    
    Ensure that `base_class` of first target is used for RBAC scope
    (cherry picked from commit b02bfcea291aec1d2a2e08e54b360e5cface35c6)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1511135
    https://bugzilla.redhat.com/show_bug.cgi?id=1511130

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
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.

6 participants