Skip to content

Commit a683dec

Browse files
authored
Merge pull request #54 from DClabaut/51-fix-create-user-before-policy
fix: Infinite loop if user has been created without ListBucket permission
2 parents 71574e0 + a4ea3c9 commit a683dec

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,22 @@ spec:
205205
# Content of the policy, as a multiline string
206206
# This should be IAM compliant JSON - follow the guidelines of the actual
207207
# S3 provider you're using, as sometimes only a subset is available.
208+
# The first Statement (Allow ListBucket) should be applied to every user,
209+
# as s3-operator uses this call to verify that credentials are valid when
210+
# reconciling an existing user.
208211
policyContent: >-
209212
{
210213
"Version": "2012-10-17",
211214
"Statement": [
215+
{
216+
"Effect": "Allow",
217+
"Action": [
218+
"s3:ListBucket"
219+
],
220+
"Resource": [
221+
"arn:aws:s3:::*"
222+
]
223+
},
212224
{
213225
"Effect": "Allow",
214226
"Action": [

controllers/user_controller.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,30 +154,6 @@ func (r *S3UserReconciler) handleS3ExistingUser(ctx context.Context, userResourc
154154
return r.handleS3NewUser(ctx, userResource)
155155
}
156156

157-
// If a matching secret is found, then we check if it is still valid, as in : do the credentials it
158-
// contains still allow authenticating the S3User on the backend ? If not, the user is deleted and recreated.
159-
// credentialsValid, err := r.S3Client.CheckUserCredentialsValid(userResource.Name, userResource.Spec.AccessKey, string(userOwnedSecret.Data["secretKey"]))
160-
credentialsValid, err := r.S3Client.CheckUserCredentialsValid(userResource.Name, string(userOwnedSecret.Data["accessKey"]), string(userOwnedSecret.Data["secretKey"]))
161-
if err != nil {
162-
logger.Error(err, "An error occurred when checking if user credentials were valid", "user", userResource.Name)
163-
return r.setS3UserStatusConditionAndUpdate(ctx, userResource, "OperatorFailed", metav1.ConditionFalse, "S3UserCredentialsCheckFailed",
164-
fmt.Sprintf("Checking the S3User %s's credentials on S3 server has failed", userResource.Name), err)
165-
}
166-
167-
if !credentialsValid {
168-
logger.Info("The secret containing the credentials will be deleted, and the user will be deleted from the S3 backend, then recreated (through another reconcile)")
169-
r.deleteSecret(ctx, &userOwnedSecret)
170-
err = r.S3Client.DeleteUser(userResource.Spec.AccessKey)
171-
if err != nil {
172-
logger.Error(err, "Could not delete user on S3 server", "user", userResource.Name)
173-
return r.setS3UserStatusConditionAndUpdate(ctx, userResource, "OperatorFailed", metav1.ConditionFalse, "S3UserDeletionFailed",
174-
fmt.Sprintf("Deletion of S3user %s on S3 server has failed", userResource.Name), err)
175-
}
176-
177-
return r.handleS3NewUser(ctx, userResource)
178-
179-
}
180-
181157
// --- End Secret management section
182158

183159
logger.Info("Checking user policies")
@@ -224,6 +200,30 @@ func (r *S3UserReconciler) handleS3ExistingUser(ctx context.Context, userResourc
224200
}
225201
}
226202

203+
// If a matching secret is found, then we check if it is still valid, as in : do the credentials it
204+
// contains still allow authenticating the S3User on the backend ? If not, the user is deleted and recreated.
205+
// credentialsValid, err := r.S3Client.CheckUserCredentialsValid(userResource.Name, userResource.Spec.AccessKey, string(userOwnedSecret.Data["secretKey"]))
206+
credentialsValid, err := r.S3Client.CheckUserCredentialsValid(userResource.Name, string(userOwnedSecret.Data["accessKey"]), string(userOwnedSecret.Data["secretKey"]))
207+
if err != nil {
208+
logger.Error(err, "An error occurred when checking if user credentials were valid", "user", userResource.Name)
209+
return r.setS3UserStatusConditionAndUpdate(ctx, userResource, "OperatorFailed", metav1.ConditionFalse, "S3UserCredentialsCheckFailed",
210+
fmt.Sprintf("Checking the S3User %s's credentials on S3 server has failed", userResource.Name), err)
211+
}
212+
213+
if !credentialsValid {
214+
logger.Info("The secret containing the credentials will be deleted, and the user will be deleted from the S3 backend, then recreated (through another reconcile)")
215+
r.deleteSecret(ctx, &userOwnedSecret)
216+
err = r.S3Client.DeleteUser(userResource.Spec.AccessKey)
217+
if err != nil {
218+
logger.Error(err, "Could not delete user on S3 server", "user", userResource.Name)
219+
return r.setS3UserStatusConditionAndUpdate(ctx, userResource, "OperatorFailed", metav1.ConditionFalse, "S3UserDeletionFailed",
220+
fmt.Sprintf("Deletion of S3user %s on S3 server has failed", userResource.Name), err)
221+
}
222+
223+
return r.handleS3NewUser(ctx, userResource)
224+
225+
}
226+
227227
logger.Info("User was reconciled without error")
228228

229229
// Re-fetch the S3User to ensure we have the latest state after updating the secret

0 commit comments

Comments
 (0)