Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actions: run: Check script exists during recipe verification #302

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions actions/run_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"errors"
"github.com/go-debos/fakemachine"
"fmt"
"os"
"path"
"strings"

Expand Down Expand Up @@ -82,6 +83,21 @@ func (run *RunAction) Verify(context *debos.DebosContext) error {
args := strings.Split(run.Script, " ")
run.scriptPath = debos.CleanPathAt(args[0], context.RecipeDir)
run.scriptArgs = args[1:]

/* Check the script exists on the filesystem (following symlinks) */
stat, err := os.Stat(run.scriptPath)
if err != nil {
return err
}

if stat.IsDir() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather then checking if it's a Dir this should proably check if it's a regular file

return fmt.Errorf("script %s is a directory", run.Script)
}

/* Check the script is executable */
if stat.Mode()&0111 == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executable and readable ideally; though i don't think golang gives you nice helpers for that unfortunately :/

return fmt.Errorf("script %s is not executable", run.Script)
}
}

return nil
Expand Down