|
7 | 7 | # NOTE: ARG declared before first FROM is global and available in all FROM statements |
8 | 8 | ARG BASE_IMAGE=ubuntu:22.04 |
9 | 9 |
|
10 | | -# Multi-stage build: Use official Rust image to build one-shot-token library |
11 | | -# SECURITY: Using official rust:1.77-slim image prevents executing unverified |
12 | | -# scripts from the internet during build time (supply chain attack mitigation) |
13 | | -# NOTE: Rust 1.77+ required for C string literal syntax (c"...") used in src/lib.rs |
14 | | -FROM rust:1.77-slim AS rust-builder |
15 | | - |
16 | | -# Copy one-shot-token source files |
17 | | -COPY one-shot-token/Cargo.toml /tmp/one-shot-token/Cargo.toml |
18 | | -COPY one-shot-token/src/ /tmp/one-shot-token/src/ |
19 | | - |
20 | | -# Build the one-shot-token library |
21 | | -WORKDIR /tmp/one-shot-token |
22 | | -RUN cargo build --release |
23 | | - |
24 | | -# Main stage |
25 | 10 | FROM ${BASE_IMAGE} |
26 | 11 |
|
27 | 12 | # Install required packages and Node.js 22 |
@@ -85,9 +70,21 @@ RUN chmod +x /usr/local/bin/setup-iptables.sh /usr/local/bin/entrypoint.sh /usr/ |
85 | 70 |
|
86 | 71 | # Copy pre-built one-shot-token library from rust-builder stage |
87 | 72 | # This prevents tokens from being read multiple times (e.g., by malicious code) |
88 | | -# SECURITY: Using multi-stage build with official Rust image avoids executing |
89 | | -# unverified scripts from the internet during build time |
90 | | -COPY --from=rust-builder /tmp/one-shot-token/target/release/libone_shot_token.so /usr/local/lib/one-shot-token.so |
| 73 | +# Build flags: -fvisibility=hidden hides internal symbols, -s strips at link time |
| 74 | +COPY one-shot-token/one-shot-token.c /tmp/one-shot-token.c |
| 75 | +RUN set -eux; \ |
| 76 | + BUILD_PKGS="gcc libc6-dev binutils"; \ |
| 77 | + apt-get update && \ |
| 78 | + ( apt-get install -y --no-install-recommends $BUILD_PKGS || \ |
| 79 | + (rm -rf /var/lib/apt/lists/* && apt-get update && \ |
| 80 | + apt-get install -y --no-install-recommends $BUILD_PKGS) ) && \ |
| 81 | + gcc -shared -fPIC -fvisibility=hidden -O2 -Wall -s \ |
| 82 | + -o /usr/local/lib/one-shot-token.so /tmp/one-shot-token.c -ldl -lpthread && \ |
| 83 | + strip --strip-unneeded /usr/local/lib/one-shot-token.so && \ |
| 84 | + rm /tmp/one-shot-token.c && \ |
| 85 | + apt-get remove -y $BUILD_PKGS && \ |
| 86 | + apt-get autoremove -y && \ |
| 87 | + rm -rf /var/lib/apt/lists/* |
91 | 88 |
|
92 | 89 | # Install Docker stub script that shows helpful error message |
93 | 90 | # Docker-in-Docker support was removed in v0.9.1 |
|
0 commit comments