Skip to content

Commit

Permalink
Merge pull request #36 from Fedosin/folder_permissions
Browse files Browse the repository at this point in the history
Allow to set custom permissions for the mounted folder
  • Loading branch information
k8s-ci-robot authored Jun 18, 2020
2 parents 0eb9883 + 070c69e commit a92afa2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
18 changes: 17 additions & 1 deletion cmd/nfsplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"fmt"
"os"
"strconv"

"github.com/spf13/cobra"

Expand All @@ -29,6 +30,7 @@ import (
var (
endpoint string
nodeID string
perm string
)

func init() {
Expand All @@ -55,6 +57,8 @@ func main() {
cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "", "CSI endpoint")
cmd.MarkPersistentFlagRequired("endpoint")

cmd.PersistentFlags().StringVar(&perm, "mount-permissions", "", "mounted folder permissions")

cmd.ParseFlags(os.Args[1:])
if err := cmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%s", err.Error())
Expand All @@ -65,6 +69,18 @@ func main() {
}

func handle() {
d := nfs.NewNFSdriver(nodeID, endpoint)
// Converting string permission representation to *uint32
var parsedPerm *uint32
if perm != "" {
permu64, err := strconv.ParseUint(perm, 8, 32)
if err != nil {
fmt.Fprintf(os.Stderr, "Incorrect mount-permissions value: %q", perm)
os.Exit(1)
}
permu32 := uint32(permu64)
parsedPerm = &permu32
}

d := nfs.NewNFSdriver(nodeID, endpoint, parsedPerm)
d.Run()
}
5 changes: 4 additions & 1 deletion pkg/nfs/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type nfsDriver struct {

endpoint string

perm *uint32

//ids *identityServer
ns *nodeServer
cap map[csi.VolumeCapability_AccessMode_Mode]bool
Expand All @@ -43,7 +45,7 @@ var (
version = "2.0.0"
)

func NewNFSdriver(nodeID, endpoint string) *nfsDriver {
func NewNFSdriver(nodeID, endpoint string, perm *uint32) *nfsDriver {
glog.Infof("Driver: %v version: %v", driverName, version)

n := &nfsDriver{
Expand All @@ -52,6 +54,7 @@ func NewNFSdriver(nodeID, endpoint string) *nfsDriver {
nodeID: nodeID,
endpoint: endpoint,
cap: map[csi.VolumeCapability_AccessMode_Mode]bool{},
perm: perm,
}

vcam := []csi.VolumeCapability_AccessMode_Mode{
Expand Down
6 changes: 6 additions & 0 deletions pkg/nfs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
return nil, status.Error(codes.Internal, err.Error())
}

if ns.Driver.perm != nil {
if err := os.Chmod(targetPath, os.FileMode(*ns.Driver.perm)); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
}

return &csi.NodePublishVolumeResponse{}, nil
}

Expand Down

0 comments on commit a92afa2

Please sign in to comment.