Files
OpenShell/tasks/scripts/test-packaging-assets.sh
Johnny Greco 58b5f8f976 feat(prover): add standalone policy boundary checker (#3289)
* feat(prover): add standalone policy maximum checker

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* refactor(prover): simplify check scope schema

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): align containment and cancellation with runtime

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): stabilize containment checks in CI

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* test(prover): avoid solver in fast-path guard test

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): align string containment with runtime

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): reject ambiguous z3 string escapes

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): align containment with runtime boundaries

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover-cli): harden cancellation and invalid input

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* feat(packaging): install policy prover with OpenShell

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* docs(prover): clarify installation and check results

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* docs(build): describe prover distribution directly

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* refactor(prover): rename maximum policy to boundary

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* refactor(prover): localize fail-closed validation

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* test(prover): cover fail-closed CLI surfaces

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* test(prover): allow CI load for REST solver proof

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): use canonical policy schema for containment

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): preserve uncertainty for runtime binary globs

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): bound policy validation work

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* docs(prover): document validation resource limits

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(prover): make containment API extensible

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* docs(prover): define containment API contract

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(ci): integrate prover with consolidated builds

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

* fix(ci): declare release packaging dependency

Signed-off-by: Johnny Greco <jogreco@nvidia.com>

---------

Signed-off-by: Johnny Greco <jogreco@nvidia.com>
2026-09-17 17:30:03 +00:00

130 lines
4.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
assert_contains() {
local file=$1
local expected=$2
if ! grep -Fq "$expected" "$file"; then
echo "FAIL: ${file} is missing expected text:" >&2
echo " ${expected}" >&2
exit 1
fi
}
assert_not_contains() {
local file=$1
local unexpected=$2
if grep -Fq "$unexpected" "$file"; then
echo "FAIL: ${file} contains stale text:" >&2
echo " ${unexpected}" >&2
exit 1
fi
}
assert_file_exists() {
local file=$1
if [[ ! -f "$file" ]]; then
echo "ERROR: ${file} not found" >&2
exit 1
fi
}
service="${ROOT}/deploy/deb/openshell-gateway.service"
spec="${ROOT}/openshell.spec"
assert_file_exists "$service"
assert_file_exists "$spec"
assert_contains \
"$service" \
'Environment=OPENSHELL_LOCAL_TLS_DIR=%h/.local/state/openshell/tls'
assert_contains \
"$service" \
'ExecStartPre=/usr/bin/openshell-gateway generate-certs --output-dir ${OPENSHELL_LOCAL_TLS_DIR} --server-san host.openshell.internal'
assert_not_contains "$service" '%S/openshell/tls'
assert_contains \
"$spec" \
'Environment=OPENSHELL_LOCAL_TLS_DIR=%%h/.local/state/openshell/tls'
assert_contains \
"$spec" \
'ExecStartPre=/usr/bin/openshell-gateway generate-certs --output-dir ${OPENSHELL_LOCAL_TLS_DIR} --server-san host.openshell.internal'
assert_contains "$spec" 'ExecStartPre=/usr/bin/openshell-gateway config preflight'
assert_contains "$spec" '%package prover'
assert_contains "$spec" '%files prover'
assert_contains "$spec" '%{_bindir}/%{name}-prover'
assert_not_contains "$spec" '%%S/openshell/tls'
# Schema-v2 package startup wiring.
snap_wrapper="${ROOT}/tasks/scripts/snap-gateway-wrapper.sh"
package_deb="${ROOT}/tasks/scripts/package-deb.sh"
assert_file_exists "$snap_wrapper"
assert_file_exists "$package_deb"
assert_contains "$service" "ExecStartPre=/usr/bin/openshell-gateway config preflight"
assert_contains "$package_deb" "\$src_dir/openshell-gateway.service"
assert_contains "$package_deb" "\$pkgroot/usr/lib/systemd/user/openshell-gateway.service"
assert_contains "$snap_wrapper" "if [ -n \"\${OPENSHELL_GATEWAY_CONFIG:-}\" ]; then"
assert_contains \
"$snap_wrapper" \
"elif [ -e \"\$CANONICAL_CONFIG_FILE\" ] || [ -L \"\$CANONICAL_CONFIG_FILE\" ]; then"
assert_contains "$snap_wrapper" "config preflight -- --config \"\$CANONICAL_CONFIG_FILE\" \"\$@\""
assert_not_contains "$snap_wrapper" "[ -f \"\$CANONICAL_CONFIG_FILE\" ]"
bash "$ROOT/tasks/scripts/test-snap-gateway-wrapper.sh" "$snap_wrapper"
if ! awk '/config preflight/ { seen = 1 } /generate-certs/ { exit !seen }' "$service"; then
echo "FAIL: Debian preflight must precede certificate generation" >&2
exit 1
fi
if ! awk \
'/^ExecStartPre=.*gateway-migrate-config / { migrated = 1 } \
/^ExecStartPre=\/usr\/bin\/openshell-gateway config preflight$/ { preflight = migrated } \
/^ExecStartPre=\/usr\/bin\/openshell-gateway generate-certs/ { exit !(preflight && migrated) }' \
"$spec"; then
echo "FAIL: RPM migration and preflight must precede certificate generation" >&2
exit 1
fi
# Build a throwaway package when Debian tooling is available to prove the
# staged unit comes from deploy/deb/. Other hosts retain the static source-to-
# destination assertion above; the real Debian upgrade lane remains required.
if command -v dpkg-deb >/dev/null 2>&1; then
package_work=$(mktemp -d "${TMPDIR:-/tmp}/openshell-package-assets.XXXXXX")
trap 'rm -rf "$package_work"' EXIT
mkdir -p "$package_work/bin" "$package_work/output"
for binary in openshell openshell-gateway openshell-prover openshell-driver-vm; do
printf '#!/bin/sh\nexit 0\n' >"$package_work/bin/$binary"
chmod +x "$package_work/bin/$binary"
done
OPENSHELL_CLI_BINARY="$package_work/bin/openshell" \
OPENSHELL_GATEWAY_BINARY="$package_work/bin/openshell-gateway" \
OPENSHELL_PROVER_BINARY="$package_work/bin/openshell-prover" \
OPENSHELL_DRIVER_VM_BINARY="$package_work/bin/openshell-driver-vm" \
OPENSHELL_DEB_VERSION=0.0.0 \
OPENSHELL_DEB_ARCH=amd64 \
OPENSHELL_OUTPUT_DIR="$package_work/output" \
"$package_deb" >/dev/null
dpkg-deb --fsys-tarfile "$package_work/output/openshell_0.0.0_amd64.deb" \
| tar -xOf - ./usr/lib/systemd/user/openshell-gateway.service \
>"$package_work/staged.service"
if ! cmp -s "$service" "$package_work/staged.service"; then
echo "FAIL: package-deb did not stage the current Debian service" >&2
exit 1
fi
if ! dpkg-deb --fsys-tarfile "$package_work/output/openshell_0.0.0_amd64.deb" \
| tar -tf - | grep -x './usr/bin/openshell-prover' >/dev/null; then
echo "FAIL: package-deb did not stage openshell-prover" >&2
exit 1
fi
else
echo "SKIP: dpkg-deb unavailable; Debian artifact staging requires its assigned lane"
fi
echo "packaging asset tests passed"