Commit fc5c45b1 authored by Geoff Simmons's avatar Geoff Simmons

Controller runs as a non-root user.

Closes #38
parent 1821f0b9
FROM golang:1.11.6 as builder FROM golang:1.11.6 as builder
RUN go get -d -v github.com/slimhazard/gogitversion && \ RUN go get -d -v github.com/slimhazard/gogitversion && \
cd /go/src/github.com/slimhazard/gogitversion && \ cd /go/src/github.com/slimhazard/gogitversion && \
make install make install
...@@ -12,6 +13,7 @@ COPY go.sum . ...@@ -12,6 +13,7 @@ COPY go.sum .
ENV GO111MODULE=on ENV GO111MODULE=on
RUN go mod download RUN go mod download
RUN go mod verify
COPY ./pkg/ /go/src/code.uplex.de/uplex-varnish/k8s-ingress/pkg/ COPY ./pkg/ /go/src/code.uplex.de/uplex-varnish/k8s-ingress/pkg/
COPY ./cmd/ /go/src/code.uplex.de/uplex-varnish/k8s-ingress/cmd/ COPY ./cmd/ /go/src/code.uplex.de/uplex-varnish/k8s-ingress/cmd/
...@@ -21,6 +23,15 @@ RUN go generate ./cmd/... && go build ./pkg/... ./cmd/... && \ ...@@ -21,6 +23,15 @@ RUN go generate ./cmd/... && go build ./pkg/... ./cmd/... && \
CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o k8s-ingress cmd/*.go CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o k8s-ingress cmd/*.go
FROM alpine:3.11.0 FROM alpine:3.11.0
ENV USER=controller UID=10001
RUN adduser --disabled-password --gecos "viking controller" \
--home "/nonexistent" --shell "/sbin/nologin" --no-create-home \
--uid "${UID}" \
"${USER}"
COPY --from=builder /go/src/code.uplex.de/uplex-varnish/k8s-ingress/k8s-ingress /k8s-ingress COPY --from=builder /go/src/code.uplex.de/uplex-varnish/k8s-ingress/k8s-ingress /k8s-ingress
COPY --from=builder /go/src/code.uplex.de/uplex-varnish/k8s-ingress/pkg/varnish/vcl/*.tmpl / COPY --from=builder /go/src/code.uplex.de/uplex-varnish/k8s-ingress/pkg/varnish/vcl/*.tmpl /
USER controller:controller
ENTRYPOINT ["/k8s-ingress"] ENTRYPOINT ["/k8s-ingress"]
...@@ -21,6 +21,9 @@ spec: ...@@ -21,6 +21,9 @@ spec:
ports: ports:
- name: http - name: http
containerPort: 8080 containerPort: 8080
volumeMounts:
- name: run
mountPath: "/run"
livenessProbe: livenessProbe:
exec: exec:
command: command:
...@@ -33,6 +36,10 @@ spec: ...@@ -33,6 +36,10 @@ spec:
command: command:
- /usr/bin/test - /usr/bin/test
- -e - -e
- /ready - /run/controller-ready
args: args:
- -readyfile=/ready - -readyfile=/run/controller-ready
volumes:
- name: run
emptyDir:
medium: "Memory"
...@@ -22,6 +22,9 @@ spec: ...@@ -22,6 +22,9 @@ spec:
ports: ports:
- name: http - name: http
containerPort: 8080 containerPort: 8080
volumeMounts:
- name: run
mountPath: "/run"
livenessProbe: livenessProbe:
exec: exec:
command: command:
...@@ -34,7 +37,11 @@ spec: ...@@ -34,7 +37,11 @@ spec:
command: command:
- /usr/bin/test - /usr/bin/test
- -e - -e
- /ready - /run/controller-ready
args: args:
- -readyfile=/ready - -readyfile=/run/controller-ready
- -class=varnish-coffee - -class=varnish-coffee
volumes:
- name: run
emptyDir:
medium: "Memory"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment