Skip to content

Support for container stub drive reuse #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
51 changes: 37 additions & 14 deletions agent/drive_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,11 @@ func (dh driveHandler) MountDrive(ctx context.Context, req *drivemount.MountDriv
logger = logger.WithField("drive_path", drive.Path())

// Do a basic check that we won't be mounting over any important system directories
resolvedDest, err := evalAnySymlinks(req.DestinationPath)
if err != nil {
return nil, errors.Wrapf(err,
"failed to evaluate any symlinks in drive mount destination %q", req.DestinationPath)
}

for _, systemDir := range bannedSystemDirs {
if isOrUnderDir(resolvedDest, systemDir) {
return nil, errors.Errorf(
"drive mount destination %q resolves to path %q under banned system directory %q",
req.DestinationPath, resolvedDest, systemDir,
)
}
if err := isSystemDir(req.DestinationPath); err != nil {
return nil, err
}

err = os.MkdirAll(req.DestinationPath, 0700)
err := os.MkdirAll(req.DestinationPath, 0700)
if err != nil {
return nil, errors.Wrapf(err, "failed to create drive mount destination %q", req.DestinationPath)
}
Expand Down Expand Up @@ -229,6 +218,40 @@ func (dh driveHandler) MountDrive(ctx context.Context, req *drivemount.MountDriv
drive.Path(), req.DestinationPath)
}

func (dh driveHandler) UnmountDrive(ctx context.Context, req *drivemount.UnmountDriveRequest) (*empty.Empty, error) {
drive, ok := dh.GetDrive(req.DriveID)
if !ok {
return nil, fmt.Errorf("drive %q could not be found", req.DriveID)
}

err := mount.Unmount(drive.Path(), 0)
if err == nil {
return &empty.Empty{}, nil
}

return nil, errors.Errorf("failed to unmount the drive %q",
drive.Path())
}

func isSystemDir(path string) error {
resolvedDest, err := evalAnySymlinks(path)
if err != nil {
return errors.Wrapf(err,
"failed to evaluate any symlinks in drive ummount destination %q", path)
}

for _, systemDir := range bannedSystemDirs {
if isOrUnderDir(resolvedDest, systemDir) {
return errors.Errorf(
"drive mount destination %q resolves to path %q under banned system directory %q",
path, resolvedDest, systemDir,
)
}
}

return nil
}

// evalAnySymlinks is similar to filepath.EvalSymlinks, except it will not return an error if part of the
// provided path does not exist. It will evaluate symlinks present in the path up to a component that doesn't
// exist, at which point it will just append the rest of the provided path to what has been resolved so far.
Expand Down
11 changes: 8 additions & 3 deletions proto/service/drivemount/drivemount.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ option go_package = "drivemount";

service DriveMounter {
rpc MountDrive(MountDriveRequest) returns (google.protobuf.Empty);
rpc UnmountDrive(UnmountDriveRequest) returns (google.protobuf.Empty);
}

message MountDriveRequest {
string DriveID = 1;
string DestinationPath = 2;
string FilesytemType = 3;
repeated string Options = 4;
}

message UnmountDriveRequest {
string DriveID = 1;
string DestinationPath = 2;
string FilesytemType = 3;
repeated string Options = 4;
}
219 changes: 212 additions & 7 deletions proto/service/drivemount/ttrpc/drivemount.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading