Skip to content

Commit

Permalink
feat: relax extensions file structure validation
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
smira committed Mar 17, 2022
1 parent 50594ab commit cd4d4c6
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 35 deletions.
4 changes: 0 additions & 4 deletions internal/pkg/extensions/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ func TestValidateFailures(t *testing.T) {
name: "norootfs",
loadError: "extension rootfs is missing",
},
{
name: "symlinks",
validateError: "symlinks are not allowed: \"/usr/local/b\"",
},
{
name: "badpaths",
validateError: "path \"/boot/vmlinuz\" is not allowed in extensions",
Expand Down
10 changes: 0 additions & 10 deletions internal/pkg/extensions/testdata/bad/symlinks/manifest.yaml

This file was deleted.

This file was deleted.

21 changes: 1 addition & 20 deletions internal/pkg/extensions/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func (ext *Extension) validateContents() error {
return fmt.Errorf("world-writeable files are not allowed: %q", itemPath)
}

// no symlinks
if d.Type().Type() == os.ModeSymlink {
return fmt.Errorf("symlinks are not allowed: %q", itemPath)
}

var st fs.FileInfo

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

// no special files
if !d.IsDir() && !d.Type().IsRegular() {
if !d.IsDir() && !d.Type().IsRegular() && d.Type().Type() != os.ModeSymlink {
return fmt.Errorf("special files are not allowed: %q", itemPath)
}

// directories should be non-empty
if d.IsDir() {
var contents []fs.DirEntry

contents, err = os.ReadDir(path)
if err != nil {
return err
}

if len(contents) == 0 {
return fmt.Errorf("empty directories are not allowed: %q", itemPath)
}
}

// regular file: check for file path being whitelisted
if !d.IsDir() {
dirPath := filepath.Dir(itemPath)
Expand Down

0 comments on commit cd4d4c6

Please sign in to comment.