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

Fix incorrectly tenant default groups #278

Merged
merged 1 commit into from
Sep 28, 2018
Merged

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Sep 26, 2018

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

This also will probably only happen for the default tenant.

The fix: When a tenant points to a group that is not a tenant group,
change the default group to point to a new tenant group.
The old group was an incorrect group.

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

I also changed the MiqGroup code to choose the correct group.

see also ManageIQ/manageiq#18025

@miq-bot add_label bug hammer/yes
@miq-bot assign @Fryguy

@miq-bot
Copy link
Member

miq-bot commented Sep 26, 2018

@kbrock Cannot apply the following label because they are not recognized: bug hammer/yes

migrate

t.reload
expect(t.default_miq_group_id).to be_truthy
Copy link
Member

Choose a reason for hiding this comment

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

This feels like an unnecessary expectation since you're going to use that column in the next expectation

@@ -0,0 +1,56 @@
class FixDefaultTenantGroup < ActiveRecord::Migration[5.0]
class Tenant < ActiveRecord::Base
belongs_to :default_miq_group, :class_name => "::FixDefaultTenantGroup::MiqGroup", :dependent => :destroy
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the :dependent => :destroy used anywhere in the migration

@kbrock
Copy link
Member Author

kbrock commented Sep 28, 2018

thnx @bdunne Made those changes


def up
say_with_time "adding default tenant groups" do
Tenant.all.reject { |t| t.default_miq_group&.tenant_group? }.each do |t|
Copy link
Member

Choose a reason for hiding this comment

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

Should we avoid looping through the list twice with something like this?

Tenant.find_each do |t|
  next if t.default_miq_group&.tenant_group?
  t.default_miq_group_id = nil
  t.add_default_miq_group
end

Copy link
Member Author

Choose a reason for hiding this comment

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

thnx, I'll fix this

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

This also will probably only happen for the default tenant.

The fix: When a tenant points to a group that is not a tenant group,
change the default group to point to a new tenant group.
The old group was an incorrect group.

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

I also changed the MiqGroup code to choose the correct group.
@miq-bot
Copy link
Member

miq-bot commented Sep 28, 2018

Checked commit kbrock@fb30ad6 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. ⭐

@kbrock
Copy link
Member Author

kbrock commented Sep 28, 2018

@miq-bot add_label Hammer/yes
This is fixing data for all customers who use manageiq since before 2016

Thanks for the code review @bdunne - made that last change

@bdunne bdunne merged commit 46cc3f2 into ManageIQ:master Sep 28, 2018
@bdunne bdunne added this to the Sprint 96 Ending Oct 8, 2018 milestone Sep 28, 2018
@bdunne bdunne assigned bdunne and unassigned Fryguy Sep 28, 2018
@kbrock kbrock deleted the bz_1625788 branch September 28, 2018 22:33
@bdunne bdunne added the data label Oct 2, 2018
@bdunne
Copy link
Member

bdunne commented Oct 2, 2018

@simaishi Since this is a data migration only (no schema changes), it should be okay to backport to hammer. Also, users with a new deployment from the hammer branch shouldn't be affected since the PR to the core repo would prevent them from getting into this situation in the first place.

simaishi pushed a commit that referenced this pull request Oct 2, 2018
Fix incorrectly tenant default groups

(cherry picked from commit 46cc3f2)
@simaishi
Copy link
Contributor

simaishi commented Oct 2, 2018

Hammer backport details:

$ git log -1
commit 4b5752c00b8f6b3853800973d90f5ba5c6b7c11f
Author: Brandon Dunne <[email protected]>
Date:   Fri Sep 28 16:42:15 2018 -0400

    Merge pull request #278 from kbrock/bz_1625788
    
    Fix incorrectly tenant default groups
    
    (cherry picked from commit 46cc3f254368ccab8a6ec68b99188b3fffd322ab)

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.

5 participants