src/mds: allow passing fs names and path in same cap

Allow passing path along with fs names and capspec while creating an MDS
cap. The new syntax looks as follows -

allow rw fsname=<fsname> path=<path>

To provide caps for multiple file systems, pass the same phrase multiple
times separated by commas -

allow rw fsname=<fsname1> path=<path1>, allow rw fsname=<fsname2>
path=<path2>, ...

This commit also makes sure that the old syntax 'allow rw path=<path>'
is supported for backwards compatibility. The old syntax would imply
'allow rw fsname=* path=<path>' and would grant read-write permission for
all FSs containing the path <path>.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
This commit is contained in:
Rishabh Dave 2020-03-17 18:09:47 +05:30
parent 91d5715be6
commit f93c4c7188
4 changed files with 18 additions and 10 deletions

View File

@ -157,3 +157,6 @@
and operate on specific Ceph file systems. The FS can be specificed using and operate on specific Ceph file systems. The FS can be specificed using
``fsname`` in caps. This also affects subcommand ``fs authorize``, the caps ``fsname`` in caps. This also affects subcommand ``fs authorize``, the caps
produce by it will be specific to the FS name passed in its arguments. produce by it will be specific to the FS name passed in its arguments.
* fs: "fs authorize" now sets MON cap to "allow <perm> fsname=<fsname>"
instead of setting it to "allow r" all the time.

View File

@ -73,6 +73,7 @@ struct MDSCapParser : qi::grammar<Iterator, MDSAuthCaps()>
match = -( match = -(
(uid >> gidlist)[_val = phoenix::construct<MDSCapMatch>(_1, _2)] | (uid >> gidlist)[_val = phoenix::construct<MDSCapMatch>(_1, _2)] |
(path >> uid >> gidlist)[_val = phoenix::construct<MDSCapMatch>(_1, _2, _3)] | (path >> uid >> gidlist)[_val = phoenix::construct<MDSCapMatch>(_1, _2, _3)] |
(fs_name >> path)[_val = phoenix::construct<MDSCapMatch>(_2, _1)] |
(path)[_val = phoenix::construct<MDSCapMatch>(_1)] | (path)[_val = phoenix::construct<MDSCapMatch>(_1)] |
(fs_name)[_val = phoenix::construct<MDSCapMatch>(std::string(), (fs_name)[_val = phoenix::construct<MDSCapMatch>(std::string(),
_1)]); _1)]);

View File

@ -77,6 +77,7 @@ extern const mds_gid_t MDS_GID_NONE;
typedef int32_t fs_cluster_id_t; typedef int32_t fs_cluster_id_t;
constexpr fs_cluster_id_t FS_CLUSTER_ID_NONE = -1; constexpr fs_cluster_id_t FS_CLUSTER_ID_NONE = -1;
// The namespace ID of the anonymous default filesystem from legacy systems // The namespace ID of the anonymous default filesystem from legacy systems
constexpr fs_cluster_id_t FS_CLUSTER_ID_ANONYMOUS = 0; constexpr fs_cluster_id_t FS_CLUSTER_ID_ANONYMOUS = 0;

View File

@ -1639,21 +1639,24 @@ bool AuthMonitor::prepare_command(MonOpRequestRef op)
mds_cap_string += mds_cap_string.empty() ? "" : ", "; mds_cap_string += mds_cap_string.empty() ? "" : ", ";
mds_cap_string += "allow " + cap; mds_cap_string += "allow " + cap;
if (filesystem != "*" && filesystem != "all") {
auto fs = mon->mdsmon()->get_fsmap().get_filesystem(filesystem);
if (!fs) {
ss << "filesystem " << filesystem << " does not exist.";
err = -EINVAL;
goto done;
} else {
mds_cap_string += " fsname=" + std::string(fs->mds_map.get_fs_name());
}
}
if (path != "/") { if (path != "/") {
mds_cap_string += " path=" + path; mds_cap_string += " path=" + path;
} }
} }
if (filesystem != "*" && filesystem != "all") { osd_cap_string += osd_cap_string.empty() ? "" : ", ";
auto fs = mon->mdsmon()->get_fsmap().get_filesystem(filesystem);
if (!fs) {
ss << "filesystem " << filesystem << " does not exist.";
err = -EINVAL;
goto done;
}
}
osd_cap_string += osd_cap_string.empty()? "" : ", ";
osd_cap_string += "allow " + osd_cap_wanted osd_cap_string += "allow " + osd_cap_wanted
+ " tag " + pg_pool_t::APPLICATION_NAME_CEPHFS + " tag " + pg_pool_t::APPLICATION_NAME_CEPHFS
+ " data=" + filesystem; + " data=" + filesystem;