-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement apparmor support * Add explanation to apparmor test
- Loading branch information
Showing
6 changed files
with
85 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use anyhow::{Context, Result}; | ||
use std::{ | ||
fs::{self}, | ||
path::Path, | ||
}; | ||
|
||
use crate::utils; | ||
|
||
const ENABLED_PARAMETER_PATH: &str = "/sys/module/apparmor/parameters/enabled"; | ||
|
||
/// Checks if AppArmor has been enabled on the system. | ||
pub fn is_enabled() -> Result<bool> { | ||
let aa_enabled = fs::read_to_string(ENABLED_PARAMETER_PATH) | ||
.with_context(|| format!("could not read {}", ENABLED_PARAMETER_PATH))?; | ||
Ok(aa_enabled.starts_with('Y')) | ||
} | ||
|
||
/// Applies an AppArmor profile to the container. | ||
pub fn apply_profile(profile: &str) -> Result<()> { | ||
if profile.is_empty() { | ||
return Ok(()); | ||
} | ||
|
||
// Try the module specific subdirectory. This is the recommended way to configure | ||
// LSMs since Linux 5.1. AppArmor has such a directory since Linux 5.8. | ||
if activate_profile(Path::new("/proc/self/attr/apparmor/exec"), profile).is_ok() { | ||
return Ok(()); | ||
} | ||
|
||
// try the legacy interface | ||
activate_profile(Path::new("/proc/self/attr/exec"), profile) | ||
} | ||
|
||
fn activate_profile(path: &Path, profile: &str) -> Result<()> { | ||
utils::ensure_procfs(path)?; | ||
utils::write_file(path, format!("exec {}", profile)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod apparmor; | ||
pub mod capabilities; | ||
pub mod commands; | ||
pub mod container; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters