Skip to content

Commit ab96161

Browse files
committed
ensure data directories have appropriate permissions
1 parent e44282e commit ab96161

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

src-tauri/cli/src/bin/dg.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::os::unix::fs::PermissionsExt;
33
use std::{
44
fmt,
5-
fs::{create_dir, OpenOptions},
5+
fs::{create_dir, set_permissions, OpenOptions, Permissions},
66
net::IpAddr,
77
path::{Path, PathBuf},
88
str::FromStr,
@@ -619,6 +619,14 @@ async fn main() {
619619
};
620620
debug!("The following configuration will be used: {config_path:?}");
621621

622+
// Ensure data directory has appropriate permissions (dg25-28)
623+
if let Err(err) = set_permissions(&config_path, Permissions::from_mode(0o700)) {
624+
warn!(
625+
"Failed to set permissions on data directory {}: {err}",
626+
config_path.display()
627+
);
628+
}
629+
622630
if let Some(("enroll", submatches)) = matches.subcommand() {
623631
debug!("Enrollment command has been selected, starting enrollment.");
624632
let token = submatches

src-tauri/src/bin/defguard-client.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
44
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
55

6-
use std::{env, str::FromStr, sync::LazyLock};
6+
use std::{
7+
env,
8+
fs::{set_permissions, Permissions},
9+
os::unix::fs::PermissionsExt,
10+
str::FromStr,
11+
sync::LazyLock,
12+
};
713

814
#[cfg(target_os = "windows")]
915
use defguard_client::utils::sync_connections;
@@ -277,15 +283,22 @@ fn main() {
277283
app.run(|app_handle, event| match event {
278284
// Startup tasks
279285
RunEvent::Ready => {
286+
// Ensure data directory has appropriate permissions (dg25-28)
287+
let data_dir = app_handle
288+
.path()
289+
.app_data_dir()
290+
.unwrap_or_else(|_| "UNDEFINED DATA DIRECTORY".into());
291+
if let Err(err) = set_permissions(&data_dir, Permissions::from_mode(0o700)) {
292+
warn!(
293+
"Failed to set permissions on data directory {}: {err}",
294+
data_dir.display()
295+
);
296+
}
280297
info!(
281298
"Application data (database file) will be stored in: {} and application logs in: {}. \
282299
Logs of the background Defguard service responsible for managing VPN connections at the \
283300
network level will be stored in: {}.",
284-
// display the path to the app data directory, convert option<pathbuf> to option<&str>
285-
app_handle
286-
.path()
287-
.app_data_dir()
288-
.unwrap_or_else(|_| "UNDEFINED DATA DIRECTORY".into()).display(),
301+
data_dir.display(),
289302
app_handle
290303
.path()
291304
.app_log_dir()

0 commit comments

Comments
 (0)