Skip to content

Commit e383ce0

Browse files
committed
Validate that the playbook path actually exists
Especially when using relative paths, and not absolute paths. Also do some sanity checking on the mode and script fields. Signed-off-by: Anders F Björklund <[email protected]>
1 parent 996b340 commit e383ce0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/limayaml/validate.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ func Validate(y *LimaYAML, warn bool) error {
208208
return fmt.Errorf("field `provision[%d].mode` must one of %q, %q, %q, %q, or %q",
209209
i, ProvisionModeSystem, ProvisionModeUser, ProvisionModeBoot, ProvisionModeDependency, ProvisionModeAnsible)
210210
}
211+
if p.Playbook != "" {
212+
if p.Mode != ProvisionModeAnsible {
213+
return fmt.Errorf("field `provision[%d].mode must be %q if playbook is set", i, ProvisionModeAnsible)
214+
}
215+
if p.Script != "" {
216+
return fmt.Errorf("field `provision[%d].script must be empty if playbook is set", i)
217+
}
218+
playbook := p.Playbook
219+
if _, err := os.Stat(playbook); err != nil {
220+
return fmt.Errorf("field `provision[%d].playbook` refers to an inaccessible path: %q: %w", i, playbook, err)
221+
}
222+
}
211223
if strings.Contains(p.Script, "LIMA_CIDATA") {
212224
logrus.Warn("provisioning scripts should not reference the LIMA_CIDATA variables")
213225
}

0 commit comments

Comments
 (0)