Skip to content

Commit b1af3cd

Browse files
authored
Upgrade golang/deps, run as non-root user (#2)
1 parent 0d02624 commit b1af3cd

8 files changed

+85
-826
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

Dockerfile

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM golang:1.17-alpine as build
1+
FROM golang:1.22-alpine as build
2+
3+
RUN addgroup -S app && adduser -S app -G app
24

35
WORKDIR /go/src/app
46

@@ -8,11 +10,14 @@ RUN go mod download
810

911
COPY . .
1012

11-
RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -tags timetzdata -o ambient-exporter
13+
RUN CGO_ENABLED=0 go build -trimpath -ldflags '-extldflags "-static"' -tags timetzdata -o ambient-exporter
1214

1315
FROM scratch
1416

1517
COPY --from=build /go/src/app/ambient-exporter /ambient-exporter
1618
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
19+
COPY --from=build /etc/passwd /etc/passwd
20+
21+
USER app
1722

1823
ENTRYPOINT ["/ambient-exporter"]

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ kubectl -n monitoring create secret generic ambient-exporter \
3737
--from-literal=AMBIENT_API_KEY=${AMBIENT_API_KEY} \
3838
--from-literal=AMBIENT_APP_KEY=${AMBIENT_APP_KEY}
3939

40+
# Using tagged manifests
4041
kubectl kustomize "https://github.com/ianunruh/ambient-exporter.git/deploy/basic?ref=v1.0.1" | \
4142
kubectl apply -n monitoring -f-
43+
44+
# Using local manifests
45+
kubectl kustomize deploy/basic | \
46+
kubectl apply -n monitoring -f-
4247
```

deploy/basic/deployment.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@ spec:
2121
limits:
2222
cpu: 250m
2323
memory: 128Mi
24+
securityContext:
25+
allowPrivilegeEscalation: false
26+
capabilities:
27+
drop:
28+
- all
29+
add:
30+
- NET_BIND_SERVICE
31+
readOnlyRootFilesystem: true
32+
runAsUser: 1000
33+
runAsGroup: 1000
34+
fsGroup: 1000

deploy/basic/kustomization.yaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
apiVersion: kustomize.config.k8s.io/v1beta1
22
kind: Kustomization
3-
commonLabels:
4-
app.kubernetes.io/name: ambient-exporter
3+
labels:
4+
- includeSelectors: true
5+
pairs:
6+
app.kubernetes.io/name: ambient-exporter
57
resources:
68
- deployment.yaml
79
- service.yaml

docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3.1"
21
services:
32
exporter:
43
build: .

go.mod

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
module github.com/ianunruh/ambient-exporter
22

3-
go 1.17
3+
go 1.22
44

55
require (
6-
github.com/prometheus/client_golang v1.11.0
7-
github.com/spf13/cobra v1.3.0
8-
github.com/stretchr/testify v1.7.0
9-
go.uber.org/zap v1.20.0
6+
github.com/prometheus/client_golang v1.19.1
7+
github.com/spf13/cobra v1.8.0
8+
github.com/stretchr/testify v1.8.1
9+
go.uber.org/zap v1.27.0
1010
)
1111

1212
require (
1313
github.com/beorn7/perks v1.0.1 // indirect
14-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
14+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1515
github.com/davecgh/go-spew v1.1.1 // indirect
16-
github.com/golang/protobuf v1.5.2 // indirect
17-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
18-
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
16+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1917
github.com/pmezard/go-difflib v1.0.0 // indirect
20-
github.com/prometheus/client_model v0.2.0 // indirect
21-
github.com/prometheus/common v0.32.1 // indirect
22-
github.com/prometheus/procfs v0.7.3 // indirect
18+
github.com/prometheus/client_model v0.6.1 // indirect
19+
github.com/prometheus/common v0.53.0 // indirect
20+
github.com/prometheus/procfs v0.15.0 // indirect
2321
github.com/spf13/pflag v1.0.5 // indirect
24-
github.com/stretchr/objx v0.1.1 // indirect
25-
go.uber.org/atomic v1.9.0 // indirect
26-
go.uber.org/multierr v1.7.0 // indirect
27-
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
28-
google.golang.org/protobuf v1.27.1 // indirect
29-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
22+
go.uber.org/multierr v1.11.0 // indirect
23+
golang.org/x/sys v0.20.0 // indirect
24+
google.golang.org/protobuf v1.34.1 // indirect
25+
gopkg.in/yaml.v3 v3.0.1 // indirect
3026
)

go.sum

+43-803
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)