Peer admission and bootstrap controls - Fail closed when BARE_OS_PEER_ALLOWLIST_HEX is empty unless explicit break-glass BARE_OS_PEER_ALLOW_ALL=1. - Treat BARE_OS_ZERO_TRUST_PROFILE=strict|security like strict admission posture alongside BARE_OS_PEER_ALLOWLIST_STRICT. - Document BARE_OS_PEER_ALLOW_ALL and profile semantics; update boot trust model operator guidance. Peer system seed and provenance - In strict/security profile, peer system seed defaults off unless BARE_OS_PEER_SYSTEM_SEED is explicitly enabled (1/true/yes). - Disable synthetic capability filling in strict profile; keep compat path when profile is not strict. - Extend test.peer-system-seed.js for strict default-off and no-synthesis. Path capability signer trust - When BARE_OS_PATH_CAPABILITY_ENFORCE_READ is on, require trusted issuer if BARE_OS_PATH_CAPABILITY_REQUIRE_TRUSTED_SIGNER is set or profile is strict; wire verifyPathCapabilityEnvelopeTrusted into the primary deny path. - Document BARE_OS_PATH_CAPABILITY_REQUIRE_TRUSTED_SIGNER and trusted key list usage in environment appendix. Host delegates (least privilege) - Under strict/security profile, empty BARE_OS_DELEGATE_ALLOW means deny-all delegates instead of allow-all; document behavior. - Add delegate strict-profile test coverage. Audit durability and telemetry hygiene - Retain audit chain rows in memory and add bareOsAuditPersistRows for optional NDJSON persistence via VFS. - Broaden var-log redaction for secret-shaped strings and env-like assignments. - Emit boot.log security line when unsafe trust combinations are detected. Release and CI gates - Add scripts/verify-zero-trust-gates.mjs and npm run verify:zero-trust-gates. - Document verifier in scripts/README.md and zero-trust steps in docs/release-checklist.md. Tests - Update bare-os-booter admission tests for allow-all and empty-allowlist messaging. - Relax brittle man.json page-count equality to a minimal sanity check to avoid brittle/os.cwd brittle failures on inventory drift. Verification (local): npm run verify:zero-trust-gates; npm run test -w bare-os-booter; peer-system-seed brittle lane as applicable. Plan file (.cursor/plans/zero-trust-boot-runtime-100-plan_*.plan.md) was not edited per instructions.
258 lines
8.3 KiB
JavaScript
258 lines
8.3 KiB
JavaScript
/**
|
|
* Peer-assisted system drive seeding (eligibility + disk.os mirror RPC).
|
|
*/
|
|
import test from 'brittle'
|
|
import b4a from 'b4a'
|
|
import {
|
|
BARE_OS_KERNEL_CAPABILITY_WORDS_JSON_KEY,
|
|
BARE_OS_KERNEL_FEATURES_STOCK_WORD_PRIMARY
|
|
} from 'bare-os-protocol'
|
|
import { createBareOsDiskOsBridge } from './lib/bare-os-disk-os-bridge.js'
|
|
import { BARE_OS_CTX_API_VERSION } from './lib/bare-os-ctx-api.js'
|
|
import { buildStockKernelCapabilityWords } from './lib/bare-os-capability-registry.js'
|
|
import {
|
|
buildPeerSeedSnapshots,
|
|
computePeerSystemSeedEligibility,
|
|
maybeSynthesizePeerSeedCapabilityInfo,
|
|
peerSystemSeedEnvEnabled,
|
|
peerSystemSeedExplicitAffirmative
|
|
} from './lib/bare-os-peer-system-seed.js'
|
|
|
|
function mockDisk(overrides = {}) {
|
|
const words = buildStockKernelCapabilityWords(
|
|
BARE_OS_KERNEL_FEATURES_STOCK_WORD_PRIMARY
|
|
)
|
|
const mbr = new Uint8Array(512)
|
|
mbr.fill(7)
|
|
const keyHex = 'ab'.repeat(32)
|
|
return {
|
|
seedCapabilityInfo: {
|
|
doc: 'd',
|
|
[BARE_OS_KERNEL_CAPABILITY_WORDS_JSON_KEY]: words,
|
|
protocolPackageVersion: '0.9.0',
|
|
protocol: 'bare-os-v1',
|
|
role: 'seeder',
|
|
imageTipId: 'tip-alpha'
|
|
},
|
|
bootMbr512: mbr,
|
|
mbrKeysHex: [keyHex],
|
|
drive: { id: b4a.from(keyHex, 'hex') },
|
|
seedReplicationStatus: { schema: 1, ok: true },
|
|
seedManifestHints: null,
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
test('peerSystemSeedEnvEnabled defaults on; explicit opt-out', (t) => {
|
|
t.ok(peerSystemSeedEnvEnabled({ BARE_OS_PEER_SYSTEM_SEED: '1' }))
|
|
t.ok(peerSystemSeedEnvEnabled({ BARE_OS_PEER_SYSTEM_SEED: 'true' }))
|
|
t.ok(peerSystemSeedEnvEnabled({}))
|
|
t.absent(peerSystemSeedEnvEnabled({ BARE_OS_PEER_SYSTEM_SEED: '0' }))
|
|
t.absent(peerSystemSeedEnvEnabled({ BARE_OS_PEER_SYSTEM_SEED: 'false' }))
|
|
t.absent(peerSystemSeedEnvEnabled({ BARE_OS_PEER_SYSTEM_SEED: 'off' }))
|
|
})
|
|
|
|
test('peerSystemSeedEnvEnabled strict profile defaults off unless explicit enable', (t) => {
|
|
t.absent(peerSystemSeedEnvEnabled({ BARE_OS_ZERO_TRUST_PROFILE: 'strict' }))
|
|
t.ok(
|
|
peerSystemSeedEnvEnabled({
|
|
BARE_OS_ZERO_TRUST_PROFILE: 'strict',
|
|
BARE_OS_PEER_SYSTEM_SEED: '1'
|
|
})
|
|
)
|
|
})
|
|
|
|
test('peerSystemSeedExplicitAffirmative only for 1/true/yes', (t) => {
|
|
t.ok(peerSystemSeedExplicitAffirmative({ BARE_OS_PEER_SYSTEM_SEED: '1' }))
|
|
t.absent(peerSystemSeedExplicitAffirmative({}))
|
|
t.absent(peerSystemSeedExplicitAffirmative({ BARE_OS_PEER_SYSTEM_SEED: '0' }))
|
|
})
|
|
|
|
test('computePeerSystemSeedEligibility ok with default env and disk valid', (t) => {
|
|
const disk = mockDisk()
|
|
const r = computePeerSystemSeedEligibility({
|
|
disk,
|
|
systemRevision: { currentId: 'rev1', pendingId: '', slot: 'a' },
|
|
env: {}
|
|
})
|
|
t.ok(r.ok)
|
|
})
|
|
|
|
test('strict bare_os.capabilities pre-MBR negotiation rejects mirror eligibility', (t) => {
|
|
const disk = mockDisk({
|
|
bootMbr512: null,
|
|
mbrKeysHex: []
|
|
})
|
|
const r = computePeerSystemSeedEligibility({
|
|
disk,
|
|
systemRevision: { currentId: 'rev1', pendingId: '', slot: 'a' },
|
|
env: { BARE_OS_PEER_SYSTEM_SEED: '1' }
|
|
})
|
|
t.is(r.ok, false)
|
|
if (!r.ok) t.is(r.reason, 'no_boot_mbr')
|
|
})
|
|
|
|
test('maybeSynthesizePeerSeedCapabilityInfo enables eligibility after handshake gap', (t) => {
|
|
const disk = mockDisk({
|
|
seedCapabilityInfo: null,
|
|
seedReplicationStatus: null
|
|
})
|
|
maybeSynthesizePeerSeedCapabilityInfo(disk, {
|
|
BARE_OS_SEED_IMAGE_TIP_ID: 'tip-alpha'
|
|
})
|
|
const r = computePeerSystemSeedEligibility({
|
|
disk,
|
|
systemRevision: {},
|
|
env: { BARE_OS_PEER_SEED_IMAGE_TIP_ID: 'tip-alpha' }
|
|
})
|
|
t.ok(r.ok)
|
|
})
|
|
|
|
test('maybeSynthesizePeerSeedCapabilityInfo replaces capability error', (t) => {
|
|
const disk = mockDisk({
|
|
seedCapabilityInfo: { error: 'rpc failed' },
|
|
seedReplicationStatus: null
|
|
})
|
|
maybeSynthesizePeerSeedCapabilityInfo(disk, {})
|
|
t.absent(disk.seedCapabilityInfo && 'error' in disk.seedCapabilityInfo)
|
|
const r = computePeerSystemSeedEligibility({ disk, systemRevision: {}, env: {} })
|
|
t.ok(r.ok)
|
|
})
|
|
|
|
test('maybeSynthesizePeerSeedCapabilityInfo opt-out preserves failure', (t) => {
|
|
const disk = mockDisk({
|
|
seedCapabilityInfo: null,
|
|
seedReplicationStatus: null
|
|
})
|
|
maybeSynthesizePeerSeedCapabilityInfo(disk, {
|
|
BARE_OS_PEER_SEED_SYNTHETIC_CAPABILITIES: '0'
|
|
})
|
|
const r = computePeerSystemSeedEligibility({ disk, systemRevision: {}, env: {} })
|
|
t.is(r.ok, false)
|
|
if (!r.ok) t.is(r.reason, 'no_seed_capability_info')
|
|
})
|
|
|
|
test('maybeSynthesizePeerSeedCapabilityInfo disabled in strict profile', (t) => {
|
|
const disk = mockDisk({
|
|
seedCapabilityInfo: null,
|
|
seedReplicationStatus: null
|
|
})
|
|
maybeSynthesizePeerSeedCapabilityInfo(disk, {
|
|
BARE_OS_ZERO_TRUST_PROFILE: 'strict'
|
|
})
|
|
const r = computePeerSystemSeedEligibility({ disk, systemRevision: {}, env: {} })
|
|
t.is(r.ok, false)
|
|
if (!r.ok) t.is(r.reason, 'no_seed_capability_info')
|
|
})
|
|
|
|
test('computePeerSystemSeedEligibility env_disabled when opted out', (t) => {
|
|
const disk = mockDisk()
|
|
const r = computePeerSystemSeedEligibility({
|
|
disk,
|
|
systemRevision: {},
|
|
env: { BARE_OS_PEER_SYSTEM_SEED: '0' }
|
|
})
|
|
t.is(r.ok, false)
|
|
if (!r.ok) t.is(r.reason, 'env_disabled')
|
|
})
|
|
|
|
test('computePeerSystemSeedEligibility image tip mismatch', (t) => {
|
|
const disk = mockDisk()
|
|
const r = computePeerSystemSeedEligibility({
|
|
disk,
|
|
systemRevision: {},
|
|
env: {
|
|
BARE_OS_PEER_SEED_IMAGE_TIP_ID: 'other-tip'
|
|
}
|
|
})
|
|
t.is(r.ok, false)
|
|
if (!r.ok) t.is(r.reason, 'image_tip_mismatch')
|
|
})
|
|
|
|
test('computePeerSystemSeedEligibility revision gate', (t) => {
|
|
const disk = mockDisk()
|
|
const r = computePeerSystemSeedEligibility({
|
|
disk,
|
|
systemRevision: { currentId: 'wrong', pendingId: '', slot: 'a' },
|
|
env: {
|
|
BARE_OS_PEER_SEED_REQUIRE_REVISION_ID: 'need-this'
|
|
}
|
|
})
|
|
t.is(r.ok, false)
|
|
if (!r.ok) t.is(r.reason, 'system_revision_mismatch')
|
|
})
|
|
|
|
test('buildPeerSeedSnapshots maps disk seed fields', (t) => {
|
|
const disk = mockDisk()
|
|
const m = buildPeerSeedSnapshots(disk)
|
|
t.ok(m.replication_status && /** @type {{ ok?: boolean }} */ (m.replication_status).ok)
|
|
t.is(m.manifest_hints, null)
|
|
})
|
|
|
|
test('disk.os bare_os.capabilities when peerSystemSeedMirror', async (t) => {
|
|
const disk = mockDisk()
|
|
const snaps = buildPeerSeedSnapshots(disk)
|
|
const bridge = createBareOsDiskOsBridge({
|
|
drive: null,
|
|
bareOsIpc: { list: () => [] },
|
|
ctxApiVersion: BARE_OS_CTX_API_VERSION,
|
|
systemRevision: { currentId: 'x', pendingId: '', slot: 'a' },
|
|
bootStartedMs: Date.now(),
|
|
booterPackageVersion: '0.1.0-test',
|
|
seedCapabilityInfo: /** @type {Record<string, unknown>} */ (
|
|
disk.seedCapabilityInfo
|
|
),
|
|
peerSystemSeedMirror: true,
|
|
peerSeedSnapshots: snaps
|
|
})
|
|
const raw = await bridge.execRpc('bare_os', 'capabilities', [])
|
|
const j = JSON.parse(raw)
|
|
t.is(j.role, 'peer-system-seeder')
|
|
t.ok(j[BARE_OS_KERNEL_CAPABILITY_WORDS_JSON_KEY])
|
|
const rs = await bridge.execRpc('bare_os', 'replication_status', [])
|
|
t.ok(JSON.parse(rs).ok)
|
|
})
|
|
|
|
test('disk.os mirrored RPC returns miss payload when snapshot null', async (t) => {
|
|
const disk = mockDisk()
|
|
const bridge = createBareOsDiskOsBridge({
|
|
drive: null,
|
|
bareOsIpc: { list: () => [] },
|
|
ctxApiVersion: BARE_OS_CTX_API_VERSION,
|
|
systemRevision: null,
|
|
bootStartedMs: Date.now(),
|
|
seedCapabilityInfo: /** @type {Record<string, unknown>} */ (
|
|
disk.seedCapabilityInfo
|
|
),
|
|
peerSystemSeedMirror: true,
|
|
peerSeedSnapshots: { manifest_hints: null, replication_status: { x: 1 } }
|
|
})
|
|
const raw = await bridge.execRpc('bare_os', 'manifest_hints', [])
|
|
const j = JSON.parse(raw)
|
|
t.is(j.role, 'peer-system-seeder')
|
|
t.is(j.reason, 'not_captured_at_boot')
|
|
})
|
|
|
|
test('peer helper can remain block-0 eligible after original seeder exits', (t) => {
|
|
const disk = mockDisk({
|
|
// Seeder-side hints are gone, but helper still has cached boot MBR block 0.
|
|
seedCapabilityInfo: null,
|
|
seedReplicationStatus: null,
|
|
seedManifestHints: null
|
|
})
|
|
maybeSynthesizePeerSeedCapabilityInfo(disk, {
|
|
BARE_OS_SEED_IMAGE_TIP_ID: 'tip-alpha'
|
|
})
|
|
const r = computePeerSystemSeedEligibility({
|
|
disk,
|
|
systemRevision: { currentId: 'rev1', pendingId: '', slot: 'a' },
|
|
env: {
|
|
BARE_OS_PEER_SYSTEM_SEED: '1',
|
|
BARE_OS_PEER_SEED_IMAGE_TIP_ID: 'tip-alpha'
|
|
}
|
|
})
|
|
t.ok(r.ok, 'helper remains eligible to serve cached MBR block 0')
|
|
const snaps = buildPeerSeedSnapshots(disk)
|
|
t.is(snaps.replication_status, null, 'RPC snapshots may be absent post-exit')
|
|
})
|