Skip to content

Commit 38857cd

Browse files
committed
On linux, use /dev/shm for tempfs storage of SSH key
This avoids persisting production SSH keys to disk. This commit also avoids manually opening the file, as the `tempfile::Builder` already does this.
1 parent 3b280fb commit 38857cd

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/git.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::collections::HashMap;
2-
use std::fs::{self, File, OpenOptions};
2+
use std::fs::{self, OpenOptions};
33
use std::io::prelude::*;
44
use std::path::{Path, PathBuf};
55

@@ -409,10 +409,15 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
409409
_ => return Err(String::from("squash_index: Could not determine credentials").into()),
410410
};
411411

412-
let temp_key_file = tempfile::Builder::new().tempfile()?;
413-
let mut file = File::create(&temp_key_file)?;
414-
file.write_all(key.as_bytes())?;
415-
drop(file);
412+
// When running on production, ensure the file is created in tmpfs and not persisted to disk
413+
#[cfg(target_os = "linux")]
414+
let mut temp_key_file = tempfile::Builder::new().tempfile_in("/dev/shm")?;
415+
416+
// For other platforms, default to std::env::tempdir()
417+
#[cfg(not(target_os = "linux"))]
418+
let mut temp_key_file = tempfile::Builder::new().tempfile()?;
419+
420+
temp_key_file.write_all(key.as_bytes())?;
416421

417422
let checkout_path = repo.checkout_path.path();
418423
let output = std::process::Command::new("git")

0 commit comments

Comments
 (0)