Skip to content

Commit

Permalink
Merge pull request #1167 from pivotal/1078-docker-config
Browse files Browse the repository at this point in the history
Write .docker config to tmp directory instead of root
  • Loading branch information
tomkennedy513 authored Mar 22, 2023
2 parents 8f80378 + fb53c4b commit eaddd96
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions cmd/completion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ func main() {
}
}

homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(errors.Wrapf(err, "error obtaining home directory"))
}

err = creds.Save(filepath.Join(homeDir, ".docker", "config.json"))
if err != nil {
log.Fatal(errors.Wrapf(err, "error writing docker creds"))
}

keychain := authn.NewMultiKeychain(k8sNodeKeychain, creds)

metadataRetriever := cnb.RemoteMetadataRetriever{
Expand Down Expand Up @@ -140,6 +130,21 @@ func main() {
}

if hasCosign() || notaryV1URL != "" {
tempDir, err := os.MkdirTemp("", "")
if err != nil {
log.Fatal(errors.Wrapf(err, "error creating temprary directory"))
}

err = creds.Save(filepath.Join(tempDir, ".docker", "config.json"))
if err != nil {
log.Fatal(errors.Wrapf(err, "error writing docker creds"))
}

err = os.Setenv("DOCKER_CONFIG", filepath.Join(tempDir, ".docker"))
if err != nil {
log.Fatal(errors.Wrapf(err, "error setting DOCKER_CONFIG env"))
}

if err := signImage(report, keychain); err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit eaddd96

Please sign in to comment.