Skip to content

Commit

Permalink
feat: added iam analyzer
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Jones <[email protected]>
  • Loading branch information
AlexsJones committed Dec 21, 2023
1 parent 07654d3 commit 8489fe5
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
131 changes: 131 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ simple-home-dir = "0.2.0"
tokio = { version = "1", features = ["full"] }
unescape = "0.1.0"
v = "0.1.0"
chrono = "0.4.31"

# Config for 'cargo dist'
[workspace.metadata.dist]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ isotope analyze -a S3
- EC2
- Orphaned Elastic IP address
- Public snapshot detection
- IAM
- Orphaned/unused key detection

### Community

Expand Down
45 changes: 45 additions & 0 deletions src/analyzer/iam_analyzer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use async_trait::async_trait;
use aws_sdk_iam::Client;
use aws_types::sdk_config::SdkConfig;
use crate::analyzer::analyzer_trait::Analyzer;
use crate::analyzer::types::AnalysisResults;
use chrono::{TimeZone, Utc};
use chrono::Duration;
pub struct IamAnalyzer {
pub config: SdkConfig
}

#[async_trait]
impl Analyzer for IamAnalyzer {

async fn run(&self) -> Option<Vec<AnalysisResults>> {
let mut results = Vec::new();
let iam = Client::new(&self.config);

// Check for unused access keys
if let Ok(keys) = iam.list_access_keys().send().await {
for key in keys.access_key_metadata {
if let Some(create_date) = key.create_date {
if !key.access_key_id.as_ref().unwrap().is_empty(){
if let Some(aws_create_date) = key.create_date {
let create_date = Utc.timestamp(aws_create_date.secs(), 0);
if create_date < Utc::now() - Duration::days(90) {
results.push(AnalysisResults {
message: format!("Unused access key: {}", key.access_key_id.as_ref().unwrap()),
advice: "Consider deleting unused access keys".to_string(),
analyzer_name: self.get_name(),
});
}
}
}
}
}
}

Some(results)
}

fn get_name(&self) -> String {
"iam".to_string()
}
}
4 changes: 4 additions & 0 deletions src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod s3_analyzer;
mod sg_analyzer;
mod sts_analyzer;
pub(crate) mod types;
mod iam_analyzer;

pub fn generate_analyzers(config: &SdkConfig) -> Vec<Box<dyn Analyzer>> {
let analyzers: Vec<Box<dyn Analyzer>> = vec![
Expand All @@ -34,6 +35,9 @@ pub fn generate_analyzers(config: &SdkConfig) -> Vec<Box<dyn Analyzer>> {
Box::new(ec2_snapshot_analyzer::EC2SnapshotAnalyzer {
config: config.clone(),
}),
Box::new(iam_analyzer::IamAnalyzer {
config: config.clone(),
})
];
analyzers
}

0 comments on commit 8489fe5

Please sign in to comment.