Skip to content

Commit

Permalink
rgw/pubsub: CreateTopic validates topic name
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cbodley committed Mar 28, 2024
1 parent 17a4fdb commit ea6a7a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions PendingReleaseNotes
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,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
Expand Down
21 changes: 19 additions & 2 deletions src/rgw/rgw_rest_pubsub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -58,6 +59,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;
}
Expand Down Expand Up @@ -135,8 +153,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;
}

Expand Down

0 comments on commit ea6a7a5

Please sign in to comment.