@@ -24,6 +24,7 @@ import (
2424 "go.podman.io/common/libimage"
2525 "go.podman.io/common/libnetwork/pasta"
2626 "go.podman.io/common/libnetwork/slirp4netns"
27+ "go.podman.io/common/pkg/libartifact/store"
2728 "tags.cncf.io/container-device-interface/pkg/parser"
2829)
2930
@@ -509,6 +510,11 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l
509510 }
510511
511512 if len (s .ArtifactVolumes ) != 0 {
513+ // Validate artifacts exist before creating the container
514+ if err := validateArtifactVolumes (ctx , rt , s .ArtifactVolumes ); err != nil {
515+ return nil , nil , nil , err
516+ }
517+
512518 vols := make ([]* libpod.ContainerArtifactVolume , 0 , len (s .ArtifactVolumes ))
513519 for _ , v := range s .ArtifactVolumes {
514520 vols = append (vols , & libpod.ContainerArtifactVolume {
@@ -755,3 +761,39 @@ func Inherit(infra *libpod.Container, s *specgen.SpecGenerator, rt *libpod.Runti
755761 }
756762 return options , infraSpec , compatibleOptions , nil
757763}
764+
765+ // validateArtifactVolumes checks that all artifacts exist and are accessible
766+ // at container creation time, preventing creation of containers that can never start.
767+ func validateArtifactVolumes (ctx context.Context , rt * libpod.Runtime , artifactVolumes []* specgen.ArtifactVolume ) error {
768+ if len (artifactVolumes ) == 0 {
769+ return nil
770+ }
771+
772+ artStore , err := rt .ArtifactStore ()
773+ if err != nil {
774+ return fmt .Errorf ("accessing artifact store: %w" , err )
775+ }
776+
777+ for _ , artifactMount := range artifactVolumes {
778+ // Use the same artifact store resolution logic as at start time
779+ // to ensure consistent validation behavior
780+ asr , err := artStore .NewArtifactStorageReference (artifactMount .Source )
781+ if err != nil {
782+ return fmt .Errorf ("invalid artifact reference %q: %w" , artifactMount .Source , err )
783+ }
784+
785+ // Validate artifact exists using the same logic as container start.
786+ // This ensures consistent behavior between creation and start time.
787+ _ /*paths*/ , err = artStore .BlobMountPaths (ctx , asr , & store.BlobMountPathOptions {
788+ FilterBlobOptions : store.FilterBlobOptions {
789+ Title : artifactMount .Title ,
790+ Digest : artifactMount .Digest ,
791+ },
792+ })
793+ if err != nil {
794+ return fmt .Errorf ("validating artifact %q: %w" , artifactMount .Source , err )
795+ }
796+ }
797+
798+ return nil
799+ }
0 commit comments