The AWS S3 Bucket Auditor is a Go-based command-line tool that performs a comprehensive security audit of your Amazon S3 buckets. It integrates with AWS Macie to check for sensitive data, providing intelligent insights while ensuring data privacy and security.
- π List Buckets: Displays all S3 buckets in your AWS account.
- π Public Access Check: Flags buckets that are publicly accessible.
- π Encryption Status: Indicates whether server-side encryption is enabled.
- π Versioning Status: Shows if versioning is enabled or disabled.
- π΅οΈ Sensitive Data Detection: Uses AWS Macie to identify buckets that may contain sensitive data.
- π Comprehensive Report: Generates a detailed audit report for security reviews.
While the AWS CLI is powerful, this tool simplifies and automates multiple security checks into a single, easy-to-use application:
- π€ Automated Multi-Check Auditing: Consolidates multiple AWS CLI commands into one automated process.
- π§ AI-Powered Insights: Integrates with AWS Macie for intelligent detection of sensitive data.
- π Simplified Output: Provides a clean, organized report that's easy to interpret.
- β‘ Concurrency for Speed: Uses Go's concurrency to perform checks faster than sequential AWS CLI commands.
- π€ User-Friendly: No need to remember complex AWS CLI commands or parameters.
- π οΈ Customizable: Open-source and written in Go, allowing for easy customization and extension.
- Go: Version 1.16 or higher installed on your system.
- AWS Account: An active AWS account with AWS Macie enabled.
- AWS Credentials: Configured AWS credentials with the necessary permissions.
- AWS Charges: Be aware that using AWS Macie may incur additional charges.
-
Clone the repository:
git clone https://github.com/yourusername/aws-s3-bucket-auditor.git
-
Navigate to the project directory:
cd aws-s3-bucket-auditor
-
Download dependencies:
go mod tidy
Ensure that your AWS credentials are properly configured. The AWS SDK for Go will look for credentials in the following order:
-
Environment variables:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_REGION
-
Shared Credentials File (~/.aws/credentials):
Configure your credentials using the AWS CLI or by manually editing the credentials file.
[default] aws_access_key_id = YOUR_ACCESS_KEY_ID aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
-
Shared Configuration File (~/.aws/config):
You can also set the default region in the configuration file.
[default] region = us-east-1
First of all make sure that Amazon Macie is enabled in your AWS account.
Ensure the S3 bucket used by Macie for storing findings has the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowMacieToStoreFindings",
"Effect": "Allow",
"Principal": {
"Service": "macie.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::findings-results/*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "YOUR_ACCOUNT_ID"
}
}
},
{
"Sid": "AllowMacieToUseGetBucketLocation",
"Effect": "Allow",
"Principal": {
"Service": "macie.amazonaws.com"
},
"Action": "s3:GetBucketLocation",
"Resource": "arn:aws:s3:::findings-results"
}
]
}
Ensure the KMS key used for encrypting Macie findings has the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowMacieToUseTheKey",
"Effect": "Allow",
"Principal": {
"Service": "macie.amazonaws.com"
},
"Action": [
"kms:GenerateDataKey",
"kms:Encrypt"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "YOUR_ACCOUNT_ID"
}
}
}
]
}
The tool requires the following AWS IAM permissions:
- S3: ListBuckets, GetBucketLocation, GetBucketAcl, GetBucketEncryption, GetBucketVersioning, GetPublicAccessBlock
- Macie: Permissions to initiate classification jobs and access findings
Build the application:
go build -o s3auditor main.go
Run the application:
./s3auditor
Sample output:
S3 Bucket Security Audit Report:
=====================================================================
Bucket Name : my-first-bucket
Region : us-east-1
Public Access : false
Encryption : AES256
Versioning : Enabled
Sensitive Data : false
---------------------------------------------------------------------
Bucket Name : public-bucket
Region : us-west-2
Public Access : true
Encryption : Not Enabled
Versioning : Disabled
Sensitive Data : true
---------------------------------------------------------------------
If you find this tool useful and would like to support further development, you can:
Your support is greatly appreciated!
Contributions are welcome! Please feel free to submit a pull request or open an issue.
This project is licensed under the MIT License - see the LICENSE file for details.
- π API Keys: Ensure your AWS credentials are securely stored and not hardcoded.
- π Compliance: Designed to help with compliance standards like GDPR and HIPAA by identifying buckets that may contain sensitive data.
- π° AWS Charges: Using AWS Macie may incur additional costs. Please refer to the AWS Macie Pricing page for details.
Feel free to customize and extend the tool:
- β Add More Checks: Incorporate additional security checks as needed.
- π Integrate Other Services: Connect with other AWS services like GuardDuty for enhanced security.
- π Improve Reporting: Enhance the output format or generate reports in different file formats.
- π€ AI-Powered Security: Integrates with AWS Macie to provide intelligent insights about sensitive data.
- π§ͺ Comprehensive Auditing: Can be extended to perform multiple security checks in a single run.
- β‘ Performance Optimized: Uses concurrency for efficient processing.
- π Open Source: Allows the community to contribute and improve the tool.
- π Educational Value: Serves as a practical example of integrating AWS services using Go.
- π₯οΈ CLI: Provides a user-friendly CLI for easy interaction. For geeky people like me, who prefer CLI over GUI.
- Additional screenshots:
To run only unit tests:
go test ./internal/... -v
Note: Integration tests can take 15-30 minutes to complete due to Macie classification jobs. Use the -short flag to skip long-running tests:
# Run with extended timeout
./tests/scripts/run_integration_tests.sh
# Skip long-running tests
go test ./test/integration/... -v -short
To run all tests:
# Run all tests (including integration tests)
go test ./... -v -timeout 30m
# Run all tests except integration tests
go test ./... -v -short
Note: Running all tests includes integration tests which:
- Require valid AWS credentials
- Can take 15-30 minutes to complete
- Will create and delete test resources in your AWS account
- May incur AWS costs (especially from Macie)