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

Added ActAsTaggable concern to MiqRequest model #17466

Merged
merged 1 commit into from
May 23, 2018

Conversation

yrudman
Copy link
Contributor

@yrudman yrudman commented May 23, 2018

MiqRequest was added to RBAC in #17208 without adding ActAsTaggable. It cause raising

[----] F, [2018-05-08T19:34:15.481475 #7215:1428924] FATAL -- : Error caught: [NoMethodError] undefined method `find_tags_by_grouping' for #<MiqRequest::ActiveRecord_Relation:0x0000000012b154b0>
/opt/rh/cfme-gemset/gems/activerecord-5.0.6/lib/active_record/relation/delegation.rb:124:in `method_missing'
/opt/rh/cfme-gemset/gems/activerecord-5.0.6/lib/active_record/relation/delegation.rb:94:in `method_missing'
/var/www/miq/vmdb/lib/rbac/filterer.rb:493:in `get_managed_filter_object_ids'
/var/www/miq/vmdb/lib/rbac/filterer.rb:426:in `calc_filtered_ids'

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1576129

BEFORE:
before

AFTER:
after

@miq-bot add-label bug, core, gaprindashvili/yes, fine/yes

@miq-bot
Copy link
Member

miq-bot commented May 23, 2018

@yrudman unrecognized command 'ad-label', ignoring...

Accepted commands are: add_label, add_reviewer, assign, close_issue, move_issue, remove_label, rm_label, set_milestone

@miq-bot
Copy link
Member

miq-bot commented May 23, 2018

Checked commit yrudman@582d4ab with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🍪

Copy link
Contributor

@lpichler lpichler left a comment

Choose a reason for hiding this comment

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

LGTM 👍 thanks @yrudman

@yrudman
Copy link
Contributor Author

yrudman commented May 23, 2018

@miq-bot add-label bug, core, gaprindashvili/yes, fine/yes

@yrudman
Copy link
Contributor Author

yrudman commented May 23, 2018

@miq-bot assign @jrafanie

@yrudman
Copy link
Contributor Author

yrudman commented May 23, 2018

@miq-bot add-label blocker

@jrafanie jrafanie merged commit 5923577 into ManageIQ:master May 23, 2018
@jrafanie jrafanie added this to the Sprint 87 Ending Jun 4, 2018 milestone May 23, 2018
@yrudman yrudman deleted the make-miq_request-act-as-taggable branch May 23, 2018 15:56
simaishi pushed a commit that referenced this pull request May 29, 2018
Added ActAsTaggable concern to MiqRequest model
(cherry picked from commit 5923577)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1583710
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit ac40681930507ccde0ffc6ced0321a1eed542010
Author: Joe Rafaniello <jrafanie@users.noreply.github.com>
Date:   Wed May 23 11:14:23 2018 -0400

    Merge pull request #17466 from yrudman/make-miq_request-act-as-taggable
    
    Added ActAsTaggable concern to MiqRequest model
    (cherry picked from commit 5923577ea5370b94c05efe74ce85b65982925593)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1583710

simaishi pushed a commit that referenced this pull request May 29, 2018
Added ActAsTaggable concern to MiqRequest model
(cherry picked from commit 5923577)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1583711
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit fb18f4d2a3b33cd6edbb98ce0f277c791f11acfc
Author: Joe Rafaniello <jrafanie@users.noreply.github.com>
Date:   Wed May 23 11:14:23 2018 -0400

    Merge pull request #17466 from yrudman/make-miq_request-act-as-taggable
    
    Added ActAsTaggable concern to MiqRequest model
    (cherry picked from commit 5923577ea5370b94c05efe74ce85b65982925593)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1583711

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
…s-taggable

Added ActAsTaggable concern to MiqRequest model
(cherry picked from commit 5923577)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1583711
@LorkScorguar
Copy link

After this fix, I don't have error on requests page, but with a account tied to a subtenant, i'm unable to see any requests even my own.

@jrafanie
Copy link
Member

jrafanie commented Jun 8, 2018

@LorkScorguar a subtenant can't see parent tenant requests via the tenant access strategy, only descendant tenant requests. Would you be able to draw a tree/picture of how your tenant structure looks, who created the request (and where they are in the tenant structure), and who's failing to "see" the request (and where they are in the tenant structure). Thanks!

@LorkScorguar
Copy link

This is what I have:
rootTenant
|
subTenant
/ |
sub2Tenant sub2Tenant2 sub2Tenant3

if a user from sub2Tenant create a request, he can't see other tenant requests (normal) but he can't see request on his tenant (abnormal), even he can't see his own requests.
User from subTenant are also unable to see requests from descendant tenant.

All users get rights from custom roles, not the default ones. I don't know if this can be the problem.

@jrafanie
Copy link
Member

@LorkScorguar I am not able to recreate this in test. Is it possible the user's role doesn't include the various miq_request_* identifiers, see here.

I wrote the following tests and am able to get your tests to pass with no code changes:

diff --git a/spec/lib/rbac/filterer_spec.rb b/spec/lib/rbac/filterer_spec.rb
index 045ff9a204..7c9eba65cc 100644
--- a/spec/lib/rbac/filterer_spec.rb
+++ b/spec/lib/rbac/filterer_spec.rb
@@ -122,6 +122,7 @@ describe Rbac::Filterer do

   let(:child_tenant)       { FactoryGirl.create(:tenant, :divisible => false, :parent => owner_tenant) }
   let(:child_group)        { FactoryGirl.create(:miq_group, :tenant => child_tenant) }
+  let(:child_user)         { FactoryGirl.create(:user, :miq_groups => [child_group]) }
   let(:child_openstack_vm) { FactoryGirl.create(:vm_openstack, :tenant => child_tenant, :miq_group => child_group) }

   describe ".search" do
@@ -621,6 +622,35 @@ describe Rbac::Filterer do
         end
       end

+      context "with accessible_tenant_ids filtering (strategy = :descendants_id)" do
+        it "can see own request" do
+          request = FactoryGirl.create(:miq_host_provision_request, :tenant => owner_tenant, :requester => owner_user)
+          results = described_class.search(:class => "MiqRequest", :user => owner_user).first
+          expect(results).to match_array [request]
+        end
+
+        it "can see other's request in same tenant" do
+          group = FactoryGirl.create(:miq_group, :tenant => owner_tenant)
+          user  = FactoryGirl.create(:user, :miq_groups => [group])
+
+          request = FactoryGirl.create(:miq_host_provision_request, :tenant => owner_tenant, :requester => owner_user)
+          results = described_class.search(:class => "MiqRequest", :user => user).first
+          expect(results).to match_array [request]
+        end
+
+        it "can't see parent tenant's request" do
+          FactoryGirl.create(:miq_host_provision_request, :tenant => owner_tenant, :requester => owner_user)
+          results = described_class.search(:class => "MiqRequest", :miq_group => child_group).first
+          expect(results).to match_array []
+        end
+
+        it "can see descendant tenant's request" do
+          request = FactoryGirl.create(:miq_host_provision_request, :tenant => child_tenant, :requester => child_user)
+          results = described_class.search(:class => "MiqRequest", :miq_group => owner_group).first
+          expect(results).to match_array [request]
+        end
+      end
+
       context "tenant access strategy VMs and Templates" do
         let(:owned_template) { FactoryGirl.create(:template_vmware, :tenant => owner_tenant) }
         let(:child_tenant)   { FactoryGirl.create(:tenant, :divisible => false, :parent => owner_tenant) }
11:28:28 ~/Code/manageiq (master) (2.4.4) + be rspec -f d spec/lib/rbac/filterer_spec.rb:625
/Users/joerafaniello/.gem/ruby/2.4.4/bundler/gems/manageiq-providers-redfish-ffa8cf8146bc/spec/factories/physical_server.rb:3: warning: toplevel constant PhysicalServer referenced by ManageIQ::Providers::Redfish::PhysicalInfraManager::PhysicalServer
Run options: include {:locations=>{"./spec/lib/rbac/filterer_spec.rb"=>[625]}}

Randomized with seed 9385

Rbac::Filterer
  .search
    with find_options_for_tenant filtering
      with accessible_tenant_ids filtering (strategy = :descendants_id)
        can see other's request in same tenant
        can't see parent tenant's request
        can see descendant tenant's request
        can see own request

Finished in 3.81 seconds (files took 9.03 seconds to load)
4 examples, 0 failures

Randomized with seed 9385 

@LorkScorguar
Copy link

@jrafanie I found the problem. It's not related to role, but to my group. On my group I have a filter by tag which is used to restrict view on some object, but miq_requests doesn't have tags, so users are unable to see their requests.

@jrafanie
Copy link
Member

Interesting @LorkScorguar. Would you be able to share the exact tag filter? I want to write a test for this. Please change the name of the filter if it's something you don't want to share.

What do you think about this @yrudman @gtanzillo @lpichler?

@LorkScorguar
Copy link

LorkScorguar commented Jun 21, 2018

@jrafanie Here are the informations:
Using the same tenant tree as before, this is what I have:

           rootTenant
               |
            subTenant
   /           |               \
sub2Tenant sub2Tenant2 sub2Tenant3

2Tags:

  • business_group, can be: team1, team2, team3
  • business_unit, can be: fr, de, uk

We have 3 user groups:
groupA, attached to rootTenant and no filter, custom role full access
groupB, attached to rootTenant and filter business_unit=fr, custom role access to catalog, services and machines
groupC, attached to sub2Tenant and filter business_unit=fr & business_group=teamC, custom role access to catalog, services and machines (same as for groupB)

groupA have no problem seeing requests
groupB and groupC can see any requests even their own
I tried to remove the filter tag on groupB and then they are able to see requests, but I can't keep it like that.

I experiment with requests and giving group right to approve/deny + tag_assign on request allow user to see the request, but tag_assign only didn't help.

@jrafanie
Copy link
Member

@LorkScorguar thank you for reporting this regression. I have recreated it in large part because of the details you provided. I hope to get a PR opened today to address it.

The fix will look like this, I just need to add more tests:

diff --git a/app/models/miq_request.rb b/app/models/miq_request.rb
index 14e069e993..8608963093 100644
--- a/app/models/miq_request.rb
+++ b/app/models/miq_request.rb
@@ -12,8 +12,6 @@ class MiqRequest < ApplicationRecord
   has_many   :miq_approvals,     :dependent   => :destroy
   has_many   :miq_request_tasks, :dependent   => :destroy

-  acts_as_miq_taggable
-
   alias_attribute :state, :request_state

   serialize   :options, Hash
diff --git a/lib/rbac/filterer.rb b/lib/rbac/filterer.rb
index b48ebb7e7b..fc68cbc937 100644
--- a/lib/rbac/filterer.rb
+++ b/lib/rbac/filterer.rb
@@ -54,7 +54,7 @@ module Rbac
       VmOrTemplate
     )

-    TAGGABLE_FILTER_CLASSES = CLASSES_THAT_PARTICIPATE_IN_RBAC - %w(EmsFolder) + %w(MiqGroup User Tenant)
+    TAGGABLE_FILTER_CLASSES = CLASSES_THAT_PARTICIPATE_IN_RBAC - %w(EmsFolder MiqRequest) + %w(MiqGroup User Tenant)

     NETWORK_MODELS_FOR_BELONGSTO_FILTER = %w(
       CloudNetwork

jrafanie added a commit to jrafanie/manageiq that referenced this pull request Jun 29, 2018
MiqRequest was changed to allow ownership for self service and limited
self-service users in ManageIQ ManageIQ#17208, BZ: 1545395

This caused a problem if you had tag filters assign to a user's group
undefined method `find_tags_by_grouping'.  This was fixed in
ManageIQ ManageIQ#17466, BZ: 1576129, and shipped with:

Fine: https://bugzilla.redhat.com/show_bug.cgi?id=1583711
Gaprindindashvili: https://bugzilla.redhat.com/show_bug.cgi?id=1583710

Unfortunately, this second fix to add taggable caused a new bug: users in
groups having tag filters could not see their own requests.

This commit changes MiqRequest to no longer be taggable, since it's not
even taggable in the UI and instead, we add MiqRequest to a list of
models that are RBAC'able but not taggable so we don't try to filter
MiqRequest based on a user's group tag filters.

Credit goes to github user LorkScorguar who reported this issue and
provided lots of diagnostics to help us fix this properly.

For gaprindashvili and fine:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1596738

For hammer:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1576129
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Jun 29, 2018
MiqRequest was changed to allow ownership for self service and limited
self-service users in ManageIQ ManageIQ#17208, BZ #1545395

This caused a problem if you had tag filters assign to a user's group
undefined method `find_tags_by_grouping'.  This was fixed in
ManageIQ ManageIQ#17466, BZ #1576129, and shipped with:

Fine: BZ #1583711
Gaprindindashvili: BZ #1583710

Unfortunately, this second fix to add taggable caused a new bug: users in
groups having tag filters could not see their own requests.

This commit changes MiqRequest to no longer be taggable, since it's not
even taggable in the UI and instead, we add MiqRequest to a list of
models that are RBAC'able but not taggable so we don't try to filter
MiqRequest based on a user's group tag filters.

Credit goes to github user LorkScorguar who reported this issue and
provided lots of diagnostics to help us fix this properly.

For gaprindashvili and fine:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1596738

For hammer:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1576129
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Jun 29, 2018
MiqRequest was changed to allow ownership for self service and limited
self-service users in ManageIQ ManageIQ#17208, BZ #1545395

This caused a problem if you had tag filters assign to a user's group
undefined method `find_tags_by_grouping'.  This was fixed in
ManageIQ ManageIQ#17466, BZ #1576129, and shipped with:

Fine: BZ #1583711
Gaprindindashvili: BZ #1583710

Unfortunately, this second fix to add taggable caused a new bug: users in
groups having tag filters could not see their own requests.

This commit changes MiqRequest to no longer be taggable, since it's not
even taggable in the UI and instead, we add MiqRequest to a list of
models that are RBAC'able but not taggable so we don't try to filter
MiqRequest based on a user's group tag filters.

Credit goes to github user LorkScorguar who reported this issue and
provided lots of diagnostics to help us fix this properly.

To test this, simply assign managed filters to a user's group, such as
/managed/environments/production, create a request for that user and
try to see that user's request.  They couldn't see it if they received
the intermediate fix, ManageIQ#17466, or if they didn't receive that fix, they'd
receive the `find_tags_by_grouping` error shown above.

For gaprindashvili and fine:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1596738

For hammer:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1576129
jrafanie added a commit to jrafanie/manageiq that referenced this pull request Jun 29, 2018
MiqRequest was changed to allow ownership for self service and limited
self-service users in ManageIQ ManageIQ#17208, BZ #1545395

This caused a problem if you had tag filters assign to a user's group
undefined method `find_tags_by_grouping'.  This was fixed in
ManageIQ ManageIQ#17466, BZ #1576129, and shipped with:

Fine: BZ #1583711
Gaprindindashvili: BZ #1583710

Unfortunately, this second fix to add taggable caused a new bug: users in
groups having tag filters could not see their own requests.

This commit changes MiqRequest to no longer be taggable, since it's not
even taggable in the UI and instead, we add MiqRequest to a list of
models that are RBAC'able but not taggable so we don't try to filter
MiqRequest based on a user's group tag filters.

Credit goes to github user LorkScorguar who reported this issue and
provided lots of diagnostics to help us fix this properly.

To test this, simply assign managed filters to a user's group, such as
/managed/environments/production, create a request for that user and
try to see that user's request.  They couldn't see it if they received
the intermediate fix, ManageIQ#17466, or if they didn't receive that fix, they'd
receive the `find_tags_by_grouping` error shown above.

For gaprindashvili and fine:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1596738

For hammer:
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1576129
@jrafanie
Copy link
Member

Fixed the followup bug reported by @LorkScorguar in #17656

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