Skip to content
Merged
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
Prev Previous commit
Next Next commit
add some replace logic for secret masking
  • Loading branch information
ecrupper committed Dec 21, 2021
commit d62f6eb3ee6a9955feba6faeff7abafb1b5c2dab
45 changes: 12 additions & 33 deletions executor/linux/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,25 +217,15 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error

secretValues := []string{}

for _, secret := range c.pipeline.Secrets {
// ignore pulling secrets coming from plugins
if !secret.Origin.Empty() {
continue
}

c.Logger.Infof("pulling %s %s secret %s", secret.Engine, secret.Type, secret.Name)

s, err := c.secret.pull(secret)
for _, secret := range ctn.Secrets {
s := ctn.Environment[strings.ToUpper(secret.Target)]
if err != nil {
c.err = err
return fmt.Errorf("unable to pull secrets: %w", err)
}
secretValues = append(secretValues, s.GetValue())
secretValues = append(secretValues, s)
}

fmt.Println("LOGGING LOGGING LOGGING")
fmt.Println(secretValues)

defer func() {
// tail the runtime container
rc, err := c.Runtime.TailContainer(ctx, ctn)
Expand All @@ -261,19 +251,16 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error
return
}

// overwrite the existing log with all bytes
//
// https://pkg.go.dev/github.com/go-vela/types/library?tab=doc#Log.SetData
// mask secrets in logs before setting them in the database.
strData := string(data)
fmt.Println("LOG")
fmt.Println(strData)
for _, secret := range secretValues {
fmt.Println("SECRET DEFER:")
fmt.Println(secret)
strData = strings.ReplaceAll(strData, secret, "********")
strData = strings.ReplaceAll(strData, secret, constants.SecretLogMask)
}
data = []byte(strData)

// overwrite the existing log with all bytes
//
// https://pkg.go.dev/github.com/go-vela/types/library?tab=doc#Log.SetData
_log.SetData(data)

logger.Debug("uploading logs")
Expand Down Expand Up @@ -338,13 +325,9 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error
//
// https://pkg.go.dev/github.com/go-vela/types/library?tab=doc#Log.AppendData

strData := string(logs.Bytes())
fmt.Println("LOG")
fmt.Println(strData)
strData := logs.String()
for _, secret := range secretValues {
fmt.Println("SECRET TIME CHUNK:")
fmt.Println(secret)
strData = strings.ReplaceAll(strData, secret, "********")
strData = strings.ReplaceAll(strData, secret, constants.SecretLogMask)
}

_log.AppendData([]byte(strData))
Expand Down Expand Up @@ -407,13 +390,9 @@ func (c *client) StreamStep(ctx context.Context, ctn *pipeline.Container) error
// update the existing log with the new bytes
//
// https://pkg.go.dev/github.com/go-vela/types/library?tab=doc#Log.AppendData
strData := string(logs.Bytes())
fmt.Println("LOG")
fmt.Println(strData)
strData := logs.String()
for _, secret := range secretValues {
fmt.Println("SECRET BYTE CHUNK:")
fmt.Println(secret)
strData = strings.ReplaceAll(strData, secret, "********")
strData = strings.ReplaceAll(strData, secret, constants.SecretLogMask)
}
_log.AppendData(logs.Bytes())

Expand Down