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

Added ability to specify gid and uid #109

Open
wants to merge 3 commits 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
2 changes: 1 addition & 1 deletion deploy/kubernetes/csi-s3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ spec:
capabilities:
add: ["SYS_ADMIN"]
allowPrivilegeEscalation: true
image: ctrox/csi-s3:v1.2.0-rc.2
image: ctrox/csi-s3:v1.3.0
imagePullPolicy: "Always"
args:
- "--endpoint=$(CSI_ENDPOINT)"
Expand Down
6 changes: 6 additions & 0 deletions deploy/kubernetes/examples/storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ parameters:
# specify which mounter to use
# can be set to rclone, s3fs, goofys or s3backer
mounter: rclone

# to use an existing bucket, specify it here:
# bucket: some-existing-bucket

# to use a non-root uid and gid, specify them here:
# uid: "33"
# gid: "33"

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 deploy/kubernetes/provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ spec:
- name: socket-dir
mountPath: /var/lib/kubelet/plugins/ch.ctrox.csi.s3-driver
- name: csi-s3
image: ctrox/csi-s3:v1.2.0-rc.2
image: ctrox/csi-s3:v1.3.0
args:
- "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(NODE_ID)"
Expand Down
12 changes: 12 additions & 0 deletions pkg/driver/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
prefix := ""
usePrefix, usePrefixError := strconv.ParseBool(params[mounter.UsePrefix])
defaultFsPath := defaultFsPath
gid := uint32(0)
uid := uint32(0)
if params[mounter.Gid] != "" {
parsed, _ := strconv.ParseInt(params[mounter.Gid], 10, 32)
gid = uint32(parsed)
}
if params[mounter.Uid] != "" {
parsed, _ := strconv.ParseInt(params[mounter.Uid], 10, 32)
uid = uint32(parsed)
}

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

client, err := s3.NewClientFromSecret(req.GetSecrets())
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type driver struct {
}

var (
vendorVersion = "v1.2.0-rc.2"
vendorVersion = "v1.3.0"
driverName = "ch.ctrox.csi.s3-driver"
)

Expand Down
2 changes: 2 additions & 0 deletions pkg/mounter/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func (goofys *goofysMounter) Mount(source string, target string) error {
Backend: &common.S3Config{
Region: goofys.region,
},
Gid: goofys.meta.Gid,
Uid: goofys.meta.Uid,
}

os.Setenv("AWS_ACCESS_KEY_ID", goofys.accessKeyID)
Expand Down
2 changes: 2 additions & 0 deletions pkg/mounter/mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const (
BucketKey = "bucket"
VolumePrefix = "prefix"
UsePrefix = "usePrefix"
Gid = "gid"
Uid = "uid"
)

// New returns a new mounter depending on the mounterType parameter
Expand Down
8 changes: 8 additions & 0 deletions pkg/mounter/rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func (rclone *rcloneMounter) Mount(source string, target string) error {
// TODO: make this configurable
"--vfs-cache-mode=writes",
}

if rclone.meta.Gid != 0 {
args = append(args, fmt.Sprintf("--gid=%d", rclone.meta.Gid))
}
if rclone.meta.Uid != 0 {
args = append(args, fmt.Sprintf("--uid=%d", rclone.meta.Uid))
}

os.Setenv("AWS_ACCESS_KEY_ID", rclone.accessKeyID)
os.Setenv("AWS_SECRET_ACCESS_KEY", rclone.secretAccessKey)
return fuseMount(target, rcloneCmd, args)
Expand Down
7 changes: 7 additions & 0 deletions pkg/mounter/s3backer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ func (s3backer *s3backerMounter) mountInit(p string) error {
args = append(args, "--ssl")
}

if s3backer.meta.Gid != 0 {
args = append(args, fmt.Sprintf("--gid=%d", s3backer.meta.Gid))
}
if s3backer.meta.Uid != 0 {
args = append(args, fmt.Sprintf("--uid=%d", s3backer.meta.Uid))
}

return fuseMount(p, s3backerCmd, args)
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/mounter/s3fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ func (s3fs *s3fsMounter) Mount(source string, target string) error {
"-o", "allow_other",
"-o", "mp_umask=000",
}

if s3fs.meta.Gid != 0 {
args = append(args, "-o")
args = append(args, fmt.Sprintf("gid=%d", s3fs.meta.Gid))
}
if s3fs.meta.Uid != 0 {
args = append(args, "-o")
args = append(args, fmt.Sprintf("uid=%d", s3fs.meta.Uid))
}

return fuseMount(target, s3fsCmd, args)
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/s3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/golang/glog"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"io"
"net/url"
"path"

"github.com/golang/glog"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)

const (
Expand Down Expand Up @@ -39,6 +40,8 @@ type FSMeta struct {
Mounter string `json:"Mounter"`
FSPath string `json:"FSPath"`
CapacityBytes int64 `json:"CapacityBytes"`
Uid uint32 `json:"Uid"`
Gid uint32 `json:"Gid"`
}

func NewClient(cfg *Config) (*s3Client, error) {
Expand Down