Skip to content

Commit b8c36f5

Browse files
committed
remove use of runtime platform
Signed-off-by: Justin Alvarez <[email protected]>
1 parent bbb3599 commit b8c36f5

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

ecs-agent/daemonimages/csidriver/driver/node.go

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"context"
2424
"fmt"
2525
"os"
26-
"runtime"
2726
"strconv"
2827
"strings"
2928

@@ -260,33 +259,15 @@ func (d *nodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
260259
sourceVolumeHostPath = strings.TrimPrefix(target, EBSPathPrefix)
261260
}
262261

263-
// chown/chmod don't work on Windows
264-
if runtime.GOOS != "windows" {
265-
// Gid is generated based on SourceVolumeHostPath
266-
gid := util.GenerateGIDFromPath(sourceVolumeHostPath)
267-
// Set permissions on the mount point to allow non-root users to access it
268-
if err := setMountPointPermissions(target, gid); err != nil {
269-
return nil, status.Errorf(codes.Internal, "Failed to set permissions on mount point %s: %v", target, err)
270-
}
271-
klog.V(4).InfoS("Successfully set permissions on mount point", "target", target, "volumeID", volumeID, "gid", gid)
272-
}
273-
274-
return &csi.NodeStageVolumeResponse{}, nil
275-
}
276-
277-
// setMountPointPermissions sets the permissions on the mount point to allow non-root users to access it
278-
func setMountPointPermissions(mountPath string, gid int) error {
279-
// Change group ownership to the provided GID
280-
if err := chownFunc(mountPath, -1, gid); err != nil {
281-
return fmt.Errorf("failed to change group ownership of %s to GID %d: %v", mountPath, gid, err)
282-
}
262+
// Gid is generated based on SourceVolumeHostPath
263+
gid := util.GenerateGIDFromPath(sourceVolumeHostPath)
283264

284-
// Set permissions to 0775 with setgid bit
285-
if err := chmodFunc(mountPath, 0775|os.ModeSetgid); err != nil {
286-
return fmt.Errorf("failed to set permissions on %s: %v", mountPath, err)
265+
// Set permissions on the mount point to allow non-root users to access it
266+
if err := setMountPointPermissions(target, gid, volumeID); err != nil {
267+
return nil, status.Errorf(codes.Internal, "Failed to set permissions on mount point %s: %v", target, err)
287268
}
288269

289-
return nil
270+
return &csi.NodeStageVolumeResponse{}, nil
290271
}
291272

292273
func newNodeService() nodeService {

ecs-agent/daemonimages/csidriver/driver/node_linux.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,19 @@ func (d *nodeService) getBlockSizeBytes(devicePath string, _ string) (int64, err
182182
}
183183
return gotSizeBytes, nil
184184
}
185+
186+
// setMountPointPermissions sets the permissions on the mount point to allow non-root users to access it
187+
func setMountPointPermissions(mountPath string, gid int, volumeID string) error {
188+
// Change group ownership to the provided GID
189+
if err := chownFunc(mountPath, -1, gid); err != nil {
190+
return fmt.Errorf("failed to change group ownership of %s to GID %d: %v", mountPath, gid, err)
191+
}
192+
193+
// Set permissions to 0775 with setgid bit
194+
if err := chmodFunc(mountPath, 0775|os.ModeSetgid); err != nil {
195+
return fmt.Errorf("failed to set permissions on %s: %v", mountPath, err)
196+
}
197+
198+
klog.V(4).InfoS("Successfully set permissions on mount point", "target", mountPath, "volumeID", volumeID, "gid", gid)
199+
return nil
200+
}

ecs-agent/daemonimages/csidriver/driver/node_windows.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"strings"
2929

3030
"github.com/aws/amazon-ecs-agent/ecs-agent/daemonimages/csidriver/mounter"
31+
"k8s.io/klog/v2"
3132
)
3233

3334
// getBlockSizeBytes gets the size of the disk in bytes
@@ -75,3 +76,9 @@ func (d *nodeService) findDevicePath(devicePath, volumeID, _ string) (string, er
7576

7677
return foundDiskNumber, nil
7778
}
79+
80+
// setMountPointPermissions is a no-op on Windows because chown/chmod don't work on Windows
81+
func setMountPointPermissions(_ string, _ int, _ string) error {
82+
klog.V(4).InfoS("Skipping setting mount point permissions on Windows")
83+
return nil
84+
}

0 commit comments

Comments
 (0)