mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 02:15:02 +01:00
mount: compare permissions against local ids without mapping them again (#12726)
* mount: compare permissions against local ids without mapping them again Access, open and create (without -defaultPermissions) ran FilerToLocal on entries that maybeReadEntry and maybeLoadEntry already return in local ids. Under a uid/gid map where a local id is also a mapped filer id, the owner was mapped twice and the check refused the file's own owner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: cache a deferred create's placeholder in filer ids The meta cache stores filer uid/gid and maps them to local ids on every read, but createRegularFile cached the deferred or writeback placeholder with the caller's local ids. The second mapping in the permission checks used to cancel that out under a swapping id map; without it the owner of a placeholder was refused. Cache a mapped clone and keep the handle's entry in local ids. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: test that a deferred create returns its entry in local ids Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b64895ed0a
commit
ecbf7af1ca
4 files changed
+80
-19
No files matched your search
@@ -91,13 +91,7 @@ func (wfs *WFS) Access(cancel <-chan struct{}, input *fuse.AccessIn) (code fuse.
|
||||
if entry == nil || entry.Attributes == nil {
|
||||
return fuse.EIO
|
||||
}
|
||||
// Map entry uid/gid from filer-space to local-space so the permission
|
||||
// check compares like with like (caller uid/gid from FUSE are local).
|
||||
fileUid, fileGid := entry.Attributes.Uid, entry.Attributes.Gid
|
||||
if wfs.option.UidGidMapper != nil {
|
||||
fileUid, fileGid = wfs.option.UidGidMapper.FilerToLocal(fileUid, fileGid)
|
||||
}
|
||||
if hasAccess(input.Uid, input.Gid, fileUid, fileGid, entry.Attributes.FileMode, input.Mask) {
|
||||
if hasAccess(input.Uid, input.Gid, entry.Attributes.Uid, entry.Attributes.Gid, entry.Attributes.FileMode, input.Mask) {
|
||||
return fuse.OK
|
||||
}
|
||||
return fuse.EACCES
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package mount
|
||||
|
||||
import (
|
||||
"context"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/go-fuse/v2/fuse"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/filer"
|
||||
"github.com/seaweedfs/seaweedfs/weed/mount/meta_cache"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
)
|
||||
|
||||
// newSwappedIdMapWFS mounts with a uid/gid map whose local ids are also
|
||||
// mapped filer ids, and caches a directory and a file owned on the filer by
|
||||
// 5000:6000, which is the local caller 123:456.
|
||||
func newSwappedIdMapWFS(t *testing.T) (wfs *WFS, fileInode uint64) {
|
||||
t.Helper()
|
||||
wfs, _ = newCreateTestWFS(t)
|
||||
mapper, err := meta_cache.NewUidGidMapper("123:5000,5000:123", "456:6000,6000:456")
|
||||
if err != nil {
|
||||
t.Fatalf("create uid/gid mapper: %v", err)
|
||||
}
|
||||
*wfs.option.UidGidMapper = *mapper
|
||||
now := time.Now().Unix()
|
||||
for _, e := range []*filer_pb.Entry{
|
||||
{Name: "owned", IsDirectory: true, Attributes: &filer_pb.FuseAttributes{FileMode: uint32(0o700 | 1<<31), Uid: 5000, Gid: 6000, Mtime: now, Crtime: now}},
|
||||
{Name: "owned.txt", Attributes: &filer_pb.FuseAttributes{FileMode: 0o600, Uid: 5000, Gid: 6000, Mtime: now, Crtime: now}},
|
||||
} {
|
||||
if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry("/", e), 0); err != nil {
|
||||
t.Fatalf("cache %s: %v", e.Name, err)
|
||||
}
|
||||
}
|
||||
fileInode = wfs.inodeToPath.Lookup(util.FullPath("/owned.txt"), now, false, false, 0, true)
|
||||
return wfs, fileInode
|
||||
}
|
||||
|
||||
func TestPermissionChecksUseLocalOwnerUnderIdMap(t *testing.T) {
|
||||
wfs, fileInode := newSwappedIdMapWFS(t)
|
||||
caller := fuse.Caller{Owner: fuse.Owner{Uid: 123, Gid: 456}}
|
||||
|
||||
if st := wfs.Access(make(chan struct{}), &fuse.AccessIn{
|
||||
InHeader: fuse.InHeader{NodeId: fileInode, Caller: caller},
|
||||
Mask: fuse.R_OK | fuse.W_OK,
|
||||
}); st != fuse.OK {
|
||||
t.Fatalf("Access by the owner = %v, want OK", st)
|
||||
}
|
||||
|
||||
fh, _, st := wfs.AcquireHandle(context.Background(), fileInode, syscall.O_RDWR, 123, 456)
|
||||
if st != fuse.OK {
|
||||
t.Fatalf("open by the owner = %v, want OK", st)
|
||||
}
|
||||
wfs.ReleaseHandle(fh.fh)
|
||||
|
||||
if _, _, st := wfs.createRegularFile(context.Background(), util.FullPath("/owned"), "new.txt", 0o600, 123, 456, 0, true, true); st != fuse.OK {
|
||||
t.Fatalf("create in the owner's directory = %v, want OK", st)
|
||||
}
|
||||
|
||||
// A deferred create's cached placeholder answers for its owner too.
|
||||
placeholder, created, st := wfs.createRegularFile(context.Background(), util.FullPath("/"), "pending.txt", 0o600, 123, 456, 0, true, true)
|
||||
if st != fuse.OK {
|
||||
t.Fatalf("deferred create = %v, want OK", st)
|
||||
}
|
||||
if got := created.GetAttributes(); got.GetUid() != 123 || got.GetGid() != 456 {
|
||||
t.Fatalf("deferred create returned %d:%d, want local 123:456", got.GetUid(), got.GetGid())
|
||||
}
|
||||
wfs.inodeToPath.Lookup(util.FullPath("/pending.txt"), time.Now().Unix(), false, false, placeholder, true)
|
||||
if st := wfs.Access(make(chan struct{}), &fuse.AccessIn{
|
||||
InHeader: fuse.InHeader{NodeId: placeholder, Caller: caller},
|
||||
Mask: fuse.R_OK | fuse.W_OK,
|
||||
}); st != fuse.OK {
|
||||
t.Fatalf("Access to a deferred create by its owner = %v, want OK", st)
|
||||
}
|
||||
}
|
||||
@@ -397,13 +397,7 @@ func (wfs *WFS) createRegularFile(ctx context.Context, dirFullPath util.FullPath
|
||||
return 0, nil, fuse.EIO
|
||||
}
|
||||
if !wfs.option.DefaultPermissions {
|
||||
// Map parent dir uid/gid from filer-space to local-space so the
|
||||
// permission check compares like with like (caller uid/gid are local).
|
||||
parentUid, parentGid := parentEntry.Attributes.Uid, parentEntry.Attributes.Gid
|
||||
if wfs.option.UidGidMapper != nil {
|
||||
parentUid, parentGid = wfs.option.UidGidMapper.FilerToLocal(parentUid, parentGid)
|
||||
}
|
||||
if !hasAccess(uid, gid, parentUid, parentGid, parentEntry.Attributes.FileMode, fuse.W_OK|fuse.X_OK) {
|
||||
if !hasAccess(uid, gid, parentEntry.Attributes.Uid, parentEntry.Attributes.Gid, parentEntry.Attributes.FileMode, fuse.W_OK|fuse.X_OK) {
|
||||
return 0, nil, fuse.Status(syscall.EACCES)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,11 +60,7 @@ func (wfs *WFS) AcquireHandle(ctx context.Context, inode uint64, flags, uid, gid
|
||||
// default_permissions the kernel already enforced them before this
|
||||
// open, so the check (and its supplementary-group lookup) is redundant.
|
||||
if !wfs.option.DefaultPermissions && entry != nil && entry.Attributes != nil {
|
||||
fileUid, fileGid := entry.Attributes.Uid, entry.Attributes.Gid
|
||||
if wfs.option.UidGidMapper != nil {
|
||||
fileUid, fileGid = wfs.option.UidGidMapper.FilerToLocal(fileUid, fileGid)
|
||||
}
|
||||
if mask := openFlagsToAccessMask(flags); mask != 0 && !hasAccess(uid, gid, fileUid, fileGid, entry.Attributes.FileMode, mask) {
|
||||
if mask := openFlagsToAccessMask(flags); mask != 0 && !hasAccess(uid, gid, entry.Attributes.Uid, entry.Attributes.Gid, entry.Attributes.FileMode, mask) {
|
||||
return nil, 0, fuse.EACCES
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user