feat(random): add explicitly granted OS entropy API

This commit is contained in:
Marqdo Agent committed 2026-11-21 10:25:11 +08:00
1 parent 6338fa10e9
commit ee0c6cc80a
20 files changed
+309 -15

No files matched your search

+9 -2
View File
@@ -23,6 +23,8 @@ pub struct SandboxSettings {
pub allow_env: Vec<String>,
/// Process program grants (ADR-0044).
pub allow_process: Vec<String>,
/// OS entropy grant (ADR-0046).
pub allow_random: bool,
/// Foreign execution grant.
pub allow_foreign: bool,
/// Plugin grants.
@@ -75,6 +77,7 @@ impl SandboxSettings {
|| !self.allow_write.is_empty()
|| !self.allow_env.is_empty()
|| !self.allow_process.is_empty()
|| self.allow_random
|| !self.allow_plugin.is_empty()
|| !self.plugins.is_empty()
|| self.trust_native_plugin
@@ -83,8 +86,8 @@ impl SandboxSettings {
if requested {
return Err(
"strict mode currently supports pure Marqdo and native Math only; \
--allow-read/--allow-write/--allow-env/--allow-process/--allow-foreign/\
--allow-plugin/--plugin/--trust-native-plugin/--kernel/--trace-file are
--allow-read/--allow-write/--allow-env/--allow-process/--allow-random/\
--allow-foreign/--allow-plugin/--plugin/--trust-native-plugin/--kernel/--trace-file are
rejected. Use --mode project for those capabilities."
.to_string(),
);
@@ -102,6 +105,7 @@ impl SandboxSettings {
|| !self.allow_write.is_empty()
|| !self.allow_env.is_empty()
|| !self.allow_process.is_empty()
|| self.allow_random
|| self.allow_foreign
|| !self.allow_plugin.is_empty()
{
@@ -128,6 +132,9 @@ impl SandboxSettings {
for program in &self.allow_process {
capabilities = capabilities.allow_process(program.clone());
}
if self.allow_random {
capabilities = capabilities.allow_random();
}
if self.allow_foreign {
capabilities = capabilities.allow_foreign();
}
+4
View File
@@ -98,6 +98,9 @@ struct SandboxArgs {
/// Grant execution of an exact program path (repeatable, ADR-0044).
#[arg(long = "allow-process", value_name = "PROGRAM")]
allow_process: Vec<String>,
/// Grant OS entropy reads (ADR-0046).
#[arg(long = "allow-random")]
allow_random: bool,
/// Grant explicit foreign kernel execution.
#[arg(long = "allow-foreign")]
allow_foreign: bool,
@@ -151,6 +154,7 @@ impl SandboxArgs {
allow_write: self.allow_write.clone(),
allow_env: self.allow_env.clone(),
allow_process: self.allow_process.clone(),
allow_random: self.allow_random,
allow_foreign: self.allow_foreign,
allow_plugin: self.allow_plugin.clone(),
fuel: self.fuel,
+19
View File
@@ -83,6 +83,8 @@ fn product_tests() -> Vec<TestFile> {
][..]
} else if name == "process.mq.md" {
&["--allow-process", "/bin/echo"][..]
} else if name == "random.mq.md" {
&["--allow-random"][..]
} else {
&[][..]
};
@@ -158,6 +160,7 @@ fn every_public_stdlib_module_has_a_product_test() {
"json.mq.md",
"path.mq.md",
"process.mq.md",
"random.mq.md",
"regex.mq.md",
"stream.mq.md",
"table.mq.md",
@@ -365,6 +368,22 @@ fn process_test_runs_an_explicitly_granted_program() {
assert_eq!(items[3]["value"], "");
}
#[test]
fn random_test_reads_bounded_entropy() {
let report = run_product_test(
product_tests()
.iter()
.find(|file| file.name == "random.mq.md")
.expect("random test"),
);
let items = report["value"]["items"].as_array().expect("list");
assert_eq!(items[0]["value"], true);
assert_eq!(items[1]["decimal"], "16");
assert_eq!(items[2]["value"], true);
assert_eq!(items[3]["value"], true);
assert_eq!(items[4]["value"], true);
}
#[test]
fn format_test_pins_value_semantics_and_handle_observation() {
let report = run_product_test(