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: v14.1.0~756^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=07c478b750c56d7dbbda42507a19c00d0fdedc15;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 --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 466fa42c1354..eb1e9ce5cd7a 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -1938,12 +1938,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 cf3b358cd351..5d38031d0f65 100644 --- a/src/rgw/rgw_iam_policy.cc +++ b/src/rgw/rgw_iam_policy.cc @@ -393,7 +393,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 acfa8f0ae30b..d629baf5936e 100644 --- a/src/test/rgw/test_rgw_iam_policy.cc +++ b/src/test/rgw/test_rgw_iam_policy.cc @@ -1169,7 +1169,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) @@ -1187,5 +1187,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 }