From f36a514f750481a5ab580e5a6c22c12da8afd9e7 Mon Sep 17 00:00:00 2001 From: Alexander Jung Date: Tue, 19 Nov 2024 16:28:42 +0100 Subject: [PATCH 1/2] fix(initrd): Change detection priority Dockerfile > File > Directory > OCI Image These are ordered by lightweightness and similarly to prevent fallbacks; e.g. a Dockerfile is technically a file so ordering a check for a file before a dockerfile first would result in the Dockerfile being used verbatim (as opposed to being built). Signed-off-by: Alexander Jung --- initrd/detect.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/initrd/detect.go b/initrd/detect.go index acfac0df5..a94281261 100644 --- a/initrd/detect.go +++ b/initrd/detect.go @@ -12,11 +12,11 @@ import ( // New attempts to return the builder for a supplied path which // will allow the provided ... func New(ctx context.Context, path string, opts ...InitrdOption) (Initrd, error) { - if builder, err := NewFromFile(ctx, path, opts...); err == nil { + if builder, err := NewFromDockerfile(ctx, path, opts...); err == nil { return builder, nil - } else if builder, err := NewFromDirectory(ctx, path, opts...); err == nil { + } else if builder, err := NewFromFile(ctx, path, opts...); err == nil { return builder, nil - } else if builder, err := NewFromDockerfile(ctx, path, opts...); err == nil { + } else if builder, err := NewFromDirectory(ctx, path, opts...); err == nil { return builder, nil } else if builder, err := NewFromOCIImage(ctx, path, opts...); err == nil { return builder, nil From 0f92d3abcf331a29ba0bc1565e67227c0263dc75 Mon Sep 17 00:00:00 2001 From: Alexander Jung Date: Tue, 19 Nov 2024 16:30:28 +0100 Subject: [PATCH 2/2] fix(initrd): Add additional check of file type Signed-off-by: Alexander Jung --- initrd/dockerfile.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/initrd/dockerfile.go b/initrd/dockerfile.go index 10f1a362e..6b888f454 100644 --- a/initrd/dockerfile.go +++ b/initrd/dockerfile.go @@ -178,6 +178,13 @@ func NewFromDockerfile(ctx context.Context, path string, opts ...InitrdOption) ( return nil, fmt.Errorf("file is not a Dockerfile") } + fi, err := os.Stat(path) + if err != nil { + return nil, fmt.Errorf("could not check Dockerfile: %w", err) + } else if fi.IsDir() { + return nil, fmt.Errorf("supplied path %s is a directory not a Dockerfile", path) + } + initrd := dockerfile{ opts: InitrdOptions{ workdir: filepath.Dir(path),