-
Notifications
You must be signed in to change notification settings - Fork 7
feat: rust one-shot-token library #791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bd90597
83e03da
d8fb6ed
ea1ffec
451e3cc
f0e4fc4
60df914
02665bc
b8ba875
d18f99c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ network: | |
| - defaults | ||
| - github | ||
| - rust | ||
| - crates.io | ||
| tools: | ||
| bash: | ||
| - "*" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -292,6 +292,16 @@ AWFEOF | |||||||
| echo "[entrypoint] Adding CARGO_HOME/bin to PATH: ${AWF_CARGO_HOME}/bin" | ||||||||
| echo "export PATH=\"${AWF_CARGO_HOME}/bin:\$PATH\"" >> "/host${SCRIPT_FILE}" | ||||||||
| echo "export CARGO_HOME=\"${AWF_CARGO_HOME}\"" >> "/host${SCRIPT_FILE}" | ||||||||
| # Also set RUSTUP_HOME if provided (needed for rustc to find toolchain) | ||||||||
| if [ -n "${AWF_RUSTUP_HOME}" ]; then | ||||||||
| echo "[entrypoint] Setting RUSTUP_HOME: ${AWF_RUSTUP_HOME}" | ||||||||
| echo "export RUSTUP_HOME=\"${AWF_RUSTUP_HOME}\"" >> "/host${SCRIPT_FILE}" | ||||||||
| fi | ||||||||
| else | ||||||||
| # Fallback: detect Cargo from default location if CARGO_HOME not provided | ||||||||
| # This ensures Rust binaries work even when CARGO_HOME env var is not set | ||||||||
| echo "# Add Cargo bin for Rust if it exists (fallback when CARGO_HOME not provided)" >> "/host${SCRIPT_FILE}" | ||||||||
| echo "[ -d \"\$HOME/.cargo/bin\" ] && export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> "/host${SCRIPT_FILE}" | ||||||||
|
||||||||
| echo "[ -d \"\$HOME/.cargo/bin\" ] && export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> "/host${SCRIPT_FILE}" | |
| echo "[ -d \"\$HOME/.cargo/bin\" ] && export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> "/host${SCRIPT_FILE}" | |
| echo "[ -d \"\$HOME/.rustup\" ] && export RUSTUP_HOME=\"\$HOME/.rustup\"" >> "/host${SCRIPT_FILE}" |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1 +1,9 @@ | ||||
| # Build output | ||||
| *.so | ||||
|
|
||||
| # Rust build artifacts | ||||
| target/ | ||||
| Cargo.lock | ||||
|
||||
| Cargo.lock |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||||||
| [package] | ||||||||||
| name = "one-shot-token" | ||||||||||
| version = "0.1.0" | ||||||||||
| edition = "2021" | ||||||||||
| description = "LD_PRELOAD library for one-shot access to sensitive environment variables" | ||||||||||
| license = "MIT" | ||||||||||
|
|
||||||||||
| [lib] | ||||||||||
| name = "one_shot_token" | ||||||||||
| crate-type = ["cdylib"] | ||||||||||
|
|
||||||||||
| [dependencies] | ||||||||||
| libc = "0.2" | ||||||||||
| once_cell = "1.19" | ||||||||||
|
Comment on lines
+13
to
+14
|
||||||||||
| libc = "0.2" | |
| once_cell = "1.19" | |
| libc = "0.2.150" | |
| once_cell = "1.19.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,39 @@ | ||
| #!/bin/bash | ||
| # Build the one-shot-token LD_PRELOAD library | ||
| # This script compiles the shared library for x86_64 Ubuntu | ||
| # This script compiles the Rust shared library | ||
|
|
||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| SOURCE_FILE="${SCRIPT_DIR}/one-shot-token.c" | ||
| OUTPUT_FILE="${SCRIPT_DIR}/one-shot-token.so" | ||
|
|
||
| echo "[build] Compiling one-shot-token.so..." | ||
|
|
||
| # Compile as a shared library with position-independent code | ||
| # -shared: create a shared library | ||
| # -fPIC: position-independent code (required for shared libs) | ||
| # -ldl: link with libdl for dlsym | ||
| # -lpthread: link with pthread for mutex | ||
| # -O2: optimize for performance | ||
| # -Wall -Wextra: enable warnings | ||
| gcc -shared -fPIC \ | ||
| -O2 -Wall -Wextra \ | ||
| -o "${OUTPUT_FILE}" \ | ||
| "${SOURCE_FILE}" \ | ||
| -ldl -lpthread | ||
|
|
||
| echo "[build] Successfully built: ${OUTPUT_FILE}" | ||
| LINK_FILE="${SCRIPT_DIR}/one-shot-token.so" | ||
|
|
||
| echo "[build] Building one-shot-token with Cargo..." | ||
|
|
||
| cd "${SCRIPT_DIR}" | ||
|
|
||
| # Build the release version | ||
| cargo build --release | ||
|
|
||
| # Determine the output file based on platform | ||
| if [[ "$(uname)" == "Darwin" ]]; then | ||
| OUTPUT_FILE="${SCRIPT_DIR}/target/release/libone_shot_token.dylib" | ||
| echo "[build] Successfully built: ${OUTPUT_FILE} (macOS)" | ||
| else | ||
| OUTPUT_FILE="${SCRIPT_DIR}/target/release/libone_shot_token.so" | ||
| echo "[build] Successfully built: ${OUTPUT_FILE}" | ||
|
|
||
| # Create symlink for backwards compatibility (Linux only) | ||
| if [[ -L "${LINK_FILE}" ]]; then | ||
| rm "${LINK_FILE}" | ||
| fi | ||
| ln -sf "target/release/libone_shot_token.so" "${LINK_FILE}" | ||
| echo "[build] Created symlink: ${LINK_FILE} -> target/release/libone_shot_token.so" | ||
| fi | ||
|
|
||
| # Verify it's a valid shared library | ||
| if file "${OUTPUT_FILE}" | grep -q "shared object"; then | ||
| echo "[build] Verified: valid shared object" | ||
| if file "${OUTPUT_FILE}" | grep -qE "shared object|dynamically linked"; then | ||
| echo "[build] Verified: valid shared library" | ||
| else | ||
| echo "[build] ERROR: Output is not a valid shared object" | ||
| echo "[build] ERROR: Output is not a valid shared library" | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dtolnay/rust-toolchain action reference is missing a version pin or SHA. While the
with: toolchain: stableconfiguration is present, the action itself should be pinned to a specific commit SHA for security and reproducibility, consistent with the convention used for other actions in this workflow (e.g., actions/checkout, actions/setup-node, etc. are all pinned to SHAs).