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
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "UOR PrismPM SDK",
"image": "ghcr.io/uor-foundation/prismpm-sdk-candidate@sha256:cd3b47d7a370c4a26b8285f5e9c3bb15e639973c55505c3809ddbe55352fea58",
"image": "ghcr.io/afflom/prismpm-sdk-patched@sha256:3dfa5f7284ace57c08bfe8d2effe2e08ab41da1a53f5820d48cccd498bd528c3",
"containerUser": "root",
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind",
"workspaceFolder": "${localWorkspaceFolder}",
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ jobs:
with:
path: .prism-proof
key: prism-proof-${{ runner.os }}-${{ runner.arch }}-sdk-${{ steps.proof-inputs.outputs.sdk }}-lean-${{ steps.proof-inputs.outputs.lean }}-${{ hashFiles('app/**', 'prismpm.lock', 'Justfile', 'rust-toolchain.toml') }}

- name: Reserve disk for the locked SDK
shell: bash
run: |
set -euo pipefail
if [[ ${RUNNER_ENVIRONMENT:-} == github-hosted && ${RUNNER_OS:-} == Linux ]]; then
sudo rm -rf -- /usr/local/lib/android /usr/share/dotnet /opt/ghc /opt/hostedtoolcache/CodeQL
fi
df -h / /var/lib/docker
- name: Run the template gate through the locked SDK
shell: bash
# A ref is passed through the environment, never spliced into the script.
Expand All @@ -72,7 +81,12 @@ jobs:
exit 64
fi
docker_config=$(mktemp -d)
trap 'rm -rf "$docker_config"' EXIT
# The SDK's /tmp is a private directory on the runner's own disk, so the
# build's scratch space is bounded by the disk the runner has, not by a
# fixed size; it is removed with the credentials when the step ends.
scratch=$(mktemp -d)
mkdir -p "$scratch/prismpm-home/.docker"
trap 'rm -rf "$docker_config" "$scratch"' EXIT
if test -f "$HOME/.docker/config.json"; then
cp "$HOME/.docker/config.json" "$docker_config/config.json"
else
Expand All @@ -81,7 +95,7 @@ jobs:
docker run --rm \
--user "$(id -u):$(id -g)" \
--group-add "$(stat -c '%g' /var/run/docker.sock)" \
--tmpfs /tmp:rw,exec,nosuid,size=2g \
--volume "$scratch:/tmp" \
--volume "$PWD:$PWD" \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "$docker_config:/tmp/prismpm-home/.docker:ro" \
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,17 @@ jobs:
exit 64
fi
docker_config=$(mktemp -d)
trap 'rm -rf "$docker_config"' EXIT
# The SDK's /tmp is a private directory on the runner's own disk, as
# bootstrap.yml has it since template 1cb0d36: the patched SDK's build
# outgrows a fixed 2 GiB tmpfs.
scratch=$(mktemp -d)
mkdir -p "$scratch/prismpm-home/.docker"
trap 'rm -rf "$docker_config" "$scratch"' EXIT
printf '{}\n' >"$docker_config/config.json"
docker run --rm \
--user "$(id -u):$(id -g)" \
--group-add "$(stat -c '%g' /var/run/docker.sock)" \
--tmpfs /tmp:rw,exec,nosuid,size=2g \
--volume "$scratch:/tmp" \
--volume "$PWD:$PWD" \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "$docker_config:/tmp/prismpm-home/.docker:ro" \
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ jobs:
exit 64
fi
docker_config=$(mktemp -d)
trap 'rm -rf "$docker_config"' EXIT
# The SDK's /tmp is a private directory on the runner's own disk, as
# bootstrap.yml has it since template 1cb0d36: the patched SDK's build
# outgrows a fixed 2 GiB tmpfs.
scratch=$(mktemp -d)
mkdir -p "$scratch/prismpm-home/.docker"
trap 'rm -rf "$docker_config" "$scratch"' EXIT
printf '{}\n' >"$docker_config/config.json"
docker run --rm \
--user "$(id -u):$(id -g)" \
--group-add "$(stat -c '%g' /var/run/docker.sock)" \
--tmpfs /tmp:rw,exec,nosuid,size=2g \
--volume "$scratch:/tmp" \
--volume "$PWD:$PWD" \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "$docker_config:/tmp/prismpm-home/.docker:ro" \
Expand Down
2 changes: 1 addition & 1 deletion app/lexlean.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spec = "lexlean/lock/2"
language = "1.2"
compiler_semantics = "5262e5b4c8b5668ae7066ad686757a6bb7f80c941d515fb9d586894fbc7de69a"
compiler_semantics = "1427f8b629013648a480454d67202788f2303f5396f1d7c70a7c350ddab6f694"
project_config_sha256 = "88b2367c9ee1822d6685b39e16d9c295f6a3b41afebd30b854e25420f950c286"
lean_toolchain = "leanprover/lean4:v4.32.1"

Expand Down
2 changes: 1 addition & 1 deletion prismpm.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion template.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"contract_digest":"sha256:67a3292cfe6e6400bc18718b6a62e8741dec8d6d6b062cb0e4077fc8d9b616f5","policy_files":[{"path":".devcontainer/devcontainer.json","sha256":"sha256:82c0f73c0a0cbe2e59772d4531551531b95f49687ff8140b66cb47de56965c3c"},{"path":".github/workflows/bootstrap.yml","sha256":"sha256:9d2bdd7a0a0260f74ce80ab965e05f7304f88b03d90b8f24dca5eda4d2283c03"},{"path":"AGENTS.md","sha256":"sha256:9a1fe3f73ab2963812c35976909c331292e1ca39ce47c0711ec1aafe8b869d87"},{"path":"VERIFICATION.md","sha256":"sha256:0912821fea354276fff5faa2b6b6ded0cdf4ef86112ad035b41a0a7a0513bd21"},{"path":"prismpm.lock","sha256":"sha256:3773d32926962ef5d2556b74e0df9b34bdaf72353022f3256ebaa04a4ba8db7f"},{"path":"template-contract.json","sha256":"sha256:67a3292cfe6e6400bc18718b6a62e8741dec8d6d6b062cb0e4077fc8d9b616f5"}],"policy_tree_sha256":"sha256:d7d7ed87a271f835b5e23f98870c0cb3c8726ee0406f3bb97125ffda49030c4c","schema":"uor/template-lock/1","sdk_image":"ghcr.io/uor-foundation/prismpm-sdk-candidate@sha256:cd3b47d7a370c4a26b8285f5e9c3bb15e639973c55505c3809ddbe55352fea58","template_repository":"https://github.com/UOR-Foundation/template","template_revision":"582ddc244563b0736aa22dcae4ff134bcaf1f1d3"}
{"contract_digest":"sha256:67a3292cfe6e6400bc18718b6a62e8741dec8d6d6b062cb0e4077fc8d9b616f5","policy_files":[{"path":".devcontainer/devcontainer.json","sha256":"sha256:77df0fd0a87ace0f9f71959055ffd05c14bcd3758f96c5ecf9d70ee6f376bf8f"},{"path":".github/workflows/bootstrap.yml","sha256":"sha256:197117436eb1d32a8d205e5897c50c92bed048bd47d8110a585c0e75c659757c"},{"path":"AGENTS.md","sha256":"sha256:9a1fe3f73ab2963812c35976909c331292e1ca39ce47c0711ec1aafe8b869d87"},{"path":"VERIFICATION.md","sha256":"sha256:0912821fea354276fff5faa2b6b6ded0cdf4ef86112ad035b41a0a7a0513bd21"},{"path":"prismpm.lock","sha256":"sha256:3dbd6a1bcb6f145f35f61e5e265495a1a6c9e071f4b2c6c89ae68f35eb600c02"},{"path":"template-contract.json","sha256":"sha256:67a3292cfe6e6400bc18718b6a62e8741dec8d6d6b062cb0e4077fc8d9b616f5"}],"policy_tree_sha256":"sha256:89db2bd9c079784e62dbb14dea622e7709b70e65fa86efec5b12a5d283b84075","schema":"uor/template-lock/1","sdk_image":"ghcr.io/afflom/prismpm-sdk-patched@sha256:3dfa5f7284ace57c08bfe8d2effe2e08ab41da1a53f5820d48cccd498bd528c3","template_repository":"https://github.com/UOR-Foundation/template","template_revision":"1cb0d36deded599eabea54d2ced0a188b753d506"}
33 changes: 30 additions & 3 deletions xtask/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ fn content_matches(bytes: &[u8], expected: &str) -> bool {
sha256(bytes) == expected
}

fn private_scratch(bootstrap: &str) -> bool {
let lines: Vec<_> = bootstrap.lines().map(str::trim).collect();
let tmp_mounts: Vec<_> = lines
.iter()
.copied()
.filter(|line| line.starts_with("--tmpfs /tmp") || line.contains(":/tmp\""))
.collect();
lines.contains(&"scratch=$(mktemp -d)")
&& lines.contains(&"trap 'rm -rf \"$docker_config\" \"$scratch\"' EXIT")
&& tmp_mounts == [r#"--volume "$scratch:/tmp" \"#]
}

fn docker_credentials_are_confined(devcontainer: &str, bootstrap: &str) -> bool {
let lines: Vec<_> = bootstrap.lines().map(str::trim).collect();
let buildx_config: Vec<_> = lines
Expand Down Expand Up @@ -103,7 +115,7 @@ fn docker_credentials_are_confined(devcontainer: &str, bootstrap: &str) -> bool
&& bootstrap.contains("--volume \"$docker_config:/tmp/prismpm-home/.docker:ro\"")
&& !bootstrap.contains("--volume \"$HOME/.docker:/tmp/prismpm-home/.docker:ro\"")
&& buildx_config == [r"--env BUILDX_CONFIG=/tmp/prismpm-buildx \"]
&& bootstrap.contains("--tmpfs /tmp:rw,exec,nosuid,size=2g")
&& private_scratch(bootstrap)
&& private_umask
}

Expand Down Expand Up @@ -1169,8 +1181,10 @@ mod tests {
"mounts":["source=${localEnv:HOME}/.docker/config.json,target=/home/vscode/.docker/config.json,type=bind,readonly"]
}"#;
let bootstrap = r#"--volume "$docker_config:/tmp/prismpm-home/.docker:ro"
scratch=$(mktemp -d)
trap 'rm -rf "$docker_config" "$scratch"' EXIT
--env BUILDX_CONFIG=/tmp/prismpm-buildx \
--tmpfs /tmp:rw,exec,nosuid,size=2g
--volume "$scratch:/tmp" \
"$image" bash -c '
umask 077
docker buildx version
Expand Down Expand Up @@ -1219,7 +1233,20 @@ docker buildx version
"--env BUILDX_CONFIG=/tmp/prismpm-buildx",
"--env BUILDX_CONFIG=/tmp/prismpm-home/buildx",
),
bootstrap.replace("--tmpfs /tmp:rw,exec,nosuid,size=2g", ""),
bootstrap.replace("--volume \"$scratch:/tmp\" \\\n", ""),
bootstrap.replace(
"--volume \"$scratch:/tmp\"",
"--tmpfs /tmp:rw,exec,nosuid,size=2g",
),
bootstrap.replace(
"--volume \"$scratch:/tmp\" \\\n",
"--volume \"$scratch:/tmp\" \\\n--tmpfs /tmp:rw,exec,nosuid,size=2g \\\n",
),
bootstrap.replace("scratch=$(mktemp -d)", "scratch=/tmp/shared"),
bootstrap.replace(
"trap 'rm -rf \"$docker_config\" \"$scratch\"' EXIT",
"trap 'rm -rf \"$docker_config\"' EXIT",
),
bootstrap.replace("umask 077", "umask 022"),
format!("{bootstrap}\n--env BUILDX_CONFIG=/tmp/other \\\n"),
] {
Expand Down
48 changes: 45 additions & 3 deletions xtask/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ fn workspace_paths(lexlean: &Value) -> Result<Vec<String>, String> {
.collect()
}

/// The digest the manifest binds for the acceptance document. PrismPM 0.4.0
/// keeps `browser_timing`, a per-run measurement, out of it: the manifest
/// hashes the canonical JSON of the acceptance without that field (sorted
/// keys, no whitespace), so two runs of one build share an attestation ID.
fn acceptance_digest(acceptance: &Value) -> Result<String, String> {
let mut comparable = acceptance.clone();
if let Some(object) = comparable.as_object_mut() {
object.remove("browser_timing");
}
serde_json::to_vec(&comparable)
.map(|bytes| hex(&bytes))
.map_err(|error| format!("application-acceptance.json: {error}"))
}

/// The whole read-time check. Pure, so each planted defect is a unit test.
fn binds(kept: &Kept, observed: &Observed) -> Result<(), String> {
if !is_id(&kept.attestation) {
Expand Down Expand Up @@ -131,10 +145,14 @@ fn binds(kept: &Kept, observed: &Observed) -> Result<(), String> {
text(&manifest, "/lexlean_attestation_sha256")?,
&hex(&kept.lexlean),
)?;
// PrismPM's own verifier reads the acceptance only in canonical framing.
if serde_json::to_vec(&acceptance).ok().as_deref() != Some(kept.acceptance.as_slice()) {
return Err("the application acceptance is not canonical JSON".into());
}
same(
"the application acceptance",
text(&manifest, "/acceptance_sha256")?,
&hex(&kept.acceptance),
&acceptance_digest(&acceptance)?,
)?;
same("the LexLean status", text(&lexlean, "/status")?, "verified")?;
same(
Expand Down Expand Up @@ -343,7 +361,7 @@ pub fn keep(root: &Path, attestation: &str) -> Result<(), Fail> {

#[cfg(test)]
mod tests {
use super::{binds, hex, Kept, Observed};
use super::{acceptance_digest, binds, hex, Kept, Observed};
use serde_json::json;

const LEAN: &str = "e8baaa71855a616dc351028f3ad2200051b0671f423a1696a100e809302d5550";
Expand Down Expand Up @@ -389,7 +407,7 @@ mod tests {
let lexlean = serde_json::to_vec(&proof.lexlean).unwrap();
let acceptance = serde_json::to_vec(&proof.acceptance).unwrap();
let manifest = serde_json::to_vec(&json!({
"acceptance_sha256": hex(&acceptance),
"acceptance_sha256": acceptance_digest(&proof.acceptance).unwrap(),
"build_id": "2".repeat(64),
"lexlean_attestation_sha256": hex(&lexlean),
"schema": "prismpm/application-verification-manifest/2"
Expand Down Expand Up @@ -422,6 +440,30 @@ mod tests {
assert_eq!(binds(&seal(&proof()), &observed()), Ok(()));
}

/// PrismPM 0.4.0 publishes per-run `browser_timing` in the acceptance and
/// leaves it out of the manifest's digest: such a proof still reads back,
/// and any other change to the acceptance still does not.
#[test]
fn browser_timing_is_outside_the_acceptance_digest() {
let mut timed = proof();
timed.acceptance["browser_timing"] = json!({"engine": "chromium", "vectors": []});
let kept = seal(&timed);
assert_ne!(
hex(&kept.acceptance),
acceptance_digest(&timed.acceptance).unwrap()
);
assert_eq!(binds(&kept, &observed()), Ok(()));

let mut changed = seal(&timed);
let mut acceptance: serde_json::Value =
serde_json::from_slice(&changed.acceptance).unwrap();
acceptance["build_id"] = json!("3".repeat(64));
changed.acceptance = serde_json::to_vec(&acceptance).unwrap();
assert!(binds(&changed, &observed())
.unwrap_err()
.starts_with("the application acceptance differs"));
}

#[test]
fn a_kept_proof_that_does_not_bind_these_inputs_is_proved_again() {
let mut plants: Vec<(&str, Kept, Observed)> = Vec::new();
Expand Down
Loading