Restrict permissions to credentials file on creation

This commit is contained in:
Matteo Settenvini 2022-07-02 19:45:24 +02:00
parent ce5503da89
commit bc9ca47e3e
Signed by: matteo
GPG Key ID: 8576CC1AD97D42DF
1 changed files with 8 additions and 0 deletions

View File

@ -112,6 +112,14 @@ impl Credentials {
} }
fn write_back(&self) -> Result<()> { fn write_back(&self) -> Result<()> {
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
if !self.config_file.exists() {
let f = std::fs::File::create(&self.config_file)?;
#[cfg(unix)]
f.metadata()?.permissions().set_mode(0o600);
}
std::fs::write(&self.config_file, toml::to_string(self)?)?; std::fs::write(&self.config_file, toml::to_string(self)?)?;
Ok(()) Ok(())
} }