Skip to content

Commit e77ee08

Browse files
committed
fix: align machine policy with hardened schema
1 parent c6d4836 commit e77ee08

23 files changed

Lines changed: 398 additions & 408 deletions

‎CHANGELOG.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@ update, not for someone reading the commit log.
2323

2424
- **Machine-wide administrator policy**: Schools and offices can deploy a JSON policy to control update checks, AI, model downloads, network access, crash reporting, and locked settings. Invalid policy files enter restricted mode. See `docs/admin-policy.md`.
2525

26-
### Added
27-
2826
- **Copy now pastes as vectors in other design apps** — An ordinary Copy also
2927
puts a transparent SVG representation on the clipboard, so Inkscape, Krita,
3028
Illustrator, or Figma receive the selection as artwork instead of layer
3129
names. In-app paste still uses the editable Varve payload, so nothing loses
3230
fidelity; very large selections keep the editable payload only, and the
3331
receiving application still needs to accept `image/svg+xml`.
3432

35-
### Added
36-
3733
- **Text frame background and border** — Give text its own optional backing fill
3834
and border without changing glyph fill or outline. The border can be set to
3935
zero to keep the background with no visible line. The style is saved with

‎apps/desktop/src-tauri/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ libc = "0.2"
7575
libc = "0.2"
7676

7777
[target.'cfg(windows)'.dependencies]
78-
windows-sys = { version = "0.61.2", features = ["Win32_Storage_FileSystem", "Win32_System_SystemInformation"] }
78+
windows-sys = { version = "0.61.2", features = ["Win32_Storage_FileSystem", "Win32_System_SystemInformation", "Win32_System_Console"] }
7979

8080
[features]
8181
default = ["ai"]

‎apps/desktop/src-tauri/src/lib.rs‎

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,9 +1145,14 @@ fn policy_status() -> PolicyStatus {
11451145
}
11461146

11471147
#[tauri::command]
1148-
fn policy_can_check_updates() -> Result<(), String> {
1149-
if policy::POLICY.permits_updates() { Ok(()) }
1150-
else { Err("Update checks are disabled by your organisation's policy".into()) }
1148+
fn policy_can_check_updates() -> bool {
1149+
policy::POLICY.permits_updates()
1150+
}
1151+
1152+
#[tauri::command]
1153+
fn policy_authorize_network_request(url: String) -> Result<(), String> {
1154+
if policy::POLICY.permits_network_url(&url) { Ok(()) }
1155+
else { Err("Network access is disabled by your organisation's policy".into()) }
11511156
}
11521157

11531158
fn is_allowed_model_download_url(url: &str) -> bool {
@@ -5392,11 +5397,12 @@ fn home_write_text_file_approved(path: String, contents: String) -> Result<(), S
53925397
}
53935398

53945399
fn model_dir(app: &tauri::AppHandle) -> Result<std::path::PathBuf, String> {
5395-
let dir = policy::model_directory().unwrap_or(
5396-
filesystem::AppDirectories::resolve(app)
5400+
let dir = match policy::model_directory() {
5401+
Some(dir) => dir,
5402+
None => filesystem::AppDirectories::resolve(app)
53975403
.map_err(|error| error.message)?
53985404
.models,
5399-
);
5405+
};
54005406
std::fs::create_dir_all(&dir).map_err(|e| format!("Failed to create models dir: {e}"))?;
54015407
Ok(dir)
54025408
}
@@ -6051,6 +6057,7 @@ pub fn run() {
60516057
updates::update_packaging_context,
60526058
policy_status,
60536059
policy_can_check_updates,
6060+
policy_authorize_network_request,
60546061
// Home commands
60556062
home_list_files,
60566063
home_list_trashed,
@@ -6182,6 +6189,10 @@ pub fn run() {
61826189
/// network initialization. Returns `None` for normal application startup.
61836190
pub fn validate_policy_cli() -> Option<i32> {
61846191
let args: Vec<String> = std::env::args().collect();
6192+
validate_policy_args(&args)
6193+
}
6194+
6195+
fn validate_policy_args(args: &[String]) -> Option<i32> {
61856196
if args.len() >= 2 && args[1] == "--validate-policy" {
61866197
if args.len() != 3 {
61876198
eprintln!("Usage: varve --validate-policy <path>");
@@ -6195,6 +6206,22 @@ pub fn validate_policy_cli() -> Option<i32> {
61956206
None
61966207
}
61976208

6209+
#[cfg(test)]
6210+
mod policy_cli_tests {
6211+
use super::validate_policy_args;
6212+
6213+
#[test]
6214+
fn validate_policy_cli_returns_success_for_a_valid_file_and_failure_for_bad_json() {
6215+
let path = std::env::temp_dir().join(format!("policy-cli-{}.json", std::process::id()));
6216+
std::fs::write(&path, r#"{"schemaVersion":1,"policies":{},"recommended":{}}"#).unwrap();
6217+
let valid = vec!["varve".to_string(), "--validate-policy".to_string(), path.display().to_string()];
6218+
assert_eq!(validate_policy_args(&valid), Some(0));
6219+
std::fs::write(&path, "{").unwrap();
6220+
assert_eq!(validate_policy_args(&valid), Some(1));
6221+
let _ = std::fs::remove_file(path);
6222+
}
6223+
}
6224+
61986225
fn appimage_dmabuf_default(is_appimage: bool, has_user_override: bool) -> Option<&'static str> {
61996226
(is_appimage && !has_user_override).then_some("1")
62006227
}

‎apps/desktop/src-tauri/src/main.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
33

44
fn main() {
5+
#[cfg(windows)]
6+
if std::env::args().nth(1).as_deref() == Some("--validate-policy") {
7+
unsafe { windows_sys::Win32::System::Console::AttachConsole(u32::MAX); }
8+
}
59
if let Some(code) = varve_desktop_lib::validate_policy_cli() {
610
std::process::exit(code);
711
}

0 commit comments

Comments
 (0)