From: Adam C. Emerson Date: Fri, 16 Nov 2018 19:42:33 +0000 (-0500) Subject: rgw: Don't treat colons specially in resource part of ARN X-Git-Tag: v12.2.11~72^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=62c0a87affaac3e26c8bda1c993234bf13cd711e;p=ceph.git rgw: Don't treat colons specially in resource part of ARN It is very important to prevent wildcards from matching across colons in some parts of the ARN. But it is equally important to allow them to do so in the last field. Fixes: http://tracker.ceph.com/issues/23817 Signed-off-by: Adam C. Emerson (cherry picked from commit 07c478b750c56d7dbbda42507a19c00d0fdedc15) --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 96007f39856..3ee90535f1f 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -1870,12 +1870,15 @@ bool match_policy(boost::string_view pattern, boost::string_view input, { const uint32_t flag2 = flag & (MATCH_POLICY_ACTION|MATCH_POLICY_ARN) ? MATCH_CASE_INSENSITIVE : 0; + const bool colonblocks = !(flag & (MATCH_POLICY_RESOURCE | + MATCH_POLICY_STRING)); const auto npos = boost::string_view::npos; boost::string_view::size_type last_pos_input = 0, last_pos_pattern = 0; while (true) { - auto cur_pos_input = input.find(":", last_pos_input); - auto cur_pos_pattern = pattern.find(":", last_pos_pattern); + auto cur_pos_input = colonblocks ? input.find(":", last_pos_input) : npos; + auto cur_pos_pattern = + colonblocks ? pattern.find(":", last_pos_pattern) : npos; auto substr_input = input.substr(last_pos_input, cur_pos_input); auto substr_pattern = pattern.substr(last_pos_pattern, cur_pos_pattern); diff --git a/src/rgw/rgw_iam_policy.cc b/src/rgw/rgw_iam_policy.cc index 9f31db2eaad..331802144db 100644 --- a/src/rgw/rgw_iam_policy.cc +++ b/src/rgw/rgw_iam_policy.cc @@ -381,7 +381,7 @@ bool ARN::match(const ARN& candidate) const { return false; } - if (!match_policy(resource, candidate.resource, MATCH_POLICY_ARN)) { + if (!match_policy(resource, candidate.resource, MATCH_POLICY_RESOURCE)) { return false; } diff --git a/src/test/rgw/test_rgw_iam_policy.cc b/src/test/rgw/test_rgw_iam_policy.cc index 738ce1b78ef..3bae06f47ee 100644 --- a/src/test/rgw/test_rgw_iam_policy.cc +++ b/src/test/rgw/test_rgw_iam_policy.cc @@ -942,7 +942,7 @@ TEST(MatchPolicy, Resource) EXPECT_TRUE(match_policy("a:b:c", "a:b:c", flag)); EXPECT_FALSE(match_policy("a:b:c", "A:B:C", flag)); // case sensitive EXPECT_TRUE(match_policy("a:*:e", "a:bcd:e", flag)); - EXPECT_FALSE(match_policy("a:*", "a:b:c", flag)); // cannot span segments + EXPECT_TRUE(match_policy("a:*", "a:b:c", flag)); // can span segments } TEST(MatchPolicy, ARN) @@ -960,5 +960,5 @@ TEST(MatchPolicy, String) EXPECT_TRUE(match_policy("a:b:c", "a:b:c", flag)); EXPECT_FALSE(match_policy("a:b:c", "A:B:C", flag)); // case sensitive EXPECT_TRUE(match_policy("a:*:e", "a:bcd:e", flag)); - EXPECT_FALSE(match_policy("a:*", "a:b:c", flag)); // cannot span segments + EXPECT_TRUE(match_policy("a:*", "a:b:c", flag)); // can span segments }