diff --git a/.gitignore b/.gitignore index 295e96b..8b18fec 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /test/e2e/e2e.test /test/e2e/ginkgo cloud-config +/.idea diff --git a/pkg/driver/node.go b/pkg/driver/node.go index 7fe72ad..c6bda8c 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -39,6 +39,24 @@ func NewNodeServer(connector cloud.Interface, mounter mount.Interface, nodeName } } +func ensurePermissions(ctx context.Context, mounter mount.Interface, targetPath string) error { + if os.PathSeparator != '/' { + return nil + } + + // containers running with different uid wouldn't be able to use regular mounts. pe. bitnami ones + ctxzap.Extract(ctx).Sugar().Infow("Ensuring permissions","targetPath", targetPath) + err := mounter.Command("chmod", "+rwx", targetPath).Run() + if err != nil { + return status.Errorf(codes.Internal, "Cannot fix permissions in %s", targetPath, err.Error()) + } + err = mounter.Command("chmod", "a+rwx", targetPath).Run() + if err != nil { + return status.Errorf(codes.Internal, "Cannot fix permissions in %s", targetPath, err.Error()) + } + return nil +} + func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) { // Check parameters @@ -114,6 +132,12 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol return nil, status.Error(codes.Internal, err.Error()) } } + + err = ensurePermissions(ctx, ns.mounter, target) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &csi.NodeStageVolumeResponse{}, nil } @@ -271,6 +295,11 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis } } + err := ensurePermissions(ctx, ns.mounter, targetPath) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + return &csi.NodePublishVolumeResponse{}, nil }