Skip to content

Commit 99d8551

Browse files
authored
Replace Alpine with Google's distroless static image for enhanced sec… (#993)
* Replace Alpine with Google's distroless static image for enhanced security and simplified maintenance. Includes CA certificates automatically and provides debug variant for troubleshooting. * security: pin distroless image to SHA and use nonroot variant - Pin gcr.io/distroless/static-debian12:nonroot to specific SHA digest - Ensures deterministic builds and prevents supply chain attacks - Use nonroot variant for enhanced security (runs as UID 65532) - Follows same pattern as Envoy proxy for consistency - Update documentation to reflect security improvements
1 parent 875d418 commit 99d8551

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-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:nonroot@sha256:e8a4044e0b4ae4257efa45fc026c0bc30ad320d43bd4c1a7d5271bd241e386d0
1514
COPY --from=build /go/bin/ratelimit /bin/ratelimit

README.md

Lines changed: 31 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)
@@ -81,6 +84,32 @@ decision is then returned to the caller.
8184

8285
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.
8386

87+
## Distroless Base Image
88+
89+
The Docker image uses Google's [distroless](https://github.com/GoogleContainerTools/distroless) base image (`gcr.io/distroless/static-debian12:nonroot`) 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.
90+
91+
The image is pinned to a specific SHA digest for deterministic builds and uses the `nonroot` variant to run as a non-privileged user, following security best practices.
92+
93+
### Benefits of Distroless:
94+
95+
- **Enhanced Security**: Minimal attack surface with no unnecessary components
96+
- **Smaller Image Size**: Significantly smaller than traditional base images
97+
- **Reduced Vulnerabilities**: Fewer components means fewer potential security issues
98+
- **Better Compliance**: Meets security requirements for minimal base images
99+
- **Non-root Execution**: Runs as a non-privileged user (UID 65532) for enhanced security
100+
- **Deterministic Builds**: Pinned to specific SHA digest ensures reproducible builds
101+
102+
### Debugging with Distroless:
103+
104+
For debugging purposes, you can use the debug variant of the distroless image:
105+
106+
```dockerfile
107+
FROM gcr.io/distroless/static-debian12:debug
108+
COPY --from=build /go/bin/ratelimit /bin/ratelimit
109+
```
110+
111+
This provides shell access and debugging tools while maintaining the security benefits of distroless.
112+
84113
# Supported Envoy APIs
85114

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

134163
## Docker-compose setup
135164

136-
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
165+
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
137166

138167
```bash
139168
docker-compose up
140169
```
141170

142-
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
143-
a minimal container to run the application, rather than the heftier container used to build it.
171+
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.
144172

145173
If you want to run with [two redis instances](#two-redis-instances), you will need to modify
146174
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)