Skip to content

Commit

Permalink
mgr/volumes: check for string values in uid/gid
Browse files Browse the repository at this point in the history
chown allows strings as per bbbfb44,
which caused this error. Eventhough uid/gid are input as CephInt, the
qa tests can pass in only string values to _fs_cmd. So try converting
the incoming uid/gid to int in create_subvolume and create_group.
It might be a valid string.

Fixes: https://tracker.ceph.com/issues/43038
Signed-off-by: Jos Collin <jcollin@redhat.com>
  • Loading branch information
joscollin committed Dec 9, 2019
1 parent 22a9a28 commit 4c1029b
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/pybind/mgr/volumes/fs/subvolume.py
Expand Up @@ -109,13 +109,23 @@ def create_subvolume(self, spec, size=None, pool=None, namespace_isolated=True,
groupstat = self.fs.stat(spec.group_path)
if uid is None:
uid = int(groupstat.st_uid)
elif uid < 0:
raise VolumeException(-errno.EINVAL, "Provide a valid uid")
else:
try:
uid = int(uid)
if uid < 0:
raise ValueError
except ValueError:
raise VolumeException(-errno.EINVAL, "Invalid uid")

if gid is None:
gid = int(groupstat.st_gid)
elif gid < 0:
raise VolumeException(-errno.EINVAL, "Provide a valid gid")
else:
try:
gid = int(gid)
if gid < 0:
raise ValueError
except ValueError:
raise VolumeException(-errno.EINVAL, "Invalid gid")

try:
self.fs.chown(subvolpath, uid, gid)
Expand Down Expand Up @@ -302,13 +312,23 @@ def create_group(self, spec, pool=None, uid=None, gid=None, mode=0o755):

if uid is None:
uid = 0
elif uid < 0:
raise VolumeException(-errno.EINVAL, "Provide a valid uid")
else:
try:
uid = int(uid)
if uid < 0:
raise ValueError
except ValueError:
raise VolumeException(-errno.EINVAL, "Invalid uid")

if gid is None:
gid = 0
elif gid < 0:
raise VolumeException(-errno.EINVAL, "Provide a valid gid")
else:
try:
gid = int(gid)
if gid < 0:
raise ValueError
except ValueError:
raise VolumeException(-errno.EINVAL, "Invalid gid")

try:
self.fs.chown(path, uid, gid)
Expand Down

0 comments on commit 4c1029b

Please sign in to comment.