Skip to content

Commit ebc035e

Browse files
committed
Replace Alpine with Google's distroless static image for enhanced security
and simplified maintenance. Includes CA certificates automatically and provides debug variant for troubleshooting.
1 parent aaa9907 commit ebc035e

File tree

3 files changed

+32
-31
lines changed

3 files changed

+32
-31
lines changed

Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ COPY script script
1010

1111
RUN CGO_ENABLED=0 GOOS=linux go build -o /go/bin/ratelimit -ldflags="-w -s" -v github.com/envoyproxy/ratelimit/src/service_cmd
1212

13-
FROM alpine:3.22.2@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412 AS final
14-
RUN apk --no-cache add ca-certificates && apk --no-cache update
13+
FROM gcr.io/distroless/static-debian12
1514
COPY --from=build /go/bin/ratelimit /bin/ratelimit

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
- [Overview](#overview)
55
- [Docker Image](#docker-image)
6+
- [Distroless Base Image](#distroless-base-image)
7+
- [Benefits of Distroless:](#benefits-of-distroless)
8+
- [Debugging with Distroless:](#debugging-with-distroless)
69
- [Supported Envoy APIs](#supported-envoy-apis)
710
- [API Deprecation History](#api-deprecation-history)
811
- [Building and Testing](#building-and-testing)
@@ -80,6 +83,28 @@ decision is then returned to the caller.
8083

8184
For every main commit, an image is pushed to [Dockerhub](https://hub.docker.com/r/envoyproxy/ratelimit/tags?page=1&ordering=last_updated). There is currently no versioning (post v1.4.0) and tags are based on commit sha.
8285

86+
## Distroless Base Image
87+
88+
The Docker image uses Google's [distroless](https://github.com/GoogleContainerTools/distroless) base image (`gcr.io/distroless/static-debian12`) for enhanced security and minimal attack surface. Distroless images contain only the application and its runtime dependencies, omitting unnecessary OS components like package managers, shells, and other utilities.
89+
90+
### Benefits of Distroless:
91+
92+
- **Enhanced Security**: Minimal attack surface with no unnecessary components
93+
- **Smaller Image Size**: Significantly smaller than traditional base images
94+
- **Reduced Vulnerabilities**: Fewer components means fewer potential security issues
95+
- **Better Compliance**: Meets security requirements for minimal base images
96+
97+
### Debugging with Distroless:
98+
99+
For debugging purposes, you can use the debug variant of the distroless image:
100+
101+
```dockerfile
102+
FROM gcr.io/distroless/static-debian12:debug
103+
COPY --from=build /go/bin/ratelimit /bin/ratelimit
104+
```
105+
106+
This provides shell access and debugging tools while maintaining the security benefits of distroless.
107+
83108
# Supported Envoy APIs
84109

85110
[v3 rls.proto](https://github.com/envoyproxy/data-plane-api/blob/master/envoy/service/ratelimit/v3/rls.proto) is currently supported.
@@ -132,14 +157,13 @@ Support for [v2 rls proto](https://github.com/envoyproxy/data-plane-api/blob/mas
132157

133158
## Docker-compose setup
134159

135-
The docker-compose setup has three containers: redis, ratelimit-build, and ratelimit. In order to run the docker-compose setup from the root of the repo, run
160+
The docker-compose setup uses a distroless-based container for the ratelimit service. In order to run the docker-compose setup from the root of the repo, run
136161

137162
```bash
138163
docker-compose up
139164
```
140165

141-
The ratelimit-build container will build the ratelimit binary. Then via a shared volume the binary will be shared with the ratelimit container. This dual container setup is used in order to use a
142-
a minimal container to run the application, rather than the heftier container used to build it.
166+
The ratelimit service is built using the main Dockerfile which uses Google's distroless base image for enhanced security and minimal attack surface. The distroless image contains only the application and its runtime dependencies, omitting unnecessary OS components like package managers and shells.
143167

144168
If you want to run with [two redis instances](#two-redis-instances), you will need to modify
145169
the docker-compose.yml file to run a second redis container, and change the environment variables

docker-compose.yml

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,20 @@ services:
1818
networks:
1919
- ratelimit-network
2020

21-
# minimal container that builds the ratelimit service binary and exits.
22-
ratelimit-build:
23-
image: golang:1.23.9-alpine
24-
working_dir: /go/src/github.com/envoyproxy/ratelimit
25-
command: go build -o /usr/local/bin/ratelimit ./src/service_cmd/main.go
26-
volumes:
27-
- .:/go/src/github.com/envoyproxy/ratelimit
28-
- binary:/usr/local/bin/
29-
30-
ratelimit-client-build:
31-
image: golang:1.23.9-alpine
32-
working_dir: /go/src/github.com/envoyproxy/ratelimit
33-
command: go build -o /usr/local/bin/ratelimit_client ./src/client_cmd/main.go
34-
volumes:
35-
- .:/go/src/github.com/envoyproxy/ratelimit
36-
- binary:/usr/local/bin/
37-
3821
ratelimit:
39-
image: alpine:3.6
40-
command: >
41-
sh -c "until test -f /usr/local/bin/ratelimit; do sleep 5; done; /usr/local/bin/ratelimit"
22+
build:
23+
context: .
24+
dockerfile: Dockerfile
25+
command: /bin/ratelimit
4226
ports:
4327
- 8080:8080
4428
- 8081:8081
4529
- 6070:6070
4630
depends_on:
4731
- redis
48-
- ratelimit-build
49-
- ratelimit-client-build
5032
networks:
5133
- ratelimit-network
5234
volumes:
53-
- binary:/usr/local/bin/
5435
- ./examples:/data
5536
environment:
5637
- USE_STATSD=false
@@ -63,6 +44,3 @@ services:
6344

6445
networks:
6546
ratelimit-network:
66-
67-
volumes:
68-
binary:

0 commit comments

Comments
 (0)