Skip to content

Commit 77d5898

Browse files
authored
Sanitize volume names (#743)
* Problem: If a user want to attach a volume that have a name with spaces or other weird symbols, it raises an error and don't allocate the VM. Solution: Sanitize the volume name before creating it. * Fix: add another action on the pending TODO.
1 parent 38c74fe commit 77d5898

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/aleph/vm/controllers/firecracker/executable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def download_kernel(self):
114114

115115
async def download_volumes(self):
116116
volumes = []
117-
# TODO: Download in parallel
117+
# TODO: Download in parallel and prevent duplicated volume names
118118
for i, volume in enumerate(self.message_content.volumes):
119119
# only persistant volume has name and mount
120120
if isinstance(volume, PersistentVolume):

src/aleph/vm/storage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,14 @@ async def get_volume_path(volume: MachineVolume, namespace: str) -> Path:
376376
return await get_existing_file(ref)
377377
elif isinstance(volume, PersistentVolume | RootfsVolume):
378378
volume_name = volume.name if isinstance(volume, PersistentVolume) else "rootfs"
379+
379380
if volume.persistence != VolumePersistence.host:
380381
msg = "Only 'host' persistence is supported"
381382
raise NotImplementedError(msg)
382383
if not re.match(r"^[\w\-_/]+$", volume_name):
383-
msg = f"Invalid value for volume name: {repr(volume_name)}"
384-
raise ValueError(msg)
384+
# Sanitize volume names
385+
logger.debug(f"Invalid values for volume name: {repr(volume_name)} detected, sanitizing")
386+
volume_name = re.sub(r"[^\w\-_]", "_", volume_name)
385387
(Path(settings.PERSISTENT_VOLUMES_DIR) / namespace).mkdir(exist_ok=True)
386388
if volume.parent:
387389
return await create_devmapper(volume, namespace)

0 commit comments

Comments
 (0)