Skip to content

Commit

Permalink
fix(worker): limit workdir path longuer using a hash (#5311)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Jul 17, 2020
1 parent 3fff3a7 commit 4b04067
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion engine/worker/internal/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ func (wk *CurrentWorker) InstallKey(key sdk.Variable) (*workerruntime.KeyRespons
}
cmd := exec.Command(gpgBin, "--import", tmpfile.Name())
var out bytes.Buffer
var outErr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &outErr
if err := cmd.Run(); err != nil {
return nil, sdk.NewError(sdk.ErrWorkerErrorCommand, fmt.Errorf("Cannot import pgp key %s : %v", key.Name, err))
outString := string(out.Bytes())
outErrString := string(outErr.Bytes())
return nil, sdk.NewError(sdk.ErrWorkerErrorCommand, fmt.Errorf("Cannot import pgp key %s (%v): %s %s", key.Name, err, outString, outErrString))
}
return &workerruntime.KeyResponse{
Type: sdk.KeyTypePGP,
Expand Down
8 changes: 5 additions & 3 deletions engine/worker/internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package internal

import (
"context"
"encoding/base64"
"crypto/md5"
"fmt"
"os"
"os/user"
Expand Down Expand Up @@ -374,8 +374,10 @@ func teardownDirectory(fs afero.Fs, dir string) error {
}

func workingDirectory(ctx context.Context, fs afero.Fs, jobInfo sdk.WorkflowNodeJobRunData, suffixes ...string) (string, error) {
var encodedName = base64.RawStdEncoding.EncodeToString([]byte(jobInfo.NodeJobRun.Job.Job.Action.Name))
paths := append([]string{encodedName}, suffixes...)
// Generate a hash of job name as workspace folder, this folder's name should not be too long as some tools are limiting path size.
data := []byte(jobInfo.NodeJobRun.Job.Job.Action.Name)
hashedName := fmt.Sprintf("%x", md5.Sum(data))
paths := append([]string{hashedName}, suffixes...)
dir := path.Join(paths...)

if _, err := fs.Stat(dir); os.IsExist(err) {
Expand Down

0 comments on commit 4b04067

Please sign in to comment.