Hello everyone,
I am currently facing an issue where I am unable to authenticate myself to our company's docker registry (Harbor) using the Go SDK method WithRegistryAuth() to pull images.
Regardless of whether I use the method or not, I receive an Unauthorized 401 error when attempting to pull an image. If I log in beforehand using the Docker CLI via docker login, it works.
Below is a minimal example of the code I am using.
func main() {
vars := []string{"HARBOR_USER", "HARBOR_PASS"}
for _, v := range vars {
if os.Getenv(v) == "" {
log.Fatalf("Environment variable %s is not set", v)
}
}
ctx := context.Background()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout), dagger.WithWorkdir(".."))
if err != nil {
panic(err)
}
defer client.Close()
golangImage := "corporate-harbor-registry.de/dockerhub/library/golang:latest"
harborUser := os.Getenv("HARBOR_USER")
harborPass := client.SetSecret("harborPass", os.Getenv("HARBOR_PASS"))
project := client.Host().Directory("./app")
builder := client.Container().
From(golangImage).
WithDirectory("/src", project).
WithWorkdir("/src").
WithRegistryAuth("corporate-harbor-registry.de", harborUser, harborPass)
builder = builder.WithExec([]string{"go", "build", "-o", "microservice"})
_, err = builder.Stdout(ctx)
if err != nil {
panic(err)
}
}
Is the login process somehow visible in the logs of the Dagger Engine? The logs I see don't seem to provide any information about it. Could this possibly be a Harbor-specific problem?