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

Commit 601b7ac

Browse files
committed
Added ability to specify gid and uid
1 parent ddbd6fd commit 601b7ac

File tree

9 files changed

+52
-4
lines changed

9 files changed

+52
-4
lines changed

deploy/kubernetes/examples/storageclass.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ parameters:
88
# specify which mounter to use
99
# can be set to rclone, s3fs, goofys or s3backer
1010
mounter: rclone
11+
1112
# to use an existing bucket, specify it here:
1213
# bucket: some-existing-bucket
14+
15+
# to use a non-root uid and gid, specify them here:
16+
# uid: "33"
17+
# gid: "33"
18+
1319
csi.storage.k8s.io/provisioner-secret-name: csi-s3-secret
1420
csi.storage.k8s.io/provisioner-secret-namespace: kube-system
1521
csi.storage.k8s.io/controller-publish-secret-name: csi-s3-secret

pkg/driver/controllerserver.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
5353
prefix := ""
5454
usePrefix, usePrefixError := strconv.ParseBool(params[mounter.UsePrefix])
5555
defaultFsPath := defaultFsPath
56+
gid := uint32(0)
57+
uid := uint32(0)
58+
if params[mounter.Gid] != "" {
59+
parsed, _ := strconv.ParseInt(params[mounter.Gid], 10, 32)
60+
gid = uint32(parsed)
61+
}
62+
if params[mounter.Uid] != "" {
63+
parsed, _ := strconv.ParseInt(params[mounter.Uid], 10, 32)
64+
uid = uint32(parsed)
65+
}
5666

5767
// check if bucket name is overridden
5868
if nameOverride, ok := params[mounter.BucketKey]; ok {
@@ -93,6 +103,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
93103
Mounter: mounterType,
94104
CapacityBytes: capacityBytes,
95105
FSPath: defaultFsPath,
106+
Uid: uid,
107+
Gid: gid,
96108
}
97109

98110
client, err := s3.NewClientFromSecret(req.GetSecrets())

pkg/driver/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type driver struct {
3333
}
3434

3535
var (
36-
vendorVersion = "v1.2.0-rc.2"
36+
vendorVersion = "v1.3.0"
3737
driverName = "ch.ctrox.csi.s3-driver"
3838
)
3939

pkg/mounter/goofys.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func (goofys *goofysMounter) Mount(source string, target string) error {
6161
Backend: &common.S3Config{
6262
Region: goofys.region,
6363
},
64+
Gid: goofys.meta.Gid,
65+
Uid: goofys.meta.Uid,
6466
}
6567

6668
os.Setenv("AWS_ACCESS_KEY_ID", goofys.accessKeyID)

pkg/mounter/mounter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const (
3333
BucketKey = "bucket"
3434
VolumePrefix = "prefix"
3535
UsePrefix = "usePrefix"
36+
Gid = "gid"
37+
Uid = "uid"
3638
)
3739

3840
// New returns a new mounter depending on the mounterType parameter

pkg/mounter/rclone.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ func (rclone *rcloneMounter) Mount(source string, target string) error {
5353
// TODO: make this configurable
5454
"--vfs-cache-mode=writes",
5555
}
56+
57+
if rclone.meta.Gid != 0 {
58+
args = append(args, fmt.Sprintf("--gid=%d", rclone.meta.Gid))
59+
}
60+
if rclone.meta.Uid != 0 {
61+
args = append(args, fmt.Sprintf("--uid=%d", rclone.meta.Uid))
62+
}
63+
5664
os.Setenv("AWS_ACCESS_KEY_ID", rclone.accessKeyID)
5765
os.Setenv("AWS_SECRET_ACCESS_KEY", rclone.secretAccessKey)
5866
return fuseMount(target, rcloneCmd, args)

pkg/mounter/s3backer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ func (s3backer *s3backerMounter) mountInit(p string) error {
116116
args = append(args, "--ssl")
117117
}
118118

119+
if s3backer.meta.Gid != 0 {
120+
args = append(args, fmt.Sprintf("--gid=%d", s3backer.meta.Gid))
121+
}
122+
if s3backer.meta.Uid != 0 {
123+
args = append(args, fmt.Sprintf("--uid=%d", s3backer.meta.Uid))
124+
}
125+
119126
return fuseMount(p, s3backerCmd, args)
120127
}
121128

pkg/mounter/s3fs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ func (s3fs *s3fsMounter) Mount(source string, target string) error {
5050
"-o", "allow_other",
5151
"-o", "mp_umask=000",
5252
}
53+
54+
if s3fs.meta.Gid != 0 {
55+
args = append(args, fmt.Sprintf("-o", fmt.Sprintf("gid=%d", s3fs.meta.Gid)))
56+
}
57+
if s3fs.meta.Uid != 0 {
58+
args = append(args, fmt.Sprintf("-o", fmt.Sprintf("uid=%d", s3fs.meta.Uid)))
59+
}
60+
5361
return fuseMount(target, s3fsCmd, args)
5462
}
5563

pkg/s3/client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"github.com/golang/glog"
9-
"github.com/minio/minio-go/v7"
10-
"github.com/minio/minio-go/v7/pkg/credentials"
118
"io"
129
"net/url"
1310
"path"
11+
12+
"github.com/golang/glog"
13+
"github.com/minio/minio-go/v7"
14+
"github.com/minio/minio-go/v7/pkg/credentials"
1415
)
1516

1617
const (
@@ -39,6 +40,8 @@ type FSMeta struct {
3940
Mounter string `json:"Mounter"`
4041
FSPath string `json:"FSPath"`
4142
CapacityBytes int64 `json:"CapacityBytes"`
43+
Uid uint32 `json:"Uid"`
44+
Gid uint32 `json:"Gid"`
4245
}
4346

4447
func NewClient(cfg *Config) (*s3Client, error) {

0 commit comments

Comments
 (0)