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

feat(compute/build): display secrets warning with --debug-mode #1063

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions pkg/commands/compute/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (c *BuildCommand) Exec(in io.Reader, out io.Writer) (err error) {
*/
metadataDisable, _ := strconv.ParseBool(c.Globals.Env.WasmMetadataDisable)
if c.MetadataEnable && !metadataDisable {
if err := c.AnnotateWasmBinaryLong(wasmtools, metadataArgs, language); err != nil {
if err := c.AnnotateWasmBinaryLong(wasmtools, metadataArgs, language, out); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -352,7 +352,7 @@ func (c *BuildCommand) AnnotateWasmBinaryShort(wasmtools string, args []string)
}

// AnnotateWasmBinaryLong annotates the Wasm binary will all available data.
func (c *BuildCommand) AnnotateWasmBinaryLong(wasmtools string, args []string, language *Language) error {
func (c *BuildCommand) AnnotateWasmBinaryLong(wasmtools string, args []string, language *Language, out io.Writer) error {
var ms runtime.MemStats
runtime.ReadMemStats(&ms)

Expand Down Expand Up @@ -450,6 +450,9 @@ func (c *BuildCommand) AnnotateWasmBinaryLong(wasmtools string, args []string, l
for _, f := range filters {
k := strings.Split(v, "=")[0]
if strings.HasPrefix(k, f) {
if c.Globals.Flags.Debug {
text.Warning(out, "We've identified and REDACTED the following secret from `env_vars` in your fastly.toml config: %s\n\n", v)
}
dc.ScriptInfo.EnvVars[i] = k + "=REDACTED"
}
}
Expand All @@ -466,6 +469,9 @@ func (c *BuildCommand) AnnotateWasmBinaryLong(wasmtools string, args []string, l

// Use TruffleHog last to hopefully catch any secret 'values'.
for _, r := range printer.Results {
if c.Globals.Flags.Debug {
text.Warning(out, "TruffleHog identified and REDACTED the following secret: %s (verified: %t)\n\n", r.Secret, r.Verified)
}
data = bytes.ReplaceAll(data, []byte(r.Secret), []byte("REDACTED"))
}

Expand Down
23 changes: 16 additions & 7 deletions pkg/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,22 @@ func (d *Data) Endpoint() (string, lookup.Source) {
// explicit flags. Consumers should bind their flag values to these fields
// directly.
type Flags struct {
// AcceptDefaults accepts defaults for all interactive prompts except Yes/No.
AcceptDefaults bool
AutoYes bool
Debug bool
Endpoint string
// AutoYes answers "yes" to all Yes/No interactive prompts.
AutoYes bool
// Debug enables debug mode and will print additional output.
Debug bool
// Endpoint is the Fastly API endpoint to use.
Endpoint string
// NonInteractive will avoid all interactive prompts.
NonInteractive bool
Profile string
Quiet bool
Token string
Verbose bool
// Profile switches the account profile for a single command invocation.
Profile string
// Quiet stops all output except direct command output or interactive prompts.
Quiet bool
// Token to use for Fastly API requests.
Token string
// Verbose enables verbose mode and will additional output.
Verbose bool
}