Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions containers/agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ RUN chmod +x /usr/local/bin/setup-iptables.sh /usr/local/bin/entrypoint.sh /usr/
# Copy pre-built one-shot-token library from rust-builder stage
# This prevents tokens from being read multiple times (e.g., by malicious code)
# Build flags: -fvisibility=hidden hides internal symbols, -s strips at link time
# -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 disables glibc fortification macros (e.g.
# __fprintf_chk) so the resulting .so loads on musl-based hosts (Alpine/ARC runners)
COPY one-shot-token/one-shot-token.c /tmp/one-shot-token.c
RUN set -eux; \
BUILD_PKGS="gcc libc6-dev binutils"; \
Expand All @@ -166,6 +168,7 @@ RUN set -eux; \
(rm -rf /var/lib/apt/lists/* && apt-get update && \
apt-get install -y --no-install-recommends $BUILD_PKGS) ) && \
gcc -shared -fPIC -fvisibility=hidden -O2 -Wall -s \
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 \
-o /usr/local/lib/one-shot-token.so /tmp/one-shot-token.c -ldl -lpthread && \
strip --strip-unneeded /usr/local/lib/one-shot-token.so && \
rm /tmp/one-shot-token.c && \
Expand Down
14 changes: 12 additions & 2 deletions containers/agent/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,18 @@ if [ "${AWF_CHROOT_ENABLED}" = "true" ]; then
# Copy the library and verify it exists after copying
if cp /usr/local/lib/one-shot-token.so /host/tmp/awf-lib/one-shot-token.so 2>/dev/null && \
[ -f /host/tmp/awf-lib/one-shot-token.so ]; then
ONE_SHOT_TOKEN_LIB="/tmp/awf-lib/one-shot-token.so"
echo "[entrypoint] One-shot token library copied to chroot at ${ONE_SHOT_TOKEN_LIB}"
# Probe compatibility with the host's dynamic linker before committing to LD_PRELOAD.
# The .so is compiled against glibc; on musl-based hosts (Alpine/ARC runners) it will
# fail to load with "symbol not found: __fprintf_chk". Running the host's /bin/true
# (which uses the host's own libc) surfaces this error without breaking anything.
if LD_PRELOAD=/host/tmp/awf-lib/one-shot-token.so /host/bin/true 2>/dev/null; then
ONE_SHOT_TOKEN_LIB="/tmp/awf-lib/one-shot-token.so"
echo "[entrypoint] One-shot token library copied to chroot at ${ONE_SHOT_TOKEN_LIB}"
else
echo "[entrypoint][WARN] one-shot-token.so failed to load on host libc (e.g. musl/Alpine)"
echo "[entrypoint][WARN] Token protection will be disabled (tokens may be readable multiple times)"
rm -f /host/tmp/awf-lib/one-shot-token.so 2>/dev/null || true
fi
else
echo "[entrypoint][WARN] Could not copy one-shot-token library to /tmp/awf-lib"
echo "[entrypoint][WARN] Token protection will be disabled (tokens may be readable multiple times)"
Expand Down
8 changes: 7 additions & 1 deletion containers/agent/one-shot-token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,18 @@ The Dockerfile compiles the library during image build with hardened flags:

```dockerfile
RUN gcc -shared -fPIC -fvisibility=hidden -O2 -Wall -s \
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 \
-o /usr/local/lib/one-shot-token.so \
/tmp/one-shot-token.c \
-ldl -lpthread && \
strip --strip-unneeded /usr/local/lib/one-shot-token.so
```

The `-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0` flags disable glibc's fortified I/O
wrappers (e.g. `__fprintf_chk`) so the library loads successfully on musl-based
hosts such as Alpine Linux (used by ARC self-hosted runners). Without these
flags the dynamic linker fails with `symbol not found: __fprintf_chk`.
Comment thread
lpcox marked this conversation as resolved.
Resolved

### Locally (for testing)

Requires Rust toolchain (install via [rustup](https://rustup.rs/)):
Expand Down Expand Up @@ -352,7 +358,7 @@ This library is one layer in AWF's security model:
## Limitations

- **Linux only**: The library is compiled for Linux (x86_64 and potentially other architectures via Rust cross-compilation)
- **glibc programs only**: Programs using musl libc or statically linked programs are not affected
- **glibc programs only**: Programs using musl libc or statically linked programs are not affected by the interception (they do not load the library); AWF degrades gracefully by falling back to tokens remaining in the environment
- **Single process**: Child processes inherit the LD_PRELOAD but have their own token state and cache (each starts fresh)

## Files
Expand Down
3 changes: 3 additions & 0 deletions containers/agent/one-shot-token/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ echo "[build] Building one-shot-token with Cargo..."
# -O2: optimize for performance
# -Wall -Wextra: enable warnings
# -s: strip symbol table and relocation info at link time
# -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0: disable glibc fortification macros
# (e.g. __fprintf_chk) so the .so loads on musl-based hosts (Alpine/ARC runners)
gcc -shared -fPIC \
-fvisibility=hidden \
-O2 -Wall -Wextra -s \
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 \
-o "${OUTPUT_FILE}" \
"${SOURCE_FILE}" \
Comment on lines +22 to 29
-ldl -lpthread
Expand Down
Loading