mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 10:18:18 +00:00
The shell wrapper wrote the runs of the image to ./.ousast, inside the repository it was scanning (the eighth session: three runs under it). It now creates ~/.cache/openultrasast/runs, mounts it at /reports, the one writable mount, and passes -e OPENULTRASAST_RUNS_DIR=/reports to its compose run, so nothing is written to the scanned directory. The override is the maintainer's choice of 2026-11-27, on a measurement. Answer 4 of the menu of 2026-11-26 was worded as the mount alone. Measured that day: compose sets OPENULTRASAST_RUNS_DIR=/reports/runs in the service, so the mount alone put the run on the host at ~/.cache/openultrasast/runs/runs/<run>, one level below a native run, and nothing prunes it there (prune_old_runs removes only run directories directly under the root whose names match the run id). With the override the run lands beside native runs. Two things the choice does not change: a scan in the image never prunes, so the wrapper's runs are removed by a later native scan on the default location; and the wrapper writes to ~/.cache/openultrasast/runs whether or not XDG_CACHE_HOME or OPENULTRASAST_RUNS_DIR moves a native run elsewhere. ops/shell/ousast.ps1 gets the same change, the maintainer's second choice: it writes %USERPROFILE%\.cache\openultrasast\runs and passes the same override. That file was edited by reading and WAS NOT RUN: there is no PowerShell on this machine. Tests: tests/test_shell_wrapper.py has a third test. It failed before the change (no runs directory under HOME) and again until the override was passed. After: 3 passed. Measured on 2026-11-27 through the shell wrapper with the real Docker, from a directory without .env, both API keys unset: `ousast scan examples --mode quick` on a copy of libpng's contrib/examples prints run_dir=/reports/<run>, the container prefix, with file_targets=4, findings=4, exit 0; the run is on the host directly under ~/.cache/openultrasast/runs, owned by the user; the scanned directory stays empty. The eight tests of tests/test_docs_site.py and tests/test_removed_plane_references.py pass, `mkdocs build --strict` exits 0, ruff format, ruff check, mypy, the three gates and compileall pass, and the gates print what they printed before the change. An independent reviewer approved the change in one round; its remarks on the README clause, on the test, on the evidence and on the width of one line are applied. Left as it is, for the maintainer: with HOME unset the shell wrapper now fails, where it wrote ./.ousast before ($HOME is empty, so the path is /.cache/openultrasast/runs, and a failed mkdir is not checked, as it was not before).
89 lines
4.3 KiB
Bash
89 lines
4.3 KiB
Bash
# OpenUltraSAST as a local command. Source this from ~/.bashrc or ~/.zshrc:
|
|
#
|
|
# source /path/to/OpenUltraSAST/ops/shell/ousast.sh
|
|
#
|
|
# Then use it like any other linter, from any directory:
|
|
#
|
|
# ousast scan .
|
|
# ousast scan src/api
|
|
#
|
|
# Docker is an implementation detail on purpose. The engine is a JVM and ~2 GB of Joern, and a contributor
|
|
# evaluating this tool should not have to install either to try it. What they get instead is a command.
|
|
#
|
|
# The one thing worth knowing: your working directory is mounted READ-ONLY, and findings are written to
|
|
# ~/.cache/openultrasast/runs, where a native scan writes them too. That directory is mounted at /reports, the
|
|
# only writable mount, so nothing is written to the directory being scanned. A tool that reads your source to
|
|
# tell you about it has no business being able to change it.
|
|
|
|
# Resolve this script's own location so the function works from anywhere, under bash or zsh.
|
|
if [ -n "${BASH_SOURCE[0]:-}" ]; then
|
|
_OUSAST_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
elif [ -n "${(%):-%N}" ] 2>/dev/null; then
|
|
_OUSAST_HOME="$(cd "$(dirname "${(%):-%N}")/../.." && pwd)"
|
|
fi
|
|
export OUSAST_HOME="${OUSAST_HOME:-$_OUSAST_HOME}"
|
|
|
|
ousast() {
|
|
local compose="$OUSAST_HOME/docker-compose.yml"
|
|
if [ ! -f "$compose" ]; then
|
|
echo "ousast: cannot find $compose (set OUSAST_HOME to the checkout)" >&2
|
|
return 1
|
|
fi
|
|
|
|
# A native install wins when it is there: it is faster, and someone who installed Joern deliberately
|
|
# should not be quietly routed through a container. It runs in the caller's directory, as the container
|
|
# does, so `.`, relative names and relative options mean the caller's files. -P keeps that directory off
|
|
# the interpreter's path, where a file of it could stand in for a module the CLI imports. Joern is looked
|
|
# for as well: the batch queries run `joern`, and with `joern-parse` alone every one fails while the scan
|
|
# still exits 0.
|
|
if [ "${OUSAST_PREFER_NATIVE:-1}" = "1" ] && command -v joern >/dev/null 2>&1 \
|
|
&& command -v joern-parse >/dev/null 2>&1 && [ -x "$OUSAST_HOME/.venv/bin/python" ]; then
|
|
"$OUSAST_HOME/.venv/bin/python" -P -m openultrasast.cli "$@"
|
|
return $?
|
|
fi
|
|
|
|
if ! command -v docker >/dev/null 2>&1; then
|
|
echo "ousast: docker is not installed, and no local joern and joern-parse were found" >&2
|
|
return 1
|
|
fi
|
|
|
|
# Build once, silently, the first time. A first run that prints a wall of build output and then works is
|
|
# worse than one that pauses and explains itself.
|
|
if ! docker image inspect "openultrasast:${OUSAST_VERSION:-dev}" >/dev/null 2>&1; then
|
|
echo "ousast: building the analysis image once (this pulls ~2 GB of engine; later runs are instant)" >&2
|
|
( cd "$OUSAST_HOME" && docker compose build ) || return 1
|
|
fi
|
|
|
|
# Rewrite paths that live under the current directory to their mounted equivalent, so `ousast scan src/api`
|
|
# means what the user expects. Anything outside the mount is left alone and warned about rather than
|
|
# silently rewritten into a path the container cannot see.
|
|
local args=() a abs
|
|
for a in "$@"; do
|
|
if [ -e "$a" ]; then
|
|
abs="$(cd "$(dirname "$a")" 2>/dev/null && pwd)/$(basename "$a")"
|
|
case "$abs" in
|
|
"$PWD") args+=("/target") ;;
|
|
"$PWD"/*) args+=("/target${abs#"$PWD"}") ;;
|
|
*) echo "ousast: $a is outside $PWD and is not mounted; passing it through unchanged" >&2
|
|
args+=("$a") ;;
|
|
esac
|
|
else
|
|
args+=("$a")
|
|
fi
|
|
done
|
|
|
|
local runs="$HOME/.cache/openultrasast/runs"
|
|
mkdir -p "$runs"
|
|
# /reports is the runs directory itself here, not a reports directory with runs under it: the override puts
|
|
# the run beside a native one, where the pruning of the default location finds it.
|
|
TARGET="$PWD" OUSAST_REPORTS="$runs" \
|
|
OUSAST_NETWORK="${OUSAST_NETWORK:-none}" \
|
|
docker compose -f "$compose" run --rm -e OPENULTRASAST_RUNS_DIR=/reports ousast "${args[@]}"
|
|
}
|
|
|
|
# The LLM judge needs the network and a key; without them the model layer still entails and only the
|
|
# `suspicion` band goes unasked. This makes that opt-in explicit rather than a surprise.
|
|
ousast-with-judge() {
|
|
OUSAST_NETWORK=bridge ousast "$@"
|
|
}
|