Skip to content

Commit a605759

Browse files
committed
feat: relax extensions file structure validation
* allow empty directories (I see no harm in having them) * allow symlinks See also siderolabs/extensions#20 Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com> (cherry picked from commit cd4d4c6)
1 parent eb16019 commit a605759

File tree

5 files changed

+2
-35
lines changed

5 files changed

+2
-35
lines changed

internal/pkg/extensions/extensions_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ func TestValidateFailures(t *testing.T) {
7676
name: "norootfs",
7777
loadError: "extension rootfs is missing",
7878
},
79-
{
80-
name: "symlinks",
81-
validateError: "symlinks are not allowed: \"/usr/local/b\"",
82-
},
8379
{
8480
name: "badpaths",
8581
validateError: "path \"/boot/vmlinuz\" is not allowed in extensions",

internal/pkg/extensions/testdata/bad/symlinks/manifest.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

internal/pkg/extensions/testdata/bad/symlinks/rootfs/usr/local/b

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a.so

internal/pkg/extensions/validate.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ func (ext *Extension) validateContents() error {
7070
return fmt.Errorf("world-writeable files are not allowed: %q", itemPath)
7171
}
7272

73-
// no symlinks
74-
if d.Type().Type() == os.ModeSymlink {
75-
return fmt.Errorf("symlinks are not allowed: %q", itemPath)
76-
}
77-
7873
var st fs.FileInfo
7974

8075
st, err = d.Info()
@@ -88,24 +83,10 @@ func (ext *Extension) validateContents() error {
8883
}
8984

9085
// no special files
91-
if !d.IsDir() && !d.Type().IsRegular() {
86+
if !d.IsDir() && !d.Type().IsRegular() && d.Type().Type() != os.ModeSymlink {
9287
return fmt.Errorf("special files are not allowed: %q", itemPath)
9388
}
9489

95-
// directories should be non-empty
96-
if d.IsDir() {
97-
var contents []fs.DirEntry
98-
99-
contents, err = os.ReadDir(path)
100-
if err != nil {
101-
return err
102-
}
103-
104-
if len(contents) == 0 {
105-
return fmt.Errorf("empty directories are not allowed: %q", itemPath)
106-
}
107-
}
108-
10990
// regular file: check for file path being whitelisted
11091
if !d.IsDir() {
11192
dirPath := filepath.Dir(itemPath)

0 commit comments

Comments
 (0)