From 89b76a87b645da7c9fd9824eb81217440a9f51b1 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 9 Oct 2025 19:24:05 +0300 Subject: [PATCH] Fix root access to VitastorFS files --- src/nfs/nfs_kv_getattr.cpp | 6 ++++++ tests/test_nfs.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/nfs/nfs_kv_getattr.cpp b/src/nfs/nfs_kv_getattr.cpp index a28399b6..d69456f3 100644 --- a/src/nfs/nfs_kv_getattr.cpp +++ b/src/nfs/nfs_kv_getattr.cpp @@ -94,6 +94,10 @@ uint32_t kv_get_access(const authsys_parms & auth_sys, const json11::Json & attr uint32_t uid = attrs["uid"].uint64_value(); uint32_t gid = attrs["gid"].uint64_value(); uint32_t access = 0; + if (!auth_sys.uid) + { + return (ACCESS3_READ|ACCESS3_LOOKUP|ACCESS3_MODIFY|ACCESS3_EXTEND|ACCESS3_DELETE|ACCESS3_EXECUTE); + } if (uid == auth_sys.uid) { access |= ((mode & (1 << 8)) ? ACCESS3_READ|ACCESS3_LOOKUP : 0); @@ -120,6 +124,8 @@ uint32_t kv_get_access(const authsys_parms & auth_sys, const json11::Json & attr bool kv_is_accessible(const authsys_parms & auth_sys, const json11::Json & attrs, uint32_t access) { uint32_t mode = attrs["mode"].is_null() ? (attrs["type"] == "dir" ? 0755 : 0644) : attrs["mode"].uint64_value(); + if (!auth_sys.uid) + return true; uint32_t mask = 1 << (access == ACCESS3_EXECUTE ? 0 : (access == ACCESS3_MODIFY || access == ACCESS3_EXTEND || access == ACCESS3_DELETE ? 1 : 2)); if (mode & mask) diff --git a/tests/test_nfs.sh b/tests/test_nfs.sh index 00f9c5e4..b4a00cee 100755 --- a/tests/test_nfs.sh +++ b/tests/test_nfs.sh @@ -13,6 +13,12 @@ sudo mount localhost:/ ./testdata/nfs -o port=2050,mountport=2050,nfsvers=3,soft MNT=$(pwd)/testdata/nfs trap "sudo umount -f $MNT"' || true; kill -9 $(jobs -p)' EXIT +touch ./testdata/nfs/f1 +chown 1000:1000 ./testdata/nfs/f1 +chmod 600 ./testdata/nfs/f1 +sudo cat ./testdata/nfs/f1 +rm ./testdata/nfs/f1 + # write small file ls -l ./testdata/nfs dd if=/dev/urandom of=./testdata/f1 bs=100k count=1