1- # This dockerfile builds a container capable of running the SSH CA bot. Note that a lot of this code is duplicated
2- # between this file and Dockerfile-kssh.
3- FROM ubuntu:18.04
4-
5- # Dependencies
6- RUN apt-get -qq update
7- RUN apt-get -qq install curl software-properties-common ca-certificates gnupg -y
8- RUN useradd -ms /bin/bash keybase
9- USER keybase
10- WORKDIR /home/keybase
1+ # This dockerfile builds a container capable of running the SSH CA bot.
112
12- # Download and verify the deb
13- # Key fingerprint from https://keybase.io/docs/server_security/our_code_signing_key
14- RUN curl --remote-name https://prerelease.keybase.io/keybase_amd64.deb
15- RUN curl --remote-name https://prerelease.keybase.io/keybase_amd64.deb.sig
16- # Import our gpg key from our website. Pulling from key servers caused a flakey build so
17- # we get the key from the Keybase website instead.
18- RUN curl -sSL https://keybase.io/docs/server_security/code_signing_key.asc | gpg --import
19- # This line will error if the fingerprint of the key in the file does not match the
20- # known fingerprint of the our PGP key
21- RUN gpg --fingerprint 222B85B0F90BE2D24CFEB93F47484E50656D16C7
22- # And then verify the signature now that we have the key
23- RUN gpg --verify keybase_amd64.deb.sig keybase_amd64.deb
24-
25- # Silence the error from dpkg about failing to configure keybase since `apt-get install -f` fixes it
26- USER root
27- RUN dpkg -i keybase_amd64.deb || true
28- RUN apt-get install -fy
29- USER keybase
3+ FROM alpine:3.11 AS builder
304
31- # Install go
32- USER root
33- RUN add-apt-repository ppa:gophers/archive -y
34- RUN apt-get update
35- RUN apt-get install golang-1.11-go git sudo -y
36- USER keybase
5+ # add dependencies
6+ RUN apk update && apk add --no-cache go curl git musl-dev gcc
7+
8+ # build keybase binary
9+ WORKDIR /go
10+ ENV GOPATH=/go
11+ ENV KEYBASE_VERSION=5.0.0
12+ RUN go get -d github.com/keybase/client/go/keybase
13+ RUN cd src/github.com/keybase/client/go/keybase && git checkout v$KEYBASE_VERSION
14+ RUN go install -tags production github.com/keybase/client/go/keybase
15+
16+ # build kbfsfuse binary (we won't use FUSE but the bot needs KBFS for exchanging Team config files)
17+ RUN go install -tags production github.com/keybase/client/go/kbfs/kbfsfuse
3718
38- # Install go dependencies (speeds up future builds)
39- COPY --chown=keybase go.mod .
40- COPY --chown=keybase go.sum .
41- RUN /usr/lib/go-1.11/ bin/go mod download
19+ # build keybaseca
20+ WORKDIR /bot-sshca
21+ COPY . ./
22+ RUN go build -o bin/keybaseca src/cmd/keybaseca/keybaseca.go
4223
43- COPY --chown=keybase ./ /home/keybase/
24+ FROM alpine:3.11
4425
45- RUN /usr/lib/go-1.11/bin/go build -o bin/keybaseca src/cmd/keybaseca/keybaseca.go
26+ # add bash for entrypoint scripts, ssh for ssh-keygen used by the bot, sudo for stepping down to keybase user
27+ RUN apk update && apk add --no-cache bash openssh sudo
4628
47- USER root
29+ # add the keybase user
30+ RUN adduser -s /bin/bash -h /home/keybase -D keybase
31+ RUN chown keybase:keybase /home/keybase
32+
33+ # this folder is needed for kbfsfuse
34+ RUN mkdir /keybase && chown -R keybase:keybase /keybase
35+
36+ USER keybase
37+ WORKDIR /home/keybase
38+
39+ # copy the keybase binaries from previous build step
40+ COPY --from=builder --chown=keybase:keybase /go/bin/keybase /usr/local/bin/
41+ COPY --from=builder --chown=keybase:keybase /go/bin/kbfsfuse /usr/local/bin/
42+ COPY --from=builder --chown=keybase:keybase /bot-sshca/bin/keybaseca bin/
43+
44+ # copy in entrypoint scripts and env.sh
45+ COPY --chown=keybase:keybase ./docker ./
46+
47+ # Run container as root but only to be able to chown the Docker bind-mount,
48+ # then immediatetly step down to the keybase user via sudo in the entrypoint scripts
49+ USER root
0 commit comments