Skip to content

Commit daa931a

Browse files
committed
Initial commit: AWS Security Scanner v1.0
0 parents  commit daa931a

17 files changed

Lines changed: 1680 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Security Scanner CI
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: [3.8, 3.9, '3.10', '3.11']
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
29+
- name: Run scanner in mock mode
30+
run: |
31+
python scanner.py --mock --output json --report-file ci-test-report
32+
33+
- name: Verify report generated
34+
run: |
35+
if [ ! -f "ci-test-report.json" ]; then
36+
echo "Error: Report not generated"
37+
exit 1
38+
fi
39+
echo "Report successfully generated"
40+
41+
- name: Run tests (when available)
42+
run: |
43+
# Uncomment when tests are added
44+
# python -m pytest tests/ -v
45+
echo "Tests not yet implemented"
46+
47+
- name: Upload test report as artifact
48+
uses: actions/upload-artifact@v3
49+
with:
50+
name: test-report-python-${{ matrix.python-version }}
51+
path: ci-test-report.json
52+
53+
lint:
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v3
57+
58+
- name: Set up Python
59+
uses: actions/setup-python@v4
60+
with:
61+
python-version: '3.10'
62+
63+
- name: Install linting tools
64+
run: |
65+
python -m pip install --upgrade pip
66+
pip install flake8 black
67+
68+
- name: Check code style with black
69+
run: |
70+
black --check scanners/ scanner.py || true
71+
72+
- name: Lint with flake8
73+
run: |
74+
# Stop the build if there are Python syntax errors or undefined names
75+
flake8 scanners/ scanner.py --count --select=E9,F63,F7,F82 --show-source --statistics || true
76+
# Exit-zero treats all errors as warnings
77+
flake8 scanners/ scanner.py --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics || true

.gitignore

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
env/
8+
venv/
9+
ENV/
10+
build/
11+
develop-eggs/
12+
dist/
13+
downloads/
14+
eggs/
15+
.eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
wheels/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
# IDEs
27+
.vscode/
28+
.idea/
29+
*.swp
30+
*.swo
31+
*~
32+
33+
# OS
34+
.DS_Store
35+
Thumbs.db
36+
37+
# Reports
38+
*.html
39+
*.json
40+
security-report*
41+
42+
# AWS Credentials
43+
.aws/
44+
credentials
45+
config
46+
47+
# Test coverage
48+
.coverage
49+
htmlcov/
50+
.pytest_cache/

ARCHITECTURE.md

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# Project Architecture & Design
2+
3+
## Overview
4+
5+
AWS Security Scanner is a Python-based CLI tool designed to identify common security misconfigurations in AWS environments. The tool follows a modular architecture that allows easy extension with new security scanners.
6+
7+
## Architecture
8+
9+
```
10+
┌─────────────────────────────────────────────────────────────┐
11+
│ CLI Interface │
12+
│ (scanner.py) │
13+
│ - Command-line argument parsing │
14+
│ - Output formatting (Console, JSON, HTML) │
15+
│ - Report generation │
16+
└────────────────────┬────────────────────────────────────────┘
17+
18+
19+
┌─────────────────────────────────────────────────────────────┐
20+
│ Scanner Modules │
21+
│ (scanners/ package) │
22+
│ │
23+
│ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │
24+
│ │ S3Scanner │ │ EC2Scanner │ │ IAMScanner │ │
25+
│ │ │ │ (planned) │ │ (planned) │ │
26+
│ └───────────────┘ └───────────────┘ └───────────────┘ │
27+
│ │
28+
└────────────────────┬────────────────────────────────────────┘
29+
30+
31+
┌─────────────────────────────────────────────────────────────┐
32+
│ Data Layer │
33+
│ │
34+
│ ┌────────────────────┐ ┌────────────────────┐ │
35+
│ │ Mock Data │ │ AWS Boto3 SDK │ │
36+
│ │ (JSON files) │ │ (future impl) │ │
37+
│ └────────────────────┘ └────────────────────┘ │
38+
│ │
39+
└─────────────────────────────────────────────────────────────┘
40+
```
41+
42+
## Design Principles
43+
44+
### 1. Modularity
45+
Each service scanner (S3, EC2, IAM) is a separate module that:
46+
- Can be developed and tested independently
47+
- Follows a consistent interface pattern
48+
- Returns findings in a standard format
49+
50+
### 2. Abstraction
51+
The scanner supports both mock and real AWS data:
52+
- **Mock Mode**: Uses JSON files for testing without AWS credentials
53+
- **Real Mode**: Uses boto3 to query actual AWS resources (future)
54+
55+
### 3. Extensibility
56+
Adding a new scanner requires:
57+
1. Creating a new scanner class in `scanners/`
58+
2. Adding mock data in `mock_data/`
59+
3. Registering the scanner in `scanner.py`
60+
61+
### 4. Severity-Based Reporting
62+
Findings are categorized by severity:
63+
- **CRITICAL**: Immediate action required (e.g., public sensitive data)
64+
- **HIGH**: Significant security risk (e.g., missing encryption)
65+
- **MEDIUM**: Important but not urgent (e.g., versioning disabled)
66+
- **LOW**: Best practice recommendations (e.g., logging disabled)
67+
68+
## Core Components
69+
70+
### 1. Scanner Base Pattern
71+
72+
Each scanner follows this pattern:
73+
74+
```python
75+
class ServiceScanner:
76+
def __init__(self, mock_mode: bool = True):
77+
"""Initialize with mock or real mode"""
78+
79+
def scan(self) -> List[Dict[str, Any]]:
80+
"""Run all security checks, return findings"""
81+
82+
def _check_specific_issue(self, resource: Dict) -> None:
83+
"""Individual security check"""
84+
85+
def get_summary(self) -> Dict[str, int]:
86+
"""Get severity summary"""
87+
```
88+
89+
### 2. Finding Format
90+
91+
Standard finding structure:
92+
93+
```python
94+
{
95+
'service': 'S3', # AWS service
96+
'resource': 'bucket-name', # Resource identifier
97+
'severity': 'CRITICAL', # CRITICAL, HIGH, MEDIUM, LOW
98+
'issue': 'Public Access Enabled', # Short issue title
99+
'description': 'Detailed explanation', # Full description
100+
'remediation': 'CLI commands to fix' # Step-by-step fix
101+
}
102+
```
103+
104+
### 3. CLI Interface
105+
106+
Uses Click for command-line interface:
107+
- `--mock`: Enable mock mode (default: True)
108+
- `--services`: Specify services to scan
109+
- `--output`: Choose output format (console, json, html)
110+
- `--report-file`: Specify output filename
111+
112+
### 4. Report Generation
113+
114+
Three output formats:
115+
- **Console**: Colored, formatted terminal output
116+
- **JSON**: Machine-readable for automation
117+
- **HTML**: Professional, shareable reports
118+
119+
## Security Checks
120+
121+
### S3 Scanner
122+
123+
| Check | Severity Logic | Description |
124+
|-------|----------------|-------------|
125+
| Public Access | CRITICAL if sensitive data, LOW if tagged public | Checks ACLs for AllUsers grants |
126+
| Public Policy | Always CRITICAL | Checks bucket policies for wildcard principals |
127+
| Encryption | HIGH if sensitive keywords, MEDIUM otherwise | Checks default encryption status |
128+
| Versioning | MEDIUM if critical data, LOW otherwise | Checks if versioning enabled |
129+
| Logging | Always LOW | Checks if access logging enabled |
130+
131+
Sensitivity detection uses keywords: `financial`, `customer`, `personal`, `pii`, `records`, `backup`
132+
133+
## Future Enhancements
134+
135+
### Phase 2: EC2 Scanner
136+
- Security group rules (0.0.0.0/0 on sensitive ports)
137+
- Unencrypted EBS volumes
138+
- IMDSv1 usage detection
139+
- Public IP assignments
140+
141+
### Phase 3: IAM Scanner
142+
- Users without MFA
143+
- Overly permissive policies
144+
- Unused access keys (>90 days)
145+
- Root account usage
146+
147+
### Phase 4: Advanced Features
148+
- Auto-remediation execution (with confirmation)
149+
- Slack/email notifications
150+
- Dashboard for trend analysis
151+
- Integration with AWS Security Hub
152+
- Custom compliance frameworks (PCI, HIPAA, etc.)
153+
154+
## Testing Strategy
155+
156+
### Current State
157+
- Manual testing with mock data
158+
- Validated against 5 different S3 bucket scenarios
159+
160+
### Planned
161+
- Unit tests for each scanner module
162+
- Integration tests with real AWS (test account)
163+
- CI/CD pipeline for automated testing
164+
- Code coverage reporting
165+
166+
## Performance Considerations
167+
168+
### Current
169+
- Mock mode: Instant (no API calls)
170+
- Scan complexity: O(n) where n = number of resources
171+
172+
### Future Optimizations
173+
- Parallel scanning across services
174+
- Caching of AWS API responses
175+
- Rate limiting awareness
176+
- Batch API calls where possible
177+
178+
## Deployment Options
179+
180+
### Local Development
181+
```bash
182+
python scanner.py --mock
183+
```
184+
185+
### AWS Lambda
186+
- Package as Lambda function
187+
- Scheduled CloudWatch Events
188+
- Write findings to S3/DynamoDB
189+
- SNS notifications for critical findings
190+
191+
### CI/CD Integration
192+
```yaml
193+
# .gitlab-ci.yml or .github/workflows/
194+
- name: Security Scan
195+
run: |
196+
python scanner.py --no-mock --output json
197+
# Parse and fail pipeline if critical findings
198+
```
199+
200+
### Docker Container
201+
```dockerfile
202+
FROM python:3.11-slim
203+
COPY . /app
204+
WORKDIR /app
205+
RUN pip install -r requirements.txt
206+
ENTRYPOINT ["python", "scanner.py"]
207+
```
208+
209+
## Contributing Guidelines
210+
211+
When adding new features:
212+
213+
1. **New Scanner**: Follow the S3Scanner pattern
214+
2. **New Check**: Add to existing scanner, maintain severity logic
215+
3. **Mock Data**: Create realistic test scenarios
216+
4. **Documentation**: Update this file and README
217+
5. **Testing**: Add unit tests (when framework ready)
218+
219+
## Security & Permissions
220+
221+
### Required IAM Permissions (Real Mode)
222+
223+
```json
224+
{
225+
"Version": "2012-10-17",
226+
"Statement": [
227+
{
228+
"Effect": "Allow",
229+
"Action": [
230+
"s3:GetBucketPublicAccessBlock",
231+
"s3:GetBucketAcl",
232+
"s3:GetBucketPolicy",
233+
"s3:GetBucketVersioning",
234+
"s3:GetBucketLogging",
235+
"s3:GetEncryptionConfiguration",
236+
"s3:ListAllMyBuckets"
237+
],
238+
"Resource": "*"
239+
}
240+
]
241+
}
242+
```
243+
244+
### Best Practices
245+
- Never commit AWS credentials
246+
- Use IAM roles when running in AWS
247+
- Rotate access keys regularly
248+
- Use read-only permissions
249+
- Enable AWS CloudTrail for audit logging
250+
251+
## License
252+
253+
MIT License - see LICENSE file for details
254+
255+
## Contact
256+
257+
For questions or contributions:
258+
- GitHub Issues: [Report bugs or request features]
259+
- Pull Requests: [Contribute code]
260+
- Email: [Your contact]
261+
262+
---
263+
264+
**Built with ❤️ by Twinkle Kamdar**

0 commit comments

Comments
 (0)