-
Notifications
You must be signed in to change notification settings - Fork 898
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
Use feature for admin #17444
Use feature for admin #17444
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks fine, but admittedly I am not the best person to be making the final say.
I think my only real gripe is that MiqProductFeature
seems like a weird place for this to live instead of MiqUserRole
, specifically from a name standpoint. I can much more easily understand that "admin"
and "superadmin"
are roles versus "product features", but maybe that is just me.
There might be implementation details that make it more desirable to put this in MiqProductFeature
versus MiqUserRole
, so not really worth holding this up for, just an observation.
app/models/miq_group.rb
Outdated
def self.with_current_user_groups(user = nil) | ||
current_user = user || User.current_user | ||
current_user.admin_user? ? all : where(:id => current_user.miq_group_ids) | ||
# paralell to User.with_groups - only show these groups |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: parallel
app/models/miq_user_role.rb
Outdated
where.not(:id => MiqUserRole.joins(:miq_product_features) | ||
.where(:miq_product_features => {:identifier => identifier}) | ||
.select(:id) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hot. 👍
@@ -25,14 +25,15 @@ class User < ApplicationRecord | |||
belongs_to :current_group, :class_name => "MiqGroup" | |||
has_and_belongs_to_many :miq_groups | |||
scope :superadmins, lambda { | |||
joins(:miq_groups => :miq_user_role).where(:miq_user_roles => {:name => MiqUserRole::SUPER_ADMIN_ROLE_NAME }) | |||
joins(:miq_groups => {:miq_user_role => :miq_product_features}) | |||
.where(:miq_product_features => {:identifier => MiqProductFeature::SUPER_ADMIN_FEATURE }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First off, totally fine with this query, and it probably doesn't need to change.
But am kinda curious where it is being used. Since we aren't setting a .select
on this, do we get all the columns back on this, or does Rails always add a table_name.*
by default instead of just a SELECT *
?
(might be the former now that I think about it)
Anyway, you really aren't changing how this worked much before, so you probably don't have to worry about it.
lib/rbac/filterer.rb
Outdated
if user_or_group.disallowed_roles | ||
scope = scope.with_allowed_roles_for(user_or_group) | ||
# hide creating admin group / roles from tenant administrators | ||
if !user_or_group.miq_user_role&.admin_user? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<rant>
God... this is the ugliest syntax addition to Ruby I have ever seen... bleh </rant>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of a serious, but minor question: Is there an extra query being hit here now by calling out to miq_user_role
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. But I figure features need to be brought back for the rest of the UI, so I've been looking the other way
app/models/user.rb
Outdated
def self.with_current_user_groups(user = nil) | ||
user ||= current_user | ||
user.admin_user? ? all : includes(:miq_groups).where(:miq_groups => {:id => user.miq_group_ids}) | ||
# paralell to MiqGroup.with_groups - only show users with these groups |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: parallel
app/models/user.rb
Outdated
@@ -171,7 +175,8 @@ def self.lookup_by_identity(username) | |||
end | |||
|
|||
def self.authorize_user(userid) | |||
return if userid.blank? || admin?(userid) | |||
# Don't authorize users with userid == "admin" | |||
return if userid.blank? || userid == "admin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few things:
- At the very least, can we
.freeze
this string? Or use an existing constant? - Is there a reason this doesn't go through
MiqUserRole
orMiqProductFeature
? I guess for simplicity and reducing risk? (cool with that being the case, just making sure)
lib/rbac/filterer.rb
Outdated
end | ||
|
||
if MiqUserRole != klass | ||
if MiqUserRole == klass | ||
scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the rational behind adding this conditional in and pushing scope_by_ids
inside the else? Just don't see the context/rational from the diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think I'll roll it back - yea, probably an unneeded change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure you need to go that far, was just curious what the rational was.
app/models/miq_group.rb
Outdated
@@ -60,8 +60,8 @@ def settings=(new_settings) | |||
super(indifferent_settings) | |||
end | |||
|
|||
def self.with_allowed_roles_for(user_or_group) | |||
includes(:miq_user_role).where.not({:miq_user_roles => {:name => user_or_group.disallowed_roles}}) | |||
def self.with_roles_excluding(disallowed_roles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of the callers for this updated? I don't see any changed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thankfully these ones got hidden due to recent commits. Just noticed where these were being used, so this question and others like it can be ignored.
app/models/miq_user_role.rb
Outdated
|
||
def self.with_allowed_roles_for(user_or_group) | ||
where.not(:name => user_or_group.disallowed_roles) | ||
def self.with_roles_excluding(disallowed_roles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of the callers for this updated? I don't see any changed here. (repeat question)
app/models/user.rb
Outdated
@@ -50,8 +50,8 @@ class User < ApplicationRecord | |||
|
|||
scope :with_same_userid, ->(id) { where(:userid => User.find(id).userid) } | |||
|
|||
def self.with_allowed_roles_for(user_or_group) | |||
includes(:miq_groups => :miq_user_role).where.not(:miq_user_roles => {:name => user_or_group.disallowed_roles}) | |||
def self.with_roles_excluding(disallowed_roles) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of the callers for this updated? I don't see any changed here. (repeat question)
c3e49cc
to
e702067
Compare
@bascar / @gtanzillo new thoughts: Currently we have a single "administrator" Role. the This is not transferrable to other roles, so instead of using If you look at the product features granted to admins, they fall in 2 different areas. It makes sense to split up the admin role into 2 types of functionality: reports and requests. Additionally, there currently are provisions to prevent tenant admins from creating an administrator user. While it makes sense to limit creation of a super admin, the admin does not have significant added privileges, so this no longer seems necessary. Instead it prevents non super admins from creating super admins. Current functionality granted to AdministratorsNOTE: While super administrators do get all administrator functionality, they are different roles
Not sure if this can address |
e702067
to
a3dfb97
Compare
move hardcoded admin logic over to rbac
the role name used to determine if it were https://bugzilla.redhat.com/show_bug.cgi?id=1090627
Admins have 2 types of escalated privileges report and request This separates the types (with 2 different product features)
a3dfb97
to
f6c02e8
Compare
Checked commits kbrock/manageiq@9c9a52f~...f6c02e8 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awesome 👍 I just have the one small question/comment
@@ -15,11 +15,11 @@ class MiqGroup < ApplicationRecord | |||
has_many :miq_widget_sets, :as => :owner, :dependent => :destroy | |||
has_many :miq_product_features, :through => :miq_user_role | |||
|
|||
virtual_column :miq_user_role_name, :type => :string, :uses => :miq_user_role | |||
virtual_delegate :name, :to => :miq_user_role, :allow_nil => true, :prefix => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come you changed this to just :name
? It seems ambiguous as it can be misconstrued as the name of the group when it's really the name of the groups role.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This did not change
The :name
refers to Role#name
. The prefix => true
tacks on the association name so the attribute name will be called miq_user_role_name
(same as it originally was)
This broke UI master :)
Fixed in ManageIQ/manageiq-ui-classic#4023 (Merged) |
Fixes mangeiq-ui-classic master failures Introduced by ManageIQ/manageiq#17444
We introduced feature miq_request_superadmin in f6c02e8 / ManageIQ#17444 The feature miq_request_approval already existed. Merging the 2 together. This fixes an inconsistency between API and UI The issue existed before this feature was introduced so this works with 17444 to fix the BZ ManageIQ#17444 https://bugzilla.redhat.com/show_bug.cgi?id=1608554
In ManageIQ#17444 and related PRs References to generic admin_user and used request_admin_user/others This removes the method for good
In ManageIQ#17444 and related PRs References to generic admin_user and used request_admin_user/others This removes the method for good
In ManageIQ#17444 and related PRs References to generic admin_user and used request_admin_user/others This removes the method for good
In ManageIQ#17444 and related PRs References to generic admin_user and used request_admin_user/others This removes the method for good
We introduced feature miq_request_superadmin in f6c02e8 / ManageIQ#17444 The feature miq_request_approval already existed. Merging the 2 together. This fixes an inconsistency between API and UI The issue existed before this feature was introduced so this works with 17444 to fix the BZ ManageIQ#17444 https://bugzilla.redhat.com/show_bug.cgi?id=1608554
We introduced feature miq_request_superadmin in f6c02e8 / ManageIQ#17444 The feature miq_request_approval already existed. Merging the 2 together. This fixes an inconsistency between API and UI The issue existed before this feature was introduced so this works with 17444 to fix the BZ ManageIQ#17444 https://bugzilla.redhat.com/show_bug.cgi?id=1608554
We introduced feature miq_request_superadmin in f6c02e8 / ManageIQ#17444 The feature miq_request_approval already existed. Merging the 2 together. This fixes an inconsistency between API and UI The issue existed before this feature was introduced so this works with 17444 to fix the BZ ManageIQ#17444 https://bugzilla.redhat.com/show_bug.cgi?id=1608554
We introduced feature miq_request_superadmin in f6c02e8 / ManageIQ#17444 The feature miq_request_approval already existed. Merging the 2 together. This fixes an inconsistency between API and UI The issue existed before this feature was introduced so this works with 17444 to fix the BZ ManageIQ#17444 https://bugzilla.redhat.com/show_bug.cgi?id=1608554
We introduced feature miq_request_superadmin in f6c02e8 / ManageIQ#17444 The feature miq_request_approval already existed. Merging the 2 together. This fixes an inconsistency between API and UI The issue existed before this feature was introduced so this works with 17444 to fix the BZ ManageIQ#17444 https://bugzilla.redhat.com/show_bug.cgi?id=1608554
In ManageIQ#17444 and related PRs References to generic admin_user and used request_admin_user/others This removes the method for good
We introduced feature miq_request_superadmin in f6c02e8 / ManageIQ#17444 The feature miq_request_approval already existed. Merging the 2 together. This fixes an inconsistency between API and UI The issue existed before this feature was introduced so this works with 17444 to fix the BZ ManageIQ#17444 https://bugzilla.redhat.com/show_bug.cgi?id=1608554
The fix here simply matches up the `if` checks used in: - `Api::ReportsController#reports_search_conditions` - `MiqReport.for_user` to both use `User#report_admin_user?` * * * Further background info: This bug is the result of a collision between the following two PRs: - ManageIQ/manageiq#15472 - ManageIQ/manageiq#17444 The first PR, ManageIQ/manageiq#15472, introduces: `Api::ReportsController#reports_search_conditions` Which uses `unless User.current_user.admin?` to check if it should use the `where_clause` from the `MiqReport.for_user` for the search conditions (passed into a `ActiveRecord` `.where` farther up the stack). The idea for this initial check is building this where clause only makes sense if it isn't an `all`, otherwise where it is used will cause an error in Postgres syntax because of `... WHERE ()` being passed This, however, doesn't match the `user.admin_user?`(at the time of ManageIQ/manageiq#15472) check that is done in `.for_user` method, which means it would be called for users that don't match the `admin` username, but still are part of either of the following roles - `"EvmRole-super_administrator"` - `"EvmRole-administrator"` The bug in question: https://bugzilla.redhat.com/show_bug.cgi?id=1650531 tested this with a custom role, which doesn't match either of those two roles, so the `User#admin?` check and `User#admin_user?` check happened to be equivalent in `5.9` (see comment ManageIQ#4 in BZ link), but not `5.10`. But, if the replication steps had instead said to: - Create a user, "User1", that is part of the "EvmGroup-administrator" group This would have also failed in the same way on `5.9` as it does on `5.10` currently. This fails on 5.10, though, because in ManageIQ/manageiq#17444, the `admin_user?` method changes to `report_admin_user?`, and it's functionality also now checks if the role is valid for querying the group role's product features the user has access to, and it only has an eject for the role that happens to be `admin?`. Meaning that the `admin` "super user" still has no problem with this query, but any other user that could still count as a `report_admin_user?` would (both users in the `EvmGroup-administrator` role and just having the proper features enabled)
The fix here simply matches up the `if` checks used in: - `Api::ReportsController#reports_search_conditions` - `MiqReport.for_user` to both use `User#report_admin_user?` * * * Further background info: This bug is the result of a collision between the following two PRs: - ManageIQ/manageiq#15472 - ManageIQ/manageiq#17444 The first PR, ManageIQ/manageiq#15472, introduces: `Api::ReportsController#reports_search_conditions` Which uses `unless User.current_user.admin?` to check if it should use the `where_clause` from the `MiqReport.for_user` for the search conditions (passed into a `ActiveRecord` `.where` farther up the stack). The idea for this initial check is building this where clause only makes sense if it isn't an `all`, otherwise where it is used will cause an error in Postgres syntax because of `... WHERE ()` being passed This, however, doesn't match the `user.admin_user?`(at the time of ManageIQ/manageiq#15472) check that is done in `.for_user` method, which means it would be called for users that don't match the `admin` username, but still are part of either of the following roles - `"EvmRole-super_administrator"` - `"EvmRole-administrator"` The bug in question: https://bugzilla.redhat.com/show_bug.cgi?id=1650531 tested this with a custom role, which doesn't match either of those two roles, so the `User#admin?` check and `User#admin_user?` check happened to be equivalent in `5.9` (see comment ManageIQ#4 in BZ link), but not `5.10`. But, if the replication steps had instead said to: - Create a user, "User1", that is part of the "EvmGroup-administrator" group This would have also failed in the same way on `5.9` as it does on `5.10` currently. This fails on 5.10, though, because in ManageIQ/manageiq#17444, the `admin_user?` method changes to `report_admin_user?`, and it's functionality also now checks if the role is valid for querying the group role's product features the user has access to, and it only has an eject for the role that happens to be `admin?`. Meaning that the `admin` "super user" still has no problem with this query, but any other user that could still count as a `report_admin_user?` would (both users in the `EvmGroup-administrator` role and just having the proper features enabled) Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1650531
Problem:
Users can not create a custom group with admin privileges.
Our best practices say to create a custom group and not use the included
Evm
ones.The reason for this request most often is focused on reporting, but also focuses on
miq_request
privileges.Before:
MiqUserRole#admin_user?
.administrator
role has been whittled down to elevated report andmiq_request
privileges.After:
admin
) now uses the the existingeverything
miq_product_feature
to grant the special privilege.admin_user?
now uses themiq_product_feature
miq_report_superadmin
to grant special privileges. (This is needed for chargeback and other reports). Introducedreport_admin_user?
for transition.admin_user?
now usesmiq_product feature
miq_request_superadmin
administrator
role checksadmin_user?
is deprecated and no longer used. Essentially, this role has been removed.tenant-administrator
checks have been simplified. Now, a super admin is the only one able to create a super admin.Future work: