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

+22
View File
@@ -321,6 +321,8 @@ pub struct Capabilities {
pub env: Vec<String>,
/// Allowed process program paths (empty = no process execution).
pub process_programs: Vec<String>,
/// Whether OS entropy may be read (ADR-0046).
pub random: bool,
/// May spawn processes (foreign kernels).
pub process: bool,
/// May run foreign kernels (Python/Node).
@@ -342,6 +344,7 @@ impl Capabilities {
net_hosts: Vec::new(),
env: Vec::new(),
process_programs: Vec::new(),
random: false,
process: false,
foreign: false,
plugins: Vec::new(),
@@ -409,6 +412,25 @@ impl Capabilities {
}
}
/// Grant OS entropy reads (ADR-0046).
pub fn allow_random(mut self) -> Self {
self.random = true;
self
}
/// Check the entropy grant.
pub fn check_random(&self, span: Option<Span>) -> Result<(), RuntimeError> {
if self.random {
Ok(())
} else {
Err(denied(
span,
"OS entropy was not granted",
"grant it with --allow-random",
))
}
}
/// Grant foreign kernel execution.
pub fn allow_foreign(mut self) -> Self {
self.foreign = true;