-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into enhance-ci-workflow
- Loading branch information
Showing
13 changed files
with
186 additions
and
198 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
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,53 +1,61 @@ | ||
|
||
use aws_types::sdk_config::SdkConfig; | ||
use crate::analyzer::analyzer_trait; | ||
use crate::analyzer::analyzer_trait::Analyzer; | ||
use crate::analyzer::types::AnalysisResults; | ||
use async_trait::async_trait; | ||
use aws_sdk_ec2; | ||
use aws_sdk_ec2::types::{Filter, PermissionGroup, SnapshotAttributeName}; | ||
use aws_types::sdk_config::SdkConfig; | ||
|
||
pub struct EC2SnapshotAnalyzer { | ||
pub config: SdkConfig | ||
pub config: SdkConfig, | ||
} | ||
|
||
#[async_trait] | ||
impl analyzer_trait::Analyzer for EC2SnapshotAnalyzer { | ||
async fn run(&self) -> Option<Vec<AnalysisResults>> { | ||
let mut results = Vec::new(); | ||
let ec2 = aws_sdk_ec2::Client::new(&self.config); | ||
|
||
// Filter to include only your snapshots if needed | ||
let filter = Filter::builder().set_name(Some("owner-id".to_string())).build(); | ||
|
||
if let Ok(snapshots) = ec2.describe_snapshots().set_filters(Some(vec![filter])).send().await { | ||
for snapshot in snapshots.snapshots.unwrap_or_default() { | ||
let snapshot_id = snapshot.snapshot_id.clone().unwrap(); | ||
|
||
// Check if the snapshot is public | ||
let attributes = ec2.describe_snapshot_attribute() | ||
.attribute(SnapshotAttributeName::CreateVolumePermission) | ||
.snapshot_id(&snapshot_id) | ||
.send().await; | ||
|
||
if let Ok(attrs) = attributes { | ||
for perm in attrs.create_volume_permissions.unwrap_or_default() { | ||
if perm.group == Some(PermissionGroup::All) { | ||
results.push(AnalysisResults { | ||
async fn run(&self) -> Option<Vec<AnalysisResults>> { | ||
let mut results = Vec::new(); | ||
let ec2 = aws_sdk_ec2::Client::new(&self.config); | ||
|
||
// Filter to include only your snapshots if needed | ||
let filter = Filter::builder() | ||
.set_name(Some("owner-id".to_string())) | ||
.build(); | ||
|
||
if let Ok(snapshots) = ec2 | ||
.describe_snapshots() | ||
.set_filters(Some(vec![filter])) | ||
.send() | ||
.await | ||
{ | ||
for snapshot in snapshots.snapshots.unwrap_or_default() { | ||
let snapshot_id = snapshot.snapshot_id.clone().unwrap(); | ||
|
||
// Check if the snapshot is public | ||
let attributes = ec2 | ||
.describe_snapshot_attribute() | ||
.attribute(SnapshotAttributeName::CreateVolumePermission) | ||
.snapshot_id(&snapshot_id) | ||
.send() | ||
.await; | ||
|
||
if let Ok(attrs) = attributes { | ||
for perm in attrs.create_volume_permissions.unwrap_or_default() { | ||
if perm.group == Some(PermissionGroup::All) { | ||
results.push(AnalysisResults { | ||
message: format!("Public EC2 Snapshot: {}", snapshot_id), | ||
advice: "Consider making this snapshot private if it contains sensitive data.".to_string(), | ||
analyzer_name: self.get_name(), | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Some(results) | ||
} | ||
|
||
fn get_name(&self) -> String { | ||
"ec2_snapshot".to_string() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Some(results) | ||
} | ||
|
||
fn get_name(&self) -> String { | ||
"ec2_snapshot".to_string() | ||
} | ||
} |
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,41 +1,40 @@ | ||
|
||
use aws_types::sdk_config::SdkConfig; | ||
use crate::analyzer::analyzer_trait; | ||
use crate::analyzer::analyzer_trait::Analyzer; | ||
use crate::analyzer::types::AnalysisResults; | ||
use async_trait::async_trait; | ||
use aws_sdk_ec2; | ||
|
||
use aws_types::sdk_config::SdkConfig; | ||
|
||
pub struct EipAnalyzer { | ||
pub config: SdkConfig | ||
pub config: SdkConfig, | ||
} | ||
#[async_trait] | ||
impl analyzer_trait::Analyzer for EipAnalyzer { | ||
async fn run(&self) -> Option<Vec<AnalysisResults>> { | ||
let mut results = Vec::new(); | ||
let ec2 = aws_sdk_ec2::Client::new(&self.config); | ||
async fn run(&self) -> Option<Vec<AnalysisResults>> { | ||
let mut results = Vec::new(); | ||
let ec2 = aws_sdk_ec2::Client::new(&self.config); | ||
|
||
if let Ok(addresses) = ec2.describe_addresses().send().await { | ||
for address in addresses.addresses.unwrap_or_default() { | ||
// Check if the Elastic IP is not associated | ||
if address.association_id.is_none() { | ||
results.push(AnalysisResults { | ||
message: format!( | ||
"Unused Elastic IP: {}", | ||
address.public_ip.clone().unwrap() | ||
), | ||
advice: "Consider releasing unused Elastic IPs to avoid charges.".to_string(), | ||
analyzer_name: self.get_name(), | ||
}); | ||
} | ||
} | ||
} | ||
if let Ok(addresses) = ec2.describe_addresses().send().await { | ||
for address in addresses.addresses.unwrap_or_default() { | ||
// Check if the Elastic IP is not associated | ||
if address.association_id.is_none() { | ||
results.push(AnalysisResults { | ||
message: format!( | ||
"Unused Elastic IP: {}", | ||
address.public_ip.clone().unwrap() | ||
), | ||
advice: "Consider releasing unused Elastic IPs to avoid charges." | ||
.to_string(), | ||
analyzer_name: self.get_name(), | ||
}); | ||
} | ||
} | ||
} | ||
|
||
Some(results) | ||
} | ||
Some(results) | ||
} | ||
|
||
fn get_name(&self) -> String { | ||
"eip".to_string() | ||
} | ||
} | ||
fn get_name(&self) -> String { | ||
"eip".to_string() | ||
} | ||
} |
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
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
Oops, something went wrong.