minio / mc

Unix like utilities for object store
https://min.io/download
GNU Affero General Public License v3.0
2.88k stars 550 forks source link

Do not fail mc-admin-policy-attach if policy already attached/detached #5058

Closed dhananjaykrutika closed 1 month ago

dhananjaykrutika commented 1 month ago

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 license. By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 license.

Description

mc admin policy attach of a policy that has been already assigned to a user should succeed. Same with detach.

Motivation and Context

Currently, attempts to attach a policy to a user who already has the policy attached to them results in a 400.

This change is to handle cases where policy attach/detach operations are automated using scripts/jobs. A re-run of the attach/detach step should not result in the failure of the entire job.

How to test this PR?

Attach a policy to a user using mc admin policy attach ... Attach the same policy again. The command should succeed.

Types of changes

Checklist:

shtripat commented 1 month ago

Fix the lint failures

cmd/admin-policy-attach.go:27: File is not `gofmt`-ed with `-s` (gofmt)
    errCodeChangeAlreadyApplied = "XMinioAdminPolicyChangeAlreadyApplied"
cmd/admin-policy-attach.go:83: File is not `gofumpt`-ed (gofumpt)
    return false
make: *** [Makefile:43: lint] Error 1
shtripat commented 1 month ago

Is it fine to suppress this error only in client side? Server still sends a 400 response for this and we are ignoring in client side.

dhananjaykrutika commented 1 month ago

@shtripat , the error is being handled in mc so that the fix can work with older versions of minio servers as well.