From 807194af2a532f12095e85addf38ec1a9743bb12 Mon Sep 17 00:00:00 2001
From: Jairo Velasco <1904410+jairov4@users.noreply.github.com>
Date: Thu, 24 Feb 2022 07:26:56 -0500
Subject: [PATCH 1/4] Fix to support containers with custom uid
---
.gitignore | 1 +
.idea/.gitignore | 8 ++++++++
.idea/cloudstack-csi-driver.iml | 9 +++++++++
.idea/modules.xml | 8 ++++++++
.idea/vcs.xml | 6 ++++++
pkg/driver/node.go | 7 +++++++
6 files changed, 39 insertions(+)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/cloudstack-csi-driver.iml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
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/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..8fd4ad3
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/../../../../:\dev\cloudstack-csi-driver\.idea/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/cloudstack-csi-driver.iml b/.idea/cloudstack-csi-driver.iml
new file mode 100644
index 0000000..338a266
--- /dev/null
+++ b/.idea/cloudstack-csi-driver.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..fc3ec80
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..9661ac7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pkg/driver/node.go b/pkg/driver/node.go
index 7fe72ad..a34fa36 100644
--- a/pkg/driver/node.go
+++ b/pkg/driver/node.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "runtime"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
@@ -107,6 +108,12 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
}
}
+ if runtime.GOOS == "linux" {
+ // containers running with different uid wouldn't be able to use regular mounts. pe. bitnami ones
+ ns.mounter.Command("chmod", "+rwx", target)
+ ns.mounter.Command("chmod", "a+rwx", target)
+ }
+
// Volume Mount
if notMnt {
err = ns.mounter.FormatAndMount(devicePath, target, fsType, mountOptions)
From 41b5b13bb71bd6deca195c5cdcd3acfdb7dacc35 Mon Sep 17 00:00:00 2001
From: Jairo Velasco <1904410+jairov4@users.noreply.github.com>
Date: Thu, 24 Feb 2022 07:29:08 -0500
Subject: [PATCH 2/4] Remove unwanted files
---
.idea/.gitignore | 8 --------
.idea/cloudstack-csi-driver.iml | 9 ---------
.idea/modules.xml | 8 --------
.idea/vcs.xml | 6 ------
4 files changed, 31 deletions(-)
delete mode 100644 .idea/.gitignore
delete mode 100644 .idea/cloudstack-csi-driver.iml
delete mode 100644 .idea/modules.xml
delete mode 100644 .idea/vcs.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 8fd4ad3..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Datasource local storage ignored files
-/../../../../:\dev\cloudstack-csi-driver\.idea/dataSources/
-/dataSources.local.xml
-# Editor-based HTTP Client requests
-/httpRequests/
diff --git a/.idea/cloudstack-csi-driver.iml b/.idea/cloudstack-csi-driver.iml
deleted file mode 100644
index 338a266..0000000
--- a/.idea/cloudstack-csi-driver.iml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index fc3ec80..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 9661ac7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
From bc0cbcbce849487c7f142fe8714ff5b73bd1883b Mon Sep 17 00:00:00 2001
From: Jairo Velasco <1904410+jairov4@users.noreply.github.com>
Date: Thu, 24 Feb 2022 07:34:58 -0500
Subject: [PATCH 3/4] Change exec point
---
pkg/driver/node.go | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/pkg/driver/node.go b/pkg/driver/node.go
index a34fa36..044d7b2 100644
--- a/pkg/driver/node.go
+++ b/pkg/driver/node.go
@@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
- "runtime"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
@@ -108,12 +107,6 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
}
}
- if runtime.GOOS == "linux" {
- // containers running with different uid wouldn't be able to use regular mounts. pe. bitnami ones
- ns.mounter.Command("chmod", "+rwx", target)
- ns.mounter.Command("chmod", "a+rwx", target)
- }
-
// Volume Mount
if notMnt {
err = ns.mounter.FormatAndMount(devicePath, target, fsType, mountOptions)
@@ -121,6 +114,13 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
return nil, status.Error(codes.Internal, err.Error())
}
}
+
+ if os.PathSeparator == '/' {
+ // containers running with different uid wouldn't be able to use regular mounts. pe. bitnami ones
+ ns.mounter.Command("chmod", "+rwx", target)
+ ns.mounter.Command("chmod", "a+rwx", target)
+ }
+
return &csi.NodeStageVolumeResponse{}, nil
}
From 861ae8b4ebe2cdf02410d34f65a84800156e9dc8 Mon Sep 17 00:00:00 2001
From: Jairo Velasco <1904410+jairov4@users.noreply.github.com>
Date: Thu, 24 Feb 2022 08:26:23 -0500
Subject: [PATCH 4/4] Error handling and tested
---
pkg/driver/node.go | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/pkg/driver/node.go b/pkg/driver/node.go
index 044d7b2..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
@@ -115,10 +133,9 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
}
}
- if os.PathSeparator == '/' {
- // containers running with different uid wouldn't be able to use regular mounts. pe. bitnami ones
- ns.mounter.Command("chmod", "+rwx", target)
- ns.mounter.Command("chmod", "a+rwx", target)
+ err = ensurePermissions(ctx, ns.mounter, target)
+ if err != nil {
+ return nil, status.Error(codes.Internal, err.Error())
}
return &csi.NodeStageVolumeResponse{}, nil
@@ -278,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
}