This commit is contained in:
Samuel Aubertin
2025-11-08 03:59:16 +01:00
commit 636098a15b
20 changed files with 1807 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
codex

15
.sloptrap Normal file
View File

@@ -0,0 +1,15 @@
# Example Sloptrap manifest.
# Project identifier used for container/image naming.
name=sloptrap
# Default targets invoked when ./sloptrap is run without explicit args.
# default_targets=run
# Extra Debian packages installed into the helper image (space-delimited list).
packages_extra=make shellcheck jq
# Additional Codex CLI switches appended when launching Codex.
codex_args=--sandbox workspace-write
# Allow the container host to be reachable from within
# allow_host_network=false

7
.sloptrapignore Normal file
View File

@@ -0,0 +1,7 @@
# Paths listed here are not mounted into the container workspace.
# Syntax mirrors .gitignore: comments with '#', glob patterns, and negation with '!'.
# Example patterns:
# secrets/
# *.pem
.git/

13
LICENSE Normal file
View File

@@ -0,0 +1,13 @@
Copyright (c) 2025 Samuel 'sk4nz' AUBERTIN sk4nz@sk4.nz
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

50
Makefile Normal file
View File

@@ -0,0 +1,50 @@
SHELL := /bin/sh
PROGRAM := sloptrap
KNOWN_INSTALL_DIRS := $(HOME)/.local/bin /usr/local/bin /opt/homebrew/bin /opt/local/bin /usr/pkg/bin /usr/bin /usr/local/sbin
AUTO_INSTALL_DIR := $(shell sh -c 'set -e; for dir in $(KNOWN_INSTALL_DIRS); do [ -n "$$dir" ] || continue; if [ -d "$$dir" ] && [ -w "$$dir" ]; then printf "%s" "$$dir"; exit 0; fi; done; fallback="$$HOME/.local/bin"; mkdir -p "$$fallback"; printf "%s" "$$fallback"')
INSTALL_DIR ?= $(AUTO_INSTALL_DIR)
INSTALL_PATH := $(DESTDIR)$(INSTALL_DIR)/$(PROGRAM)
COLOR_TEXT := \033[38;5;247m
COLOR_HIGHLIGHT := \033[38;5;202m
COLOR_ERROR := \033[38;5;160m
COLOR_COMMENT := \033[38;5;242m
RESET := \033[0m
PREFIX_TEXT := \033[38;5;247m░\033[0m
PREFIX_HIGHLIGHT := \033[38;5;202m█\033[0m
PREFIX_ERROR := \033[38;5;160m▒\033[0m
PREFIX_COMMENT := \033[38;5;242m▒\033[0m
.PHONY: help install update uninstall regress
help:
@printf '%b%bsloptrap%b installer %b\n' '$(PREFIX_TEXT)' '$(COLOR_HIGHLIGHT)' '$(COLOR_TEXT)' '$(RESET)'
@printf '%b%b make install %b[INSTALL_DIR=%s]%b\n' '$(PREFIX_TEXT)' '$(COLOR_HIGHLIGHT)' '$(COLOR_COMMENT)' '$(INSTALL_DIR)' '$(RESET)'
@printf '%b%b make uninstall%b\n' '$(PREFIX_TEXT)' '$(COLOR_HIGHLIGHT)' '$(RESET)'
install update: $(PROGRAM)
@action="Installing"; if [ -f "$(INSTALL_PATH)" ]; then action="Updating"; fi; \
printf '%b%b%s%b sloptrap %b(%s)%b\n' '$(PREFIX_COMMENT)' '$(COLOR_HIGHLIGHT)' "$$action" '$(COLOR_TEXT)' '$(COLOR_COMMENT)' '$(INSTALL_PATH)' '$(RESET)'
@install -Dm755 $(PROGRAM) "$(INSTALL_PATH)"
@printf '%b%bSuccess!%b Run it with:%b\n' '$(PREFIX_COMMENT)' '$(COLOR_HIGHLIGHT)' '$(COLOR_TEXT)' '$(RESET)'
@printf '%b%b%b %s /path/to/project%b\n' '$(PREFIX_HIGHLIGHT)' '$(COLOR_HIGHLIGHT)' '\033[1m' '$(PROGRAM)' '$(RESET)'
@printf '%b%bExample files to configure your project:%b\n' '$(PREFIX_TEXT)' '$(COLOR_TEXT)' '$(RESET)'
@printf '%b%b /path/to/project/%b.sloptrap%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(COLOR_TEXT)' '$(RESET)'
@printf '%b%b name=your-project%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(RESET)'
@printf '%b%b default_targets=build run%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(RESET)'
@printf '%b%b packages_extra=make jq%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(RESET)'
@printf '%b%b codex_args=--sandbox workspace-write%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(RESET)'
@printf '%b%b allow_host_network=false%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(RESET)'
@printf '%b%b /path/to/project/%b.sloptrapignore%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(COLOR_TEXT)' '$(RESET)'
@printf '%b%b .git/%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(RESET)'
@printf '%b%b secrets/%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(RESET)'
@printf '%b%b build/output.log%b\n' '$(PREFIX_COMMENT)' '$(COLOR_COMMENT)' '$(RESET)'
uninstall:
@printf '%b%bRemoving%b %b%s%b\n' '$(PREFIX_COMMENT)' '$(COLOR_TEXT)' '$(COLOR_TEXT)' '$(COLOR_COMMENT)' '$(INSTALL_PATH)' '$(RESET)'
@rm -f "$(INSTALL_PATH)"
regress:
@./tests/run_tests.sh

142
README.md Normal file
View File

@@ -0,0 +1,142 @@
# Sloptrap
Sloptrap runs the OpenAI Codex CLI inside a container with a predictable and locked-down filesystem view. The launcher script (`sloptrap`) resolves the project manifest, builds the support image directly, and starts Codex with the requested target (defaults to `run`). Hardened parsing blocks container escapes via manifest or ignore directives, verifies the downloaded Codex binary, and keeps the runtime environment minimal.
## Dependencies
- Podman ≥ 4 (Sloptrap refuses to run without it unless you explicitly override `SLOPTRAP_CONTAINER_ENGINE`).
- GNU `bash`, `curl`, `tar`, `sha256sum`, `realpath` (from GNU coreutils), and `jq` on the host.
- Network access to `https://github.com/openai/codex/releases/` for fetching the Codex binary.
- Enough local disk space to build the container image and cache Codex under `${HOME}/.codex`.
> Tip: set `SLOPTRAP_CONTAINER_ENGINE=<engine>` if you need to override the default Podman requirement (for example, when running inside a CI wrapper that only exposes Docker).
## Quick Start
1. Place `sloptrap` somewhere on your PATH/shared drive (the helper Dockerfile and Codex binary are bundled and downloaded automatically).
2. (Optional) Create a project-specific manifest and ignore file:
```bash
cat > your-project/.sloptrap <<'EOF'
name=your-project
default_targets=run
packages_extra=make
codex_args=--sandbox workspace-write
EOF
cat > your-project/.sloptrapignore <<'EOF'
.git/
secrets/
EOF
```
3. Run `./sloptrap your-project`. On the first invocation Sloptrap:
- builds `your-project-sloptrap-image` if missing,
- verifies the Codex binary hash,
- creates `${HOME}/.codex` and runs `login` if credentials are absent.
4. Subsequent calls reuse the image; use `--dry-run` first to inspect the container command that would be executed.
5. Run `make regress` from the repo root to execute the regression suite (ShellCheck plus adversarial harness) before committing changes.
Use `./sloptrap your-project shell` to enter a troubleshooting shell inside the container or `./sloptrap your-project clean` to remove cached images and state.
## How It Works
- The project directory mounts at `/workspace`, and `${HOME}/.codex` mounts at `/codex`.
- `.sloptrapignore` entries (if present) are overlaid by tmpfs (for directories) or empty bind mounts (for files) so Codex cannot read the masked content. Paths are normalised and must remain inside the project tree; attempting to mask parent directories or symlink escapes fails fast.
- Sloptrap launches containers on an isolated network (`bridge` on Docker, `slirp4netns` on Podman) with `--cap-drop=ALL`, `--security-opt no-new-privileges`, a read-only root filesystem, and tmpfs-backed `/tmp`, `/run`, and `/run/lock`. Projects that explicitly set `allow_host_network=true` in their manifest opt into `--network host`.
- The helper Dockerfile is embedded inside `sloptrap`; set `SLOPTRAP_DOCKERFILE_PATH=/path/to/custom/Dockerfile` if you need to supply your own recipe. The default image installs `curl`, `bash`, `ca-certificates`, `libstdc++6`, `git`, `ripgrep`, `xxd`, and `file`, so most debugging helpers are already available without adding `packages_extra`.
- The container user matches the host UID/GID (`--userns=keep-id` on Podman or `--user UID:GID` on Docker).
- The runtime environment is fixed to HOME/XDG variables pointing at `/codex`; manifest-controlled environment injection is disabled.
## `.sloptrap` Manifest Reference
The manifest is optional. When absent, Sloptrap derives:
- `name = basename(project directory)`
- `default_targets = run`
- `packages_extra = ""` (none)
- `codex_args = "--sandbox workspace-write"`
Supported keys when the manifest is present:
| Key | Default | Notes |
| --- | --- | --- |
| `name` | project directory name | Must match `^[A-Za-z0-9_.-]+$`. Used for image/container naming. |
| `default_targets` | `run` | Space-separated targets invoked when none are provided on the CLI. |
| `packages_extra` | *empty* | Additional Debian packages installed during `docker/podman build`. Tokens must be alphanumeric plus `+.-`. |
| `codex_args` | `--sandbox workspace-write` | Passed verbatim to the Codex CLI entrypoint. Tokens are shell-split, so quote values with spaces (e.g., `--profile security-audit`). |
| `allow_host_network` | `false` | `true` opts into `--network host`; keep `false` unless the project absolutely requires direct access to host-local services. |
`codex_args` are appended after the default sandbox flag, and Sloptrap refuses to run if the resulting `--sandbox` mode is anything other than `workspace-write` or `workspace-read-only`.
Values containing `$`, `` ` ``, or newlines are rejected to prevent command injection. Setting illegal keys or malformed values aborts the run before containers start.
### `.sloptrapignore`
- Parsed using gitignore-style globbing with support for `!negation`.
- Entries must stay within the project root after resolving symlinks; attempts to reference `.`/`..`, absolute paths, or symlink escapes raise errors.
- Directory matches become `--mount type=tmpfs,target=/workspace/<path>`. File matches bind to empty files within `.sloptrap-ignores/session-<pid>/`.
- The helper directory is removed automatically on exit or during `./sloptrap <project> clean`.
## CLI Reference
```
./sloptrap [--dry-run] [--print-config] <code-directory> [target ...]
```
Options:
- `--dry-run` &mdash; print the container/engine commands that would run without executing them.
- `--print-config` &mdash; output the resolved manifest values, defaults, and ignore list.
- `-h, --help` &mdash; display usage.
- `--` &mdash; stop option parsing; remaining arguments are treated as targets.
Behaviour:
- Missing manifests are treated as default configuration.
- `SLOPTRAP_CONTAINER_ENGINE` overrides engine auto-detection.
- If `${HOME}/.codex/auth.json` is absent, Sloptrap prepends a login run before executing your targets.
- Exit status mirrors the last target executed; errors in parsing or setup abort early with a message.
`--print-config` fields include `manifest_present=true|false`, resolved paths, and the sanitised ignore mount roots so you can confirm what will be hidden inside the container.
### Regression Suite
- `make regress` (or `tests/run_tests.sh`) runs `shellcheck` against `sloptrap` and then executes every scenario in `tests/run_tests.sh`, including the container build path check.
- The suite must pass cleanly; ShellCheck diagnostics or scenario regressions cause a non-zero exit and should be fixed before shipping changes.
## Built-in Targets
Targets are supplied after the code directory (or via `default_targets` in the manifest). When omitted, Sloptrap defaults to `run`.
| Target | Description |
| --- | --- |
| `build` | Download Codex (if missing), verify SHA-256, and build the container image. |
| `build-if-missing` | No-op when the image already exists; otherwise delegates to `build`. |
| `rebuild` | Rebuild the image from scratch (`--no-cache`). |
| `run` | Default goal. Runs the container with Codex as entrypoint and passes `codex_args`. |
| `login` | Starts Codex in login mode to bootstrap `${HOME}/.codex`. |
| `shell` | Launches `/bin/bash` inside the container for debugging. |
| `stop` | Best-effort stop of the running container (if any). |
| `clean` | Removes `.sloptrap-ignores`, deletes the container/image, and stops the container if necessary. |
The launcher executes targets sequentially, so `./sloptrap repo build run` performs an explicit rebuild before invoking Codex. Extra targets may be added in the future; unknown names fail fast.
## Execution Environment
- Container engine: Podman or Docker with identical command lines. Podman uses `--userns=keep-id`; Docker receives the equivalent `--user UID:GID`.
- Filesystem view: the project directory mounts at `/workspace`; `${HOME}/.codex` mounts at `/codex`.
- Ignore filter: `.sloptrapignore` entries are overlaid with tmpfs directories or empty bind mounts so data remains unavailable to Codex.
- Network: the container always runs with `--network host`. Sloptrap does not filter or proxy outbound traffic.
- Process context: capabilities are dropped, `no-new-privileges` is set, the root filesystem is read-only, and scratch paths (`/tmp`, `/run`, `/run/lock`) are tmpfs mounts. Resource limits follow the launcher defaults.
- Codex configuration: runtime flags come from `codex_args`. Persistent Codex state is stored under `${HOME}/.codex`.
## Threat Model and Limits
- **Outbound disclosure**: prompts and referenced data travel from the container to the configured LLM endpoint. Any file content within `/workspace` or environment data exposed to the process can appear in that traffic.
- **Shared storage**: `/workspace` and `/codex` are the only host mounts. Files written to these locations become visible on the host and to the LLM provider through prompts.
- **Environment surface**: the container receives a minimal fixed environment (HOME/XDG paths, `CODEX_HOME`). The manifest no longer allows injecting additional environment variables.
- **Process isolation**: the container runs without additional Linux capabilities and with a read-only root filesystem. The container and host still share the same kernel; a kernel-level escape would affect host confidentiality.
- **Networking stance**: traffic is unrestricted once it leaves the container. Sloptrap does not enforce an allowlist or DNS policy, and `--network host` is always used because the bundled Codex CLI must reach an upstream LLM provider. If you require an offline or firewalled workflow, Sloptrap is not an appropriate launcher.
- **Persistence**: Codex history and logs accumulate under `${HOME}/.codex`. Sensitive prompts recorded on disk remain on the host after the session. Because `.git/` is ignored inside the container, any historical secrets in Git objects stay outside the LLM context unless explicitly surfaced in the working tree.
- **Codex cache hygiene**: the `${HOME}/.codex` mount remains writable by the container and will hold tokens, cached prompts, and other state. Rotate credentials regularly and avoid co-locating unrelated secrets inside that directory.
- **Secret scanning**: Sloptrap does not perform secret discovery or redaction; any credentials present in the project remain available to Codex and the upstream provider.
- **Local model exception**: pointing Codex at a local or self-hosted model keeps data within the host network boundary, but the filesystem and environment exposure described above is unchanged.
These constraints focus on limiting host data exposure to the Codex session while acknowledging that any material introduced into the context window may leave the environment through the upstream API.

1248
sloptrap Executable file

File diff suppressed because it is too large Load Diff

12
tests/README.md Normal file
View File

@@ -0,0 +1,12 @@
# Test Scenarios
This directory contains cases that stress Sloptrap's hardening and deployment flow. Each subdirectory mimics a user repository and focuses on a single class of behaviour. Use `run_tests.sh` to execute the automated checks with stubbed tooling.
Current scenarios:
- `mount_injection/` — exercises `.sloptrapignore` entries with `,` and `=` to ensure mount escape characters remain escaped and forces `build_if_missing` to execute the Codex download/build path.
- `root_target/` — ensures attempts to mask the project root are rejected.
- `symlink_escape/` — confirms symlink targets resolving outside the project are blocked.
- `manifest_injection/` — ensures disallowed `make.*` overrides abort parsing.
- `helper_symlink/` — ensures `.sloptrap-ignores` cannot be a symlink to directories outside the project.
- `secret_mask/` — verifies masked files remain hidden even when Sloptrap remaps the workspace mount.

View File

@@ -0,0 +1 @@
../..

View File

@@ -0,0 +1 @@
secrets/

View File

@@ -0,0 +1 @@
make.BAD-FLAG=1

1
tests/mount_injection/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.sloptrap-ignores

View File

@@ -0,0 +1 @@
attack,source=/etc/passwd

View File

@@ -0,0 +1 @@
fake passwd content

View File

@@ -0,0 +1 @@
.

308
tests/run_tests.sh Executable file
View File

@@ -0,0 +1,308 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR=$(
cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1
pwd -P
)
SLOPTRAP_BIN="$ROOT_DIR/sloptrap"
TEST_ROOT="$ROOT_DIR/tests"
if [[ ! -x $SLOPTRAP_BIN ]]; then
printf 'error: sloptrap launcher not found at %s\n' "$SLOPTRAP_BIN" >&2
exit 1
fi
failures=()
run_shellcheck() {
printf '==> shellcheck\n'
if ! command -v shellcheck >/dev/null 2>&1; then
record_failure "shellcheck: shellcheck binary not found in PATH"
return
fi
if ! shellcheck "$SLOPTRAP_BIN"; then
record_failure "shellcheck: lint errors detected"
fi
}
setup_stub_env() {
STUB_BIN=$(mktemp -d)
STUB_HOME=$(mktemp -d)
STUB_LOG=$(mktemp)
cat >"$STUB_BIN/podman" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
if [[ -z ${FAKE_PODMAN_LOG:-} ]]; then
printf 'FAKE_PODMAN_LOG is not set\n' >&2
exit 1
fi
verify_secret_mounts() {
local -a args=("$@")
if [[ -z ${SECRET_MASK_EXPECTED_TARGET:-} ]]; then
return 0
fi
local saw=0
local idx=0
while (( idx < ${#args[@]} )); do
local arg=${args[$idx]}
if [[ $arg == "--mount" ]]; then
((idx++))
if (( idx >= ${#args[@]} )); then
printf 'podman stub: --mount missing spec\n' >&2
return 1
fi
local spec=${args[$idx]}
local target=""
local source=""
IFS=',' read -r -a parts <<< "$spec"
for part in "${parts[@]}"; do
case $part in
target=*)
target=${part#target=}
;;
source=*)
source=${part#source=}
;;
esac
done
if [[ -n ${SECRET_MASK_EXPECTED_TARGET:-} && $target == "$SECRET_MASK_EXPECTED_TARGET" ]]; then
saw=1
if [[ -z $source || ! -f $source ]]; then
printf 'podman stub: masked source missing for %s\n' "$target" >&2
return 1
fi
if [[ -s $source ]]; then
printf 'podman stub: masked source leaked contents (%s)\n' "$source" >&2
return 1
fi
fi
fi
((idx++))
done
if [[ $saw -eq 0 ]]; then
printf 'podman stub: target %s not mounted\n' "${SECRET_MASK_EXPECTED_TARGET:-}" >&2
return 1
fi
return 0
}
if [[ ${1-} == "image" && ${2-} == "inspect" && ${FAKE_PODMAN_INSPECT_FAIL:-0} == 1 ]]; then
echo "FAKE PODMAN (fail): $*" >>"$FAKE_PODMAN_LOG"
exit 1
fi
if [[ ${SECRET_MASK_VERIFY:-0} == 1 && ${1-} == "run" ]]; then
if ! verify_secret_mounts "$@"; then
echo "FAKE PODMAN (secret-check failed): $*" >>"$FAKE_PODMAN_LOG"
exit 1
fi
fi
echo "FAKE PODMAN: $*" >>"$FAKE_PODMAN_LOG"
exit 0
EOF
chmod +x "$STUB_BIN/podman"
cat >"$STUB_BIN/curl" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
if [[ ${1-} == "-fsSL" ]]; then
cat <<'JSON'
{"assets":[{"name":"codex-x86_64-unknown-linux-gnu.tar.gz","digest":"sha256:feedface"}]}
JSON
exit 0
fi
if [[ ${1-} == "-Lso" ]]; then
if [[ $# -lt 3 ]]; then
echo "curl stub expected output path" >&2
exit 1
fi
output=$2
: >"$output"
exit 0
fi
printf 'curl stub encountered unsupported args: %s\n' "$*" >&2
exit 1
EOF
chmod +x "$STUB_BIN/curl"
cat >"$STUB_BIN/jq" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
while [[ $# -gt 0 ]]; do
case "$1" in
-r)
shift
continue
;;
*)
break
;;
esac
done
cat >/dev/null
printf 'sha256:feedface\n'
EOF
chmod +x "$STUB_BIN/jq"
cat >"$STUB_BIN/sha256sum" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
if [[ ${1-} == "-c" ]]; then
shift
if [[ ${1-} == "-" ]]; then
shift
cat >/dev/null
exit 0
fi
fi
printf 'sha256sum stub encountered unsupported args: %s\n' "$*" >&2
exit 1
EOF
chmod +x "$STUB_BIN/sha256sum"
cat >"$STUB_BIN/tar" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
dest=""
new_name="codex"
while [[ $# -gt 0 ]]; do
case "$1" in
-C)
shift
if [[ $# -eq 0 ]]; then
echo "tar stub missing directory for -C" >&2
exit 1
fi
dest=$1
;;
--transform=*)
transform=${1#--transform=}
transform=${transform#s/}
rest=${transform#*/}
new_name=${rest%%/*}
;;
esac
shift
done
[[ -n $dest ]] || dest="."
mkdir -p "$dest"
cat >"$dest/$new_name" <<'BIN'
#!/usr/bin/env bash
echo "fake codex"
BIN
chmod +x "$dest/$new_name"
EOF
chmod +x "$STUB_BIN/tar"
}
teardown_stub_env() {
rm -rf "${STUB_BIN:-}" "${STUB_HOME:-}"
rm -f "${STUB_LOG:-}"
}
record_failure() {
failures+=("$1")
}
run_mount_injection() {
local scenario_dir="$TEST_ROOT/mount_injection"
printf '==> mount_injection\n'
setup_stub_env
rm -rf "$scenario_dir/.sloptrap-ignores"
if ! PATH="$STUB_BIN:$PATH" HOME="$STUB_HOME" FAKE_PODMAN_LOG="$STUB_LOG" FAKE_PODMAN_INSPECT_FAIL=1 \
"$SLOPTRAP_BIN" "$scenario_dir" >/dev/null 2>&1; then
record_failure "mount_injection: sloptrap exited non-zero"
teardown_stub_env
return
fi
if ! grep -q -- "--mount type=bind" "$STUB_LOG"; then
record_failure "mount_injection: bind mount invocation missing"
fi
if grep -q -- "attack,source=/etc/passwd" "$STUB_LOG"; then
record_failure "mount_injection: unescaped mount key detected"
fi
if ! grep -q -- "attack\\\\,source\\\\=/etc/passwd" "$STUB_LOG"; then
record_failure "mount_injection: escaped mount key missing"
fi
if ! grep -q -- "FAKE PODMAN: build " "$STUB_LOG"; then
record_failure "mount_injection: image build path did not trigger"
fi
teardown_stub_env
}
run_root_target() {
local scenario_dir="$TEST_ROOT/root_target"
printf '==> root_target\n'
if "$SLOPTRAP_BIN" --dry-run "$scenario_dir" >/dev/null 2>&1; then
record_failure "root_target: expected rejection for project-root mask"
return
fi
}
run_symlink_escape() {
local scenario_dir="$TEST_ROOT/symlink_escape"
printf '==> symlink_escape\n'
local secret_path="$ROOT_DIR/secrets.txt"
touch "$secret_path"
if "$SLOPTRAP_BIN" --dry-run "$scenario_dir" >/dev/null 2>&1; then
record_failure "symlink_escape: expected failure for symlink escape"
rm -f "$secret_path"
return
fi
rm -f "$secret_path"
}
run_manifest_injection() {
local scenario_dir="$TEST_ROOT/manifest_injection"
printf '==> manifest_injection\n'
if "$SLOPTRAP_BIN" --dry-run "$scenario_dir" >/dev/null 2>&1; then
record_failure "manifest_injection: expected rejection of bad make override"
return
fi
}
run_helper_symlink() {
local scenario_dir="$TEST_ROOT/helper_symlink"
printf '==> helper_symlink\n'
if "$SLOPTRAP_BIN" --dry-run "$scenario_dir" >/dev/null 2>&1; then
record_failure "helper_symlink: expected rejection when helper directory is a symlink"
fi
if "$SLOPTRAP_BIN" "$scenario_dir" clean >/dev/null 2>&1; then
record_failure "helper_symlink: expected rejection for clean when helper directory is a symlink"
fi
}
run_secret_mask() {
local scenario_dir="$TEST_ROOT/secret_mask"
printf '==> secret_mask\n'
setup_stub_env
local custom_workdir="/alt-workspace"
if ! PATH="$STUB_BIN:$PATH" HOME="$STUB_HOME" FAKE_PODMAN_LOG="$STUB_LOG" \
FAKE_PODMAN_INSPECT_FAIL=1 SECRET_MASK_VERIFY=1 \
SECRET_MASK_EXPECTED_TARGET="${custom_workdir}/secret.txt" \
SLOPTRAP_WORKDIR="$custom_workdir" \
"$SLOPTRAP_BIN" "$scenario_dir" >/dev/null 2>&1; then
record_failure "secret_mask: masking check failed"
teardown_stub_env
return
fi
teardown_stub_env
}
run_shellcheck
run_mount_injection
run_root_target
run_symlink_escape
run_manifest_injection
run_helper_symlink
run_secret_mask
if [[ ${#failures[@]} -gt 0 ]]; then
printf '\nTest failures:\n'
for entry in "${failures[@]}"; do
printf ' - %s\n' "$entry"
done
exit 1
fi
printf '\nAll regression checks passed.\n'

View File

@@ -0,0 +1 @@
secret.txt

View File

@@ -0,0 +1 @@
super-secret-token

View File

@@ -0,0 +1 @@
cheat/secrets.txt

1
tests/symlink_escape/cheat Symbolic link
View File

@@ -0,0 +1 @@
../..