Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: restrict access permissions on /boot/ignition{,/config.ign} #571

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use anyhow::{bail, Context, Result};
use lazy_static::lazy_static;
use nix::mount;
use regex::Regex;
use std::fs::{copy as fscopy, create_dir_all, read_dir, File, OpenOptions};
use std::fs::{
copy as fscopy, create_dir_all, read_dir, set_permissions, File, OpenOptions, Permissions,
};
use std::io::{copy, Read, Seek, SeekFrom, Write};
use std::os::unix::fs::FileTypeExt;
use std::os::unix::fs::{FileTypeExt, PermissionsExt};
use std::path::{Path, PathBuf};

use crate::blockdev::*;
Expand Down Expand Up @@ -248,7 +250,21 @@ fn write_ignition(
// make parent directory
let mut config_dest = mountpoint.to_path_buf();
config_dest.push("ignition");
create_dir_all(&config_dest).context("creating Ignition config directory")?;
if !config_dest.is_dir() {
create_dir_all(&config_dest).with_context(|| {
format!(
"creating Ignition config directory {}",
config_dest.display()
)
})?;
// Ignition data may contain secrets; restrict to root
set_permissions(&config_dest, Permissions::from_mode(0o700)).with_context(|| {
format!(
"setting file mode for Ignition directory {}",
config_dest.display()
)
})?;
}

// do the copy
config_dest.push("config.ign");
Expand All @@ -262,6 +278,13 @@ fn write_ignition(
config_dest.display()
)
})?;
// Ignition config may contain secrets; restrict to root
set_permissions(&config_dest, Permissions::from_mode(0o600)).with_context(|| {
bgilbert marked this conversation as resolved.
Show resolved Hide resolved
format!(
"setting file mode for destination Ignition config {}",
config_dest.display()
)
})?;
copy(&mut config_in, &mut config_out).context("writing Ignition config")?;

Ok(())
Expand Down