Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/sha256"
"fmt"
"github.com/google/uuid"
"io"
"os"
"path"
"sort"
Expand Down Expand Up @@ -394,11 +395,28 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest)
}
}

klog.V(2).Infof("Access point root directory : %s", accessPoint.AccessPointRootDir)
if accessPoint.AccessPointRootDir == "/" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when accessPoint.AccessPointRootDir is an empty string? (The field seems not mandatory when creating an AP, so could in rare cases be empty).

According to my understanding the efs-plugin mounts the entire filesystem in /var/lib/csi/pv/<fsap-id> and later calls os.RemoveAll(target, accessPoint.AccessPointRootDir). Now if accessPoint.AccessPointRootDir is empty, the left-over path for os.RemoveAll is /var/lib/csi/pv/<fsap-id> which represents the entire filesystem. I'm I right with that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pull AccessPointRootDir from an API call to the AWS EFS console API:

accessPoint, err := localCloud.DescribeAccessPoint(ctx, accessPointId)

The API layer has empty access point root dirs default to the root path, so an empty access point root dir shouldn't be possible.

But, I agree, we should validate our assumptions and add a check, just in case.

return nil, status.Errorf(codes.Internal, "Could not delete efs root dir '/'")
}

target := TempMountPathPrefix + "/" + accessPointId
if err := d.mounter.MakeDir(target); err != nil {
return nil, status.Errorf(codes.Internal, "Could not create dir %q: %v", target, err)
}
if err := d.mounter.Mount(fileSystemId, target, "efs", mountOptions); err != nil {
targetDir, err := os.Open(target)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not read dir %q: %v", target, err)
}
_, err = targetDir.Readdir(1)
if err != io.EOF {
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not read dir %q: %v", target, err)
} else {
return nil, status.Errorf(codes.Internal, "Expected empty directory %s", target)
}
}
os.Remove(target)
return nil, status.Errorf(codes.Internal, "Could not mount %q at %q: %v", fileSystemId, target, err)
}
Expand Down
35 changes: 35 additions & 0 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2974,6 +2974,41 @@ func TestDeleteVolume(t *testing.T) {
mockCtl.Finish()
},
},
{
name: "Fail: Access point root directory is '/'",
testFunc: func(t *testing.T) {
mockCtl := gomock.NewController(t)
mockCloud := mocks.NewMockCloud(mockCtl)
mockMounter := mocks.NewMockMounter(mockCtl)

driver := &Driver{
endpoint: endpoint,
cloud: mockCloud,
mounter: mockMounter,
gidAllocator: NewGidAllocator(),
deleteAccessPointRootDir: true,
}

req := &csi.DeleteVolumeRequest{
VolumeId: volumeId,
}

accessPoint := &cloud.AccessPoint{
AccessPointId: apId,
FileSystemId: fsId,
AccessPointRootDir: "/",
CapacityGiB: 0,
}

ctx := context.Background()
mockCloud.EXPECT().DescribeAccessPoint(gomock.Eq(ctx), gomock.Eq(apId)).Return(accessPoint, nil)
_, err := driver.DeleteVolume(ctx, req)
if err == nil {
t.Fatalf("DeleteVolume did not fail")
}
mockCtl.Finish()
},
},
}

for _, tc := range testCases {
Expand Down