|
| 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