Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/acl: add enable-acl flag and version checking #4421

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ func config(ctx *cli.Context) error {
format.MaxClientVersion = new
clientVer = true
}
case "enable-acl":
// cannot disable
if ctx.Bool(flag) {
format.EnableACL = true
format.MinClientVersion = "1.2.0-A"
}
}
}
if msg.Len() == 0 {
Expand Down
10 changes: 10 additions & 0 deletions cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ func formatManagementFlags() []cli.Flag {
Value: 1,
Usage: "number of days after which removed files will be permanently deleted",
},
&cli.BoolFlag{
Name: "enable-acl",
Value: false,
Usage: "enable POSIX ACL (this flag is irreversible once enabled)",
},
})
}

Expand Down Expand Up @@ -436,7 +441,12 @@ func format(c *cli.Context) error {
DirStats: true,
MetaVersion: meta.MaxVersion,
MinClientVersion: "1.1.0-A",
EnableACL: c.Bool("enable-acl"),
}
if format.EnableACL {
format.MinClientVersion = "1.2.0-A"
}

if format.AccessKey == "" && os.Getenv("ACCESS_KEY") != "" {
format.AccessKey = os.Getenv("ACCESS_KEY")
_ = os.Unsetenv("ACCESS_KEY")
Expand Down
61 changes: 61 additions & 0 deletions cmd/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ import (
"github.com/agiledragon/gomonkey/v2"
"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/juicedata/juicefs/pkg/version"
"github.com/juicedata/juicefs/pkg/vfs"
"github.com/redis/go-redis/v9"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -233,3 +235,62 @@ func Test_configEqual(t *testing.T) {
}
}
}

func tryMountTemp(t *testing.T, bucket *string, extraFormatOpts []string, extraMountOpts []string) error {
_ = resetTestMeta()
testDir := t.TempDir()
if bucket != nil {
*bucket = testDir
}
formatArgs := []string{"", "format", "--bucket", testDir, testMeta, testVolume}
if extraFormatOpts != nil {
formatArgs = append(formatArgs, extraFormatOpts...)
}
if err := Main(formatArgs); err != nil {
return fmt.Errorf("format failed: %w", err)
}

// must do reset, otherwise will panic
ResetHttp()

mountArgs := []string{"", "mount", "--enable-xattr", testMeta, testMountPoint, "--attr-cache", "0", "--entry-cache", "0", "--dir-entry-cache", "0", "--no-usage-report"}
if extraMountOpts != nil {
mountArgs = append(mountArgs, extraMountOpts...)
}

errChan := make(chan error, 1)
go func() {
errChan <- Main(mountArgs)
}()

select {
case err := <-errChan:
if err != nil {
return fmt.Errorf("mount failed: %w", err)
}
case <-time.After(3 * time.Second):
}

inode, err := utils.GetFileInode(testMountPoint)
if err != nil {
return fmt.Errorf("get file inode failed: %w", err)
}
if inode != 1 {
return fmt.Errorf("mount failed: inode of %s is not 1", testMountPoint)
}
t.Logf("mount %s success", testMountPoint)
return nil
}

func TestMountVersionMatch(t *testing.T) {
oriVersion := version.Version()
version.SetVersion("1.1.0")
defer version.SetVersion(oriVersion)

err := tryMountTemp(t, nil, nil, nil)
assert.Nil(t, err)
umountTemp(t)

err = tryMountTemp(t, nil, []string{"--enable-acl=true"}, nil)
assert.Contains(t, err.Error(), "check version")
}
14 changes: 13 additions & 1 deletion pkg/fuse/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package fuse

import (
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -445,13 +446,24 @@ func Serve(v *vfs.VFS, options string, xattrs, ioctl bool) error {
opt.SingleThreaded = false
opt.MaxBackground = 50
opt.EnableLocks = true
opt.EnableAcl = conf.Format.EnableACL
opt.DisableXAttrs = !xattrs
opt.EnableIoctl = ioctl
opt.IgnoreSecurityLabels = true
opt.MaxWrite = 1 << 20
opt.MaxReadAhead = 1 << 20
opt.DirectMount = true
opt.AllowOther = os.Getuid() == 0

if opt.EnableAcl && conf.NonDefaultPermission {
return errors.New("cannot mount without default_permissions when format with enable-acl")
}

if opt.EnableAcl && opt.DisableXAttrs {
logger.Infof("The format \"enable-acl\" flag wiil enable the xattrs feature.")
opt.DisableXAttrs = false
}
opt.IgnoreSecurityLabels = !opt.EnableAcl

for _, n := range strings.Split(options, ",") {
if n == "allow_other" || n == "allow_root" {
opt.AllowOther = true
Expand Down
1 change: 1 addition & 0 deletions pkg/meta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ type Format struct {
MinClientVersion string `json:",omitempty"`
MaxClientVersion string `json:",omitempty"`
DirStats bool `json:",omitempty"`
EnableACL bool
}

func (f *Format) update(old *Format, force bool) error {
Expand Down
3 changes: 2 additions & 1 deletion pkg/meta/metadata-sub.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"EncryptKey": "AQSttslKOSE/hQT/gmaMniCsdPF8JdPRfoYK6zFkdUOnifYwBA==",
"KeyEncrypted": true,
"TrashDays": 1,
"MetaVersion": 1
"MetaVersion": 1,
"EnableACL": false
},
"Counters": {
"usedSpace": 115392512,
Expand Down
3 changes: 2 additions & 1 deletion pkg/meta/metadata.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"EncryptKey": "AQSttslKOSE/hQT/gmaMniCsdPF8JdPRfoYK6zFkdUOnifYwBA==",
"KeyEncrypted": true,
"TrashDays": 1,
"MetaVersion": 1
"MetaVersion": 1,
"EnableACL": false
},
"Counters": {
"usedSpace": 115392512,
Expand Down
4 changes: 4 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func Version() string {
return fmt.Sprintf("%d.%d.%d%s+%s", ver.major, ver.minor, ver.patch, pr, ver.build)
}

func SetVersion(v string) {
ver = *Parse(v)
}

func Compare(vs string) (int, error) {
v := Parse(vs)
if v == nil {
Expand Down
Loading