go-github icon indicating copy to clipboard operation
go-github copied to clipboard

x509: certificate signed by unknown authority

Open OGKevin opened this issue 8 years ago • 5 comments

Hi,

I'm not sure if this has something to do with https://github.com/golang/go/issues/24652 but I'm running this SDK in a simple

FROM alpine

WORKDIR /app
COPY --from=builder /http /http

ENTRYPOINT /http

container and it seems to be triggering a Get https://api.github.com/repos/OGKevin/x/pulls/x: x509: a certificate signed by unknown authority error, when the code executes

pullRequest, _,err:= handler.client.PullRequests.Get(...)

I did some research and could not find anything concrete. Most results, without even mentioning docker, are about docker registry. The only thing that came close was the above-referenced issue but I'm missing some knowledge to conclude if that's indeed related.

Maybe you guys have an idea why this is happening? Because this is a bubbled up error, the stack trace does not show the actual reason, but I think that could be recovered by tracing if needed.

OGKevin avatar Nov 10 '18 07:11 OGKevin

Ah, solved. needed to add steps to properly update ca-certificates

OGKevin avatar Nov 10 '18 07:11 OGKevin

@OGKevin how did you solve it?

renskiy avatar Jan 15 '19 15:01 renskiy

@renskiy I've added the following to my dockerfile

RUN apk update \
        && apk upgrade \
        && apk add --no-cache \
        ca-certificates \
        && update-ca-certificates 2>/dev/null || true

To update the ca-certificates

OGKevin avatar Jan 15 '19 16:01 OGKevin

If anyone ends up here simply because of the title, I'll add that for me I was building a Go application via a builder image into a final image, just like the Dockerfile in this ticket, but the change that I had to make wasn't the ca-certificate installation command, but to just change my final image from scratch to alpine. That did add about 6MB to my final image, but I can live with that. After that, the error went away. For reference, I received the error while interacting with the Google Sheets API via Oauth2

alkrauss48 avatar Jan 28 '22 02:01 alkrauss48

I still use from scratch like is recommended here: https://dev.to/ivan/go-build-a-minimal-docker-image-in-just-three-steps-514i but then to solve the certificates problem, I add this COPY command from the builder:

# Create the minimal runtime image
FROM scratch

# copy the ca-certificate.crt from the build stage
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
...

I hope that helps.

gmlewis avatar Jan 28 '22 02:01 gmlewis