Skip to content

Commit

Permalink
Properly create tenant default group for population
Browse files Browse the repository at this point in the history
When creating a tenant, if there are already groups in the database,
it would assign a random group.
This would manifest by having a seemingly random group assigned to newly
discovered VMs/Hosts. There can then be privilege issues as the admins
possibly don't have access to the group.

This only happens for customers who had a database before tenancy
was introduced in 2015. It incorrectly assigned during the migration
process in 20151021174140_assign_tenant_default_group

The fix: it will now only assign a tenant group.

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

I'm also adding a migration to automatically fix customer's databases
Since the issue was introduced in a migration in the first place.
  • Loading branch information
kbrock committed Sep 26, 2018
1 parent dc7975f commit 2816f9b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/miq_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ def self.create_tenant_group(tenant)

create_with(
:description => "Tenant #{tenant_full_name} access",
:group_type => TENANT_GROUP,
:default_tenant_role => MiqUserRole.default_tenant_role
).find_or_create_by!(:tenant_id => tenant.id)
).find_or_create_by!(
:group_type => TENANT_GROUP,
:tenant_id => tenant.id,
)
end

def self.sort_by_desc
Expand Down
18 changes: 18 additions & 0 deletions spec/models/tenant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,22 @@
expect(sub_tenant.parent_id = tenant.id).to eq(tenant.id)
end
end

describe "#create" do
it "properly creates a default group" do
# create a tenant, but one that doesn't have a default_miq_group
# this is only possibly during an upgrade
tenant.save!
tenant.default_miq_group.delete
tenant.update_attribute(:default_miq_group_id, nil)
# lets make sure the tenant doesn't get assigned this user created group (the bug)
false_group = FactoryGirl.create(:miq_group, :tenant_id => tenant.id)

# 20151021174140_assign_tenant_default_group.rb
tenant.send(:create_tenant_group)

expect(tenant.default_miq_group).not_to eq(false_group)
expect(tenant.default_miq_group).to be_tenant_group
end
end
end

0 comments on commit 2816f9b

Please sign in to comment.