Repository files navigation

🐚 stage2 — the Lock.Boot loader

Part of Lock.Boot. The preferred stage2 layering in the chain (stage0 → stage1 → stage2) — replaceable, like any lockboot stage, with your own. It is a payload-agnostic loader, not a container runtime: it takes any container image, seals it into a measured, TPM-bound, integrity-checked form, and boots it. "Run this Docker container under Lock.Boot."

By the time this runs, the layers below have admitted and verified it (sha256/ed25519, PCR 14). Trust and verification are not this layer's concern — it consumes an already-trusted payload.

The idea

A small, low-churn loader binary (bootstrap, static-musl, PID 1) with a container image appended to it as a self-extracting zip. The workload never touches the loader — you swap the appended image freely without recompiling the (audited, reproducible) loader. stage1 measures the whole loader+image into PCR 14, so the image identity is attested for free. Deployment is just packaging: docker export → mkfs.erofs → veritysetup → zip → append to the loader ELF.

Using it

Build the loader and the packaging image once:

make build-x86_64 docker-build-erofs
# build-x86_64 -> target/x86_64-unknown-linux-musl/release/bootstrap (the loader ELF)# docker-build-erofs -> lockboot:erofs-builder (a one-shot CLI; mkruntime.sh is its entrypoint)

The image is the tool. Mount just the loader ELF, pipe any container rootfs in on stdin, and the bootable stage2 comes out on stdout — no repo bind-mount, no host filesystem tools:

docker export"$(docker create --rm myimage)" \
| docker run --rm -i \
-v "$PWD/target/x86_64-unknown-linux-musl/release/bootstrap:/bootstrap:ro" \
lockboot:erofs-builder --bootstrap /bootstrap - - > stage2

The rootfs argument (- above) can instead be a .tar, a directory, or a single binary (installed as /init); the output (-) can be a path. docker run --rm lockboot:erofs-builder --help lists the env knobs (DATA_SIZE_MB, ROOTFS_UUID, VERITY_SALT, SOURCE_DATE_EPOCH), all reproducible by default. Serve the resulting stage2 as your payload; stage0/stage1 admit it by sha256/ed25519.

Technical details

How it boots (loader = PID 1)

  1. Read its own payload from /proc/self/exe (a memfd) — the appended zip carries rootfs.erofs (+ its dm-verity hash tree), a deterministic empty data-base.img, and verity.json.
  2. Bind the config: hash the verbatim stdin JSON into PCR 15, then rewind fd 0 so the workload reads the exact same bytes.
  3. Derive keys from the TPM, bound to the boot-chain PCRs (see below).
  4. Runtime (p2) — flush the erofs to the partition only if it doesn't already verify, then dm-verity-mount it read-only.
  5. Root — assemble an overlay: the verity'd erofs as the immutable lower, a tmpfs upper. The merged / is therefore pure verity'd erofs at every boot — runtime writes hit RAM and can never persist to shadow the measured code.
  6. Data (p3) — bring up /data: dm-cryptaes-xts-plain64 (AES-256-XTS), grown online to fill the disk. Confidential; the TPM-derived key binds it to the boot chain.
  7. Attest — copy stage1's attestation and drop stage2's alongside it in an ephemeral /run/lockboot/.
  8. switch_root onto the overlay and exec /init — the image's own entrypoint, handed the verbatim config on stdin. Transparent: stage2 imposes no config schema of its own.

Security model

LayerMechanismGuarantee
Code / rootfserofs + dm-verity, measured into PCR 14, under an ephemeral overlayImmutable, integrity-verified, re-attestable each boot — no persistent code modification
Configverbatim stdin JSON → hashed → PCR 15Disk key bound to config; any change ⇒ fresh disk (fail-closed)
Data/data: dm-crypt aes-xts-plain64 (AES-256-XTS)Confidential (confidentiality-only): at-rest tamper garbles rather than being cryptographically detected — media integrity is left to the storage layer (EBS et al.)
KeysTPM-derived under a PolicyPCR session over a curated PCR setNo LUKS/header; drift in bound PCRs (code/config/firmware) ⇒ superblock decrypts to garbage ⇒ re-initialized (fail-closed)

See PCR-BINDING.md for the bound PCR set, the {5,10} exclusions, and the IMA analysis.

Building & testing

Everything builds inside the shared lockboot:build image (no host toolchain); the runtime image is forged in the build-time-only lockboot:erofs-builder — none of those tools ship to the instance. Reproducible: the loader ELF and the payload zip are each byte-deterministic.

make lock # generate Cargo.lock (first time)
make check test# cargo check + test the workspace
make ci # fmt + clippy + test (the CI gate)
make pack-x86_64 # pack the bundled example -> build/x86_64/pack/stage2
make test-pivot-x86_64 # boot a packed stage2 under the QEMU/swtpm harness

unzip -l build/<arch>/pack/stage2 inspects a packed payload.

Crates

  • bootstrap — the loader: read the appended payload, bring up persistence, pivot onto the overlay root, exec /init.
  • payload — the minimal appended-zip reader (self-extracting; reads /proc/self/exe).
  • blockdev — raw device-mapper ioctls (no libdevmapper): dm-verity, dm-crypt (XTS), byte-stable GPT grow/discovery, ext4 online grow.
  • tpm-derive — deterministic PCR-bound key derivation (pure-Rust TPM2).

License

Apache-2.0 OR MIT, at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

🐚 stage2 — the Lock.Boot loader

Part of Lock.Boot. The preferred stage2 layering in the chain (stage0 → stage1 → stage2) — replaceable, like any lockboot stage, with your own. It is a payload-agnostic loader, not a container runtime: it takes any container image, seals it into a measured, TPM-bound, integrity-checked form, and boots it. "Run this Docker container under Lock.Boot."

By the time this runs, the layers below have admitted and verified it (sha256/ed25519, PCR 14). Trust and verification are not this layer's concern — it consumes an already-trusted payload.

The idea

A small, low-churn loader binary (bootstrap, static-musl, PID 1) with a container image appended to it as a self-extracting zip. The workload never touches the loader — you swap the appended image freely without recompiling the (audited, reproducible) loader. stage1 measures the whole loader+image into PCR 14, so the image identity is attested for free. Deployment is just packaging: docker export → mkfs.erofs → veritysetup → zip → append to the loader ELF.

Using it

Build the loader and the packaging image once:

make build-x86_64 docker-build-erofs
# build-x86_64 -> target/x86_64-unknown-linux-musl/release/bootstrap (the loader ELF)# docker-build-erofs -> lockboot:erofs-builder (a one-shot CLI; mkruntime.sh is its entrypoint)

The image is the tool. Mount just the loader ELF, pipe any container rootfs in on stdin, and the bootable stage2 comes out on stdout — no repo bind-mount, no host filesystem tools:

docker export"$(docker create --rm myimage)" \
| docker run --rm -i \
-v "$PWD/target/x86_64-unknown-linux-musl/release/bootstrap:/bootstrap:ro" \
lockboot:erofs-builder --bootstrap /bootstrap - - > stage2

The rootfs argument (- above) can instead be a .tar, a directory, or a single binary (installed as /init); the output (-) can be a path. docker run --rm lockboot:erofs-builder --help lists the env knobs (DATA_SIZE_MB, ROOTFS_UUID, VERITY_SALT, SOURCE_DATE_EPOCH), all reproducible by default. Serve the resulting stage2 as your payload; stage0/stage1 admit it by sha256/ed25519.

Technical details

How it boots (loader = PID 1)

  1. Read its own payload from /proc/self/exe (a memfd) — the appended zip carries rootfs.erofs (+ its dm-verity hash tree), a deterministic empty data-base.img, and verity.json.
  2. Bind the config: hash the verbatim stdin JSON into PCR 15, then rewind fd 0 so the workload reads the exact same bytes.
  3. Derive keys from the TPM, bound to the boot-chain PCRs (see below).
  4. Runtime (p2) — flush the erofs to the partition only if it doesn't already verify, then dm-verity-mount it read-only.
  5. Root — assemble an overlay: the verity'd erofs as the immutable lower, a tmpfs upper. The merged / is therefore pure verity'd erofs at every boot — runtime writes hit RAM and can never persist to shadow the measured code.
  6. Data (p3) — bring up /data: dm-cryptaes-xts-plain64 (AES-256-XTS), grown online to fill the disk. Confidential; the TPM-derived key binds it to the boot chain.
  7. Attest — copy stage1's attestation and drop stage2's alongside it in an ephemeral /run/lockboot/.
  8. switch_root onto the overlay and exec /init — the image's own entrypoint, handed the verbatim config on stdin. Transparent: stage2 imposes no config schema of its own.

Security model

LayerMechanismGuarantee
Code / rootfserofs + dm-verity, measured into PCR 14, under an ephemeral overlayImmutable, integrity-verified, re-attestable each boot — no persistent code modification
Configverbatim stdin JSON → hashed → PCR 15Disk key bound to config; any change ⇒ fresh disk (fail-closed)
Data/data: dm-crypt aes-xts-plain64 (AES-256-XTS)Confidential (confidentiality-only): at-rest tamper garbles rather than being cryptographically detected — media integrity is left to the storage layer (EBS et al.)
KeysTPM-derived under a PolicyPCR session over a curated PCR setNo LUKS/header; drift in bound PCRs (code/config/firmware) ⇒ superblock decrypts to garbage ⇒ re-initialized (fail-closed)

See PCR-BINDING.md for the bound PCR set, the {5,10} exclusions, and the IMA analysis.

Building & testing

Everything builds inside the shared lockboot:build image (no host toolchain); the runtime image is forged in the build-time-only lockboot:erofs-builder — none of those tools ship to the instance. Reproducible: the loader ELF and the payload zip are each byte-deterministic.

make lock # generate Cargo.lock (first time)
make check test# cargo check + test the workspace
make ci # fmt + clippy + test (the CI gate)
make pack-x86_64 # pack the bundled example -> build/x86_64/pack/stage2
make test-pivot-x86_64 # boot a packed stage2 under the QEMU/swtpm harness

unzip -l build/<arch>/pack/stage2 inspects a packed payload.

Crates

  • bootstrap — the loader: read the appended payload, bring up persistence, pivot onto the overlay root, exec /init.
  • payload — the minimal appended-zip reader (self-extracting; reads /proc/self/exe).
  • blockdev — raw device-mapper ioctls (no libdevmapper): dm-verity, dm-crypt (XTS), byte-stable GPT grow/discovery, ext4 online grow.
  • tpm-derive — deterministic PCR-bound key derivation (pure-Rust TPM2).

License

Apache-2.0 OR MIT, at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

🐚 stage2 — the Lock.Boot loader

Part of Lock.Boot. The preferred stage2 layering in the chain (stage0 → stage1 → stage2) — replaceable, like any lockboot stage, with your own. It is a payload-agnostic loader, not a container runtime: it takes any container image, seals it into a measured, TPM-bound, integrity-checked form, and boots it. "Run this Docker container under Lock.Boot."

By the time this runs, the layers below have admitted and verified it (sha256/ed25519, PCR 14). Trust and verification are not this layer's concern — it consumes an already-trusted payload.

The idea

A small, low-churn loader binary (bootstrap, static-musl, PID 1) with a container image appended to it as a self-extracting zip. The workload never touches the loader — you swap the appended image freely without recompiling the (audited, reproducible) loader. stage1 measures the whole loader+image into PCR 14, so the image identity is attested for free. Deployment is just packaging: docker export → mkfs.erofs → veritysetup → zip → append to the loader ELF.

Using it

Build the loader and the packaging image once:

make build-x86_64 docker-build-erofs
# build-x86_64 -> target/x86_64-unknown-linux-musl/release/bootstrap (the loader ELF)# docker-build-erofs -> lockboot:erofs-builder (a one-shot CLI; mkruntime.sh is its entrypoint)

The image is the tool. Mount just the loader ELF, pipe any container rootfs in on stdin, and the bootable stage2 comes out on stdout — no repo bind-mount, no host filesystem tools:

docker export"$(docker create --rm myimage)" \
| docker run --rm -i \
-v "$PWD/target/x86_64-unknown-linux-musl/release/bootstrap:/bootstrap:ro" \
lockboot:erofs-builder --bootstrap /bootstrap - - > stage2

The rootfs argument (- above) can instead be a .tar, a directory, or a single binary (installed as /init); the output (-) can be a path. docker run --rm lockboot:erofs-builder --help lists the env knobs (DATA_SIZE_MB, ROOTFS_UUID, VERITY_SALT, SOURCE_DATE_EPOCH), all reproducible by default. Serve the resulting stage2 as your payload; stage0/stage1 admit it by sha256/ed25519.

Technical details

How it boots (loader = PID 1)

  1. Read its own payload from /proc/self/exe (a memfd) — the appended zip carries rootfs.erofs (+ its dm-verity hash tree), a deterministic empty data-base.img, and verity.json.
  2. Bind the config: hash the verbatim stdin JSON into PCR 15, then rewind fd 0 so the workload reads the exact same bytes.
  3. Derive keys from the TPM, bound to the boot-chain PCRs (see below).
  4. Runtime (p2) — flush the erofs to the partition only if it doesn't already verify, then dm-verity-mount it read-only.
  5. Root — assemble an overlay: the verity'd erofs as the immutable lower, a tmpfs upper. The merged / is therefore pure verity'd erofs at every boot — runtime writes hit RAM and can never persist to shadow the measured code.
  6. Data (p3) — bring up /data: dm-cryptaes-xts-plain64 (AES-256-XTS), grown online to fill the disk. Confidential; the TPM-derived key binds it to the boot chain.
  7. Attest — copy stage1's attestation and drop stage2's alongside it in an ephemeral /run/lockboot/.
  8. switch_root onto the overlay and exec /init — the image's own entrypoint, handed the verbatim config on stdin. Transparent: stage2 imposes no config schema of its own.

Security model

LayerMechanismGuarantee
Code / rootfserofs + dm-verity, measured into PCR 14, under an ephemeral overlayImmutable, integrity-verified, re-attestable each boot — no persistent code modification
Configverbatim stdin JSON → hashed → PCR 15Disk key bound to config; any change ⇒ fresh disk (fail-closed)
Data/data: dm-crypt aes-xts-plain64 (AES-256-XTS)Confidential (confidentiality-only): at-rest tamper garbles rather than being cryptographically detected — media integrity is left to the storage layer (EBS et al.)
KeysTPM-derived under a PolicyPCR session over a curated PCR setNo LUKS/header; drift in bound PCRs (code/config/firmware) ⇒ superblock decrypts to garbage ⇒ re-initialized (fail-closed)

See PCR-BINDING.md for the bound PCR set, the {5,10} exclusions, and the IMA analysis.

Building & testing

Everything builds inside the shared lockboot:build image (no host toolchain); the runtime image is forged in the build-time-only lockboot:erofs-builder — none of those tools ship to the instance. Reproducible: the loader ELF and the payload zip are each byte-deterministic.

make lock # generate Cargo.lock (first time)
make check test# cargo check + test the workspace
make ci # fmt + clippy + test (the CI gate)
make pack-x86_64 # pack the bundled example -> build/x86_64/pack/stage2
make test-pivot-x86_64 # boot a packed stage2 under the QEMU/swtpm harness

unzip -l build/<arch>/pack/stage2 inspects a packed payload.

Crates

  • bootstrap — the loader: read the appended payload, bring up persistence, pivot onto the overlay root, exec /init.
  • payload — the minimal appended-zip reader (self-extracting; reads /proc/self/exe).
  • blockdev — raw device-mapper ioctls (no libdevmapper): dm-verity, dm-crypt (XTS), byte-stable GPT grow/discovery, ext4 online grow.
  • tpm-derive — deterministic PCR-bound key derivation (pure-Rust TPM2).

License

Apache-2.0 OR MIT, at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

🐚 stage2 — the Lock.Boot loader

Part of Lock.Boot. The preferred stage2 layering in the chain (stage0 → stage1 → stage2) — replaceable, like any lockboot stage, with your own. It is a payload-agnostic loader, not a container runtime: it takes any container image, seals it into a measured, TPM-bound, integrity-checked form, and boots it. "Run this Docker container under Lock.Boot."

By the time this runs, the layers below have admitted and verified it (sha256/ed25519, PCR 14). Trust and verification are not this layer's concern — it consumes an already-trusted payload.

The idea

A small, low-churn loader binary (bootstrap, static-musl, PID 1) with a container image appended to it as a self-extracting zip. The workload never touches the loader — you swap the appended image freely without recompiling the (audited, reproducible) loader. stage1 measures the whole loader+image into PCR 14, so the image identity is attested for free. Deployment is just packaging: docker export → mkfs.erofs → veritysetup → zip → append to the loader ELF.

Using it

Build the loader and the packaging image once:

make build-x86_64 docker-build-erofs
# build-x86_64 -> target/x86_64-unknown-linux-musl/release/bootstrap (the loader ELF)# docker-build-erofs -> lockboot:erofs-builder (a one-shot CLI; mkruntime.sh is its entrypoint)

The image is the tool. Mount just the loader ELF, pipe any container rootfs in on stdin, and the bootable stage2 comes out on stdout — no repo bind-mount, no host filesystem tools:

docker export"$(docker create --rm myimage)" \
| docker run --rm -i \
-v "$PWD/target/x86_64-unknown-linux-musl/release/bootstrap:/bootstrap:ro" \
lockboot:erofs-builder --bootstrap /bootstrap - - > stage2

The rootfs argument (- above) can instead be a .tar, a directory, or a single binary (installed as /init); the output (-) can be a path. docker run --rm lockboot:erofs-builder --help lists the env knobs (DATA_SIZE_MB, ROOTFS_UUID, VERITY_SALT, SOURCE_DATE_EPOCH), all reproducible by default. Serve the resulting stage2 as your payload; stage0/stage1 admit it by sha256/ed25519.

Technical details

How it boots (loader = PID 1)

  1. Read its own payload from /proc/self/exe (a memfd) — the appended zip carries rootfs.erofs (+ its dm-verity hash tree), a deterministic empty data-base.img, and verity.json.
  2. Bind the config: hash the verbatim stdin JSON into PCR 15, then rewind fd 0 so the workload reads the exact same bytes.
  3. Derive keys from the TPM, bound to the boot-chain PCRs (see below).
  4. Runtime (p2) — flush the erofs to the partition only if it doesn't already verify, then dm-verity-mount it read-only.
  5. Root — assemble an overlay: the verity'd erofs as the immutable lower, a tmpfs upper. The merged / is therefore pure verity'd erofs at every boot — runtime writes hit RAM and can never persist to shadow the measured code.
  6. Data (p3) — bring up /data: dm-cryptaes-xts-plain64 (AES-256-XTS), grown online to fill the disk. Confidential; the TPM-derived key binds it to the boot chain.
  7. Attest — copy stage1's attestation and drop stage2's alongside it in an ephemeral /run/lockboot/.
  8. switch_root onto the overlay and exec /init — the image's own entrypoint, handed the verbatim config on stdin. Transparent: stage2 imposes no config schema of its own.

Security model

LayerMechanismGuarantee
Code / rootfserofs + dm-verity, measured into PCR 14, under an ephemeral overlayImmutable, integrity-verified, re-attestable each boot — no persistent code modification
Configverbatim stdin JSON → hashed → PCR 15Disk key bound to config; any change ⇒ fresh disk (fail-closed)
Data/data: dm-crypt aes-xts-plain64 (AES-256-XTS)Confidential (confidentiality-only): at-rest tamper garbles rather than being cryptographically detected — media integrity is left to the storage layer (EBS et al.)
KeysTPM-derived under a PolicyPCR session over a curated PCR setNo LUKS/header; drift in bound PCRs (code/config/firmware) ⇒ superblock decrypts to garbage ⇒ re-initialized (fail-closed)

See PCR-BINDING.md for the bound PCR set, the {5,10} exclusions, and the IMA analysis.

Building & testing

Everything builds inside the shared lockboot:build image (no host toolchain); the runtime image is forged in the build-time-only lockboot:erofs-builder — none of those tools ship to the instance. Reproducible: the loader ELF and the payload zip are each byte-deterministic.

make lock # generate Cargo.lock (first time)
make check test# cargo check + test the workspace
make ci # fmt + clippy + test (the CI gate)
make pack-x86_64 # pack the bundled example -> build/x86_64/pack/stage2
make test-pivot-x86_64 # boot a packed stage2 under the QEMU/swtpm harness

unzip -l build/<arch>/pack/stage2 inspects a packed payload.

Crates

  • bootstrap — the loader: read the appended payload, bring up persistence, pivot onto the overlay root, exec /init.
  • payload — the minimal appended-zip reader (self-extracting; reads /proc/self/exe).
  • blockdev — raw device-mapper ioctls (no libdevmapper): dm-verity, dm-crypt (XTS), byte-stable GPT grow/discovery, ext4 online grow.
  • tpm-derive — deterministic PCR-bound key derivation (pure-Rust TPM2).

License

Apache-2.0 OR MIT, at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

🐚 stage2 — the Lock.Boot loader

Part of Lock.Boot. The preferred stage2 layering in the chain (stage0 → stage1 → stage2) — replaceable, like any lockboot stage, with your own. It is a payload-agnostic loader, not a container runtime: it takes any container image, seals it into a measured, TPM-bound, integrity-checked form, and boots it. "Run this Docker container under Lock.Boot."

By the time this runs, the layers below have admitted and verified it (sha256/ed25519, PCR 14). Trust and verification are not this layer's concern — it consumes an already-trusted payload.

The idea

A small, low-churn loader binary (bootstrap, static-musl, PID 1) with a container image appended to it as a self-extracting zip. The workload never touches the loader — you swap the appended image freely without recompiling the (audited, reproducible) loader. stage1 measures the whole loader+image into PCR 14, so the image identity is attested for free. Deployment is just packaging: docker export → mkfs.erofs → veritysetup → zip → append to the loader ELF.

Using it

Build the loader and the packaging image once:

make build-x86_64 docker-build-erofs
# build-x86_64 -> target/x86_64-unknown-linux-musl/release/bootstrap (the loader ELF)# docker-build-erofs -> lockboot:erofs-builder (a one-shot CLI; mkruntime.sh is its entrypoint)

The image is the tool. Mount just the loader ELF, pipe any container rootfs in on stdin, and the bootable stage2 comes out on stdout — no repo bind-mount, no host filesystem tools:

docker export"$(docker create --rm myimage)" \
| docker run --rm -i \
-v "$PWD/target/x86_64-unknown-linux-musl/release/bootstrap:/bootstrap:ro" \
lockboot:erofs-builder --bootstrap /bootstrap - - > stage2

The rootfs argument (- above) can instead be a .tar, a directory, or a single binary (installed as /init); the output (-) can be a path. docker run --rm lockboot:erofs-builder --help lists the env knobs (DATA_SIZE_MB, ROOTFS_UUID, VERITY_SALT, SOURCE_DATE_EPOCH), all reproducible by default. Serve the resulting stage2 as your payload; stage0/stage1 admit it by sha256/ed25519.

Technical details

How it boots (loader = PID 1)

  1. Read its own payload from /proc/self/exe (a memfd) — the appended zip carries rootfs.erofs (+ its dm-verity hash tree), a deterministic empty data-base.img, and verity.json.
  2. Bind the config: hash the verbatim stdin JSON into PCR 15, then rewind fd 0 so the workload reads the exact same bytes.
  3. Derive keys from the TPM, bound to the boot-chain PCRs (see below).
  4. Runtime (p2) — flush the erofs to the partition only if it doesn't already verify, then dm-verity-mount it read-only.
  5. Root — assemble an overlay: the verity'd erofs as the immutable lower, a tmpfs upper. The merged / is therefore pure verity'd erofs at every boot — runtime writes hit RAM and can never persist to shadow the measured code.
  6. Data (p3) — bring up /data: dm-cryptaes-xts-plain64 (AES-256-XTS), grown online to fill the disk. Confidential; the TPM-derived key binds it to the boot chain.
  7. Attest — copy stage1's attestation and drop stage2's alongside it in an ephemeral /run/lockboot/.
  8. switch_root onto the overlay and exec /init — the image's own entrypoint, handed the verbatim config on stdin. Transparent: stage2 imposes no config schema of its own.

Security model

LayerMechanismGuarantee
Code / rootfserofs + dm-verity, measured into PCR 14, under an ephemeral overlayImmutable, integrity-verified, re-attestable each boot — no persistent code modification
Configverbatim stdin JSON → hashed → PCR 15Disk key bound to config; any change ⇒ fresh disk (fail-closed)
Data/data: dm-crypt aes-xts-plain64 (AES-256-XTS)Confidential (confidentiality-only): at-rest tamper garbles rather than being cryptographically detected — media integrity is left to the storage layer (EBS et al.)
KeysTPM-derived under a PolicyPCR session over a curated PCR setNo LUKS/header; drift in bound PCRs (code/config/firmware) ⇒ superblock decrypts to garbage ⇒ re-initialized (fail-closed)

See PCR-BINDING.md for the bound PCR set, the {5,10} exclusions, and the IMA analysis.

Building & testing

Everything builds inside the shared lockboot:build image (no host toolchain); the runtime image is forged in the build-time-only lockboot:erofs-builder — none of those tools ship to the instance. Reproducible: the loader ELF and the payload zip are each byte-deterministic.

make lock # generate Cargo.lock (first time)
make check test# cargo check + test the workspace
make ci # fmt + clippy + test (the CI gate)
make pack-x86_64 # pack the bundled example -> build/x86_64/pack/stage2
make test-pivot-x86_64 # boot a packed stage2 under the QEMU/swtpm harness

unzip -l build/<arch>/pack/stage2 inspects a packed payload.

Crates

  • bootstrap — the loader: read the appended payload, bring up persistence, pivot onto the overlay root, exec /init.
  • payload — the minimal appended-zip reader (self-extracting; reads /proc/self/exe).
  • blockdev — raw device-mapper ioctls (no libdevmapper): dm-verity, dm-crypt (XTS), byte-stable GPT grow/discovery, ext4 online grow.
  • tpm-derive — deterministic PCR-bound key derivation (pure-Rust TPM2).

License

Apache-2.0 OR MIT, at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

🐚 stage2 — the Lock.Boot loader

Part of Lock.Boot. The preferred stage2 layering in the chain (stage0 → stage1 → stage2) — replaceable, like any lockboot stage, with your own. It is a payload-agnostic loader, not a container runtime: it takes any container image, seals it into a measured, TPM-bound, integrity-checked form, and boots it. "Run this Docker container under Lock.Boot."

By the time this runs, the layers below have admitted and verified it (sha256/ed25519, PCR 14). Trust and verification are not this layer's concern — it consumes an already-trusted payload.

The idea

A small, low-churn loader binary (bootstrap, static-musl, PID 1) with a container image appended to it as a self-extracting zip. The workload never touches the loader — you swap the appended image freely without recompiling the (audited, reproducible) loader. stage1 measures the whole loader+image into PCR 14, so the image identity is attested for free. Deployment is just packaging: docker export → mkfs.erofs → veritysetup → zip → append to the loader ELF.

Using it

Build the loader and the packaging image once:

make build-x86_64 docker-build-erofs
# build-x86_64 -> target/x86_64-unknown-linux-musl/release/bootstrap (the loader ELF)# docker-build-erofs -> lockboot:erofs-builder (a one-shot CLI; mkruntime.sh is its entrypoint)

The image is the tool. Mount just the loader ELF, pipe any container rootfs in on stdin, and the bootable stage2 comes out on stdout — no repo bind-mount, no host filesystem tools:

docker export"$(docker create --rm myimage)" \
| docker run --rm -i \
-v "$PWD/target/x86_64-unknown-linux-musl/release/bootstrap:/bootstrap:ro" \
lockboot:erofs-builder --bootstrap /bootstrap - - > stage2

The rootfs argument (- above) can instead be a .tar, a directory, or a single binary (installed as /init); the output (-) can be a path. docker run --rm lockboot:erofs-builder --help lists the env knobs (DATA_SIZE_MB, ROOTFS_UUID, VERITY_SALT, SOURCE_DATE_EPOCH), all reproducible by default. Serve the resulting stage2 as your payload; stage0/stage1 admit it by sha256/ed25519.

Technical details

How it boots (loader = PID 1)

  1. Read its own payload from /proc/self/exe (a memfd) — the appended zip carries rootfs.erofs (+ its dm-verity hash tree), a deterministic empty data-base.img, and verity.json.
  2. Bind the config: hash the verbatim stdin JSON into PCR 15, then rewind fd 0 so the workload reads the exact same bytes.
  3. Derive keys from the TPM, bound to the boot-chain PCRs (see below).
  4. Runtime (p2) — flush the erofs to the partition only if it doesn't already verify, then dm-verity-mount it read-only.
  5. Root — assemble an overlay: the verity'd erofs as the immutable lower, a tmpfs upper. The merged / is therefore pure verity'd erofs at every boot — runtime writes hit RAM and can never persist to shadow the measured code.
  6. Data (p3) — bring up /data: dm-cryptaes-xts-plain64 (AES-256-XTS), grown online to fill the disk. Confidential; the TPM-derived key binds it to the boot chain.
  7. Attest — copy stage1's attestation and drop stage2's alongside it in an ephemeral /run/lockboot/.
  8. switch_root onto the overlay and exec /init — the image's own entrypoint, handed the verbatim config on stdin. Transparent: stage2 imposes no config schema of its own.

Security model

LayerMechanismGuarantee
Code / rootfserofs + dm-verity, measured into PCR 14, under an ephemeral overlayImmutable, integrity-verified, re-attestable each boot — no persistent code modification
Configverbatim stdin JSON → hashed → PCR 15Disk key bound to config; any change ⇒ fresh disk (fail-closed)
Data/data: dm-crypt aes-xts-plain64 (AES-256-XTS)Confidential (confidentiality-only): at-rest tamper garbles rather than being cryptographically detected — media integrity is left to the storage layer (EBS et al.)
KeysTPM-derived under a PolicyPCR session over a curated PCR setNo LUKS/header; drift in bound PCRs (code/config/firmware) ⇒ superblock decrypts to garbage ⇒ re-initialized (fail-closed)

See PCR-BINDING.md for the bound PCR set, the {5,10} exclusions, and the IMA analysis.

Building & testing

Everything builds inside the shared lockboot:build image (no host toolchain); the runtime image is forged in the build-time-only lockboot:erofs-builder — none of those tools ship to the instance. Reproducible: the loader ELF and the payload zip are each byte-deterministic.

make lock # generate Cargo.lock (first time)
make check test# cargo check + test the workspace
make ci # fmt + clippy + test (the CI gate)
make pack-x86_64 # pack the bundled example -> build/x86_64/pack/stage2
make test-pivot-x86_64 # boot a packed stage2 under the QEMU/swtpm harness

unzip -l build/<arch>/pack/stage2 inspects a packed payload.

Crates

  • bootstrap — the loader: read the appended payload, bring up persistence, pivot onto the overlay root, exec /init.
  • payload — the minimal appended-zip reader (self-extracting; reads /proc/self/exe).
  • blockdev — raw device-mapper ioctls (no libdevmapper): dm-verity, dm-crypt (XTS), byte-stable GPT grow/discovery, ext4 online grow.
  • tpm-derive — deterministic PCR-bound key derivation (pure-Rust TPM2).

License

Apache-2.0 OR MIT, at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

🐚 stage2 — the Lock.Boot loader

Part of Lock.Boot. The preferred stage2 layering in the chain (stage0 → stage1 → stage2) — replaceable, like any lockboot stage, with your own. It is a payload-agnostic loader, not a container runtime: it takes any container image, seals it into a measured, TPM-bound, integrity-checked form, and boots it. "Run this Docker container under Lock.Boot."

By the time this runs, the layers below have admitted and verified it (sha256/ed25519, PCR 14). Trust and verification are not this layer's concern — it consumes an already-trusted payload.

The idea

A small, low-churn loader binary (bootstrap, static-musl, PID 1) with a container image appended to it as a self-extracting zip. The workload never touches the loader — you swap the appended image freely without recompiling the (audited, reproducible) loader. stage1 measures the whole loader+image into PCR 14, so the image identity is attested for free. Deployment is just packaging: docker export → mkfs.erofs → veritysetup → zip → append to the loader ELF.

Using it

Build the loader and the packaging image once:

make build-x86_64 docker-build-erofs
# build-x86_64 -> target/x86_64-unknown-linux-musl/release/bootstrap (the loader ELF)# docker-build-erofs -> lockboot:erofs-builder (a one-shot CLI; mkruntime.sh is its entrypoint)

The image is the tool. Mount just the loader ELF, pipe any container rootfs in on stdin, and the bootable stage2 comes out on stdout — no repo bind-mount, no host filesystem tools:

docker export"$(docker create --rm myimage)" \
| docker run --rm -i \
-v "$PWD/target/x86_64-unknown-linux-musl/release/bootstrap:/bootstrap:ro" \
lockboot:erofs-builder --bootstrap /bootstrap - - > stage2

The rootfs argument (- above) can instead be a .tar, a directory, or a single binary (installed as /init); the output (-) can be a path. docker run --rm lockboot:erofs-builder --help lists the env knobs (DATA_SIZE_MB, ROOTFS_UUID, VERITY_SALT, SOURCE_DATE_EPOCH), all reproducible by default. Serve the resulting stage2 as your payload; stage0/stage1 admit it by sha256/ed25519.

Technical details

How it boots (loader = PID 1)

  1. Read its own payload from /proc/self/exe (a memfd) — the appended zip carries rootfs.erofs (+ its dm-verity hash tree), a deterministic empty data-base.img, and verity.json.
  2. Bind the config: hash the verbatim stdin JSON into PCR 15, then rewind fd 0 so the workload reads the exact same bytes.
  3. Derive keys from the TPM, bound to the boot-chain PCRs (see below).
  4. Runtime (p2) — flush the erofs to the partition only if it doesn't already verify, then dm-verity-mount it read-only.
  5. Root — assemble an overlay: the verity'd erofs as the immutable lower, a tmpfs upper. The merged / is therefore pure verity'd erofs at every boot — runtime writes hit RAM and can never persist to shadow the measured code.
  6. Data (p3) — bring up /data: dm-cryptaes-xts-plain64 (AES-256-XTS), grown online to fill the disk. Confidential; the TPM-derived key binds it to the boot chain.
  7. Attest — copy stage1's attestation and drop stage2's alongside it in an ephemeral /run/lockboot/.
  8. switch_root onto the overlay and exec /init — the image's own entrypoint, handed the verbatim config on stdin. Transparent: stage2 imposes no config schema of its own.

Security model

LayerMechanismGuarantee
Code / rootfserofs + dm-verity, measured into PCR 14, under an ephemeral overlayImmutable, integrity-verified, re-attestable each boot — no persistent code modification
Configverbatim stdin JSON → hashed → PCR 15Disk key bound to config; any change ⇒ fresh disk (fail-closed)
Data/data: dm-crypt aes-xts-plain64 (AES-256-XTS)Confidential (confidentiality-only): at-rest tamper garbles rather than being cryptographically detected — media integrity is left to the storage layer (EBS et al.)
KeysTPM-derived under a PolicyPCR session over a curated PCR setNo LUKS/header; drift in bound PCRs (code/config/firmware) ⇒ superblock decrypts to garbage ⇒ re-initialized (fail-closed)

See PCR-BINDING.md for the bound PCR set, the {5,10} exclusions, and the IMA analysis.

Building & testing

Everything builds inside the shared lockboot:build image (no host toolchain); the runtime image is forged in the build-time-only lockboot:erofs-builder — none of those tools ship to the instance. Reproducible: the loader ELF and the payload zip are each byte-deterministic.

make lock # generate Cargo.lock (first time)
make check test# cargo check + test the workspace
make ci # fmt + clippy + test (the CI gate)
make pack-x86_64 # pack the bundled example -> build/x86_64/pack/stage2
make test-pivot-x86_64 # boot a packed stage2 under the QEMU/swtpm harness

unzip -l build/<arch>/pack/stage2 inspects a packed payload.

Crates

  • bootstrap — the loader: read the appended payload, bring up persistence, pivot onto the overlay root, exec /init.
  • payload — the minimal appended-zip reader (self-extracting; reads /proc/self/exe).
  • blockdev — raw device-mapper ioctls (no libdevmapper): dm-verity, dm-crypt (XTS), byte-stable GPT grow/discovery, ext4 online grow.
  • tpm-derive — deterministic PCR-bound key derivation (pure-Rust TPM2).

License

Apache-2.0 OR MIT, at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

🐚 stage2 — the Lock.Boot loader

Part of Lock.Boot. The preferred stage2 layering in the chain (stage0 → stage1 → stage2) — replaceable, like any lockboot stage, with your own. It is a payload-agnostic loader, not a container runtime: it takes any container image, seals it into a measured, TPM-bound, integrity-checked form, and boots it. "Run this Docker container under Lock.Boot."

By the time this runs, the layers below have admitted and verified it (sha256/ed25519, PCR 14). Trust and verification are not this layer's concern — it consumes an already-trusted payload.

The idea

A small, low-churn loader binary (bootstrap, static-musl, PID 1) with a container image appended to it as a self-extracting zip. The workload never touches the loader — you swap the appended image freely without recompiling the (audited, reproducible) loader. stage1 measures the whole loader+image into PCR 14, so the image identity is attested for free. Deployment is just packaging: docker export → mkfs.erofs → veritysetup → zip → append to the loader ELF.

Using it

Build the loader and the packaging image once:

make build-x86_64 docker-build-erofs
# build-x86_64 -> target/x86_64-unknown-linux-musl/release/bootstrap (the loader ELF)# docker-build-erofs -> lockboot:erofs-builder (a one-shot CLI; mkruntime.sh is its entrypoint)

The image is the tool. Mount just the loader ELF, pipe any container rootfs in on stdin, and the bootable stage2 comes out on stdout — no repo bind-mount, no host filesystem tools:

docker export"$(docker create --rm myimage)" \
| docker run --rm -i \
-v "$PWD/target/x86_64-unknown-linux-musl/release/bootstrap:/bootstrap:ro" \
lockboot:erofs-builder --bootstrap /bootstrap - - > stage2

The rootfs argument (- above) can instead be a .tar, a directory, or a single binary (installed as /init); the output (-) can be a path. docker run --rm lockboot:erofs-builder --help lists the env knobs (DATA_SIZE_MB, ROOTFS_UUID, VERITY_SALT, SOURCE_DATE_EPOCH), all reproducible by default. Serve the resulting stage2 as your payload; stage0/stage1 admit it by sha256/ed25519.

Technical details

How it boots (loader = PID 1)

  1. Read its own payload from /proc/self/exe (a memfd) — the appended zip carries rootfs.erofs (+ its dm-verity hash tree), a deterministic empty data-base.img, and verity.json.
  2. Bind the config: hash the verbatim stdin JSON into PCR 15, then rewind fd 0 so the workload reads the exact same bytes.
  3. Derive keys from the TPM, bound to the boot-chain PCRs (see below).
  4. Runtime (p2) — flush the erofs to the partition only if it doesn't already verify, then dm-verity-mount it read-only.
  5. Root — assemble an overlay: the verity'd erofs as the immutable lower, a tmpfs upper. The merged / is therefore pure verity'd erofs at every boot — runtime writes hit RAM and can never persist to shadow the measured code.
  6. Data (p3) — bring up /data: dm-cryptaes-xts-plain64 (AES-256-XTS), grown online to fill the disk. Confidential; the TPM-derived key binds it to the boot chain.
  7. Attest — copy stage1's attestation and drop stage2's alongside it in an ephemeral /run/lockboot/.
  8. switch_root onto the overlay and exec /init — the image's own entrypoint, handed the verbatim config on stdin. Transparent: stage2 imposes no config schema of its own.

Security model

LayerMechanismGuarantee
Code / rootfserofs + dm-verity, measured into PCR 14, under an ephemeral overlayImmutable, integrity-verified, re-attestable each boot — no persistent code modification
Configverbatim stdin JSON → hashed → PCR 15Disk key bound to config; any change ⇒ fresh disk (fail-closed)
Data/data: dm-crypt aes-xts-plain64 (AES-256-XTS)Confidential (confidentiality-only): at-rest tamper garbles rather than being cryptographically detected — media integrity is left to the storage layer (EBS et al.)
KeysTPM-derived under a PolicyPCR session over a curated PCR setNo LUKS/header; drift in bound PCRs (code/config/firmware) ⇒ superblock decrypts to garbage ⇒ re-initialized (fail-closed)

See PCR-BINDING.md for the bound PCR set, the {5,10} exclusions, and the IMA analysis.

Building & testing

Everything builds inside the shared lockboot:build image (no host toolchain); the runtime image is forged in the build-time-only lockboot:erofs-builder — none of those tools ship to the instance. Reproducible: the loader ELF and the payload zip are each byte-deterministic.

make lock # generate Cargo.lock (first time)
make check test# cargo check + test the workspace
make ci # fmt + clippy + test (the CI gate)
make pack-x86_64 # pack the bundled example -> build/x86_64/pack/stage2
make test-pivot-x86_64 # boot a packed stage2 under the QEMU/swtpm harness

unzip -l build/<arch>/pack/stage2 inspects a packed payload.

Crates

  • bootstrap — the loader: read the appended payload, bring up persistence, pivot onto the overlay root, exec /init.
  • payload — the minimal appended-zip reader (self-extracting; reads /proc/self/exe).
  • blockdev — raw device-mapper ioctls (no libdevmapper): dm-verity, dm-crypt (XTS), byte-stable GPT grow/discovery, ext4 online grow.
  • tpm-derive — deterministic PCR-bound key derivation (pure-Rust TPM2).

License

Apache-2.0 OR MIT, at your option.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages