@@ -658,6 +658,9 @@ func validateVolumeAttachments(attachments []VolumeAttachment, allowSystemVolume
658658
659659 seenPaths := make (map [string ]bool )
660660 for _ , vol := range attachments {
661+ reservedPrefix := volumes .ReservedVolumeIDPrefix (vol .VolumeID )
662+ isReservedVolume := reservedPrefix != ""
663+
661664 // Validate mount path is absolute
662665 if ! filepath .IsAbs (vol .MountPath ) {
663666 return fmt .Errorf ("volume %s: mount path %q must be absolute" , vol .VolumeID , vol .MountPath )
@@ -666,16 +669,15 @@ func validateVolumeAttachments(attachments []VolumeAttachment, allowSystemVolume
666669 // Clean the path to normalize it
667670 cleanPath := filepath .Clean (vol .MountPath )
668671
669- // Check for system directories
670- if isSystemDirectory (cleanPath ) {
672+ // Check for system directories. Internal instances may only bypass this
673+ // restriction when attaching reserved internal volumes.
674+ if isSystemDirectory (cleanPath ) && ! (allowSystemVolumes && isReservedVolume ) {
671675 return fmt .Errorf ("volume %s: cannot mount to system directory %q" , vol .VolumeID , cleanPath )
672676 }
673677
674678 // Reserved internal volume IDs are attachable only by internal instances
675- if ! allowSystemVolumes {
676- if prefix := volumes .ReservedVolumeIDPrefix (vol .VolumeID ); prefix != "" {
677- return fmt .Errorf ("volume %s: volume IDs with the prefix %q are reserved for internal use" , vol .VolumeID , prefix )
678- }
679+ if ! allowSystemVolumes && isReservedVolume {
680+ return fmt .Errorf ("volume %s: volume IDs with the prefix %q are reserved for internal use" , vol .VolumeID , reservedPrefix )
679681 }
680682
681683 // Check for duplicate mount paths
0 commit comments