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

Adding ability to specify uid/gid when using goofys. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Adding ability to specify uid/gid when using goofys.
With this change, while setting up your StorageClass, you can specify the
uid and gid that goofys should use when mounting your file system. These
two new options are goofysuid and goofysgid.
  • Loading branch information
RexMorgan committed Aug 29, 2019
commit b54578fc3ea647226d9338a87e2c4f41a8faef5f
8 changes: 8 additions & 0 deletions deploy/kubernetes/storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ parameters:
# specify which mounter to use
# can be set to rclone, s3fs, goofys or s3backer
mounter: rclone

# goofys allows the following additional optional parameters to be passed

# The uid to mount the volume as.
# goofysuid: "1000"
# The gid to mount the volume as.
# goofysgid: "1000"

csi.storage.k8s.io/provisioner-secret-name: csi-s3-secret
csi.storage.k8s.io/provisioner-secret-namespace: kube-system
csi.storage.k8s.io/controller-publish-secret-name: csi-s3-secret
Expand Down
2 changes: 1 addition & 1 deletion pkg/s3/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type Mounter interface {
Stage(stagePath string) error
Unstage(stagePath string) error
Mount(source string, target string) error
Mount(source string, target string, attrib map[string]string) error
}

const (
Expand Down
24 changes: 23 additions & 1 deletion pkg/s3/mounter_goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ package s3
import (
"fmt"
"os"
"strconv"

"context"

"github.com/golang/glog"
goofysApi "github.com/kahing/goofys/api"
)

const (
goofysCmd = "goofys"
defaultRegion = "us-east-1"
goofysUIDKey = "goofysuid"
goofysGIDKey = "goofysgid"
)

// Implements Mounter
Expand Down Expand Up @@ -46,13 +50,21 @@ func (goofys *goofysMounter) Unstage(stageTarget string) error {
return nil
}

func (goofys *goofysMounter) Mount(source string, target string) error {
func (goofys *goofysMounter) Mount(source string, target string, attrib map[string]string) error {
uid := uint32FromMap(goofysUIDKey, 0, attrib)
gid := uint32FromMap(goofysGIDKey, 0, attrib)

glog.V(4).Infof("target %v\nendpoint %v\nregion %v\nuid %v\ngid %v\nattrib %v\n",
target, goofys.endpoint, goofys.region, uid, gid, attrib)

goofysCfg := &goofysApi.Config{
MountPoint: target,
Endpoint: goofys.endpoint,
Region: goofys.region,
DirMode: 0755,
FileMode: 0644,
Uid: uid,
Gid: gid,
MountOptions: map[string]string{
"allow_other": "",
},
Expand All @@ -69,3 +81,13 @@ func (goofys *goofysMounter) Mount(source string, target string) error {
}
return nil
}

func uint32FromMap(key string, defaultValue uint32, attrib map[string]string) uint32 {
value := defaultValue
if valueStr, found := attrib[key]; found {
if i, err := strconv.ParseUint(valueStr, 10, 32); err == nil {
value = uint32(i)
}
}
return value
}
2 changes: 1 addition & 1 deletion pkg/s3/mounter_rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (rclone *rcloneMounter) Unstage(stageTarget string) error {
return nil
}

func (rclone *rcloneMounter) Mount(source string, target string) error {
func (rclone *rcloneMounter) Mount(source string, target string, attrib map[string]string) error {
args := []string{
"mount",
fmt.Sprintf(":s3:%s/%s", rclone.bucket.Name, rclone.bucket.FSPath),
Expand Down
2 changes: 1 addition & 1 deletion pkg/s3/mounter_s3backer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s3backer *s3backerMounter) Unstage(stageTarget string) error {
return fuseUnmount(stageTarget)
}

func (s3backer *s3backerMounter) Mount(source string, target string) error {
func (s3backer *s3backerMounter) Mount(source string, target string, attrib map[string]string) error {
device := path.Join(source, s3backerDevice)
// second mount will mount the 'file' as a filesystem
err := mount.New("").Mount(device, target, s3backerFsType, []string{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/s3/mounter_s3fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s3fs *s3fsMounter) Unstage(stageTarget string) error {
return nil
}

func (s3fs *s3fsMounter) Mount(source string, target string) error {
func (s3fs *s3fsMounter) Mount(source string, target string, attrib map[string]string) error {
if err := writes3fsPass(s3fs.pwFileContent); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/s3/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if err != nil {
return nil, err
}
if err := mounter.Mount(stagingTargetPath, targetPath); err != nil {
if err := mounter.Mount(stagingTargetPath, targetPath, attrib); err != nil {
return nil, err
}

Expand Down