{
if (m.auid != -1LL) {
out << "auid " << m.auid << " ";
- } else if (!m.pool_namespace.pool_name.empty() || m.pool_namespace.nspace) {
+ }
+
+ if (!m.pool_namespace.pool_name.empty() || m.pool_namespace.nspace) {
out << m.pool_namespace;
- } else if (!m.pool_tag.application.empty()) {
+ }
+
+ if (!m.pool_tag.application.empty()) {
out << m.pool_tag;
}
{
std::vector<bool> class_allowed(classes.size(), false);
for (auto &grant : grants) {
- if (grant.is_capable(pool_name, ns, pool_auid, application_metadata, object, op_may_read,
- op_may_write, classes, &class_allowed)) {
+ if (grant.is_capable(pool_name, ns, pool_auid, application_metadata,
+ object, op_may_read, op_may_write, classes,
+ &class_allowed)) {
return true;
}
}
match = (
pooltag [_val = phoenix::construct<OSDCapMatch>(_1)] |
+ (nspace >> pooltag) [_val = phoenix::construct<OSDCapMatch>(_1, _2)] |
(auid >> object_prefix) [_val = phoenix::construct<OSDCapMatch>(_1, _2)] |
(pool_name >> nspace >> object_prefix) [_val = phoenix::construct<OSDCapMatch>(_1, _2, _3)] |
- (pool_name >> object_prefix) [_val = phoenix::construct<OSDCapMatch>(_1, _2)]);
+ (pool_name >> object_prefix) [_val = phoenix::construct<OSDCapMatch>(_1, _2)]
+ );
// rwxa := * | [r][w][x] [class-read] [class-write]
rwxa =
return false;
}
-
"allow pool foo namespace=nfoo rwx ; allow pool bar namespace=nbar r",
"allow pool foo namespace nfoo rwx ;allow pool bar namespace nbar r",
"allow pool foo namespace=nfoo rwx; allow pool bar namespace nbar object_prefix rbd r",
+ "allow rwx namespace=nfoo tag cephfs data=cephfs_a",
+ "allow rwx namespace foo tag cephfs data =cephfs_a",
"allow pool foo namespace=nfoo* rwx",
"allow pool foo namespace=\"\" rwx; allow pool bar namespace='' object_prefix rbd r",
"allow pool foo namespace \"\" rwx; allow pool bar namespace '' object_prefix rbd r",
ASSERT_TRUE(cap.is_capable("foo", "", 0, {{"application", {{"foo", "bar"}, {"key2", "value"}}}, {"app2", {{"foo", "bar"}}}}, "foo", true, true, {}));
}
+TEST(OSDCap, NSPool)
+{
+ OSDCap cap;
+ ASSERT_TRUE(cap.parse("allow rwx namespace ns tag application key=value", NULL));
+
+ ASSERT_TRUE(cap.is_capable("foo", "ns", 0, {{"application", {{"key", "value"}}}}, "foo", true, true, {}));
+
+ ASSERT_FALSE(cap.is_capable("foo", "", 0, {{"application", {{"key", "value"}}}}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "ns", 0, {}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "ns2", 0, {{"application", {{"key", "value"}}}}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "ns", 0, {{"application", {{"key", "value2"}}}}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "ns", 0, {{"application", {{"key2", "value"}}}}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "", 0, {}, "foo", true, true, {}));
+}
+
+TEST(OSDCap, NSPoolGlob)
+{
+ OSDCap cap;
+ ASSERT_TRUE(cap.parse("allow rwx namespace ns* tag application key=value", NULL));
+
+ ASSERT_TRUE(cap.is_capable("foo", "ns", 0, {{"application", {{"key", "value"}}}}, "foo", true, true, {}));
+
+ ASSERT_TRUE(cap.is_capable("foo", "ns2", 0, {{"application", {{"key", "value"}}}}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "", 0, {{"application", {{"key", "value"}}}}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "ns", 0, {}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "ns", 0, {{"application", {{"key", "value2"}}}}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "ns", 0, {{"application", {{"key2", "value"}}}}, "foo", true, true, {}));
+ ASSERT_FALSE(cap.is_capable("foo", "", 0, {}, "foo", true, true, {}));
+}
+
TEST(OSDCap, OutputParsed)
{
struct CapsTest {
{"allow class-read object_prefix rbd_children, allow pool libvirt-pool-test rwx",
"osdcap[grant(object_prefix rbd_children class-read),grant(pool libvirt-pool-test rwx)]"},
{"allow rwx tag application key=value",
- "osdcap[grant(app application key key val value rwx)]"}
+ "osdcap[grant(app application key key val value rwx)]"},
+ {"allow rwx namespace ns* tag application key=value",
+ "osdcap[grant(namespace ns* app application key key val value rwx)]"}
};
size_t num_tests = sizeof(test_values) / sizeof(*test_values);