Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/publish-current-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ jobs:
cleanup_extract
trap - EXIT

- name: Verify real signed payload recovery on the isolated candidate
shell: bash
run: |
set -euo pipefail
evidence="$RUNNER_TEMP/server-evidence"
docker run --rm --read-only --security-opt no-new-privileges \
--tmpfs /tmp:rw,nosuid,size=256m \
--mount "type=bind,source=$GITHUB_WORKSPACE/source/scripts/probe-security-payload-recovery.sh,target=/probe/run.sh,readonly" \
--mount "type=bind,source=$GITHUB_WORKSPACE/source/server/scripts/download-ubuntu-security-updates.sh,target=/probe/download.sh,readonly" \
--mount "type=bind,source=$GITHUB_WORKSPACE/source/server/security/ubuntu-security-approved-records.tsv,target=/probe/approved.tsv,readonly" \
--mount "type=bind,source=$GITHUB_WORKSPACE/source/server/security/ubuntu-security-packages.lock,target=/probe/versions.lock,readonly" \
--entrypoint /bin/sh "$CANDIDATE_IMAGE" /probe/run.sh \
>"$evidence/security-payload-recovery.json"
jq -e '.status == "PASS_NATIVE_OFFICIAL_PAYLOAD_RECOVERY" and .forcedPayloadFailures == 1 and .actualAptHelper and .runtimePackageSetUnchanged and .aptSourcesUnchanged' \
"$evidence/security-payload-recovery.json"

- name: Verify the actual candidate JDK security runtime
shell: bash
working-directory: source
Expand Down Expand Up @@ -896,6 +912,7 @@ jobs:
sha256sum \
build.log \
brotli-runtime.txt \
security-payload-recovery.json \
candidate.log \
candidate-smoke.txt \
"host-api-${HOST_API_VERSION}.tar.gz" \
Expand Down Expand Up @@ -940,6 +957,7 @@ jobs:
"$evidence/SHA256SUMS" \
"$evidence/build.log" \
"$evidence/brotli-runtime.txt" \
"$evidence/security-payload-recovery.json" \
"$evidence/candidate.log" \
"$evidence/candidate-smoke.txt" \
"$evidence/host-api-${HOST_API_VERSION}.tar.gz" \
Expand Down
5 changes: 5 additions & 0 deletions docs/releases/server-1.6.617.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Inventory completeness does not erase Lato/PositionCalculator index limitations.
Related-upstream Bootstrap/noVNC matches retain their raw results and exact
source applicability boundaries. KVM and AWS remain outside this repair.

Signed Ubuntu recovery also covers an authenticated index followed by a missing
or temporarily unavailable package payload. Only another official Ubuntu pool
may supply the already reviewed exact bytes; hash, TLS, signature, version or
architecture failures remain blocking. Runtime package installation stays offline.

## Upgrade and rollback

Follow the normal Server upgrade guide. Preserve environment overrides, named
Expand Down
65 changes: 65 additions & 0 deletions scripts/probe-security-payload-recovery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/sh
# Isolated release-image probe: real signed APT indexes and apt-helper, with one
# test-only payload transport fault. Never installs packages or changes sources.
set -eu
test "$#" -eq 0
. /etc/os-release
test "$ID:$VERSION_ID" = ubuntu:26.04
test -x /usr/lib/apt/apt-helper
test "$(dpkg-query -W -f='${Version}' apt)" = 3.2.1ubuntu0.1
scratch=$(mktemp -d /tmp/pst-native-payload.XXXXXX)
trap 'rm -rf "$scratch"' EXIT HUP INT TERM
package=libgcrypt20
version=$(awk -F= '$1 == "libgcrypt20" {print $2}' /probe/versions.lock)
test -n "$version"
awk -F '\t' -v v="$version" '$1 == "libgcrypt20" && $2 == v && NF == 5 {print}' /probe/approved.tsv >"$scratch/record"
test "$(wc -l < "$scratch/record")" -eq 1
expected_arch=$(cut -f3 "$scratch/record")
expected_size=$(cut -f4 "$scratch/record")
expected_sha=$(cut -f5 "$scratch/record")
snapshot=$(sed -n 's/^# snapshot=//p' /probe/approved.tsv)
printf '%s\n' "$snapshot" | grep -Eq '^[0-9]{8}T[0-9]{6}Z$'
printf '%s\n' "$expected_sha" | grep -Eq '^[a-f0-9]{64}$'
printf '%s\n' "$expected_size" | grep -Eq '^[1-9][0-9]*$'
test "$expected_arch" = "$(dpkg --print-architecture)"
printf '%s=%s\n' "$package" "$version" >"$scratch/versions.lock"
packages_before=$(dpkg-query -W -f='${Package}\t${Version}\t${db:Status-Status}\n' | sha256sum)
sources_before=$(find /etc/apt -type f -exec sha256sum {} + | LC_ALL=C sort | sha256sum)
mkdir "$scratch/bin"
cat >"$scratch/bin/apt-get" <<'SH'
#!/bin/sh
download=0; print_uris=0; target=0
for value do
case "$value" in
download) download=1 ;;
--print-uris) print_uris=1 ;;
libgcrypt20=*) target=1 ;;
esac
done
if test "$download:$print_uris:$target" = 1:0:1; then
printf 'forced\n' >>"$PASTURESTACK_NATIVE_FAULT_COUNT"
echo '503 Service Unavailable (isolated payload fault)' >&2
exit 100
fi
exec /usr/bin/apt-get "$@"
SH
chmod 0700 "$scratch/bin/apt-get"
if PATH="$scratch/bin:$PATH" TMPDIR="$scratch" \
PASTURESTACK_NATIVE_FAULT_COUNT="$scratch/fault-count" \
PASTURESTACK_SECURITY_SNAPSHOT="$snapshot" \
PASTURESTACK_APPROVED_SECURITY_RECORDS=/probe/approved.tsv \
/bin/sh /probe/download.sh "$scratch/versions.lock" /etc/ssl/certs/ca-certificates.crt "$scratch/output" \
>"$scratch/probe.log" 2>&1; then :; else cat "$scratch/probe.log" >&2; exit 1; fi
test "$(wc -l < "$scratch/fault-count")" -eq 1
grep -Fx "OFFICIAL_SECURITY_PAYLOAD_RECOVERED package=$package version=$version sha256=$expected_sha" "$scratch/probe.log" >/dev/null
grep -Fx 'UBUNTU_SECURITY_DEBS_VERIFIED packages=1' "$scratch/probe.log" >/dev/null
file="$scratch/output/$package.deb"
printf '%s %s\n' "$expected_sha" "$file" | sha256sum -c - >/dev/null
test "$(wc -c < "$file")" -eq "$expected_size"
test "$(dpkg-deb -f "$file" Package)" = "$package"
test "$(dpkg-deb -f "$file" Version)" = "$version"
test "$(dpkg-deb -f "$file" Architecture)" = "$expected_arch"
test "$packages_before" = "$(dpkg-query -W -f='${Package}\t${Version}\t${db:Status-Status}\n' | sha256sum)"
test "$sources_before" = "$(find /etc/apt -type f -exec sha256sum {} + | LC_ALL=C sort | sha256sum)"
printf '{"status":"PASS_NATIVE_OFFICIAL_PAYLOAD_RECOVERY","package":"%s","version":"%s","sha256":"%s","bytes":%s,"snapshot":"%s","forcedPayloadFailures":1,"actualAptHelper":true,"runtimePackageSetUnchanged":true,"aptSourcesUnchanged":true}\n' \
"$package" "$version" "$expected_sha" "$expected_size" "$snapshot"
51 changes: 47 additions & 4 deletions scripts/test-signed-security-mirror-recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ def path(value):
required=['Acquire::https::Verify-Peer=true','Acquire::https::Verify-Host=true',
'Acquire::AllowInsecureRepositories=false','APT::Get::AllowUnauthenticated=false','Acquire::ForceHash=sha256']
assert all(value in args for value in required)
mode=os.environ['FIXTURE_MODE']
if name=='apt-helper':
with path(os.environ['FIXTURE_CALLS']).open('a') as f:f.write(json.dumps({'args':args,'mirror':True,'tool':'apt-helper'})+'\n')
position=args.index('download-file');url,target,expected=args[position+1:]
assert url in ['https://archive.ubuntu.com/ubuntu/pool/main/f/fixture/fixture_2.0_amd64.deb',
'https://security.ubuntu.com/ubuntu/pool/main/f/fixture/fixture_2.0_amd64.deb']
body=path(os.environ['FIXTURE_BODY'])
assert expected=='SHA256:'+hashlib.sha256(body.read_bytes()).hexdigest()
if mode=='download-pools-fail' or mode=='download-second-pool' and 'archive.ubuntu.com' in url:
print('503 Service Unavailable');sys.exit(100)
if mode=='download-helper-hash':print('503 Hash Sum mismatch');sys.exit(100)
path(target).write_bytes(b'corrupt' if mode=='download-corrupt' else body.read_bytes());sys.exit(0)
config=path(next(a.split('=',1)[1] for a in args if a.startswith('Dir::Etc::sourcelist='))).read_text()
mirror='snapshot.ubuntu.com' not in config
mode=os.environ['FIXTURE_MODE']
with path(os.environ['FIXTURE_CALLS']).open('a') as f:f.write(json.dumps({'args':args,'mirror':mirror})+'\n')
if 'update' in args:
if not mirror and mode!='normal':
if not mirror and mode!='normal' and not mode.startswith('download-'):
print('NO_PUBKEY invalid signature' if mode=='signature' else '503 Service Unavailable');sys.exit(100)
if mirror and mode=='mirror-fails':print('503 Service Unavailable');sys.exit(100)
sys.exit(0)
Expand All @@ -42,8 +53,15 @@ def path(value):
origin='https://security.ubuntu.com/ubuntu/' if mirror else 'https://snapshot.ubuntu.com/ubuntu/20261123T000000Z/'
if mode=='origin':origin='https://untrusted.invalid/'
digest='d'*64 if mode=='index-digest' else hashlib.sha256(body.read_bytes()).hexdigest()
print("'"+origin+"pool/fixture.deb' fixture.deb "+str(body.stat().st_size)+' SHA256:'+digest)
print("'"+origin+"pool/main/f/fixture/fixture_2.0_amd64.deb' fixture.deb "+str(body.stat().st_size)+' SHA256:'+digest)
else:
if mode.startswith('download-'):
message={'download-404':'404 Not Found','download-hash':'503 Hash Sum mismatch',
'download-certificate':'503 Certificate verification failed',
'download-signature':'503 BADSIG invalid signature',
'download-version':'Version not found'}.get(mode,'503 Service Unavailable')
(pathlib.Path.cwd()/'partial.deb').write_bytes(b'incomplete')
print(message);sys.exit(100)
shutil.copyfile(body,pathlib.Path.cwd()/'fixture.deb')
if mode=='changed-bytes':(pathlib.Path.cwd()/'fixture.deb').write_bytes(b'changed')
'''
Expand All @@ -61,9 +79,11 @@ def run_owner(self,mode='transport',record='valid',approved=True):
(root/'body').write_bytes(BODY);(root/'ca').write_text('fixture CA')
(root/'os-release').write_text('ID=ubuntu\nVERSION_ID=26.04\n',newline='\n')
source=SOURCE.read_text(encoding='utf-8');self.assertEqual(1,source.count('. /etc/os-release'))
self.assertEqual(1,source.count('/usr/lib/apt/apt-helper'))
source=source.replace('/usr/lib/apt/apt-helper','"$FIXTURE_APT_HELPER"')
(root/'actual-owner.sh').write_text(source.replace('. /etc/os-release','. "'+shell_path(root/'os-release')+'"'),encoding='utf-8',newline='\n')
(root/'shim.py').write_text(FAKE,encoding='utf-8',newline='\n')
commands=['apt-get','dpkg','dpkg-deb']
commands=['apt-get','apt-helper','dpkg','dpkg-deb']
# The bundled Windows POSIX shell has no sha256sum executable.
# Compute actual bytes with hashlib, never return a fixture digest.
if os.name=='nt' and not shutil.which('sha256sum'):commands.append('sha256sum')
Expand All @@ -83,6 +103,7 @@ def run_owner(self,mode='transport',record='valid',approved=True):
env.update(PATH=shell_path(bin)+':'+shell_path(Path(shell).parent)+':/usr/bin:/bin',TMPDIR=shell_path(root),
FIXTURE_PYTHON=sys.executable,FIXTURE_SHIM=str(root/'shim.py'),FIXTURE_BODY=str(root/'body'),
FIXTURE_CALLS=str(root/'calls.jsonl'),FIXTURE_MODE=mode,
FIXTURE_APT_HELPER=shell_path(bin/'apt-helper'),
PASTURESTACK_APPROVED_SECURITY_RECORDS=shell_path(root/'approved.tsv') if approved else '')
result=subprocess.run([shell,shell_path(root/'actual-owner.sh'),shell_path(root/'versions.lock'),
shell_path(root/'ca'),shell_path(root/'out')],env=env,capture_output=True,timeout=20)
Expand Down Expand Up @@ -128,4 +149,26 @@ def test_current_approved_records_exactly_match_the_version_lock(self):
self.assertIn('COPY security/ubuntu-security-approved-records.tsv /build/ubuntu-security-approved-records.tsv',recipe)
self.assertIn('PASTURESTACK_APPROVED_SECURITY_RECORDS=/build/ubuntu-security-approved-records.tsv',recipe)

def test_signed_index_success_payload_transport_failure_recovers_exact_bytes(self):
for mode in ('download-transport','download-404','download-second-pool'):
code,calls,error=self.run_owner(mode)
self.assertEqual(0,code,error)
helpers=[c for c in calls if c.get('tool')=='apt-helper']
self.assertEqual(2 if mode=='download-second-pool' else 1,len(helpers))
self.assertFalse(any(c['mirror'] for c in calls if c.get('tool')!='apt-helper'))

def test_payload_signature_tls_hash_or_version_errors_never_use_another_origin(self):
for mode in ('download-signature','download-certificate','download-hash','download-version'):
code,calls,error=self.run_owner(mode)
self.assertNotEqual(0,code,(mode,error))
self.assertFalse(any(c.get('tool')=='apt-helper' for c in calls))
code,calls,error=self.run_owner('download-transport',approved=False)
self.assertNotEqual(0,code);self.assertFalse(any(c.get('tool')=='apt-helper' for c in calls))

def test_payload_changed_bytes_and_exhausted_official_pools_fail_closed(self):
for mode,count in (('download-corrupt',1),('download-helper-hash',1),('download-pools-fail',2)):
code,calls,error=self.run_owner(mode)
self.assertNotEqual(0,code,(mode,error))
self.assertEqual(count,len([c for c in calls if c.get('tool')=='apt-helper']))

if __name__=='__main__':unittest.main(verbosity=2)
45 changes: 44 additions & 1 deletion server/scripts/download-ubuntu-security-updates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,50 @@ while IFS= read -r entry || test -n "$entry"; do
case "$expected_size" in ''|*[!0-9]*) exit 1;; esac
test "$(awk '{print $3}' "$tmp/uri")" = "$expected_size"
fi
(cd "$tmp/download" && apt_security download "$entry")
if (cd "$tmp/download" && apt_security download "$entry") >"$tmp/download.log" 2>&1; then
cat "$tmp/download.log"
else
download_status=$?
# A signed index being reachable does not establish payload availability.
# Recover only reviewed bytes from another official pool; keep the
# authenticated index, version and all subsequent package checks.
if test -z "$approved" || test -z "$expected_size" || test -z "$expected_arch" ||
! grep -Eq '404|50[0234]|timed out|Could not (connect|resolve)|Temporary failure resolving' "$tmp/download.log" ||
grep -Eiq 'NO_PUBKEY|BADSIG|EXPKEYSIG|signature|Hash (Sum )?mismatch|certificate verification|certificate.*(failed|invalid)' "$tmp/download.log"; then
cat "$tmp/download.log" >&2; exit "$download_status"
fi
authenticated_uri=$(cut -d "'" -f2 "$tmp/uri")
case "$authenticated_uri" in
"https://snapshot.ubuntu.com/ubuntu/$snapshot/"*) pool=${authenticated_uri#"https://snapshot.ubuntu.com/ubuntu/$snapshot/"} ;;
https://archive.ubuntu.com/ubuntu/*) pool=${authenticated_uri#https://archive.ubuntu.com/ubuntu/} ;;
https://security.ubuntu.com/ubuntu/*) pool=${authenticated_uri#https://security.ubuntu.com/ubuntu/} ;;
*) echo 'Untrusted authenticated package origin' >&2; exit 1 ;;
esac
case "$pool" in pool/main/*) ;; *) echo 'Untrusted official pool path' >&2; exit 1 ;; esac
case "$pool" in *'..'*|*'?'*|*'#'*|*'\\'*) echo 'Unsafe official pool path' >&2; exit 1 ;; esac
recovered=0
for origin in https://archive.ubuntu.com/ubuntu https://security.ubuntu.com/ubuntu; do
# This directory is newly owned by this invocation; failed APT
# downloads must not leave a second partial package for adoption.
rm -f "$tmp/download/"*.deb
if /usr/lib/apt/apt-helper \
-o Acquire::https::CaInfo="$trusted_ca" \
-o Acquire::https::Verify-Peer=true -o Acquire::https::Verify-Host=true \
-o Acquire::AllowInsecureRepositories=false -o APT::Get::AllowUnauthenticated=false \
-o Acquire::ForceHash=sha256 -o Acquire::Retries=2 \
-o Acquire::https::Timeout=30 -o Acquire::http::Timeout=30 \
download-file "$origin/$pool" "$tmp/download/recovered.deb" "SHA256:$digest" \
>"$tmp/pool.log" 2>&1; then
recovered=1; break
fi
if ! grep -Eq '404|50[0234]|timed out|Could not (connect|resolve)|Temporary failure resolving' "$tmp/pool.log" ||
grep -Eiq 'NO_PUBKEY|BADSIG|EXPKEYSIG|signature|Hash (Sum )?mismatch|certificate verification|certificate.*(failed|invalid)' "$tmp/pool.log"; then
cat "$tmp/pool.log" >&2; exit 1
fi
done
test "$recovered" -eq 1 || { cat "$tmp/pool.log" >&2; exit 1; }
printf 'OFFICIAL_SECURITY_PAYLOAD_RECOVERED package=%s version=%s sha256=%s\n' "$package" "$version" "$digest"
fi
set -- "$tmp/download/"*.deb
test "$#" -eq 1
test -f "$1"
Expand Down