-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add fail-closed sbx bounded-query backend #6764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lpcox
merged 4 commits into
lpcox-add-sbx-broker-ingress
from
lpcox-add-sbx-query-runner
Jul 31, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cbdf123
feat: add fail-closed sbx query backend
lpcox 69ed4b9
Merge remote-tracking branch 'origin/lpcox-add-sbx-broker-ingress' in…
lpcox 46b01aa
fix: address sbx query runner review feedback
lpcox 56d38d5
test: validate bounded-query runtime matrix (#6780)
lpcox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const PRIMARY_BACKENDS = new Set(['docker', 'gvisor', 'sbx']); | ||
| const QUERY_BACKENDS = new Set(['docker', 'gvisor', 'sbx']); | ||
| const LIFECYCLE_CLASSES = new Set(['preflight', 'startup', 'query', 'cleanup']); | ||
| const CAPABILITY_STATES = new Set(['supported', 'unavailable', 'blocked']); | ||
| const CATEGORY_PATTERN = /^[a-z][a-z0-9-]{0,63}$/; | ||
|
|
||
| function assertTelemetryValue(allowed, value, field) { | ||
| if (!allowed.has(value)) throw new Error(`Invalid bounded-query telemetry ${field}`); | ||
| } | ||
|
|
||
| function buildRuntimeTelemetryRecord(event) { | ||
| assertTelemetryValue(PRIMARY_BACKENDS, event.primaryBackend, 'primaryBackend'); | ||
| assertTelemetryValue(QUERY_BACKENDS, event.queryBackend, 'queryBackend'); | ||
| assertTelemetryValue(LIFECYCLE_CLASSES, event.lifecycleClass, 'lifecycleClass'); | ||
| assertTelemetryValue(CAPABILITY_STATES, event.capabilityState, 'capabilityState'); | ||
| if (typeof event.category !== 'string' || !CATEGORY_PATTERN.test(event.category)) { | ||
| throw new Error('Invalid bounded-query telemetry category'); | ||
| } | ||
| return Object.freeze({ | ||
| primaryBackend: event.primaryBackend, | ||
| queryBackend: event.queryBackend, | ||
| lifecycleClass: event.lifecycleClass, | ||
| capabilityState: event.capabilityState, | ||
| category: event.category, | ||
| }); | ||
| } | ||
|
|
||
| function createRuntimeTelemetry(auditDir) { | ||
| fs.mkdirSync(auditDir, { recursive: true, mode: 0o700 }); | ||
| const telemetryPath = path.join(auditDir, 'runtime-telemetry.jsonl'); | ||
| let fd = fs.openSync(telemetryPath, 'a', 0o600); | ||
| return { | ||
| emit(event) { | ||
| const record = buildRuntimeTelemetryRecord(event); | ||
| if (fd === undefined) return; | ||
| try { | ||
| fs.writeSync(fd, `${JSON.stringify(record)}\n`); | ||
| } catch { | ||
| process.stderr.write('[bounded-query] runtime telemetry unavailable\n'); | ||
| try { | ||
| fs.closeSync(fd); | ||
| } catch { | ||
| // The generic telemetry failure above is the only safe diagnostic. | ||
| } | ||
| fd = undefined; | ||
| } | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| module.exports = { buildRuntimeTelemetryRecord, createRuntimeTelemetry }; |
103 changes: 103 additions & 0 deletions
103
containers/bounded-query/broker/sbx-capability-probe.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #!/usr/bin/env node | ||
| 'use strict'; | ||
|
|
||
| const defaultSbxClient = require('./sbx-client'); | ||
|
|
||
| const AUDITED_SBX_VERSION = '0.37.1'; | ||
| const REQUIRED_CREATE_FLAGS = Object.freeze([ | ||
| '--cpus', | ||
| '--memory', | ||
| '--name', | ||
| '--template', | ||
| ]); | ||
| const REQUIRED_EXEC_FLAGS = Object.freeze([ | ||
| '--user', | ||
| '--workdir', | ||
| ]); | ||
|
|
||
| /** | ||
| * Capabilities that sbx must expose before AWF can safely launch a query VM. | ||
| * | ||
| * sbx v0.37.1 lacks the final five controls. Local or kit network rules are | ||
| * insufficient because organization governance can replace them. | ||
| */ | ||
| const REQUIRED_HARD_ISOLATION_FLAGS = Object.freeze([ | ||
| '--network=none', | ||
| '--pids-limit', | ||
| '--disk-limit', | ||
| '--ulimit-fsize', | ||
| '--mount-target', | ||
| ]); | ||
|
|
||
| function includesFlag(help, flag) { | ||
| const escaped = flag.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | ||
| return new RegExp(`(^|[\\s,])${escaped}(?=([=\\s,]|$))`, 'm').test(help); | ||
| } | ||
|
|
||
| async function inspectHelp(sbx, command) { | ||
| const result = await sbx.runSbx([command, '--help'], 10_000); | ||
| return result.exitCode === 0 ? result.stdout : ''; | ||
| } | ||
|
|
||
| async function probeSbxCapabilities(sbx = defaultSbxClient) { | ||
| const versionResult = await sbx.runSbx(['version'], 10_000); | ||
| const daemonResult = await sbx.runSbx(['ls'], 10_000); | ||
| const createHelp = await inspectHelp(sbx, 'create'); | ||
| const execHelp = await inspectHelp(sbx, 'exec'); | ||
| const versionMatch = /\bv?(\d+\.\d+\.\d+)\b/.exec(versionResult.stdout); | ||
| const version = versionMatch ? versionMatch[1] : undefined; | ||
| const missing = []; | ||
|
|
||
| // AWF has not published the immutable Python-only sbx template/bootstrap | ||
| // because current sbx cannot yet enforce the controls below. | ||
| missing.push('pinned AWF Python query template and bootstrap'); | ||
|
|
||
| if (versionResult.exitCode !== 0 || !version || daemonResult.exitCode !== 0) { | ||
| missing.push('authenticated sbx CLI/daemon'); | ||
| } | ||
| if (version && version !== AUDITED_SBX_VERSION) { | ||
| missing.push(`audited sbx version ${AUDITED_SBX_VERSION} (found ${version})`); | ||
| } | ||
| for (const flag of REQUIRED_CREATE_FLAGS) { | ||
| if (!includesFlag(createHelp, flag)) missing.push(`sbx create ${flag}`); | ||
| } | ||
| for (const flag of REQUIRED_EXEC_FLAGS) { | ||
| if (!includesFlag(execHelp, flag)) missing.push(`sbx exec ${flag}`); | ||
| } | ||
| for (const flag of REQUIRED_HARD_ISOLATION_FLAGS) { | ||
| if (!includesFlag(createHelp, flag)) missing.push(`sbx create ${flag}`); | ||
| } | ||
|
|
||
| return Object.freeze({ | ||
| supported: missing.length === 0, | ||
| version, | ||
| auditedVersion: AUDITED_SBX_VERSION, | ||
| missing: Object.freeze(missing), | ||
| }); | ||
| } | ||
|
|
||
| async function main() { | ||
| const report = await probeSbxCapabilities(); | ||
| process.stdout.write(`${JSON.stringify(report)}\n`); | ||
| process.exitCode = report.supported ? 0 : 1; | ||
| } | ||
|
|
||
| if (require.main === module) { | ||
| main().catch((error) => { | ||
| process.stdout.write(`${JSON.stringify({ | ||
| supported: false, | ||
| auditedVersion: AUDITED_SBX_VERSION, | ||
| missing: ['capability probe failed'], | ||
| error: error.message, | ||
| })}\n`); | ||
| process.exitCode = 1; | ||
| }); | ||
| } | ||
|
|
||
| module.exports = { | ||
| AUDITED_SBX_VERSION, | ||
| REQUIRED_CREATE_FLAGS, | ||
| REQUIRED_EXEC_FLAGS, | ||
| REQUIRED_HARD_ISOLATION_FLAGS, | ||
| probeSbxCapabilities, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.