Skip to content

Commit 13d0cb7

Browse files
authored
Don't try to chown/chmod on Windows (#4838)
Signed-off-by: Justin Alvarez <alvajus@amazon.com>
1 parent eeb7412 commit 13d0cb7

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,30 +261,15 @@ func (d *nodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
261261

262262
// Gid is generated based on SourceVolumeHostPath
263263
gid := util.GenerateGIDFromPath(sourceVolumeHostPath)
264+
264265
// Set permissions on the mount point to allow non-root users to access it
265-
if err := setMountPointPermissions(target, gid); err != nil {
266+
if err := setMountPointPermissions(target, gid, volumeID); err != nil {
266267
return nil, status.Errorf(codes.Internal, "Failed to set permissions on mount point %s: %v", target, err)
267268
}
268-
klog.V(4).InfoS("Successfully set permissions on mount point", "target", target, "volumeID", volumeID, "gid", gid)
269269

270270
return &csi.NodeStageVolumeResponse{}, nil
271271
}
272272

273-
// setMountPointPermissions sets the permissions on the mount point to allow non-root users to access it
274-
func setMountPointPermissions(mountPath string, gid int) error {
275-
// Change group ownership to the provided GID
276-
if err := chownFunc(mountPath, -1, gid); err != nil {
277-
return fmt.Errorf("failed to change group ownership of %s to GID %d: %v", mountPath, gid, err)
278-
}
279-
280-
// Set permissions to 0775 with setgid bit
281-
if err := chmodFunc(mountPath, 0775|os.ModeSetgid); err != nil {
282-
return fmt.Errorf("failed to set permissions on %s: %v", mountPath, err)
283-
}
284-
285-
return nil
286-
}
287-
288273
func newNodeService() nodeService {
289274
klog.V(4).InfoS("New node service")
290275
nodeMounter, err := newNodeMounter()

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_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ func TestSetMountPointPermissions(t *testing.T) {
991991
}
992992

993993
// Call the function
994-
err := setMountPointPermissions(tc.mountPath, tc.gid)
994+
err := setMountPointPermissions(tc.mountPath, tc.gid, "volumeID")
995995

996996
// Verify results
997997
if tc.expectedError {

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)