@@ -2,6 +2,7 @@ package driver
2
2
3
3
import (
4
4
"context"
5
+ "math"
5
6
"os"
6
7
"path"
7
8
"strconv"
@@ -78,10 +79,38 @@ func (d DirectoryProvisioner) Provision(ctx context.Context, req *csi.CreateVolu
78
79
}
79
80
}
80
81
81
- klog .V (5 ).Infof ("Provisioning directory with permissions %s" , perms )
82
+ var uid int64
83
+ if value , ok := volumeParams [Uid ]; ok {
84
+ uid , err = strconv .ParseInt (value , 10 , 64 )
85
+ if err != nil {
86
+ return nil , status .Errorf (codes .InvalidArgument , "Failed to parse invalid %v: %v" , Uid , err )
87
+ }
88
+ if uid < 0 {
89
+ return nil , status .Errorf (codes .InvalidArgument , "%v must be greater or equal than 0" , Uid )
90
+ }
91
+ if uid > math .MaxInt {
92
+ return nil , status .Errorf (codes .InvalidArgument , "%v must be lesser than math.MaxInt" , Uid )
93
+ }
94
+ }
95
+
96
+ var gid int64
97
+ if value , ok := volumeParams [Gid ]; ok {
98
+ gid , err = strconv .ParseInt (value , 10 , 64 )
99
+ if err != nil {
100
+ return nil , status .Errorf (codes .InvalidArgument , "Failed to parse invalid %v: %v" , Gid , err )
101
+ }
102
+ if gid < 0 {
103
+ return nil , status .Errorf (codes .InvalidArgument , "%v must be greater or equal than 0" , Gid )
104
+ }
105
+ if gid > math .MaxInt {
106
+ return nil , status .Errorf (codes .InvalidArgument , "%v must be lesser than math.MaxInt" , Gid )
107
+ }
108
+ }
109
+
110
+ klog .V (5 ).Infof ("Provisioning directory with permissions %s, uid %d, gid %d" , perms , uid , gid )
82
111
83
112
provisionedDirectory := path .Join (target , provisionedPath )
84
- err = d .osClient .MkDirAllWithPermsNoOwnership (provisionedDirectory , perms )
113
+ err = d .osClient .MkDirAllWithPerms (provisionedDirectory , perms , int ( uid ), int ( gid ) )
85
114
if err != nil {
86
115
return nil , status .Errorf (codes .Internal , "Could not provision directory: %v" , err )
87
116
}
0 commit comments