Fix: Harden pinned runtime activation
This commit is contained in:
+163
-44
@@ -126,12 +126,17 @@ _set_artifact_arch() {
|
||||
esac
|
||||
}
|
||||
|
||||
_archive_path_is_safe() {
|
||||
local member="$1"
|
||||
[[ -n "$member" && "$member" != /* && "$member" != *'//'*
|
||||
&& ! "$member" =~ (^|/)\.\.?(/|$) ]]
|
||||
}
|
||||
|
||||
_archive_member_is_safe() {
|
||||
local member="$1" expected_top="$2"
|
||||
[[ -n "$member" && "$member" != /* && "$member" != *'//'*
|
||||
&& ! "$member" =~ (^|/)\.\.?(/|$)
|
||||
&& ( "$member" == "$expected_top" || "$member" == "$expected_top/" \
|
||||
|| "$member" == "$expected_top/"* ) ]]
|
||||
_archive_path_is_safe "$member"
|
||||
[[ "$member" == "$expected_top" || "$member" == "$expected_top/" \
|
||||
|| "$member" == "$expected_top/"* ]]
|
||||
}
|
||||
|
||||
_tree_links_stay_inside() {
|
||||
@@ -142,17 +147,59 @@ _tree_links_stay_inside() {
|
||||
done < <(find "$root" -type l -print0)
|
||||
}
|
||||
|
||||
_atomic_symlink() {
|
||||
local target="$1" destination="$2" directory temporary
|
||||
_tree_hardlinks_stay_inside() {
|
||||
local root="$1" device inode link_count key
|
||||
local -A names_in_tree=() inode_links=()
|
||||
while read -r device inode link_count; do
|
||||
key="$device:$inode"
|
||||
names_in_tree["$key"]=$(( ${names_in_tree[$key]:-0} + 1 ))
|
||||
inode_links["$key"]="$link_count"
|
||||
done < <(find "$root" -type f -printf '%D %i %n\n')
|
||||
for key in "${!names_in_tree[@]}"; do
|
||||
[[ "${names_in_tree[$key]}" == "${inode_links[$key]}" ]] || return 1
|
||||
done
|
||||
}
|
||||
|
||||
_atomic_symlink() (
|
||||
local target="$1" destination="$2" directory temporary=""
|
||||
trap '[[ -z "$temporary" ]] || rm -f -- "$temporary"' EXIT
|
||||
trap 'exit 130' INT
|
||||
trap 'exit 143' TERM
|
||||
directory="$(dirname -- "$destination")"
|
||||
mkdir -p -- "$directory" || return 1
|
||||
temporary="$(mktemp "$directory/.$(basename -- "$destination").link.XXXXXX")" || return 1
|
||||
rm -f -- "$temporary" || return 1
|
||||
ln -s -- "$target" "$temporary" || return 1
|
||||
if ! mv -Tf -- "$temporary" "$destination"; then
|
||||
rm -f -- "$temporary"
|
||||
return 1
|
||||
fi
|
||||
)
|
||||
|
||||
_activate_directory_no_replace() {
|
||||
local staged="$1" destination="$2"
|
||||
mv -Tn -- "$staged" "$destination" || return 1
|
||||
[[ ! -e "$staged" && ! -L "$staged" && -d "$destination" && ! -L "$destination" ]]
|
||||
}
|
||||
|
||||
_write_runtime_receipt() {
|
||||
local directory="$1" artifact_digest="$2" binary_digest="$3"
|
||||
local receipt="$directory/.panama-provenance"
|
||||
[[ -d "$directory" && ! -L "$directory" && ! -e "$receipt" && ! -L "$receipt" ]] \
|
||||
|| return 1
|
||||
( umask 077 && printf 'schema=1\nartifact_sha256=%s\nbinary_sha256=%s\n' \
|
||||
"$artifact_digest" "$binary_digest" > "$receipt" )
|
||||
}
|
||||
|
||||
_runtime_receipt_matches() {
|
||||
local directory="$1" binary="$2" artifact_digest="$3" binary_digest="$4"
|
||||
local receipt="$directory/.panama-provenance" actual
|
||||
[[ -d "$directory" && ! -L "$directory"
|
||||
&& -f "$receipt" && ! -L "$receipt"
|
||||
&& -f "$binary" && ! -L "$binary" ]] || return 1
|
||||
cmp -s "$receipt" <(printf 'schema=1\nartifact_sha256=%s\nbinary_sha256=%s\n' \
|
||||
"$artifact_digest" "$binary_digest") || return 1
|
||||
actual="$(sha256sum "$binary" | awk '{ print $1 }')" || return 1
|
||||
[[ "$actual" == "$binary_digest" ]]
|
||||
}
|
||||
|
||||
_load_nvm() {
|
||||
@@ -165,8 +212,13 @@ _load_nvm() {
|
||||
declare -F nvm >/dev/null
|
||||
}
|
||||
|
||||
_install_node() {
|
||||
_install_node() (
|
||||
local artifact_arch machine_arch archive_top parent target stage archive extract listing member
|
||||
local artifact_digest binary_digest staged_binary
|
||||
stage=""
|
||||
trap '[[ -z "$stage" ]] || rm -rf -- "$stage"' EXIT
|
||||
trap 'exit 130' INT
|
||||
trap 'exit 143' TERM
|
||||
_set_artifact_arch || return 1
|
||||
_load_nvm || return 1
|
||||
case "$artifact_arch" in
|
||||
@@ -176,8 +228,12 @@ _install_node() {
|
||||
archive_top="node-v${INSTALLER_PROVENANCE[NODE_VERSION]}-linux-$machine_arch"
|
||||
parent="${NVM_DIR:-$HOME/.nvm}/versions/node"
|
||||
target="$parent/v${INSTALLER_PROVENANCE[NODE_VERSION]}"
|
||||
artifact_digest="${INSTALLER_PROVENANCE[NODE_${artifact_arch}_SHA256]}"
|
||||
binary_digest="${INSTALLER_PROVENANCE[NODE_${artifact_arch}_BINARY_SHA256]}"
|
||||
if [[ -e "$target" || -L "$target" ]]; then
|
||||
[[ -d "$target" && ! -L "$target" && -x "$target/bin/node"
|
||||
_runtime_receipt_matches "$target" "$target/bin/node" \
|
||||
"$artifact_digest" "$binary_digest" || return 1
|
||||
[[ -x "$target/bin/node"
|
||||
&& "$($target/bin/node --version 2>/dev/null)" == "v${INSTALLER_PROVENANCE[NODE_VERSION]}" ]] \
|
||||
|| return 1
|
||||
nvm alias default "${INSTALLER_PROVENANCE[NODE_VERSION]}" >/dev/null 2>&1 || return 1
|
||||
@@ -204,17 +260,34 @@ _install_node() {
|
||||
done <<<"$listing"
|
||||
tar -xJf "$archive" --no-same-owner --no-same-permissions -C "$extract" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
[[ -d "$extract/$archive_top" && ! -L "$extract/$archive_top"
|
||||
&& -x "$extract/$archive_top/bin/node"
|
||||
&& "$($extract/$archive_top/bin/node --version 2>/dev/null)" \
|
||||
== "v${INSTALLER_PROVENANCE[NODE_VERSION]}" ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_tree_links_stay_inside "$extract/$archive_top" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
mv -- "$extract/$archive_top" "$target" || { rm -rf -- "$stage"; return 1; }
|
||||
_tree_hardlinks_stay_inside "$extract/$archive_top" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
staged_binary="$extract/$archive_top/bin/node"
|
||||
[[ "$(sha256sum "$staged_binary" | awk '{ print $1 }')" == "$binary_digest" ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
[[ -d "$extract/$archive_top" && ! -L "$extract/$archive_top"
|
||||
&& -x "$staged_binary"
|
||||
&& "$($staged_binary --version 2>/dev/null)" \
|
||||
== "v${INSTALLER_PROVENANCE[NODE_VERSION]}" ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_write_runtime_receipt "$extract/$archive_top" "$artifact_digest" "$binary_digest" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_activate_directory_no_replace "$extract/$archive_top" "$target" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_runtime_receipt_matches "$target" "$target/bin/node" \
|
||||
"$artifact_digest" "$binary_digest" || { rm -rf -- "$stage"; return 1; }
|
||||
[[ -x "$target/bin/node"
|
||||
&& "$($target/bin/node --version 2>/dev/null)" \
|
||||
== "v${INSTALLER_PROVENANCE[NODE_VERSION]}" ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_tree_links_stay_inside "$target" || { rm -rf -- "$stage"; return 1; }
|
||||
_tree_hardlinks_stay_inside "$target" || { rm -rf -- "$stage"; return 1; }
|
||||
rm -rf -- "$stage"
|
||||
stage=""
|
||||
nvm alias default "${INSTALLER_PROVENANCE[NODE_VERSION]}" >/dev/null 2>&1
|
||||
}
|
||||
)
|
||||
|
||||
install_node() {
|
||||
_install_node || _record_installer_failure Node
|
||||
@@ -226,15 +299,20 @@ setup_node() {
|
||||
}
|
||||
|
||||
install_pnpm() {
|
||||
if sudo dnf install -y pnpm >/dev/null; then
|
||||
if require_reviewed_fedora_release \
|
||||
&& sudo dnf install -y --repo=fedora --repo=updates pnpm >/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
_record_installer_failure pnpm
|
||||
}
|
||||
|
||||
_install_bun() {
|
||||
_install_bun() (
|
||||
local artifact_arch archive_top target bin_link parent stage archive listing
|
||||
local staged_binary version_dir
|
||||
local staged_binary version_dir artifact_digest binary_digest
|
||||
stage=""
|
||||
trap '[[ -z "$stage" ]] || rm -rf -- "$stage"' EXIT
|
||||
trap 'exit 130' INT
|
||||
trap 'exit 143' TERM
|
||||
_set_artifact_arch || return 1
|
||||
case "$artifact_arch" in
|
||||
X86_64) archive_top=bun-linux-x64 ;;
|
||||
@@ -243,8 +321,12 @@ _install_bun() {
|
||||
version_dir="$HOME/.bun/versions/${INSTALLER_PROVENANCE[BUN_VERSION]}"
|
||||
target="$version_dir/bin/bun"
|
||||
bin_link="$HOME/.bun/bin/bun"
|
||||
artifact_digest="${INSTALLER_PROVENANCE[BUN_${artifact_arch}_SHA256]}"
|
||||
binary_digest="${INSTALLER_PROVENANCE[BUN_${artifact_arch}_BINARY_SHA256]}"
|
||||
if [[ -e "$version_dir" || -L "$version_dir" ]]; then
|
||||
[[ -d "$version_dir" && ! -L "$version_dir" && -x "$target"
|
||||
_runtime_receipt_matches "$version_dir" "$target" \
|
||||
"$artifact_digest" "$binary_digest" || return 1
|
||||
[[ -x "$target"
|
||||
&& "$($target --version 2>/dev/null)" == "${INSTALLER_PROVENANCE[BUN_VERSION]}" ]] \
|
||||
|| return 1
|
||||
[[ -L "$bin_link" && "$(readlink -- "$bin_link")" == "$target" ]] \
|
||||
@@ -264,22 +346,35 @@ _install_bun() {
|
||||
return 1
|
||||
fi
|
||||
listing="$(unzip -Z1 "$archive")" || { rm -rf -- "$stage"; return 1; }
|
||||
[[ "$listing" == "$archive_top/bun" ]] || { rm -rf -- "$stage"; return 1; }
|
||||
_archive_member_is_safe "$listing" "$archive_top" \
|
||||
[[ "$listing" == "$archive_top/"$'\n'"$archive_top/bun" ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
while IFS= read -r member; do
|
||||
_archive_member_is_safe "$member" "$archive_top" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
done <<<"$listing"
|
||||
mkdir -m 0700 "$stage/extract" "$stage/version" "$stage/version/bin" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
unzip -q "$archive" -d "$stage/extract" || { rm -rf -- "$stage"; return 1; }
|
||||
staged_binary="$stage/extract/$archive_top/bun"
|
||||
[[ -f "$staged_binary" && ! -L "$staged_binary" && -x "$staged_binary"
|
||||
&& "$(sha256sum "$staged_binary" | awk '{ print $1 }')" == "$binary_digest"
|
||||
&& "$($staged_binary --version 2>/dev/null)" == "${INSTALLER_PROVENANCE[BUN_VERSION]}" ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
mv -- "$staged_binary" "$stage/version/bin/bun" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
mv -- "$stage/version" "$version_dir" || { rm -rf -- "$stage"; return 1; }
|
||||
_write_runtime_receipt "$stage/version" "$artifact_digest" "$binary_digest" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_activate_directory_no_replace "$stage/version" "$version_dir" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_runtime_receipt_matches "$version_dir" "$target" \
|
||||
"$artifact_digest" "$binary_digest" || { rm -rf -- "$stage"; return 1; }
|
||||
[[ -x "$target" && "$($target --version 2>/dev/null)" \
|
||||
== "${INSTALLER_PROVENANCE[BUN_VERSION]}" ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
rm -rf -- "$stage"
|
||||
stage=""
|
||||
_atomic_symlink "$target" "$bin_link"
|
||||
}
|
||||
)
|
||||
|
||||
install_bun() {
|
||||
_install_bun || _record_installer_failure Bun
|
||||
@@ -292,20 +387,23 @@ _codex_version_matches() {
|
||||
[[ "$output" =~ (^|[^0-9])${version_pattern}([^0-9]|$) ]]
|
||||
}
|
||||
|
||||
_install_codex() {
|
||||
local artifact_arch machine_arch archive_name version_dir target bin_link parent
|
||||
local stage archive listing staged_binary
|
||||
_install_codex() (
|
||||
local artifact_arch version_dir target bin_link parent expected_listing member
|
||||
local stage archive listing staged_binary artifact_digest binary_digest
|
||||
stage=""
|
||||
trap '[[ -z "$stage" ]] || rm -rf -- "$stage"' EXIT
|
||||
trap 'exit 130' INT
|
||||
trap 'exit 143' TERM
|
||||
_set_artifact_arch || return 1
|
||||
case "$artifact_arch" in
|
||||
X86_64) machine_arch=x86_64 ;;
|
||||
AARCH64) machine_arch=aarch64 ;;
|
||||
esac
|
||||
archive_name="codex-$machine_arch-unknown-linux-musl"
|
||||
version_dir="$HOME/.local/lib/panama/codex/${INSTALLER_PROVENANCE[CODEX_VERSION]}"
|
||||
target="$version_dir/codex"
|
||||
bin_link="$HOME/.local/bin/codex"
|
||||
artifact_digest="${INSTALLER_PROVENANCE[CODEX_${artifact_arch}_SHA256]}"
|
||||
binary_digest="${INSTALLER_PROVENANCE[CODEX_${artifact_arch}_BINARY_SHA256]}"
|
||||
if [[ -e "$version_dir" || -L "$version_dir" ]]; then
|
||||
[[ -d "$version_dir" && ! -L "$version_dir" && -x "$target" ]] || return 1
|
||||
_runtime_receipt_matches "$version_dir" "$target" \
|
||||
"$artifact_digest" "$binary_digest" || return 1
|
||||
[[ -x "$target" ]] || return 1
|
||||
_codex_version_matches "$target" || return 1
|
||||
[[ -L "$bin_link" && "$(readlink -- "$bin_link")" == "$target" ]] \
|
||||
|| _atomic_symlink "$target" "$bin_link"
|
||||
@@ -324,31 +422,47 @@ _install_codex() {
|
||||
return 1
|
||||
fi
|
||||
listing="$(tar -tzf "$archive")" || { rm -rf -- "$stage"; return 1; }
|
||||
[[ "$listing" == "$archive_name" ]] || { rm -rf -- "$stage"; return 1; }
|
||||
[[ "$listing" != /* && ! "$listing" =~ (^|/)\.\.?(/|$) ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
expected_listing=$'bin/\nbin/codex\nbin/codex-code-mode-host\ncodex-package.json\ncodex-path/\ncodex-path/rg\ncodex-resources/\ncodex-resources/bwrap\ncodex-resources/zsh/\ncodex-resources/zsh/bin/\ncodex-resources/zsh/bin/zsh'
|
||||
[[ "$listing" == "$expected_listing" ]] || { rm -rf -- "$stage"; return 1; }
|
||||
while IFS= read -r member; do
|
||||
_archive_path_is_safe "$member" || { rm -rf -- "$stage"; return 1; }
|
||||
done <<<"$listing"
|
||||
mkdir -m 0700 "$stage/extract" "$stage/version" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
tar -xzf "$archive" --no-same-owner --no-same-permissions -C "$stage/extract" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
staged_binary="$stage/extract/$archive_name"
|
||||
[[ -f "$staged_binary" && ! -L "$staged_binary" && -x "$staged_binary" ]] \
|
||||
_tree_links_stay_inside "$stage/extract" || { rm -rf -- "$stage"; return 1; }
|
||||
_tree_hardlinks_stay_inside "$stage/extract" || { rm -rf -- "$stage"; return 1; }
|
||||
staged_binary="$stage/extract/bin/codex"
|
||||
[[ -f "$staged_binary" && ! -L "$staged_binary" && -x "$staged_binary"
|
||||
&& "$(sha256sum "$staged_binary" | awk '{ print $1 }')" == "$binary_digest" ]] \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_codex_version_matches "$staged_binary" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
mv -- "$staged_binary" "$stage/version/codex" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
mv -- "$stage/version" "$version_dir" || { rm -rf -- "$stage"; return 1; }
|
||||
_write_runtime_receipt "$stage/version" "$artifact_digest" "$binary_digest" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_activate_directory_no_replace "$stage/version" "$version_dir" \
|
||||
|| { rm -rf -- "$stage"; return 1; }
|
||||
_runtime_receipt_matches "$version_dir" "$target" \
|
||||
"$artifact_digest" "$binary_digest" || { rm -rf -- "$stage"; return 1; }
|
||||
_codex_version_matches "$target" || { rm -rf -- "$stage"; return 1; }
|
||||
rm -rf -- "$stage"
|
||||
stage=""
|
||||
_atomic_symlink "$target" "$bin_link"
|
||||
}
|
||||
)
|
||||
|
||||
install_codex() {
|
||||
_install_codex || _record_installer_failure Codex
|
||||
}
|
||||
|
||||
_install_rustdesk() {
|
||||
_install_rustdesk() (
|
||||
local artifact_arch installed_version="" work rpm_path status=0
|
||||
work=""
|
||||
trap '[[ -z "$work" ]] || rm -rf -- "$work"' EXIT
|
||||
trap 'exit 130' INT
|
||||
trap 'exit 143' TERM
|
||||
_set_artifact_arch || return 1
|
||||
if [[ "$artifact_arch" == AARCH64 ]]; then
|
||||
log "RustDesk ${INSTALLER_PROVENANCE[RUSTDESK_VERSION]} has no reviewed aarch64 RPM"
|
||||
@@ -367,10 +481,14 @@ _install_rustdesk() {
|
||||
rm -rf -- "$work"
|
||||
return 1
|
||||
fi
|
||||
sudo dnf install -y --setopt=localpkg_gpgcheck=1 "$rpm_path" >/dev/null || status=$?
|
||||
# RustDesk 1.4.9's reviewed RPM is unsigned. Its exact SHA-256 is the trust
|
||||
# assertion; this exception applies only to the verified private local file
|
||||
# and does not change signature policy for any repository.
|
||||
sudo dnf install -y --setopt=localpkg_gpgcheck=0 "$rpm_path" >/dev/null || status=$?
|
||||
rm -rf -- "$work"
|
||||
work=""
|
||||
return "$status"
|
||||
}
|
||||
)
|
||||
|
||||
install_rustdesk() {
|
||||
_install_rustdesk || _record_installer_failure RustDesk
|
||||
@@ -945,7 +1063,8 @@ _install_claude_code() {
|
||||
"$staged_key" /etc/pki/rpm-gpg/RPM-GPG-KEY-claude-code-panama \
|
||||
"$staged_repo" /etc/yum.repos.d/claude-code.repo || status=$?
|
||||
if (( status == 0 )); then
|
||||
sudo dnf install -y claude-code || status=$?
|
||||
sudo dnf install -y --repo=claude-code --repo=fedora --repo=updates \
|
||||
claude-code || status=$?
|
||||
fi
|
||||
rm -rf -- "$work"
|
||||
return "$status"
|
||||
|
||||
Reference in New Issue
Block a user