Skip to content

Commit 642b69d

Browse files
committed
Address part of comments.
1 parent c3feb60 commit 642b69d

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

toolkit/tools/imagecustomizerapi/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ func (c *Config) IsValid() (err error) {
101101
}
102102
}
103103

104-
if slices.ContainsFunc(c.Storage.Verity, func(v Verity) bool {
104+
// Check if any verity entry has a non-empty hash signature path.
105+
hasVerityHashSignature := slices.ContainsFunc(c.Storage.Verity, func(v Verity) bool {
105106
return v.HashSignaturePath != ""
106-
}) {
107+
})
108+
109+
if hasVerityHashSignature {
107110
if !sliceutils.ContainsValue(c.PreviewFeatures, PreviewFeatureOutputArtifacts) {
108111
return fmt.Errorf("the 'output-artifacts' preview feature must be enabled to use 'verity.hashSignaturePath'")
109112
}

toolkit/tools/imagecustomizerapi/storage.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package imagecustomizerapi
55

66
import (
77
"fmt"
8-
"path/filepath"
98
"strings"
109

1110
"github.com/microsoft/azurelinux/toolkit/tools/internal/logger"
@@ -224,8 +223,6 @@ func (s *Storage) IsValid() error {
224223
}
225224

226225
func ValidateVerityMounts(verityDevices []Verity, verityDeviceMountPoint map[*Verity]*MountPoint) error {
227-
const bootMountPoint = "/boot"
228-
229226
for i := range verityDevices {
230227
verity := &verityDevices[i]
231228

@@ -248,17 +245,6 @@ func ValidateVerityMounts(verityDevices []Verity, verityDeviceMountPoint map[*Ve
248245
if !sliceutils.ContainsValue(mountOptions, "ro") {
249246
return fmt.Errorf("verity device's (%s) mount must include the 'ro' mount option", verity.Id)
250247
}
251-
252-
if verity.HashSignaturePath != "" {
253-
sigPath := filepath.Clean(verity.HashSignaturePath)
254-
255-
if !strings.HasPrefix(sigPath, bootMountPoint+"/") {
256-
return fmt.Errorf(
257-
"verity.hashSignaturePath (%s) must be located under ESP mount point (%s)",
258-
sigPath, bootMountPoint,
259-
)
260-
}
261-
}
262248
}
263249

264250
return nil

toolkit/tools/imagecustomizerapi/verity.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ package imagecustomizerapi
55

66
import (
77
"fmt"
8+
"path/filepath"
89
"regexp"
10+
"strings"
911
)
1012

1113
const (
1214
DeviceMapperPath = "/dev/mapper"
15+
bootMountPoint = "/boot"
1316

1417
VerityRootDeviceName = "root"
1518
VerityUsrDeviceName = "usr"
@@ -96,6 +99,14 @@ func (v *Verity) IsValid() error {
9699
if err := validatePath(v.HashSignaturePath); err != nil {
97100
return fmt.Errorf("invalid hashSignaturePath:\n%w", err)
98101
}
102+
103+
sigPath := filepath.Clean(v.HashSignaturePath)
104+
if !strings.HasPrefix(sigPath, bootMountPoint+"/") {
105+
return fmt.Errorf(
106+
"verity.hashSignaturePath (%s) must be located under /boot mount point (%s)",
107+
sigPath, bootMountPoint,
108+
)
109+
}
99110
}
100111

101112
return nil

0 commit comments

Comments
 (0)