Skip to content

Commit a8a574e

Browse files
committed
actions/run: Check script exists during recipe verification
If a script doesn't exist or the permissions are wrong, the recipe exits during execution. Let's check early if the script exists on the host filesystem and that the file has executable permission bit set. Signed-off-by: Christopher Obbard <[email protected]>
1 parent a95ed84 commit a8a574e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

actions/run_action.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ package actions
4545
import (
4646
"errors"
4747
"github.com/go-debos/fakemachine"
48+
"fmt"
49+
"os"
4850
"path"
4951
"strings"
5052

@@ -68,6 +70,21 @@ func (run *RunAction) Verify(context *debos.DebosContext) error {
6870
if run.Script == "" && run.Command == "" {
6971
return errors.New("Script and Command both cannot be empty")
7072
}
73+
74+
if run.Script != "" {
75+
argv := strings.SplitN(run.Script, " ", 2)
76+
script := debos.CleanPathAt(argv[0], context.RecipeDir)
77+
78+
stat, err := os.Stat(script)
79+
if err != nil {
80+
return err
81+
}
82+
83+
if stat.IsDir() || stat.Mode()&0111 == 0 {
84+
return fmt.Errorf("Script %s is not executable", script)
85+
}
86+
}
87+
7188
return nil
7289
}
7390

0 commit comments

Comments
 (0)