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

Migrations: Revert remove ACL migration #5942

Merged
merged 5 commits into from
May 31, 2023
Merged

Conversation

N-o-Z
Copy link
Member

@N-o-Z N-o-Z commented May 23, 2023

Linked Issue

Closes #5941

Change Description

Introduce ACL migration as part of a rolling upgrade

@N-o-Z N-o-Z added include-changelog PR description should be included in next release changelog team/versioning-engine Team versioning engine labels May 23, 2023
@N-o-Z N-o-Z requested review from guy-har, Jonathan-Rosenberg and a team May 23, 2023 12:01
@N-o-Z N-o-Z self-assigned this May 23, 2023
Comment on lines 116 to 120
ctx := context.Background()

mig := migrations.NewACLsMigrator(nil, false)

for _, tt := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ctx := context.Background()
mig := migrations.NewACLsMigrator(nil, false)
for _, tt := range tests {
ctx := context.Background()
mig := migrations.NewACLsMigrator(nil, false)
for _, tt := range tests {

Comment on lines 122 to 124
permission, err := mig.ComputePermission(ctx, tt.Actions)

if permission != tt.Permission {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
permission, err := mig.ComputePermission(ctx, tt.Actions)
if permission != tt.Permission {
permission, err := mig.ComputePermission(ctx, tt.Actions)
if permission != tt.Permission {

Comment on lines 122 to 130
permission, err := mig.ComputePermission(ctx, tt.Actions)

if permission != tt.Permission {
t.Errorf("Got permission %s when expecting %s", permission, tt.Permission)
}

if !errors.Is(err, tt.Err) {
t.Errorf("Got error %s but expected %s", err, tt.Err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Need to verify expected error first
  • In case there is an err we need to skip permissions check

// #####################################################################################
// #
// rbac_to_acl #
// #
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we replace these headers with function doc or package level docs.
There are some examples (https://tip.golang.org/doc/comment)

Comment on lines 137 to 139
for i, a := range perms {
for j, b := range perms {
t.Run(fmt.Sprintf("%s:%s", a, b), func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest not to create a subtest for each check - just print the combination in the error.


// handle migrate within ACLs
if version == kv.ACLMigrateVersion {
if force {
Copy link
Contributor

Choose a reason for hiding this comment

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

Update using force flag should be handled by migrate level, not on a specific migrate to acl, as it is relevant no matter to which level you like to force the update - the level just have to be less or equal to the latest compiled with the binary.

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 more complicated then that. The force was designed specifically for ACLMigrationVersion (blocking migration). It was not designed for a rolling upgrade. I suggest to use the force flag per migration

Comment on lines +10 to +16
func updateKVSchemaVersion(ctx context.Context, kvStore kv.Store, version uint) error {
err := kv.SetDBSchemaVersion(ctx, kvStore, version)
if err != nil {
return fmt.Errorf("failed to upgrade version, to fix this re-run migration: %w", err)
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would keep this one as part of rbac_to_acl as it looks like another helper for the specific code

Copy link
Member Author

Choose a reason for hiding this comment

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

This is being used in both import_premissions.py and rbac_to_acl.py.

return addedActionsSlice
}

// BroaderPermission returns true if a offers strictly more permissions that b.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// BroaderPermission returns true if a offers strictly more permissions that b.
// BroaderPermission returns true if a offers strictly more permissions that b. Unknown ACLPermission will panic.

Comment on lines +420 to +430
addedActions := make(map[string]struct{}, len(allAllowedActions))
for _, action := range permissions.Actions {
if someActionMatches(action, allAllowedActions) && !someActionMatches(action, alreadyAllowedActions) {
addedActions[action] = struct{}{}
}
}
addedActionsSlice := make([]string, 0, len(addedActions))
for action := range addedActions {
addedActionsSlice = append(addedActionsSlice, action)
}
return addedActionsSlice
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are going over a unique array of actions, to verify someActionMatches - why do we need a map (like we need to make sure to have unique keys) and transform it to a slice at the end.
Looks like we just need to add the relevant actions to a slice and return.

Copy link
Member Author

@N-o-Z N-o-Z May 28, 2023

Choose a reason for hiding this comment

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

I'd rather not touch this code. It was written by @guy-har and already been battle tested.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks - will look into it in a different PR.

Comment on lines 406 to 408
var (
allAllowedActions map[string]struct{}
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var (
allAllowedActions map[string]struct{}
)
var allAllowedActions map[string]struct{}

@N-o-Z N-o-Z requested a review from nopcoder May 28, 2023 08:57
Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

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

LGTM - minor suggestions about the code comment

// rbac_to_acl #
// #
// #####################################################################################
// # rbac_to_acl test code
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// # rbac_to_acl test code
// TestGetMinPermission - rbac_to_acl test code

Comment on lines 225 to 226
// # import_permissions test code

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// # import_permissions test code
// TestMigrateImportPermissions - import_permissions test code

Comment on lines +420 to +430
addedActions := make(map[string]struct{}, len(allAllowedActions))
for _, action := range permissions.Actions {
if someActionMatches(action, allAllowedActions) && !someActionMatches(action, alreadyAllowedActions) {
addedActions[action] = struct{}{}
}
}
addedActionsSlice := make([]string, 0, len(addedActions))
for action := range addedActions {
addedActionsSlice = append(addedActionsSlice, action)
}
return addedActionsSlice
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks - will look into it in a different PR.

Copy link
Contributor

@guy-har guy-har 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, requesting changes due to the "warning" and "force" behavior that changed

Comment on lines +113 to +115
_, err = rbacToACL(ctx, authService, true, updateTime, func(groupID string, acl model.ACL, warn error) {
groupReports = append(groupReports, Warning{GroupID: groupID, ACL: acl, Warn: warn})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC you are forcing it even if you have errors.
AFAIK this is not the expected behavior, it might perform unwanted changes (such as upgrading users to admin)

@N-o-Z N-o-Z enabled auto-merge (squash) May 31, 2023 08:43
@N-o-Z N-o-Z merged commit acbc0dc into master May 31, 2023
@N-o-Z N-o-Z deleted the task/add-acl-migration branch May 31, 2023 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include-changelog PR description should be included in next release changelog team/versioning-engine Team versioning engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrations: Revert remove ACL migration from code
3 participants