]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: PutObjectLockConfiguration can enable object lock on existing buckets 62063/head
authorCasey Bodley <cbodley@redhat.com>
Thu, 20 Feb 2025 19:42:37 +0000 (14:42 -0500)
committerCasey Bodley <cbodley@redhat.com>
Mon, 10 Mar 2025 16:05:21 +0000 (12:05 -0400)
AWS now allows PutObjectLockConfiguration on existing buckets, even if
x-amz-bucket-object-lock-enabled was not specified on bucket creation

object lock still requires the bucket to be versioning-enabled, so such
requests are rejected otherwise. if the bucket is versioning-enabled but
not object-lock-enabled, enable the BUCKET_OBJ_LOCK_ENABLED flag

this logic was moved into retry_raced_bucket_write() in case the request
races with PutBucketVersioning

Fixes: https://tracker.ceph.com/issues/70013
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit b454668983fe45687f9f77c75628a4d641dd545b)

Conflicts:
src/rgw/rgw_op.cc put_info() doesn't take optional_yield

PendingReleaseNotes
src/rgw/rgw_op.cc

index 82755aceeed5888cd966bd39cafdda4861073f73..fc5292aad065c0eb094f4bd7df2460e0a461c955 100644 (file)
@@ -4,6 +4,8 @@
 * RBD: The ``try-netlink`` mapping option for rbd-nbd has become the default
   and is now deprecated. If the NBD netlink interface is not supported by the
   kernel, then the mapping is retried using the legacy ioctl interface.
+* RGW: PutObjectLockConfiguration can now be used to enable S3 Object Lock on an
+  existing versioning-enabled bucket that was not created with Object Lock enabled.
 
 >=18.2.4
 --------
index 09f1597962943a1fea0f1a72754b935e46b11e5c..54de4256cde1651faa4053d9308053a54e08b37b 100644 (file)
@@ -8381,8 +8381,9 @@ int RGWPutBucketObjectLock::verify_permission(optional_yield y)
 
 void RGWPutBucketObjectLock::execute(optional_yield y)
 {
-  if (!s->bucket->get_info().obj_lock_enabled()) {
-    s->err.message = "object lock configuration can't be set if bucket object lock not enabled";
+  if (!s->bucket->get_info().versioning_enabled()) {
+    s->err.message = "Object lock cannot be enabled unless the "
+        "bucket has versioning enabled";
     ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl;
     op_ret = -ERR_INVALID_BUCKET_STATE;
     return;
@@ -8424,6 +8425,17 @@ void RGWPutBucketObjectLock::execute(optional_yield y)
   }
 
   op_ret = retry_raced_bucket_write(this, s->bucket.get(), [this] {
+    if (!s->bucket->get_info().obj_lock_enabled()) {
+      // automatically enable object lock if the bucket is versioning-enabled
+      if (!s->bucket->get_info().versioning_enabled()) {
+        s->err.message = "Object lock cannot be enabled unless the "
+            "bucket has versioning enabled";
+        ldpp_dout(this, 4) << "ERROR: " << s->err.message << dendl;
+        return -ERR_INVALID_BUCKET_STATE;
+      }
+      s->bucket->get_info().flags |= BUCKET_OBJ_LOCK_ENABLED;
+    }
+
     s->bucket->get_info().obj_lock = obj_lock;
     op_ret = s->bucket->put_info(this, false, real_time());
     return op_ret;