Merge pull request #4 from mmckeen-nv/codex/harden-installer
[codex] Harden local installer
This commit is contained in:
@@ -72,17 +72,22 @@ From the repository root:
|
|||||||
|
|
||||||
The installer:
|
The installer:
|
||||||
|
|
||||||
- checks Node, npm, Docker, and OpenShell CLI availability;
|
- checks Node, npm, Docker, OpenShell CLI availability, sandbox inventory reachability, and default port occupancy;
|
||||||
- installs npm dependencies;
|
- installs npm dependencies with `npm ci` when `package-lock.json` exists;
|
||||||
|
- runs a non-blocking `npm audit` summary;
|
||||||
- creates `.env.local` if needed;
|
- creates `.env.local` if needed;
|
||||||
- generates a local dashboard password, signing secret, and recovery token if they are missing;
|
- generates a local dashboard password, signing secret, and recovery token if they are missing;
|
||||||
- runs `npm run build` as a verification step;
|
- runs `npm run build` as a verification step.
|
||||||
- removes `.next` afterward so the development server starts cleanly.
|
|
||||||
|
It refuses to run as root unless `--allow-root` is supplied. It does not install or manage a systemd service.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./install.sh --no-build
|
./install.sh --no-build
|
||||||
|
./install.sh --no-audit
|
||||||
|
./install.sh --clean-next
|
||||||
|
./install.sh --allow-root
|
||||||
./install.sh --start
|
./install.sh --start
|
||||||
./install.sh --help
|
./install.sh --help
|
||||||
```
|
```
|
||||||
|
|||||||
+90
-8
@@ -3,6 +3,7 @@
|
|||||||
# Development installer for the local OpenShell sandbox control dashboard.
|
# Development installer for the local OpenShell sandbox control dashboard.
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
umask 077
|
||||||
|
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
YELLOW='\033[1;33m'
|
YELLOW='\033[1;33m'
|
||||||
@@ -16,6 +17,9 @@ MIN_NODE_MAJOR=20
|
|||||||
|
|
||||||
DO_BUILD=1
|
DO_BUILD=1
|
||||||
DO_START=0
|
DO_START=0
|
||||||
|
DO_AUDIT=1
|
||||||
|
DO_CLEAN_NEXT=0
|
||||||
|
ALLOW_ROOT=0
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@@ -26,11 +30,14 @@ Usage:
|
|||||||
|
|
||||||
Options:
|
Options:
|
||||||
--no-build Install and configure without running npm run build
|
--no-build Install and configure without running npm run build
|
||||||
|
--no-audit Skip the non-blocking npm audit summary
|
||||||
|
--clean-next Remove .next after a successful build for a clean dev start
|
||||||
|
--allow-root Permit running as root
|
||||||
--start Start the development server after install
|
--start Start the development server after install
|
||||||
--help Show this help
|
--help Show this help
|
||||||
|
|
||||||
This project is in development. The installer prepares a local dev/operator
|
This project is in development. The installer prepares a local dev/operator
|
||||||
environment; it is not a hardened production deployment.
|
environment; it is not a systemd/production service installer.
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +47,18 @@ while [[ $# -gt 0 ]]; do
|
|||||||
DO_BUILD=0
|
DO_BUILD=0
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--no-audit)
|
||||||
|
DO_AUDIT=0
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--clean-next)
|
||||||
|
DO_CLEAN_NEXT=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--allow-root)
|
||||||
|
ALLOW_ROOT=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--start)
|
--start)
|
||||||
DO_START=1
|
DO_START=1
|
||||||
shift
|
shift
|
||||||
@@ -73,6 +92,40 @@ require_command() {
|
|||||||
command -v "$1" >/dev/null 2>&1 || fail "$1 is required but was not found."
|
command -v "$1" >/dev/null 2>&1 || fail "$1 is required but was not found."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
port_owner() {
|
||||||
|
local port="$1"
|
||||||
|
if command -v lsof >/dev/null 2>&1; then
|
||||||
|
lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null | awk 'NR == 2 {print $1 " pid=" $2}'
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v ss >/dev/null 2>&1; then
|
||||||
|
ss -ltnp "sport = :$port" 2>/dev/null | awk 'NR == 2 {print $NF}'
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_port() {
|
||||||
|
local port="$1"
|
||||||
|
local label="$2"
|
||||||
|
local owner
|
||||||
|
owner="$(port_owner "$port" || true)"
|
||||||
|
if [[ -n "$owner" ]]; then
|
||||||
|
warn "Port $port ($label) is already in use by $owner."
|
||||||
|
warn "If you use --start, stop the existing process first or expect startup to fail."
|
||||||
|
else
|
||||||
|
log "Port $port ($label) is available"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
find_openshell() {
|
||||||
|
if command -v openshell >/dev/null 2>&1; then
|
||||||
|
command -v openshell
|
||||||
|
elif [[ -x "$HOME/.local/bin/openshell" ]]; then
|
||||||
|
printf '%s\n' "$HOME/.local/bin/openshell"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
node_major() {
|
node_major() {
|
||||||
node -p "Number(process.versions.node.split('.')[0])"
|
node -p "Number(process.versions.node.split('.')[0])"
|
||||||
}
|
}
|
||||||
@@ -95,6 +148,10 @@ echo -e "${GREEN}=== ${APP_NAME} Installer ===${NC}"
|
|||||||
echo "Development build: expect sharp edges; do not expose this UI broadly without hardening."
|
echo "Development build: expect sharp edges; do not expose this UI broadly without hardening."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
if [[ "${EUID:-$(id -u)}" -eq 0 && "$ALLOW_ROOT" -ne 1 ]]; then
|
||||||
|
fail "Refusing to run as root. Rerun as the dashboard user, or pass --allow-root if you really mean it."
|
||||||
|
fi
|
||||||
|
|
||||||
require_command node
|
require_command node
|
||||||
require_command npm
|
require_command npm
|
||||||
require_command docker
|
require_command docker
|
||||||
@@ -111,15 +168,24 @@ if ! docker ps >/dev/null 2>&1; then
|
|||||||
fi
|
fi
|
||||||
log "Docker is reachable: $(docker --version)"
|
log "Docker is reachable: $(docker --version)"
|
||||||
|
|
||||||
if command -v openshell >/dev/null 2>&1; then
|
OPENSHELL_BIN="$(find_openshell || true)"
|
||||||
log "OpenShell CLI: $(openshell --version 2>/dev/null || echo installed)"
|
if [[ -n "$OPENSHELL_BIN" ]]; then
|
||||||
elif [[ -x "$HOME/.local/bin/openshell" ]]; then
|
log "OpenShell CLI: $("$OPENSHELL_BIN" --version 2>/dev/null || echo "$OPENSHELL_BIN")"
|
||||||
log "OpenShell CLI: $("$HOME/.local/bin/openshell" --version 2>/dev/null || echo "$HOME/.local/bin/openshell")"
|
if "$OPENSHELL_BIN" sandbox list >/dev/null 2>&1; then
|
||||||
|
log "OpenShell sandbox inventory command is reachable"
|
||||||
|
else
|
||||||
|
warn "OpenShell CLI exists, but 'openshell sandbox list' did not complete successfully."
|
||||||
|
warn "The dashboard can install, but inventory and lifecycle operations may be degraded."
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
warn "OpenShell CLI was not found on PATH or at ~/.local/bin/openshell."
|
warn "OpenShell CLI was not found on PATH or at ~/.local/bin/openshell."
|
||||||
warn "Sandbox create/delete, policy grants, terminal, and dashboard proxy features require it."
|
warn "Sandbox create/delete, policy grants, terminal, and dashboard proxy features require it."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
check_port 3000 "dashboard HTTP"
|
||||||
|
check_port 3001 "OpenClaw dashboard websocket sidecar"
|
||||||
|
check_port 3011 "operator terminal upstream"
|
||||||
|
|
||||||
if docker ps --format '{{.Names}}' | grep -Eq '^openshell-cluster-'; then
|
if docker ps --format '{{.Names}}' | grep -Eq '^openshell-cluster-'; then
|
||||||
log "OpenShell gateway container detected:"
|
log "OpenShell gateway container detected:"
|
||||||
docker ps --format ' {{.Names}}\t{{.Image}}\t{{.Ports}}' | grep -E 'openshell-cluster-' || true
|
docker ps --format ' {{.Names}}\t{{.Image}}\t{{.Ports}}' | grep -E 'openshell-cluster-' || true
|
||||||
@@ -128,8 +194,20 @@ else
|
|||||||
warn "Install can continue, but the UI will show limited inventory until OpenShell is started."
|
warn "Install can continue, but the UI will show limited inventory until OpenShell is started."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "Installing npm dependencies"
|
if [[ -f package-lock.json ]]; then
|
||||||
npm install
|
log "Installing npm dependencies with npm ci"
|
||||||
|
npm ci
|
||||||
|
else
|
||||||
|
log "Installing npm dependencies with npm install"
|
||||||
|
npm install
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$DO_AUDIT" -eq 1 ]]; then
|
||||||
|
log "Running non-blocking npm audit summary"
|
||||||
|
if ! npm audit --audit-level=moderate; then
|
||||||
|
warn "npm audit reported vulnerabilities. Review the output above before exposing this UI beyond a trusted LAN."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$ENV_FILE" ]]; then
|
if [[ ! -f "$ENV_FILE" ]]; then
|
||||||
log "Creating $ENV_FILE"
|
log "Creating $ENV_FILE"
|
||||||
@@ -159,8 +237,10 @@ chmod 600 "$ENV_FILE" || true
|
|||||||
if [[ "$DO_BUILD" -eq 1 ]]; then
|
if [[ "$DO_BUILD" -eq 1 ]]; then
|
||||||
log "Running production build check"
|
log "Running production build check"
|
||||||
npm run build
|
npm run build
|
||||||
|
if [[ "$DO_CLEAN_NEXT" -eq 1 ]]; then
|
||||||
rm -rf .next
|
rm -rf .next
|
||||||
log "Removed production .next cache so npm run dev starts cleanly"
|
log "Removed production .next cache because --clean-next was requested"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
@@ -173,6 +253,8 @@ echo ""
|
|||||||
echo "Start the development server:"
|
echo "Start the development server:"
|
||||||
echo " npm run dev"
|
echo " npm run dev"
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "This installer does not install or manage a systemd service."
|
||||||
|
echo ""
|
||||||
echo "Open:"
|
echo "Open:"
|
||||||
echo " http://localhost:3000"
|
echo " http://localhost:3000"
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user