GoogleCloudPlatform / docker-credential-gcr

A Docker credential helper for GCR users
https://gcr.io
Apache License 2.0
284 stars 91 forks source link

Unable to use binary built from source #136

Closed sudo-bmitch closed 1 year ago

sudo-bmitch commented 1 year ago

While debugging an auth issue with regclient, I'm not able to reproduce the released binary:

First, setup an environment in a container to minimize externalities:

$ docker container run -it --rm --net host \
  -v "/etc/passwd:/etc/passwd:ro" -v "/etc/group:/etc/group:ro" \
  -u "$(id -u):$(id -g)" -e HOME \
  -v "$(pwd)/gcr-debug-home:${HOME}" \
  -v "${HOME}/.config/gcloud:${HOME}/.config/gcloud:ro" \
  golang:1.17.13 /bin/bash

bmitch:/go$ go install github.com/regclient/regclient/cmd/regctl@latest
go: downloading github.com/regclient/regclient v0.4.8
go: downloading github.com/opencontainers/go-digest v1.0.0
go: downloading github.com/sirupsen/logrus v1.9.0
go: downloading golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
go: downloading github.com/spf13/cobra v1.3.0
go: downloading github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7
go: downloading golang.org/x/sync v0.1.0
go: downloading golang.org/x/sys v0.7.0
go: downloading github.com/spf13/pflag v1.0.5

bmitch:/go$ regctl registry set --cred-helper docker-credential-gcr gcr.io

Then build the binary from source:

bmitch:/go$ git clone https://github.com/GoogleCloudPlatform/docker-credential-gcr.git -b v2.1.8 --depth 1
Cloning into 'docker-credential-gcr'...
remote: Enumerating objects: 67, done.
remote: Counting objects: 100% (67/67), done.
remote: Compressing objects: 100% (66/66), done.
remote: Total 67 (delta 14), reused 26 (delta 0), pack-reused 0
Receiving objects: 100% (67/67), 70.74 KiB | 3.72 MiB/s, done.
Resolving deltas: 100% (14/14), done.
Note: switching to '62afb2723512fd6572c6300024e0c94f734b0ae3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

bmitch:/go$ cd docker-credential-gcr

bmitch:/go/docker-credential-gcr$ CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/GoogleCloudPlatform/docker-credential-gcr/config.Version=v2.1.8" .
go: downloading github.com/google/subcommands v1.2.0
go: downloading github.com/docker/cli v20.10.12+incompatible
go: downloading github.com/docker/docker-credential-helpers v0.6.4
go: downloading github.com/toqueteos/webbrowser v1.2.0
go: downloading golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
go: downloading cloud.google.com/go/compute v1.1.0
go: downloading golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
go: downloading cloud.google.com/go v0.100.2
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/docker/docker v20.10.12+incompatible
go: downloading github.com/sirupsen/logrus v1.8.1
go: downloading golang.org/x/sys v0.0.0-20220114195835-da31bd327af9

bmitch:/go/docker-credential-gcr$ ln -sf "$(pwd)/docker-credential-gcr" /go/bin/docker-credential-gcr

bmitch:/go/docker-credential-gcr$ echo "gcr.io" | docker-credential-gcr get
{"ServerURL":"gcr.io","Username":"_dcgcr_v2_1_8_token","Secret":"*REDACTED*"}

Attempt to copy an image:

bmitch:/go/docker-credential-gcr$ regctl image copy gcr.io/${repo}:latest gcr.io/${repo}:v1
WARN[0000] Sleeping for backoff                          Host=gcr.io Seconds=1.9999932679999999
WARN[0002] Sleeping for backoff                          Host=gcr.io Seconds=3.9999887320000003
WARN[0006] Sleeping for backoff                          Host=gcr.io Seconds=7.9998425730000005
WARN[0014] Failed to get source manifest                 err="failed to get manifest gcr.io/*repo*:latest: unauthorized" ref="gcr.io/*repop*:latest"
failed to get manifest gcr.io/*repo*:latest: unauthorized

Curl the released binary and retry:

bmitch:/go/docker-credential-gcr$ mkdir /go/curl

bmitch:/go/docker-credential-gcr$ cd /go/curl

bmitch:/go/curl$ curl -L https://github.com/GoogleCloudPlatform/docker-credential-gcr/releases/download/v2.1.8/docker-credential-gcr_linux_amd64-2.1.8.tar.gz | tar -xvzf - docker-credential-gcr
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
docker-credential-gcr
100 2233k  100 2233k    0     0  3850k      0 --:--:-- --:--:-- --:--:-- 7318k

bmitch:/go/curl$ ln -sf "$(pwd)/docker-credential-gcr" /go/bin/docker-credential-gcr

bmitch:/go/curl$ regctl image copy gcr.io/${repo}:latest gcr.io/${repo}:v1

bmitch:/go/curl$ 

As best I can tell, I've built the binary identically:

bmitch:/go/curl$ go version -m docker-credential-gcr
docker-credential-gcr: go1.17.13
        path    github.com/GoogleCloudPlatform/docker-credential-gcr
        mod     github.com/GoogleCloudPlatform/docker-credential-gcr    (devel)
        dep     cloud.google.com/go/compute     v1.1.0  h1:pyPhehLfZ6pVzRgJmXGYvCY4K7WSWRhVw0AwhgVvS84=
        dep     github.com/docker/cli   v20.10.12+incompatible  h1:lZlz0uzG+GH+c0plStMUdF/qk3ppmgnswpR5EbqzVGA=
        dep     github.com/docker/docker        v20.10.12+incompatible  h1:CEeNmFM0QZIsJCZKMkZx0ZcahTiewkrgiwfYD+dfl1U=
        dep     github.com/docker/docker-credential-helpers     v0.6.4  h1:axCks+yV+2MR3/kZhAmy07yC56WZ2Pwu/fKWtKuZB0o=
        dep     github.com/google/subcommands   v1.2.0  h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
        dep     github.com/pkg/errors   v0.9.1  h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
        dep     github.com/sirupsen/logrus      v1.8.1  h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
        dep     github.com/toqueteos/webbrowser v1.2.0  h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
        dep     golang.org/x/net        v0.0.0-20220127200216-cd36cc0744dd      h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
        dep     golang.org/x/oauth2     v0.0.0-20211104180415-d3ed0bb246c8      h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg=
        dep     golang.org/x/sys        v0.0.0-20220114195835-da31bd327af9      h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=

bmitch:/go/curl$ ./docker-credential-gcr version
Google Container Registry Docker credential helper 2.1.8

bmitch:/go/curl$ cd ../docker-credential-gcr/

bmitch:/go/docker-credential-gcr$ go version -m docker-credential-gcr
docker-credential-gcr: go1.17.13
        path    github.com/GoogleCloudPlatform/docker-credential-gcr
        mod     github.com/GoogleCloudPlatform/docker-credential-gcr    (devel)
        dep     cloud.google.com/go/compute     v1.1.0  h1:pyPhehLfZ6pVzRgJmXGYvCY4K7WSWRhVw0AwhgVvS84=
        dep     github.com/docker/cli   v20.10.12+incompatible  h1:lZlz0uzG+GH+c0plStMUdF/qk3ppmgnswpR5EbqzVGA=
        dep     github.com/docker/docker        v20.10.12+incompatible  h1:CEeNmFM0QZIsJCZKMkZx0ZcahTiewkrgiwfYD+dfl1U=
        dep     github.com/docker/docker-credential-helpers     v0.6.4  h1:axCks+yV+2MR3/kZhAmy07yC56WZ2Pwu/fKWtKuZB0o=
        dep     github.com/google/subcommands   v1.2.0  h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
        dep     github.com/pkg/errors   v0.9.1  h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
        dep     github.com/sirupsen/logrus      v1.8.1  h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
        dep     github.com/toqueteos/webbrowser v1.2.0  h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
        dep     golang.org/x/net        v0.0.0-20220127200216-cd36cc0744dd      h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
        dep     golang.org/x/oauth2     v0.0.0-20211104180415-d3ed0bb246c8      h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg=
        dep     golang.org/x/sys        v0.0.0-20220114195835-da31bd327af9      h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=

bmitch:/go/docker-credential-gcr$ ./docker-credential-gcr version
Google Container Registry Docker credential helper v2.1.8

Is there something I'm missing to build a binary that can be used similar to the released binary.

sudo-bmitch commented 1 year ago

Thank you to @jonjohnsonjr for spotting my error. There was a "v" in the version injected to the go build. Dropping that now works:

CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/GoogleCloudPlatform/docker-credential-gcr/config.Version=2.1.8" .