]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/pubsub: CreateTopic validates topic name 56670/head
authorCasey Bodley <cbodley@redhat.com>
Thu, 28 Mar 2024 17:47:30 +0000 (13:47 -0400)
committerCasey Bodley <cbodley@redhat.com>
Wed, 3 Apr 2024 14:23:19 +0000 (10:23 -0400)
existing topics may have invalid names, so this is only enforced by
CreateTopic

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

PendingReleaseNotes
src/rgw/rgw_rest_pubsub.cc

index 5c402fcd50cf2c375818382fa1297e30803bde8e..a3a26e2fe65339a7a26c0db228832d1264c463d1 100644 (file)
@@ -111,6 +111,9 @@ CephFS: Disallow delegating preallocated inode ranges to clients. Config
   See https://docs.ceph.com/en/latest/rados/operations/balancer/ for more information.
 * CephFS: Full support for subvolumes and subvolume groups is now available
   for snap_schedule Manager module.
+* RGW: The SNS CreateTopic API now enforces the same topic naming requirements as AWS:
+  Topic names must be made up of only uppercase and lowercase ASCII letters, numbers,
+  underscores, and hyphens, and must be between 1 and 256 characters long.
 * RBD: When diffing against the beginning of time (`fromsnapname == NULL`) in
   fast-diff mode (`whole_object == true` with `fast-diff` image feature enabled
   and valid), diff-iterate is now guaranteed to execute locally if exclusive
index 191f535d82bd48c31792fd0b650ff7b196a77be4..f915135885f0843ad21dd282fd781890f88b64f7 100644 (file)
@@ -4,6 +4,7 @@
 #include <algorithm>
 #include <boost/tokenizer.hpp>
 #include <optional>
+#include <regex>
 #include "rgw_iam_policy.h"
 #include "rgw_rest_pubsub.h"
 #include "rgw_pubsub_push.h"
@@ -57,6 +58,23 @@ bool validate_and_update_endpoint_secret(rgw_pubsub_dest& dest, CephContext *cct
   return true;
 }
 
+bool validate_topic_name(const std::string& name, std::string& message)
+{
+  constexpr size_t max_topic_name_length = 256;
+  if (name.size() > max_topic_name_length) {
+    message = "Name cannot be longer than 256 characters";
+    return false;
+  }
+
+  std::regex pattern("[A-Za-z0-9_-]+");
+  if (!std::regex_match(name, pattern)) {
+    message = "Name must be made up of only uppercase and lowercase "
+        "ASCII letters, numbers, underscores, and hyphens";
+    return false;
+  }
+  return true;
+}
+
 bool topic_has_endpoint_secret(const rgw_pubsub_topic& topic) {
     return topic.dest.stored_secret;
 }
@@ -133,8 +151,7 @@ class RGWPSCreateTopicOp : public RGWOp {
 
   int get_params() {
     topic_name = s->info.args.get("Name");
-    if (topic_name.empty()) {
-      ldpp_dout(this, 1) << "CreateTopic Action 'Name' argument is missing" << dendl;
+    if (!validate_topic_name(topic_name, s->err.message)) {
       return -EINVAL;
     }