Give each session VM its hidden secrets, attest them, and

This commit is contained in:
Chris Scott committed 2026-12-03 19:53:07 -05:00
1 parent a58dcc96d4
commit 4ea3ecca9e
3 files changed
+567 -42

No files matched your search

+49 -8
View File
@@ -79,9 +79,13 @@ function waitGate(kind) {
if (!stateDir) stderrExit('missing ${FAKE_MSB_STATE_ENV}', 2)
fs.mkdirSync(stateDir, { recursive: true })
const loggedEnv = {}
for (const [key, value] of Object.entries(process.env)) {
if (key.startsWith('OCM_SECRET_') && typeof value === 'string') loggedEnv[key] = value
}
fs.appendFileSync(
path.join(stateDir, 'calls.jsonl'),
JSON.stringify({ argv: [process.argv[1]].concat(args) }) + '\\n',
JSON.stringify({ argv: [process.argv[1]].concat(args), env: loggedEnv }) + '\\n',
)
const spec = readJson(path.join(stateDir, 'spec.json'), {})
@@ -90,6 +94,24 @@ const state = readJson(statePath, { vms: {} })
state.vms = state.vms || {}
const saveState = () => writeJson(statePath, state)
function secretEntries(name) {
const conf = readJson(path.join(stateDir, 'vms', name, 'secrets.json'), {})
return Object.keys(conf).map((envVar) => {
const entry = conf[envVar] || {}
const allow = Array.isArray(entry.allow) ? entry.allow : []
return {
env_var: envVar,
value: '',
source: { kind: 'env', var: envVar },
placeholder: entry.placeholder,
allowed_hosts: allow.map((host) => host.startsWith('*.') ? { wildcard: host.slice(2) } : { exact: host }),
substitution: { headers: true, query: false, body: false },
passthrough_hosts: [],
require_tls_identity: true,
}
})
}
function tmpfsSize(memoryMib) {
return Math.min(512, Math.max(1, Math.floor(memoryMib / 4)))
}
@@ -126,6 +148,17 @@ function synthesize(vm, name) {
follow_root_symlinks: false,
})
mounts.push({ type: 'Tmpfs', guest: '/tmp', size_mib: tmpfsSize(vm.memoryMib), options: mountOptions() })
const network = {
enabled: true,
ports: [],
policy: spec.policy,
max_connections: null,
trust_host_cas: false,
}
const secrets = secretEntries(name)
if (secrets.length > 0) {
network.secrets = { secrets, violation_action: 'block' }
}
return {
name,
image: { Oci: { reference: spec.image } },
@@ -152,13 +185,7 @@ function synthesize(vm, name) {
rlimits: [],
mounts,
patches: [],
network: {
enabled: true,
ports: [],
policy: spec.policy,
max_connections: null,
trust_host_cas: false,
},
network,
init: null,
pull_policy: 'IfMissing',
security_profile: 'default',
@@ -210,6 +237,13 @@ switch (command) {
const memory = valueAfter('-m') || '0M'
const sessionLabel = valuesAfter('--label').find((label) => label.startsWith('ocm.session='))
clearInspect(name)
const secretConfPath = valueAfter('--secret-conf')
const secretsPath = path.join(stateDir, 'vms', name, 'secrets.json')
if (secretConfPath) {
writeJson(secretsPath, readJson(secretConfPath, {}))
} else {
fs.rmSync(secretsPath, { force: true })
}
const sharedRoots = new Set(spec.sharedMountRoots || [])
state.vms[name] = {
projectMounts: valuesAfter('--mount-dir').map((mount) => mount.split(':')[0]).filter((host) => !sharedRoots.has(host)),
@@ -243,12 +277,19 @@ switch (command) {
const name = args[args.length - 1]
if (name) fail('rm-' + name)
if (name) clearInspect(name)
if (name) fs.rmSync(path.join(stateDir, 'vms', name, 'secrets.json'), { force: true })
if (name && state.vms[name]) {
delete state.vms[name]
saveState()
}
break
}
case 'modify': {
fail('modify')
const name = args[1] || ''
if (name) fail('modify-' + name)
break
}
case 'volume':
fail('volume')
break