diff --git a/scripts/appctl b/scripts/appctl
index 0d5b2e6..071c3b9 100755
--- a/scripts/appctl
+++ b/scripts/appctl
@@ -8,6 +8,7 @@ set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENGINE="$SCRIPT_DIR/appctl_engine.py"
+PYTHON_BIN="${PYTHON_BIN:-python3}"
ENV_FILE="/run/secrets/rendered/traefik-deployments.env"
if [ ! -f "$ENV_FILE" ] && [ -f "/run/secrets/traefik-deployments.env" ]; then
ENV_FILE="/run/secrets/traefik-deployments.env"
@@ -64,7 +65,7 @@ show_help() {
setup_app_env() {
local query="$1"
local resolved_json
- resolved_json=$(python3 "$ENGINE" resolve "$query" 2>/dev/null || true)
+ resolved_json=$("$PYTHON_BIN" "$ENGINE" resolve "$query" || true)
if [ -z "$resolved_json" ]; then
echo "❌ Error: Service '$query' not found under $SITES_DIR or Core"
@@ -72,10 +73,10 @@ setup_app_env() {
fi
# Extract fields via python json
- TARGET_TYPE=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d.get('type', 'app'))" "$resolved_json")
- APP_DIR=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['dir_path'])" "$resolved_json")
- CANONICAL_NAME=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['name'])" "$resolved_json")
- TARGET_CONTAINER=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d.get('container', ''))" "$resolved_json")
+ TARGET_TYPE=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d.get('type', 'app'))" "$resolved_json")
+ APP_DIR=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d['dir_path'])" "$resolved_json")
+ CANONICAL_NAME=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d['name'])" "$resolved_json")
+ TARGET_CONTAINER=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d.get('container', ''))" "$resolved_json")
if [ "$TARGET_TYPE" = "core" ] || [ "$TARGET_TYPE" = "core_service" ]; then
if [ ! -d "$CORE_DIR" ]; then
@@ -93,7 +94,7 @@ setup_app_env() {
return
fi
- RESOLVED_DOMAIN=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['domain'])" "$resolved_json")
+ RESOLVED_DOMAIN=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d['domain'])" "$resolved_json")
# 1. Base infrastructure defaults
export PROXY_NETWORK="${PROXY_NETWORK:-proxy-net}"
@@ -110,7 +111,7 @@ setup_app_env() {
# 3. Dynamic environment variables from app.yaml (e.g. PROJECT_PATH, MEDIA_PATH, etc.)
while IFS= read -r -d '' k && IFS= read -r -d '' v; do
export "$k=$v"
- done < <(python3 -c "
+ done < <("$PYTHON_BIN" -c "
import json, re, sys
RESERVED = {'PATH', 'LD_PRELOAD', 'IFS', 'SHELL', 'USER', 'CORE_DIR', 'SITES_DIR', 'ENV_FILE', 'HOMESERVER_ENV'}
d = json.loads(sys.argv[1])
@@ -151,23 +152,23 @@ APP=$2
case "$COMMAND" in
list|status)
- python3 "$ENGINE" list "${@:2}"
+ "$PYTHON_BIN" "$ENGINE" list "${@:2}"
;;
ssl)
- python3 "$ENGINE" ssl "${@:2}"
+ "$PYTHON_BIN" "$ENGINE" ssl "${@:2}"
;;
info)
if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi
- python3 "$ENGINE" info "${@:2}"
+ "$PYTHON_BIN" "$ENGINE" info "${@:2}"
;;
sync)
- python3 "$ENGINE" sync "${@:2}"
+ "$PYTHON_BIN" "$ENGINE" sync "${@:2}"
;;
complete)
- python3 "$ENGINE" complete "${@:2}"
+ "$PYTHON_BIN" "$ENGINE" complete "${@:2}"
;;
resolve)
- python3 "$ENGINE" resolve "${@:2}"
+ "$PYTHON_BIN" "$ENGINE" resolve "${@:2}"
;;
completion)
cat <<'EOF'
fix(scripts): support PYTHON_BIN in appctl and unmask resolve stderr
- Introduce configurable PYTHON_BIN="${PYTHON_BIN:-python3}" in scripts/appctl.
- Remove blind '2>/dev/null' on engine resolve in setup_app_env to prevent
masking manifest validation failures and runtime exceptions.
- Propagate active Python interpreter and PYTHONPATH in security invariant
injection test to prevent Nix wrapper bare-python PATH shadowing.
This commit is contained in:
1 parent
6997da3a58
commit
c8a12345b8
2 files changed
+23
-18
No files matched your search
+18
-17
@@ -8,6 +8,7 @@ set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
ENGINE="$SCRIPT_DIR/appctl_engine.py"
|
||||
PYTHON_BIN="${PYTHON_BIN:-python3}"
|
||||
ENV_FILE="/run/secrets/rendered/traefik-deployments.env"
|
||||
if [ ! -f "$ENV_FILE" ] && [ -f "/run/secrets/traefik-deployments.env" ]; then
|
||||
ENV_FILE="/run/secrets/traefik-deployments.env"
|
||||
@@ -64,7 +65,7 @@ show_help() {
|
||||
setup_app_env() {
|
||||
local query="$1"
|
||||
local resolved_json
|
||||
resolved_json=$(python3 "$ENGINE" resolve "$query" 2>/dev/null || true)
|
||||
resolved_json=$("$PYTHON_BIN" "$ENGINE" resolve "$query" || true)
|
||||
|
||||
if [ -z "$resolved_json" ]; then
|
||||
echo "❌ Error: Service '$query' not found under $SITES_DIR or Core"
|
||||
@@ -72,10 +73,10 @@ setup_app_env() {
|
||||
fi
|
||||
|
||||
# Extract fields via python json
|
||||
TARGET_TYPE=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d.get('type', 'app'))" "$resolved_json")
|
||||
APP_DIR=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['dir_path'])" "$resolved_json")
|
||||
CANONICAL_NAME=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['name'])" "$resolved_json")
|
||||
TARGET_CONTAINER=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d.get('container', ''))" "$resolved_json")
|
||||
TARGET_TYPE=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d.get('type', 'app'))" "$resolved_json")
|
||||
APP_DIR=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d['dir_path'])" "$resolved_json")
|
||||
CANONICAL_NAME=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d['name'])" "$resolved_json")
|
||||
TARGET_CONTAINER=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d.get('container', ''))" "$resolved_json")
|
||||
|
||||
if [ "$TARGET_TYPE" = "core" ] || [ "$TARGET_TYPE" = "core_service" ]; then
|
||||
if [ ! -d "$CORE_DIR" ]; then
|
||||
@@ -93,7 +94,7 @@ setup_app_env() {
|
||||
return
|
||||
fi
|
||||
|
||||
RESOLVED_DOMAIN=$(python3 -c "import json, sys; d=json.loads(sys.argv[1]); print(d['domain'])" "$resolved_json")
|
||||
RESOLVED_DOMAIN=$("$PYTHON_BIN" -c "import json, sys; d=json.loads(sys.argv[1]); print(d['domain'])" "$resolved_json")
|
||||
|
||||
# 1. Base infrastructure defaults
|
||||
export PROXY_NETWORK="${PROXY_NETWORK:-proxy-net}"
|
||||
@@ -110,7 +111,7 @@ setup_app_env() {
|
||||
# 3. Dynamic environment variables from app.yaml (e.g. PROJECT_PATH, MEDIA_PATH, etc.)
|
||||
while IFS= read -r -d '' k && IFS= read -r -d '' v; do
|
||||
export "$k=$v"
|
||||
done < <(python3 -c "
|
||||
done < <("$PYTHON_BIN" -c "
|
||||
import json, re, sys
|
||||
RESERVED = {'PATH', 'LD_PRELOAD', 'IFS', 'SHELL', 'USER', 'CORE_DIR', 'SITES_DIR', 'ENV_FILE', 'HOMESERVER_ENV'}
|
||||
d = json.loads(sys.argv[1])
|
||||
@@ -151,23 +152,23 @@ APP=$2
|
||||
|
||||
case "$COMMAND" in
|
||||
list|status)
|
||||
python3 "$ENGINE" list "${@:2}"
|
||||
"$PYTHON_BIN" "$ENGINE" list "${@:2}"
|
||||
;;
|
||||
ssl)
|
||||
python3 "$ENGINE" ssl "${@:2}"
|
||||
"$PYTHON_BIN" "$ENGINE" ssl "${@:2}"
|
||||
;;
|
||||
info)
|
||||
if [ -z "$APP" ]; then echo "❌ Error: Service name required"; exit 1; fi
|
||||
python3 "$ENGINE" info "${@:2}"
|
||||
"$PYTHON_BIN" "$ENGINE" info "${@:2}"
|
||||
;;
|
||||
sync)
|
||||
python3 "$ENGINE" sync "${@:2}"
|
||||
"$PYTHON_BIN" "$ENGINE" sync "${@:2}"
|
||||
;;
|
||||
complete)
|
||||
python3 "$ENGINE" complete "${@:2}"
|
||||
"$PYTHON_BIN" "$ENGINE" complete "${@:2}"
|
||||
;;
|
||||
resolve)
|
||||
python3 "$ENGINE" resolve "${@:2}"
|
||||
"$PYTHON_BIN" "$ENGINE" resolve "${@:2}"
|
||||
;;
|
||||
completion)
|
||||
cat <<'EOF'
|
||||
@@ -242,7 +243,7 @@ EOF
|
||||
else
|
||||
echo "🚀 Starting $CANONICAL_NAME ($APP_DIR)..."
|
||||
cd "$APP_DIR" && docker compose up -d --remove-orphans "${@:3}"
|
||||
python3 "$ENGINE" sync >/dev/null 2>&1 || true
|
||||
"$PYTHON_BIN" "$ENGINE" sync >/dev/null 2>&1 || true
|
||||
fi
|
||||
;;
|
||||
down)
|
||||
@@ -257,7 +258,7 @@ EOF
|
||||
else
|
||||
echo "🛑 Stopping $CANONICAL_NAME ($APP_DIR)..."
|
||||
cd "$APP_DIR" && docker compose down "${@:3}"
|
||||
python3 "$ENGINE" sync >/dev/null 2>&1 || true
|
||||
"$PYTHON_BIN" "$ENGINE" sync >/dev/null 2>&1 || true
|
||||
fi
|
||||
;;
|
||||
restart)
|
||||
@@ -277,7 +278,7 @@ EOF
|
||||
else
|
||||
echo "🔄 Restarting $CANONICAL_NAME ($APP_DIR)..."
|
||||
cd "$APP_DIR" && docker compose down && docker compose up -d "${@:3}"
|
||||
python3 "$ENGINE" sync >/dev/null 2>&1 || true
|
||||
"$PYTHON_BIN" "$ENGINE" sync >/dev/null 2>&1 || true
|
||||
fi
|
||||
;;
|
||||
update)
|
||||
@@ -318,7 +319,7 @@ EOF
|
||||
echo "🚀 Recreating container stack..."
|
||||
cd "$APP_DIR" && docker compose up -d --remove-orphans "${@:3}"
|
||||
|
||||
python3 "$ENGINE" sync >/dev/null 2>&1 || true
|
||||
"$PYTHON_BIN" "$ENGINE" sync >/dev/null 2>&1 || true
|
||||
echo "✨ $CANONICAL_NAME successfully updated!"
|
||||
;;
|
||||
pull)
|
||||
|
||||
@@ -5,6 +5,7 @@ Security invariant tests for Docker Compose and container isolation.
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
@@ -135,7 +136,10 @@ exit 0
|
||||
# 3. Execute scripts/appctl config vuln-app directly
|
||||
appctl_path = CORE_ROOT / "scripts" / "appctl"
|
||||
env = os.environ.copy()
|
||||
env["PATH"] = f"{mock_bin}:{env['PATH']}"
|
||||
if "NIX_PYTHONPATH" in env and "PYTHONPATH" not in env:
|
||||
env["PYTHONPATH"] = env["NIX_PYTHONPATH"]
|
||||
env["PATH"] = f"{mock_bin}:{Path(sys.executable).parent}:{env['PATH']}"
|
||||
env["PYTHON_BIN"] = sys.executable
|
||||
env["SITES_DIR"] = str(sites_dir)
|
||||
env["HOMELAB_DOMAIN"] = "example.test"
|
||||
env["CORE_DIR"] = str(CORE_ROOT)
|
||||
|
||||
Reference in new issue
Block a user