From cb459acd3d4f9c1ce1e8a256aa1d35a00892cd20 Mon Sep 17 00:00:00 2001 From: Quentin GODRON Date: Tue, 9 Sep 2025 15:30:46 +0200 Subject: [PATCH 1/2] fix and enhance logging message on policy deletion --- internal/controller/user/reconcile.go | 4 ++-- internal/s3/client/impl/minioS3Client.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/controller/user/reconcile.go b/internal/controller/user/reconcile.go index 333ea92..d6b4ffe 100644 --- a/internal/controller/user/reconcile.go +++ b/internal/controller/user/reconcile.go @@ -377,7 +377,7 @@ func (r *S3UserReconciler) handleUpdate( policyFound := slices.Contains(userResource.Spec.Policies, policy) if !policyFound { logger.Info( - fmt.Sprintf("S3User policy definition doesn't contain policy %s", policy), + fmt.Sprintf("S3User has unexpected policy not in definition: %s", policy), "userResource", userResource.Name, "NamespacedName", @@ -391,7 +391,7 @@ func (r *S3UserReconciler) handleUpdate( policyFound := slices.Contains(userPolicies, policy) if !policyFound { logger.Info( - fmt.Sprintf("S3User policy definition must contain policy %s", policy), + fmt.Sprintf("S3User is missing policy from definition: %s", policy), "userResource", userResource.Name, "NamespacedName", diff --git a/internal/s3/client/impl/minioS3Client.go b/internal/s3/client/impl/minioS3Client.go index 5f53b0f..85dfa8b 100644 --- a/internal/s3/client/impl/minioS3Client.go +++ b/internal/s3/client/impl/minioS3Client.go @@ -539,7 +539,7 @@ func (minioS3Client *MinioS3Client) RemovePoliciesFromUser( } s3Logger.Error( err, - "an error occurred when attaching a policy to the user", + "an error occurred when detaching a policy to the user", "code", errAsResp.Code, ) From 16806356bc148954ce7268a1680ebc66d0b26993 Mon Sep 17 00:00:00 2001 From: Quentin GODRON Date: Tue, 9 Sep 2025 17:41:55 +0200 Subject: [PATCH 2/2] try to delete possible whitespaces so that empty result return an empty list --- internal/s3/client/impl/minioS3Client.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/s3/client/impl/minioS3Client.go b/internal/s3/client/impl/minioS3Client.go index 85dfa8b..7e54f7d 100644 --- a/internal/s3/client/impl/minioS3Client.go +++ b/internal/s3/client/impl/minioS3Client.go @@ -469,10 +469,11 @@ func (minioS3Client *MinioS3Client) GetUserPolicies(accessKey string) ([]string, return []string{}, err } - if len(strings.Split(userInfo.PolicyName, ",")) == 1 && slices.Contains(strings.Split(userInfo.PolicyName, ","), "") { + userPolicies := strings.Split(strings.TrimSpace(userInfo.PolicyName), ",") + if len(userPolicies) == 1 && slices.Contains(userPolicies, "") { return []string{}, nil } - return strings.Split(userInfo.PolicyName, ","), nil + return userPolicies, nil } func (minioS3Client *MinioS3Client) CheckUserCredentialsValid(