Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit b54578f

Browse files
committed
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.
1 parent 6a23dba commit b54578f

File tree

7 files changed

+36
-6
lines changed

7 files changed

+36
-6
lines changed

deploy/kubernetes/storageclass.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ parameters:
88
# specify which mounter to use
99
# can be set to rclone, s3fs, goofys or s3backer
1010
mounter: rclone
11+
12+
# goofys allows the following additional optional parameters to be passed
13+
14+
# The uid to mount the volume as.
15+
# goofysuid: "1000"
16+
# The gid to mount the volume as.
17+
# goofysgid: "1000"
18+
1119
csi.storage.k8s.io/provisioner-secret-name: csi-s3-secret
1220
csi.storage.k8s.io/provisioner-secret-namespace: kube-system
1321
csi.storage.k8s.io/controller-publish-secret-name: csi-s3-secret

pkg/s3/mounter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type Mounter interface {
1515
Stage(stagePath string) error
1616
Unstage(stagePath string) error
17-
Mount(source string, target string) error
17+
Mount(source string, target string, attrib map[string]string) error
1818
}
1919

2020
const (

pkg/s3/mounter_goofys.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ package s3
33
import (
44
"fmt"
55
"os"
6+
"strconv"
67

78
"context"
89

10+
"github.com/golang/glog"
911
goofysApi "github.com/kahing/goofys/api"
1012
)
1113

1214
const (
1315
goofysCmd = "goofys"
1416
defaultRegion = "us-east-1"
17+
goofysUIDKey = "goofysuid"
18+
goofysGIDKey = "goofysgid"
1519
)
1620

1721
// Implements Mounter
@@ -46,13 +50,21 @@ func (goofys *goofysMounter) Unstage(stageTarget string) error {
4650
return nil
4751
}
4852

49-
func (goofys *goofysMounter) Mount(source string, target string) error {
53+
func (goofys *goofysMounter) Mount(source string, target string, attrib map[string]string) error {
54+
uid := uint32FromMap(goofysUIDKey, 0, attrib)
55+
gid := uint32FromMap(goofysGIDKey, 0, attrib)
56+
57+
glog.V(4).Infof("target %v\nendpoint %v\nregion %v\nuid %v\ngid %v\nattrib %v\n",
58+
target, goofys.endpoint, goofys.region, uid, gid, attrib)
59+
5060
goofysCfg := &goofysApi.Config{
5161
MountPoint: target,
5262
Endpoint: goofys.endpoint,
5363
Region: goofys.region,
5464
DirMode: 0755,
5565
FileMode: 0644,
66+
Uid: uid,
67+
Gid: gid,
5668
MountOptions: map[string]string{
5769
"allow_other": "",
5870
},
@@ -69,3 +81,13 @@ func (goofys *goofysMounter) Mount(source string, target string) error {
6981
}
7082
return nil
7183
}
84+
85+
func uint32FromMap(key string, defaultValue uint32, attrib map[string]string) uint32 {
86+
value := defaultValue
87+
if valueStr, found := attrib[key]; found {
88+
if i, err := strconv.ParseUint(valueStr, 10, 32); err == nil {
89+
value = uint32(i)
90+
}
91+
}
92+
return value
93+
}

pkg/s3/mounter_rclone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (rclone *rcloneMounter) Unstage(stageTarget string) error {
3636
return nil
3737
}
3838

39-
func (rclone *rcloneMounter) Mount(source string, target string) error {
39+
func (rclone *rcloneMounter) Mount(source string, target string, attrib map[string]string) error {
4040
args := []string{
4141
"mount",
4242
fmt.Sprintf(":s3:%s/%s", rclone.bucket.Name, rclone.bucket.FSPath),

pkg/s3/mounter_s3backer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (s3backer *s3backerMounter) Unstage(stageTarget string) error {
8181
return fuseUnmount(stageTarget)
8282
}
8383

84-
func (s3backer *s3backerMounter) Mount(source string, target string) error {
84+
func (s3backer *s3backerMounter) Mount(source string, target string, attrib map[string]string) error {
8585
device := path.Join(source, s3backerDevice)
8686
// second mount will mount the 'file' as a filesystem
8787
err := mount.New("").Mount(device, target, s3backerFsType, []string{})

pkg/s3/mounter_s3fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (s3fs *s3fsMounter) Unstage(stageTarget string) error {
3434
return nil
3535
}
3636

37-
func (s3fs *s3fsMounter) Mount(source string, target string) error {
37+
func (s3fs *s3fsMounter) Mount(source string, target string, attrib map[string]string) error {
3838
if err := writes3fsPass(s3fs.pwFileContent); err != nil {
3939
return err
4040
}

pkg/s3/nodeserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8989
if err != nil {
9090
return nil, err
9191
}
92-
if err := mounter.Mount(stagingTargetPath, targetPath); err != nil {
92+
if err := mounter.Mount(stagingTargetPath, targetPath, attrib); err != nil {
9393
return nil, err
9494
}
9595

0 commit comments

Comments
 (0)