Skip to content

Commit 5f3815e

Browse files
committed
mon/OSDMonitor: relax cap enforcement for unmanaged snapshots
Since commit 4972e05 ("mon/OSDMonitor: enforce caps when creating/deleting unmanaged snapshots"), a) write access to the MON service, b) write access to the OSD service for a pool or c) permission for "osd pool op unmanaged-snap" command for a pool is required. For "profile rbd" we configure read-only access to the MON service and rely on write access to the OSD service, however the corresponding check in is_osd_writable() is too strict. A OSD cap like "profile rbd namespace=myns" or "allow w namespace=myns" allows write access to myns namespace of any pool, but is_osd_writable() disallows operations with unmanaged snapshots with such a cap because its match.pool_namespace.pool_name.empty() is true. This condition appears to serve as the "doesn't include support for the application tag" guard, but it should actually be match.pool_tag.is_match_all() (or match.pool_tag.application.empty() if open-coded) -- no restriction on the pool name doesn't automatically mean that there is a restriction on the application tag. Fixes: https://tracker.ceph.com/issues/69679 Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 3d94457 commit 5f3815e

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

qa/workunits/rbd/permissions.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ create_users() {
4949
ceph auth get-or-create client.snap_none mon 'allow r' >> $KEYRING
5050
ceph auth get-or-create client.snap_all mon 'allow r' osd 'allow w' >> $KEYRING
5151
ceph auth get-or-create client.snap_pool mon 'allow r' osd 'allow w pool=images' >> $KEYRING
52+
ceph auth get-or-create client.snap_pool_namespace mon 'allow r' osd 'allow w pool=images namespace=foo' >> $KEYRING
53+
ceph auth get-or-create client.snap_namespace mon 'allow r' osd 'allow w namespace=foo' >> $KEYRING
54+
ceph auth get-or-create client.snap_tag mon 'allow r' osd 'allow w tag fooapp *=*' >> $KEYRING
5255
ceph auth get-or-create client.snap_profile_all mon 'allow r' osd 'profile rbd' >> $KEYRING
5356
ceph auth get-or-create client.snap_profile_pool mon 'allow r' osd 'profile rbd pool=images' >> $KEYRING
57+
ceph auth get-or-create client.snap_profile_pool_namespace mon 'allow r' osd 'profile rbd pool=images namespace=foo' >> $KEYRING
58+
ceph auth get-or-create client.snap_profile_namespace mon 'allow r' osd 'profile rbd namespace=foo' >> $KEYRING
5459

5560
ceph auth get-or-create client.mon_write mon 'allow *' >> $KEYRING
5661
}
@@ -208,12 +213,27 @@ test_remove_self_managed_snapshots() {
208213
create_self_managed_snapshot snap_pool images
209214
expect 1 create_self_managed_snapshot snap_pool volumes
210215

216+
create_self_managed_snapshot snap_pool_namespace images
217+
expect 1 create_self_managed_snapshot snap_pool_namespace volumes
218+
219+
create_self_managed_snapshot snap_namespace images
220+
create_self_managed_snapshot snap_namespace volumes
221+
222+
expect 1 create_self_managed_snapshot snap_tag images
223+
expect 1 create_self_managed_snapshot snap_tag volumes
224+
211225
create_self_managed_snapshot snap_profile_all images
212226
create_self_managed_snapshot snap_profile_all volumes
213227

214228
create_self_managed_snapshot snap_profile_pool images
215229
expect 1 create_self_managed_snapshot snap_profile_pool volumes
216230

231+
create_self_managed_snapshot snap_profile_pool_namespace images
232+
expect 1 create_self_managed_snapshot snap_profile_pool_namespace volumes
233+
234+
create_self_managed_snapshot snap_profile_namespace images
235+
create_self_managed_snapshot snap_profile_namespace volumes
236+
217237
# Ensure users cannot delete self-managed snapshots w/o permissions
218238
expect 1 remove_self_managed_snapshot snap_none images
219239
expect 1 remove_self_managed_snapshot snap_none volumes
@@ -224,11 +244,26 @@ test_remove_self_managed_snapshots() {
224244
remove_self_managed_snapshot snap_pool images
225245
expect 1 remove_self_managed_snapshot snap_pool volumes
226246

247+
remove_self_managed_snapshot snap_pool_namespace images
248+
expect 1 remove_self_managed_snapshot snap_pool_namespace volumes
249+
250+
remove_self_managed_snapshot snap_namespace images
251+
remove_self_managed_snapshot snap_namespace volumes
252+
253+
expect 1 remove_self_managed_snapshot snap_tag images
254+
expect 1 remove_self_managed_snapshot snap_tag volumes
255+
227256
remove_self_managed_snapshot snap_profile_all images
228257
remove_self_managed_snapshot snap_profile_all volumes
229258

230259
remove_self_managed_snapshot snap_profile_pool images
231260
expect 1 remove_self_managed_snapshot snap_profile_pool volumes
261+
262+
remove_self_managed_snapshot snap_profile_pool_namespace images
263+
expect 1 remove_self_managed_snapshot snap_profile_pool_namespace volumes
264+
265+
remove_self_managed_snapshot snap_profile_namespace images
266+
remove_self_managed_snapshot snap_profile_namespace volumes
232267
}
233268

234269
test_rbd_support() {

src/mon/OSDMonitor.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,14 @@ bool is_osd_writable(const OSDCapGrant& grant, const std::string* pool_name) {
270270
auto& match = grant.match;
271271
if (match.is_match_all()) {
272272
return true;
273-
} else if (pool_name != nullptr &&
274-
!match.pool_namespace.pool_name.empty() &&
275-
match.pool_namespace.pool_name == *pool_name) {
276-
return true;
273+
} else if (pool_name != nullptr) {
274+
if (!match.pool_namespace.pool_name.empty()) {
275+
if (match.pool_namespace.pool_name == *pool_name) {
276+
return true;
277+
}
278+
} else if (match.pool_tag.is_match_all()) {
279+
return true;
280+
}
277281
}
278282
}
279283
return false;

0 commit comments

Comments
 (0)