Skip to content

Commit

Permalink
osd/OSDCap: allow rbd.metadata_list method under rbd-read-only profile
Browse files Browse the repository at this point in the history
This was missed in commit acc447d ("osd/OSDCap: rbd profile
permits use of rbd.metadata_list cls method") which adjusted only
"profile rbd" OSD cap.  Listing image metadata is an essential part
of opening the image and "profile rbd-read-only" OSD cap must allow
it too.

While at it, constrain the existing grant for rbd profile from "any
object in the pool" to just "rbd_info object in the global namespace of
the pool" as this is where pool-level image metadata actually lives.

Fixes: https://tracker.ceph.com/issues/61382
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit b580cda)
  • Loading branch information
idryomov committed Jun 1, 2023
1 parent 1a16f1a commit 877ca0d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/osd/OSDCap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ void OSDCapGrant::expand_profile()
OSDCapSpec(osd_rwxa_t(OSD_CAP_CLS_R)));
profile_grants.emplace_back(OSDCapMatch(string(), "rbd_mirroring"),
OSDCapSpec(osd_rwxa_t(OSD_CAP_CLS_R)));
profile_grants.emplace_back(OSDCapMatch(profile.pool_namespace.pool_name),
profile_grants.emplace_back(OSDCapMatch(profile.pool_namespace.pool_name,
"", "rbd_info"),
OSDCapSpec("rbd", "metadata_list"));
profile_grants.emplace_back(OSDCapMatch(profile.pool_namespace),
OSDCapSpec(osd_rwxa_t(OSD_CAP_R |
Expand All @@ -348,6 +349,9 @@ void OSDCapGrant::expand_profile()
}
if (profile.name == "rbd-read-only") {
// RBD read-only grant
profile_grants.emplace_back(OSDCapMatch(profile.pool_namespace.pool_name,
"", "rbd_info"),
OSDCapSpec("rbd", "metadata_list"));
profile_grants.emplace_back(OSDCapMatch(profile.pool_namespace),
OSDCapSpec(osd_rwxa_t(OSD_CAP_R |
OSD_CAP_CLS_R)));
Expand Down
43 changes: 43 additions & 0 deletions src/test/osd/osdcap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,49 @@ TEST(OSDCap, AllowProfile) {
{{"rbd", "child_detach", true, true, true}}, addr));
ASSERT_FALSE(cap.is_capable("abc", "", {}, "rbd_header.ABC", false, false,
{{"rbd", "other function", true, true, true}}, addr));

cap.grants.clear();
ASSERT_TRUE(cap.parse("profile rbd pool pool1 namespace ns1", nullptr));
ASSERT_TRUE(cap.is_capable("pool1", "", {}, "rbd_info", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_TRUE(cap.is_capable("pool1", "ns1", {}, "rbd_info", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_FALSE(cap.is_capable("pool1", "ns2", {}, "rbd_info", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_FALSE(cap.is_capable("pool2", "", {}, "rbd_info", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_FALSE(cap.is_capable("pool1", "", {}, "asdf", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_FALSE(cap.is_capable("pool1", "", {}, "rbd_info", false, false,
{{"rbd", "other_method", true, false, true}},
addr));

cap.grants.clear();
ASSERT_TRUE(cap.parse("profile rbd-read-only pool pool1 namespace ns1",
nullptr));
ASSERT_TRUE(cap.is_capable("pool1", "", {}, "rbd_info", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_TRUE(cap.is_capable("pool1", "ns1", {}, "rbd_info", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_FALSE(cap.is_capable("pool1", "ns2", {}, "rbd_info", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_FALSE(cap.is_capable("pool2", "", {}, "rbd_info", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_FALSE(cap.is_capable("pool1", "", {}, "asdf", false, false,
{{"rbd", "metadata_list", true, false, true}},
addr));
ASSERT_FALSE(cap.is_capable("pool1", "", {}, "rbd_info", false, false,
{{"rbd", "other_method", true, false, true}},
addr));
}

TEST(OSDCap, network) {
Expand Down

0 comments on commit 877ca0d

Please sign in to comment.