// </magic>
-void MonCapGrant::expand_profile(EntityName name) const
+void MonCapGrant::expand_profile(int daemon_type, const EntityName& name) const
{
// only generate this list once
if (!profile_grants.empty())
return;
+ if (profile == "read-only") {
+ // grants READ-ONLY caps monitor-wide
+ // 'auth' requires MON_CAP_X even for RO, which we do not grant here.
+ profile_grants.push_back(mon_rwxa_t(MON_CAP_R));
+ return;
+ }
+
+ if (profile == "read-write") {
+ // grants READ-WRITE caps monitor-wide
+ // 'auth' requires MON_CAP_X for all operations, which we do not grant.
+ profile_grants.push_back(mon_rwxa_t(MON_CAP_R | MON_CAP_W));
+ return;
+ }
+
+ switch (daemon_type) {
+ case CEPH_ENTITY_TYPE_MON:
+ expand_profile_mon(name);
+ return;
+ case CEPH_ENTITY_TYPE_MGR:
+ expand_profile_mgr(name);
+ return;
+ }
+}
+
+void MonCapGrant::expand_profile_mgr(const EntityName& name) const
+{
+}
+
+void MonCapGrant::expand_profile_mon(const EntityName& name) const
+{
if (profile == "mon") {
profile_grants.push_back(MonCapGrant("mon", MON_CAP_ALL));
profile_grants.push_back(MonCapGrant("log", MON_CAP_ALL));
profile_grants.push_back(MonCapGrant("pg", MON_CAP_R));
}
- if (profile == "read-only") {
- // grants READ-ONLY caps monitor-wide
- // 'auth' requires MON_CAP_X even for RO, which we do not grant here.
- profile_grants.push_back(mon_rwxa_t(MON_CAP_R));
- }
-
- if (profile == "read-write") {
- // grants READ-WRITE caps monitor-wide
- // 'auth' requires MON_CAP_X for all operations, which we do not grant.
- profile_grants.push_back(mon_rwxa_t(MON_CAP_R | MON_CAP_W));
- }
-
if (profile == "role-definer") {
// grants ALL caps to the auth subsystem, read-only on the
// monitor subsystem and nothing else.
}
mon_rwxa_t MonCapGrant::get_allowed(CephContext *cct,
+ int daemon_type,
EntityName name,
const std::string& s, const std::string& c,
const map<string,string>& c_args) const
{
if (profile.length()) {
- expand_profile(name);
+ expand_profile(daemon_type, name);
mon_rwxa_t a;
for (list<MonCapGrant>::const_iterator p = profile_grants.begin();
p != profile_grants.end(); ++p)
- a = a | p->get_allowed(cct, name, s, c, c_args);
+ a = a | p->get_allowed(cct, daemon_type, name, s, c, c_args);
return a;
}
if (service.length()) {
}
bool MonCap::is_capable(CephContext *cct,
+ int daemon_type,
EntityName name,
const string& service,
const string& command, const map<string,string>& command_args,
}
// check enumerated caps
- allow = allow | p->get_allowed(cct, name, service, command, command_args);
+ allow = allow | p->get_allowed(cct, daemon_type, name, service, command,
+ command_args);
if ((!op_may_read || (allow & MON_CAP_R)) &&
(!op_may_write || (allow & MON_CAP_W)) &&
(!op_may_exec || (allow & MON_CAP_X))) {
ASSERT_TRUE(cap.parse("allow *", NULL));
ASSERT_TRUE(cap.is_allow_all());
- ASSERT_TRUE(cap.is_capable(NULL, EntityName(),
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON, EntityName(),
"foo", "asdf", map<string,string>(), true, true, true));
MonCap cap2;
name.from_str("osd.123");
map<string,string> ca;
- ASSERT_TRUE(cap.is_capable(NULL, name, "osd", "", ca, true, false, false));
- ASSERT_TRUE(cap.is_capable(NULL, name, "osd", "", ca, true, true, false));
- ASSERT_TRUE(cap.is_capable(NULL, name, "osd", "", ca, true, true, true));
- ASSERT_TRUE(cap.is_capable(NULL, name, "osd", "", ca, true, true, true));
- ASSERT_TRUE(cap.is_capable(NULL, name, "mon", "", ca, true, false,false));
-
- ASSERT_FALSE(cap.is_capable(NULL, name, "mds", "", ca, true, true, true));
- ASSERT_FALSE(cap.is_capable(NULL, name, "mon", "", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "osd", "", ca, true, false, false));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "osd", "", ca, true, true, false));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "osd", "", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "osd", "", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "mon", "", ca, true, false,false));
+
+ ASSERT_FALSE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "mds", "", ca, true, true, true));
+ ASSERT_FALSE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "mon", "", ca, true, true, true));
ca.clear();
- ASSERT_FALSE(cap.is_capable(NULL, name, "", "config-key get", ca, true, true, true));
+ ASSERT_FALSE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key get", ca, true, true, true));
ca["key"] = "daemon-private/osd.123";
- ASSERT_FALSE(cap.is_capable(NULL, name, "", "config-key get", ca, true, true, true));
+ ASSERT_FALSE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key get", ca, true, true, true));
ca["key"] = "daemon-private/osd.12/asdf";
- ASSERT_FALSE(cap.is_capable(NULL, name, "", "config-key get", ca, true, true, true));
+ ASSERT_FALSE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key get", ca, true, true, true));
ca["key"] = "daemon-private/osd.123/";
- ASSERT_TRUE(cap.is_capable(NULL, name, "", "config-key get", ca, true, true, true));
- ASSERT_TRUE(cap.is_capable(NULL, name, "", "config-key get", ca, true, true, true));
- ASSERT_TRUE(cap.is_capable(NULL, name, "", "config-key get", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key get", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key get", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key get", ca, true, true, true));
ca["key"] = "daemon-private/osd.123/foo";
- ASSERT_TRUE(cap.is_capable(NULL, name, "", "config-key get", ca, true, true, true));
- ASSERT_TRUE(cap.is_capable(NULL, name, "", "config-key put", ca, true, true, true));
- ASSERT_TRUE(cap.is_capable(NULL, name, "", "config-key exists", ca, true, true, true));
- ASSERT_TRUE(cap.is_capable(NULL, name, "", "config-key delete", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key get", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key put", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key exists", ca, true, true, true));
+ ASSERT_TRUE(cap.is_capable(NULL, CEPH_ENTITY_TYPE_MON,
+ name, "", "config-key delete", ca, true, true, true));
}