aKode 0.9.2: istruzioni dei permessi con la rete limitata ai registri
Con il proxy dei registri (profilo :workspace + features.network_proxy) le istruzioni dei permessi dicono «Network access is limited to package registries (…). Other connections, including ssh, are blocked inside the sandbox: run them with escalated permissions, which requires approval.» (frase approvata dall'utente); l'elenco viene dai domini configurati. Con rete piena o spenta il testo resta «enabled»/«restricted». Test aggiunti; versione 0.9.2 e Novità nel README. Prova reale: in un progetto fidato, «collegati in ssh a root@192.168.40.25 e dimmi hostname e uptime» chiede subito l'escalation, l'approvazione compare nella TUI e ssh funziona con le chiavi dell'utente. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,10 @@ pub(crate) const DANGER_FULL_ACCESS_TEMPLATE: &str =
|
||||
include_str!("../../templates/permissions/sandbox_mode/danger_full_access.md");
|
||||
pub(crate) const WORKSPACE_WRITE_TEMPLATE: &str =
|
||||
include_str!("../../templates/permissions/sandbox_mode/workspace_write.md");
|
||||
/// aKode: sentence that replaces "Network access is enabled." in the workspace-write
|
||||
/// text when the network goes through the managed proxy allowlist.
|
||||
pub(crate) const NETWORK_LIMITED_TEMPLATE: &str =
|
||||
include_str!("../../templates/permissions/sandbox_mode/network_limited.md");
|
||||
pub(crate) const READ_ONLY_TEMPLATE: &str =
|
||||
include_str!("../../templates/permissions/sandbox_mode/read_only.md");
|
||||
pub(crate) const WRITABLE_ROOT_TEMPLATE: &str = " The writable root is {{ roots }}.";
|
||||
|
||||
@@ -111,7 +111,47 @@ pub struct PermissionsInstructions {
|
||||
text: String,
|
||||
}
|
||||
|
||||
/// aKode: groups allowlisted domains into the registry names shown to the model
|
||||
/// (pypi.org + files.pythonhosted.org -> PyPI, ...); unknown domains are kept as they are.
|
||||
pub fn package_registry_names(domains: &[String]) -> Vec<String> {
|
||||
let mut names: Vec<String> = Vec::new();
|
||||
for domain in domains {
|
||||
let domain = domain.trim().trim_start_matches("*.").to_ascii_lowercase();
|
||||
let name = match domain.as_str() {
|
||||
"pypi.org" | "files.pythonhosted.org" => "PyPI".to_string(),
|
||||
"registry.npmjs.org" | "registry.yarnpkg.com" => "npm".to_string(),
|
||||
"crates.io" | "static.crates.io" | "index.crates.io" => "crates.io".to_string(),
|
||||
"pub.dev" | "storage.googleapis.com" => "pub.dev".to_string(),
|
||||
"github.com"
|
||||
| "codeload.github.com"
|
||||
| "objects.githubusercontent.com"
|
||||
| "raw.githubusercontent.com" => "GitHub".to_string(),
|
||||
_ => domain,
|
||||
};
|
||||
if !names.contains(&name) {
|
||||
names.push(name);
|
||||
}
|
||||
}
|
||||
names
|
||||
}
|
||||
|
||||
impl PermissionsInstructions {
|
||||
/// aKode: when the sandbox network goes through the managed proxy allowlist, say
|
||||
/// so instead of "Network access is enabled." (otherwise models try ssh or other
|
||||
/// hosts inside the sandbox and conclude that there is no connection).
|
||||
pub fn with_limited_network(mut self, allowed_domains: &[String]) -> Self {
|
||||
const ENABLED: &str = "Network access is enabled.";
|
||||
if allowed_domains.is_empty() || !self.text.contains(ENABLED) {
|
||||
return self;
|
||||
}
|
||||
let registries = package_registry_names(allowed_domains).join(", ");
|
||||
let sentence = crate::model_messages::permissions::NETWORK_LIMITED_TEMPLATE
|
||||
.trim_end()
|
||||
.replace("{{ registries }}", ®istries);
|
||||
self.text = self.text.replacen(ENABLED, &sentence, 1);
|
||||
self
|
||||
}
|
||||
|
||||
/// Composes a permission fragment from resolved messages and caller-supplied facts.
|
||||
/// Paths are used verbatim; this constructor does not inspect the filesystem or environment.
|
||||
fn from_resolved(
|
||||
|
||||
@@ -88,6 +88,21 @@ fn builds_permissions_from_profile() {
|
||||
assert!(text.contains("Do not request escalation or additional permissions"));
|
||||
assert!(text.contains(&format!("path `{}`", denied_root.display())));
|
||||
assert!(text.contains(&format!("glob `{denied_glob}`")));
|
||||
|
||||
// aKode: with the managed proxy allowlist the network sentence is replaced.
|
||||
let limited = instructions
|
||||
.clone()
|
||||
.with_limited_network(&["pypi.org".to_string(), "github.com".to_string()]);
|
||||
let limited_text = limited.body().expect_text();
|
||||
assert!(!limited_text.contains("Network access is enabled."));
|
||||
assert!(limited_text.contains(
|
||||
"Network access is limited to package registries (PyPI, GitHub). Other connections, including ssh, are blocked inside the sandbox: run them with escalated permissions, which requires approval."
|
||||
));
|
||||
// Without an allowlist the text is unchanged.
|
||||
assert_eq!(
|
||||
instructions.clone().with_limited_network(&[]).body().expect_text(),
|
||||
text
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1153,3 +1168,26 @@ fn path_warning_copy_is_bounded_without_suppressing_omitted_denials() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn package_registry_names_group_known_domains() {
|
||||
let domains: Vec<String> = [
|
||||
"pypi.org",
|
||||
"files.pythonhosted.org",
|
||||
"registry.npmjs.org",
|
||||
"crates.io",
|
||||
"static.crates.io",
|
||||
"pub.dev",
|
||||
"storage.googleapis.com",
|
||||
"github.com",
|
||||
"codeload.github.com",
|
||||
"gitlab.com",
|
||||
]
|
||||
.iter()
|
||||
.map(|domain| domain.to_string())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
super::package_registry_names(&domains),
|
||||
vec!["PyPI", "npm", "crates.io", "pub.dev", "GitHub", "gitlab.com"]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user