Skip to content

Commit

Permalink
When pack is run with --verbose, it should not print registry creds
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <[email protected]>
  • Loading branch information
natalieparellano committed May 5, 2022
1 parent 04f7318 commit 0385092
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/build/phase_config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewPhaseConfigProvider(name string, lifecycleExec *LifecycleExecution, ops
lifecycleExec.logger.Debugf("Running the %s on OS %s with:", style.Symbol(provider.Name()), style.Symbol(provider.os))
lifecycleExec.logger.Debug("Container Settings:")
lifecycleExec.logger.Debugf(" Args: %s", style.Symbol(strings.Join(provider.ctrConf.Cmd, " ")))
lifecycleExec.logger.Debugf(" System Envs: %s", style.Symbol(strings.Join(provider.ctrConf.Env, " ")))
lifecycleExec.logger.Debugf(" System Envs: %s", style.Symbol(strings.Join(sanitized(provider.ctrConf.Env), " ")))
lifecycleExec.logger.Debugf(" Image: %s", style.Symbol(provider.ctrConf.Image))
lifecycleExec.logger.Debugf(" User: %s", style.Symbol(provider.ctrConf.User))
lifecycleExec.logger.Debugf(" Labels: %s", style.Symbol(fmt.Sprintf("%s", provider.ctrConf.Labels)))
Expand All @@ -84,6 +84,18 @@ func NewPhaseConfigProvider(name string, lifecycleExec *LifecycleExecution, ops
return provider
}

func sanitized(origEnv []string) []string {
var sanitizedEnv []string
for _, env := range origEnv {
if strings.HasPrefix(env, "CNB_REGISTRY_AUTH") {
sanitizedEnv = append(sanitizedEnv, "CNB_REGISTRY_AUTH=<redacted>")
continue
}
sanitizedEnv = append(sanitizedEnv, env)
}
return sanitizedEnv
}

func (p *PhaseConfigProvider) ContainerConfig() *container.Config {
return p.ctrConf
}
Expand Down
31 changes: 31 additions & 0 deletions internal/build/phase_config_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,37 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
h.AssertContainsMatch(t, outBuf.String(), `Binds: \'\S+:\S+layers \S+:\S+workspace'`)
h.AssertContains(t, outBuf.String(), "Network Mode: ''")
})

when("there is registry auth", func() {
it("sanitizes the output", func() {
authConfig := "some-auth-config"

var outBuf bytes.Buffer
logger := logging.NewLogWithWriters(&outBuf, &outBuf, logging.WithVerbose())

docker, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.38"))
h.AssertNil(t, err)

defaultBuilder, err := fakes.NewFakeBuilder()
h.AssertNil(t, err)

opts := build.LifecycleOptions{
AppPath: "some-app-path",
Builder: defaultBuilder,
}

lifecycleExec, err := build.NewLifecycleExecution(logger, docker, opts)
h.AssertNil(t, err)

_ = build.NewPhaseConfigProvider(
"some-name",
lifecycleExec,
build.WithRegistryAccess(authConfig),
)

h.AssertContains(t, outBuf.String(), "System Envs: 'CNB_REGISTRY_AUTH=<redacted> CNB_PLATFORM_API=0.4'")
})
})
})
})
}

0 comments on commit 0385092

Please sign in to comment.