lambda-security-scanner 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lambda_security_scanner-1.0.0/LICENSE +21 -0
- lambda_security_scanner-1.0.0/PKG-INFO +497 -0
- lambda_security_scanner-1.0.0/README.md +458 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/__init__.py +11 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/checks/__init__.py +0 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/checks/access_control.py +636 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/checks/base.py +104 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/checks/code_security.py +212 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/checks/function_config.py +454 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/checks/logging_monitoring.py +175 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/checks/network_security.py +207 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/cli.py +394 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/compliance.py +203 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/html_reporter.py +214 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/scanner.py +1154 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/templates/report.html +397 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner/utils.py +191 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner.egg-info/PKG-INFO +497 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner.egg-info/SOURCES.txt +32 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner.egg-info/dependency_links.txt +1 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner.egg-info/entry_points.txt +2 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner.egg-info/requires.txt +13 -0
- lambda_security_scanner-1.0.0/lambda_security_scanner.egg-info/top_level.txt +1 -0
- lambda_security_scanner-1.0.0/pyproject.toml +81 -0
- lambda_security_scanner-1.0.0/setup.cfg +4 -0
- lambda_security_scanner-1.0.0/tests/test_access_control.py +426 -0
- lambda_security_scanner-1.0.0/tests/test_cli.py +154 -0
- lambda_security_scanner-1.0.0/tests/test_code_security.py +209 -0
- lambda_security_scanner-1.0.0/tests/test_compliance.py +240 -0
- lambda_security_scanner-1.0.0/tests/test_function_config.py +504 -0
- lambda_security_scanner-1.0.0/tests/test_logging_monitoring.py +173 -0
- lambda_security_scanner-1.0.0/tests/test_network_security.py +263 -0
- lambda_security_scanner-1.0.0/tests/test_scanner.py +1191 -0
- lambda_security_scanner-1.0.0/tests/test_scoring.py +227 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Toc Consulting
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lambda-security-scanner
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A comprehensive AWS Lambda security scanner with multi-framework compliance mapping
|
|
5
|
+
Author-email: Toc Consulting <tarek@tocconsulting.fr>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/TocConsulting/lambda-security-scanner
|
|
8
|
+
Project-URL: Documentation, https://github.com/TocConsulting/lambda-security-scanner#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/TocConsulting/lambda-security-scanner
|
|
10
|
+
Project-URL: Issues, https://github.com/TocConsulting/lambda-security-scanner/issues
|
|
11
|
+
Keywords: aws,lambda,serverless,security,compliance,scanner,cloud,audit
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Security
|
|
16
|
+
Classifier: Topic :: System :: Systems Administration
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: boto3>=1.26.0
|
|
27
|
+
Requires-Dist: botocore>=1.29.0
|
|
28
|
+
Requires-Dist: rich>=13.0.0
|
|
29
|
+
Requires-Dist: click>=8.1.0
|
|
30
|
+
Requires-Dist: jinja2>=3.1.6
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=7.2.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<img src="https://raw.githubusercontent.com/TocConsulting/lambda-security-scanner/main/assets/lambda-security-scanner-logo.png" alt="Lambda Security Scanner" style="max-width: 100%; height: auto;">
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
<p align="center">
|
|
45
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-brightgreen.svg" alt="License: MIT"></a>
|
|
46
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="Python"></a>
|
|
47
|
+
<a href="https://aws.amazon.com/lambda/"><img src="https://img.shields.io/badge/AWS-Lambda-orange.svg" alt="AWS"></a>
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
A comprehensive AWS Lambda security scanner with 19 security checks across 5 categories and compliance mapping for 10 frameworks (81 controls). Features multi-threaded scanning, secret detection in environment variables, and interactive HTML dashboards.
|
|
51
|
+
|
|
52
|
+
## Key Features
|
|
53
|
+
|
|
54
|
+
### **Comprehensive Security Analysis**
|
|
55
|
+
- **Function Configuration**: Deprecated runtime detection, timeout tuning, environment variable secret scanning, ephemeral storage, external layers, X-Ray tracing, dead letter queues
|
|
56
|
+
- **Access Control**: Resource policy public access, function URL authentication, CORS wildcard origins, overly permissive execution roles, shared role detection
|
|
57
|
+
- **Network Security**: VPC configuration, multi-AZ deployment, unrestricted security group egress
|
|
58
|
+
- **Logging & Monitoring**: CloudWatch log group validation, log retention policies, reserved concurrency
|
|
59
|
+
- **Code & Supply Chain**: Code signing configuration, event source mapping failure destinations
|
|
60
|
+
|
|
61
|
+
### **Compliance Frameworks**
|
|
62
|
+
- **AWS Foundational Security Best Practices (FSBP)**: 5 Lambda-specific controls
|
|
63
|
+
- **CIS AWS Compute Services Benchmark**: 8 controls (scanner-defined IDs mapped to the benchmark's Lambda guidance; see note below)
|
|
64
|
+
- **PCI DSS v4.0.1**: 8 controls
|
|
65
|
+
- **HIPAA Security Rule**: 9 controls
|
|
66
|
+
- **SOC 2**: 11 controls
|
|
67
|
+
- **ISO 27001:2022**: 11 controls
|
|
68
|
+
- **ISO 27017:2015**: 4 cloud security controls
|
|
69
|
+
- **ISO 27018:2019**: 5 PII protection controls
|
|
70
|
+
- **GDPR (EU) 2016/679**: 8 controls
|
|
71
|
+
- **NIST SP 800-53 Rev5**: 12 controls
|
|
72
|
+
|
|
73
|
+
### **Performance & Usability**
|
|
74
|
+
- **Multi-threaded Scanning**: Parallel function analysis with ThreadPoolExecutor
|
|
75
|
+
- **Rich Console Output**: Progress bars, colored output, and formatted tables
|
|
76
|
+
- **Multiple Report Formats**: JSON, CSV, HTML, and compliance-specific reports
|
|
77
|
+
- **Beautiful HTML Reports**: Interactive dashboard with Chart.js visualizations
|
|
78
|
+
- **Flexible Targeting**: Scan all functions, specific names, or exclude by name
|
|
79
|
+
|
|
80
|
+
### **Production Ready**
|
|
81
|
+
- **Modular Architecture**: Facade pattern with 5 dedicated checker modules
|
|
82
|
+
- **Thread-safe Sessions**: Thread-local boto3 session management
|
|
83
|
+
- **Graceful Degradation**: AccessDenied errors don't crash scans
|
|
84
|
+
- **Mutual Exclusion Scoring**: Overlapping check variants use highest deduction only
|
|
85
|
+
|
|
86
|
+
## Quick Start
|
|
87
|
+
|
|
88
|
+
### Installation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Install from source
|
|
92
|
+
git clone https://github.com/TocConsulting/lambda-security-scanner.git
|
|
93
|
+
cd lambda-security-scanner
|
|
94
|
+
pip install .
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Docker Installation
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Build from source
|
|
101
|
+
docker build -t lambda-security-scanner .
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Basic Usage
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Scan all Lambda functions
|
|
108
|
+
lambda-security-scanner security
|
|
109
|
+
|
|
110
|
+
# Scan with specific AWS profile
|
|
111
|
+
lambda-security-scanner security --profile production
|
|
112
|
+
|
|
113
|
+
# Scan specific functions only
|
|
114
|
+
lambda-security-scanner security -n my-function -n other-function
|
|
115
|
+
|
|
116
|
+
# Exclude specific functions
|
|
117
|
+
lambda-security-scanner security --exclude-function test-func
|
|
118
|
+
|
|
119
|
+
# Compliance report only
|
|
120
|
+
lambda-security-scanner security --compliance-only
|
|
121
|
+
|
|
122
|
+
# JSON report only, quiet mode (for CI/CD)
|
|
123
|
+
lambda-security-scanner security -f json -q
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Commands
|
|
127
|
+
|
|
128
|
+
### Security Command
|
|
129
|
+
|
|
130
|
+
Scan Lambda functions for security vulnerabilities and compliance issues.
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
lambda-security-scanner security [OPTIONS]
|
|
134
|
+
|
|
135
|
+
Options:
|
|
136
|
+
-n, --function-name TEXT Specific function name(s) to scan (multiple)
|
|
137
|
+
--exclude-function TEXT Function name(s) to exclude
|
|
138
|
+
--compliance-only Generate compliance report only
|
|
139
|
+
-r, --region TEXT AWS region (default: us-east-1)
|
|
140
|
+
-p, --profile TEXT AWS profile name
|
|
141
|
+
-o, --output-dir TEXT Output directory (default: ./output)
|
|
142
|
+
-f, --output-format TEXT Report format: json, csv, html, all (default: all)
|
|
143
|
+
-w, --max-workers INTEGER Worker threads (default: 5)
|
|
144
|
+
-q, --quiet Suppress console output except errors
|
|
145
|
+
-d, --debug Enable debug logging
|
|
146
|
+
-h, --help Show help
|
|
147
|
+
|
|
148
|
+
# Top-level options (before the 'security' command):
|
|
149
|
+
# lambda-security-scanner --version
|
|
150
|
+
# lambda-security-scanner --help
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
**Examples:**
|
|
154
|
+
```bash
|
|
155
|
+
# Scan all functions with default settings
|
|
156
|
+
lambda-security-scanner security
|
|
157
|
+
|
|
158
|
+
# Scan specific functions in a different region
|
|
159
|
+
lambda-security-scanner security -n my-api -n my-worker -r eu-west-1
|
|
160
|
+
|
|
161
|
+
# Fast compliance-only scan with HTML output
|
|
162
|
+
lambda-security-scanner security --compliance-only -f html -p production
|
|
163
|
+
|
|
164
|
+
# High-performance scan with more threads
|
|
165
|
+
lambda-security-scanner security -w 20 -r eu-west-1
|
|
166
|
+
|
|
167
|
+
# JSON report only, quiet mode (for CI/CD)
|
|
168
|
+
lambda-security-scanner security -f json -q
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Security Checks
|
|
172
|
+
|
|
173
|
+
### 19 Checks Across 5 Categories
|
|
174
|
+
|
|
175
|
+
| ID | Check | Severity | Category |
|
|
176
|
+
|-----|------------------------------------------|-------------------|-----------------------|
|
|
177
|
+
| A.1 | Deprecated/EOL runtime | HIGH/CRITICAL/LOW | Function Config |
|
|
178
|
+
| A.2 | Maximum timeout (900s) | LOW | Function Config |
|
|
179
|
+
| A.3 | Environment variable secrets | CRITICAL/HIGH | Function Config |
|
|
180
|
+
| A.4 | Large ephemeral storage | LOW | Function Config |
|
|
181
|
+
| A.5 | External Lambda layers | MEDIUM | Function Config |
|
|
182
|
+
| A.6 | X-Ray tracing disabled | LOW | Function Config |
|
|
183
|
+
| A.7 | No dead letter queue | LOW | Function Config |
|
|
184
|
+
| B.1 | Resource policy public access | CRITICAL | Access Control |
|
|
185
|
+
| B.2 | Function URL no authentication | CRITICAL | Access Control |
|
|
186
|
+
| B.3 | Function URL CORS allows all origins | HIGH | Access Control |
|
|
187
|
+
| B.4 | Overly permissive execution role | CRITICAL/HIGH | Access Control |
|
|
188
|
+
| B.5 | Shared execution role | HIGH | Access Control |
|
|
189
|
+
| C.1 | No VPC configuration | LOW | Network Security |
|
|
190
|
+
| C.2 | VPC single AZ | MEDIUM | Network Security |
|
|
191
|
+
| C.3 | Unrestricted SG egress | MEDIUM | Network Security |
|
|
192
|
+
| D.1 | Log group missing/no retention | MEDIUM | Logging & Monitoring |
|
|
193
|
+
| D.2 | No reserved concurrency | LOW | Logging & Monitoring |
|
|
194
|
+
| E.1 | No code signing | MEDIUM/LOW | Code & Supply Chain |
|
|
195
|
+
| E.2 | ESM without failure destination | MEDIUM | Code & Supply Chain |
|
|
196
|
+
|
|
197
|
+
### Secret Detection in Environment Variables (A.3)
|
|
198
|
+
|
|
199
|
+
The scanner decodes and scans Lambda environment variables for exposed secrets:
|
|
200
|
+
|
|
201
|
+
| Pattern | Examples |
|
|
202
|
+
|---------|----------|
|
|
203
|
+
| AWS Access Keys | `AKIA...`, `ASIA...` |
|
|
204
|
+
| AWS Secret Keys | `aws_secret_access_key=...` |
|
|
205
|
+
| Passwords | `PASSWORD=`, `DB_PASSWORD=`, `SECRET_KEY=` |
|
|
206
|
+
| Private Keys | `-----BEGIN PRIVATE KEY-----` |
|
|
207
|
+
| GitHub Tokens | `ghp_...`, `gho_...`, `ghs_...` |
|
|
208
|
+
| API Keys | `api_key=`, `api_token=`, `AUTH_TOKEN=` |
|
|
209
|
+
| Connection Strings | `postgres://user:pass@host/db` |
|
|
210
|
+
| SaaS Tokens | Slack, Stripe (`sk_live_`), Twilio, SendGrid |
|
|
211
|
+
|
|
212
|
+
**Safe references are not flagged.** A secret-named variable whose value is a managed-secret reference (a Secrets Manager / SSM / KMS ARN, an SSM parameter path like `/app/db/pwd`, or a CloudFormation `{{resolve:...}}` dynamic reference) is the AWS-recommended pattern and is treated as clean, not as a leaked secret. Trivial config values (booleans, ports, environment names) are likewise ignored.
|
|
213
|
+
|
|
214
|
+
## Compliance Frameworks
|
|
215
|
+
|
|
216
|
+
| Framework | Controls | Focus |
|
|
217
|
+
|-----------|----------|-------|
|
|
218
|
+
| AWS-FSBP | 5 | Lambda-specific Security Hub controls |
|
|
219
|
+
| CIS | 8 | Compute Services Benchmark |
|
|
220
|
+
| PCI DSS v4.0.1 | 8 | Payment card data protection |
|
|
221
|
+
| HIPAA | 9 | Healthcare data security |
|
|
222
|
+
| SOC 2 | 11 | Service organization controls |
|
|
223
|
+
| ISO 27001:2022 | 11 | Information security management |
|
|
224
|
+
| ISO 27017:2015 | 4 | Cloud security controls |
|
|
225
|
+
| ISO 27018:2019 | 5 | PII protection in cloud |
|
|
226
|
+
| GDPR | 8 | EU data protection regulation |
|
|
227
|
+
| NIST 800-53 Rev5 | 12 | Federal security controls |
|
|
228
|
+
|
|
229
|
+
> **Note on control IDs:** Most frameworks use their official citations (e.g. HIPAA `164.312(a)(1)`, ISO 27001 `A.5.15`, SOC 2 `CC6.1`, NIST `AC-3`). The **CIS** entries map to the real **CIS AWS Compute Services Benchmark** Lambda guidance, but the `CIS-Lambda.N` identifiers are this scanner's own labels, not the benchmark's official recommendation numbers (which are section `5.x`). They are an alignment aid, not verbatim CIS control numbers.
|
|
230
|
+
|
|
231
|
+
## Docker Usage
|
|
232
|
+
|
|
233
|
+
### Basic Docker Commands
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# Show help
|
|
237
|
+
docker run --rm lambda-security-scanner --help
|
|
238
|
+
|
|
239
|
+
# Show security command help
|
|
240
|
+
docker run --rm lambda-security-scanner security --help
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Security Scanning with Docker
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Scan using mounted AWS credentials
|
|
247
|
+
docker run --rm \
|
|
248
|
+
-v ~/.aws:/root/.aws:ro \
|
|
249
|
+
-v $(pwd)/output:/app/output \
|
|
250
|
+
lambda-security-scanner security
|
|
251
|
+
|
|
252
|
+
# Scan with specific AWS profile
|
|
253
|
+
docker run --rm \
|
|
254
|
+
-v ~/.aws:/root/.aws:ro \
|
|
255
|
+
-v $(pwd)/output:/app/output \
|
|
256
|
+
lambda-security-scanner security --profile production
|
|
257
|
+
|
|
258
|
+
# Scan specific functions
|
|
259
|
+
docker run --rm \
|
|
260
|
+
-v ~/.aws:/root/.aws:ro \
|
|
261
|
+
-v $(pwd)/output:/app/output \
|
|
262
|
+
lambda-security-scanner security -n my-function
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Using Environment Variables for AWS Credentials
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
docker run --rm \
|
|
269
|
+
-e AWS_ACCESS_KEY_ID \
|
|
270
|
+
-e AWS_SECRET_ACCESS_KEY \
|
|
271
|
+
-e AWS_DEFAULT_REGION=us-east-1 \
|
|
272
|
+
-v $(pwd)/output:/app/output \
|
|
273
|
+
lambda-security-scanner security
|
|
274
|
+
|
|
275
|
+
# With session token (for temporary credentials/assumed roles)
|
|
276
|
+
docker run --rm \
|
|
277
|
+
-e AWS_ACCESS_KEY_ID \
|
|
278
|
+
-e AWS_SECRET_ACCESS_KEY \
|
|
279
|
+
-e AWS_SESSION_TOKEN \
|
|
280
|
+
-e AWS_DEFAULT_REGION=us-east-1 \
|
|
281
|
+
-v $(pwd)/output:/app/output \
|
|
282
|
+
lambda-security-scanner security
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Docker Volume Mounts
|
|
286
|
+
|
|
287
|
+
| Mount | Purpose |
|
|
288
|
+
|-------|---------|
|
|
289
|
+
| `-v ~/.aws:/root/.aws:ro` | Mount AWS credentials (read-only) |
|
|
290
|
+
| `-v $(pwd)/output:/app/output` | Save reports to local directory |
|
|
291
|
+
|
|
292
|
+
## Prerequisites
|
|
293
|
+
|
|
294
|
+
### Python Requirements
|
|
295
|
+
- Python 3.10 or higher
|
|
296
|
+
- Required packages (installed automatically):
|
|
297
|
+
- `boto3>=1.26.0`
|
|
298
|
+
- `botocore>=1.29.0`
|
|
299
|
+
- `rich>=13.0.0`
|
|
300
|
+
- `click>=8.1.0`
|
|
301
|
+
- `jinja2>=3.1.0`
|
|
302
|
+
|
|
303
|
+
### AWS Requirements
|
|
304
|
+
- AWS credentials configured (via AWS CLI, environment variables, or IAM roles)
|
|
305
|
+
- Required permissions:
|
|
306
|
+
|
|
307
|
+
```json
|
|
308
|
+
{
|
|
309
|
+
"Version": "2012-10-17",
|
|
310
|
+
"Statement": [{
|
|
311
|
+
"Effect": "Allow",
|
|
312
|
+
"Action": [
|
|
313
|
+
"lambda:ListFunctions",
|
|
314
|
+
"lambda:GetFunctionConfiguration",
|
|
315
|
+
"lambda:GetPolicy",
|
|
316
|
+
"lambda:GetFunctionUrlConfig",
|
|
317
|
+
"lambda:GetFunctionCodeSigningConfig",
|
|
318
|
+
"lambda:GetCodeSigningConfig",
|
|
319
|
+
"lambda:GetFunctionConcurrency",
|
|
320
|
+
"lambda:ListEventSourceMappings",
|
|
321
|
+
"iam:ListAttachedRolePolicies",
|
|
322
|
+
"iam:GetPolicy",
|
|
323
|
+
"iam:GetPolicyVersion",
|
|
324
|
+
"iam:ListRolePolicies",
|
|
325
|
+
"iam:GetRolePolicy",
|
|
326
|
+
"ec2:DescribeSubnets",
|
|
327
|
+
"ec2:DescribeSecurityGroups",
|
|
328
|
+
"logs:DescribeLogGroups",
|
|
329
|
+
"sts:GetCallerIdentity"
|
|
330
|
+
],
|
|
331
|
+
"Resource": "*"
|
|
332
|
+
}]
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Security Scoring
|
|
337
|
+
|
|
338
|
+
Each function receives a security score (0-100) starting at **100 points**:
|
|
339
|
+
|
|
340
|
+
| Check | Condition | Deduction | Severity |
|
|
341
|
+
|-------|-----------|-----------|----------|
|
|
342
|
+
| B.1 | Resource policy allows public access | -25 | CRITICAL |
|
|
343
|
+
| B.2 | Function URL AuthType NONE | -25 | CRITICAL |
|
|
344
|
+
| A.3 | Env var secrets, no KMS (mutually excl.) | -20 | CRITICAL |
|
|
345
|
+
| B.4 | Admin-equivalent access (Administrator/PowerUser/IAMFull or `*`) | -20 | CRITICAL |
|
|
346
|
+
| A.1 | Runtime blocked | -15 | HIGH |
|
|
347
|
+
| A.1 | Runtime deprecated | -10 | HIGH |
|
|
348
|
+
| B.3 | CORS allows all origins | -10 | HIGH |
|
|
349
|
+
| B.4 | Service-level wildcard actions (e.g. `s3:*`) | -10 | HIGH |
|
|
350
|
+
| B.4 | Privilege escalation permissions | -10 | HIGH |
|
|
351
|
+
| B.5 | Shared execution role | -10 | HIGH |
|
|
352
|
+
| A.3 | Env var secrets, has KMS (mutually excl.) | -10 | HIGH |
|
|
353
|
+
| C.2 | VPC single AZ | -5 | MEDIUM |
|
|
354
|
+
| C.3 | Unrestricted SG egress | -5 | MEDIUM |
|
|
355
|
+
| D.1 | Log group missing or no retention | -5 | MEDIUM |
|
|
356
|
+
| A.6 | X-Ray tracing disabled | -2 | LOW |
|
|
357
|
+
| A.7 | No dead letter queue | -2 | LOW |
|
|
358
|
+
| D.2 | No reserved concurrency | -2 | LOW |
|
|
359
|
+
| E.1 | No code signing config | -5 | MEDIUM |
|
|
360
|
+
| E.2 | ESM without failure destination | -5 | MEDIUM |
|
|
361
|
+
| A.5 | External Lambda layers | -3 | MEDIUM |
|
|
362
|
+
| C.1 | No VPC configuration | -3 | LOW |
|
|
363
|
+
| A.1 | Runtime near EOL | -3 | LOW |
|
|
364
|
+
| E.1 | Code signing policy Warn (not Enforce) | -3 | LOW |
|
|
365
|
+
| A.2 | Maximum timeout (900s) | -2 | LOW |
|
|
366
|
+
| A.4 | Large ephemeral storage | -2 | LOW |
|
|
367
|
+
|
|
368
|
+
**Mutual exclusion rules:**
|
|
369
|
+
- A.1: Only the highest-severity runtime deduction applies (blocked > deprecated > near_eol)
|
|
370
|
+
- A.3: Only one of the two variants applies (no KMS > has KMS)
|
|
371
|
+
- E.1: Only one of the two variants applies (no config > Warn policy)
|
|
372
|
+
|
|
373
|
+
**Formula**: `Score = max(0, 100 - total_deductions)`
|
|
374
|
+
|
|
375
|
+
### Score Interpretation
|
|
376
|
+
|
|
377
|
+
| Score Range | Level | Action |
|
|
378
|
+
|-------------|-------|--------|
|
|
379
|
+
| 90-100 | Excellent | Maintain current posture |
|
|
380
|
+
| 70-89 | Good | Address minor gaps |
|
|
381
|
+
| 50-69 | Needs Improvement | Fix medium-priority issues |
|
|
382
|
+
| 0-49 | Poor | Immediate action required |
|
|
383
|
+
|
|
384
|
+
## Output Files
|
|
385
|
+
|
|
386
|
+
The scanner generates reports in the specified output directory:
|
|
387
|
+
|
|
388
|
+
### JSON Report (`lambda_scan_region_timestamp.json`)
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"summary": {
|
|
392
|
+
"scan_time": "2026-03-11T10:30:45",
|
|
393
|
+
"region": "us-east-1",
|
|
394
|
+
"account_id": "123456789012",
|
|
395
|
+
"total_functions": 25,
|
|
396
|
+
"average_security_score": 82.3
|
|
397
|
+
},
|
|
398
|
+
"results": [...]
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### CSV Report (`lambda_scan_region_timestamp.csv`)
|
|
403
|
+
Spreadsheet-friendly format with all key metrics and compliance status.
|
|
404
|
+
|
|
405
|
+
### HTML Report (`lambda_scan_region_timestamp.html`)
|
|
406
|
+
Interactive dashboard with:
|
|
407
|
+
- **Executive Summary**: Key metrics and risk indicators
|
|
408
|
+
- **Score Distribution**: Bar chart of function security scores
|
|
409
|
+
- **Compliance Overview**: Bar chart across all 10 frameworks
|
|
410
|
+
- **Severity Breakdown**: Doughnut chart of findings by severity
|
|
411
|
+
- **Function Details**: Sortable table with score bars
|
|
412
|
+
- **Critical Findings**: Table of high/critical severity issues
|
|
413
|
+
|
|
414
|
+
### Compliance Report (`lambda_compliance_region_timestamp.json`)
|
|
415
|
+
Per-function compliance evaluation across all 10 frameworks with passed/failed control details.
|
|
416
|
+
|
|
417
|
+
## Modular Architecture
|
|
418
|
+
|
|
419
|
+
```
|
|
420
|
+
lambda_security_scanner/
|
|
421
|
+
├── scanner.py # Main scanner orchestration (facade pattern)
|
|
422
|
+
├── cli.py # Click CLI interface
|
|
423
|
+
├── compliance.py # 81 controls across 10 frameworks
|
|
424
|
+
├── html_reporter.py # Jinja2 HTML report generation
|
|
425
|
+
├── utils.py # Logging, scoring, formatting
|
|
426
|
+
├── checks/ # Security check modules
|
|
427
|
+
│ ├── base.py # BaseChecker (session factory, error handling)
|
|
428
|
+
│ ├── function_config.py # A.1-A.7: Runtime, secrets, layers, tracing
|
|
429
|
+
│ ├── access_control.py # B.1-B.5: Policies, URLs, roles
|
|
430
|
+
│ ├── network_security.py # C.1-C.3: VPC, AZ, security groups
|
|
431
|
+
│ ├── logging_monitoring.py # D.1-D.2: Log groups, concurrency
|
|
432
|
+
│ └── code_security.py # E.1-E.2: Code signing, ESM
|
|
433
|
+
└── templates/
|
|
434
|
+
└── report.html # Interactive HTML dashboard
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
## Development
|
|
438
|
+
|
|
439
|
+
### Setting Up Development Environment
|
|
440
|
+
|
|
441
|
+
```bash
|
|
442
|
+
git clone https://github.com/TocConsulting/lambda-security-scanner.git
|
|
443
|
+
cd lambda-security-scanner
|
|
444
|
+
|
|
445
|
+
python -m venv venv
|
|
446
|
+
source venv/bin/activate
|
|
447
|
+
|
|
448
|
+
pip install -e ".[dev]"
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
## Testing
|
|
452
|
+
|
|
453
|
+
```bash
|
|
454
|
+
# Install development dependencies
|
|
455
|
+
pip install -e ".[dev]"
|
|
456
|
+
|
|
457
|
+
# Run all tests
|
|
458
|
+
python -m pytest tests/ -v
|
|
459
|
+
|
|
460
|
+
# Run specific test file
|
|
461
|
+
python -m pytest tests/test_compliance.py -v
|
|
462
|
+
|
|
463
|
+
# Run with coverage
|
|
464
|
+
python -m pytest tests/ --cov=lambda_security_scanner --cov-report=html
|
|
465
|
+
|
|
466
|
+
# Code formatting
|
|
467
|
+
black lambda_security_scanner/ tests/
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
## Support & Contributing
|
|
471
|
+
|
|
472
|
+
### Getting Help
|
|
473
|
+
- **Documentation**: Check this README and inline help (`--help`)
|
|
474
|
+
- **Issues**: Report bugs via [GitHub Issues](https://github.com/TocConsulting/lambda-security-scanner/issues)
|
|
475
|
+
|
|
476
|
+
### Contributing
|
|
477
|
+
We welcome contributions! Please:
|
|
478
|
+
1. Fork the repository
|
|
479
|
+
2. Create a feature branch
|
|
480
|
+
3. Add tests for new functionality
|
|
481
|
+
4. Submit a pull request
|
|
482
|
+
|
|
483
|
+
## License
|
|
484
|
+
|
|
485
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
486
|
+
|
|
487
|
+
## Acknowledgments
|
|
488
|
+
|
|
489
|
+
- **AWS Security Best Practices**: Based on official AWS security recommendations
|
|
490
|
+
- **CIS Benchmarks**: Maps findings to the CIS AWS Compute Services Benchmark Lambda guidance (scanner-defined control identifiers)
|
|
491
|
+
- **[ec2-security-scanner](https://github.com/TocConsulting/ec2-security-scanner)**: Architecture and design patterns
|
|
492
|
+
|
|
493
|
+
---
|
|
494
|
+
|
|
495
|
+
**Security Notice**: This tool is designed for defensive security purposes only. Always ensure you have proper authorization before scanning AWS resources. The tool requires read-only permissions and does not modify any AWS resources.
|
|
496
|
+
|
|
497
|
+
**Performance Note**: The scanner uses parallel function analysis with ThreadPoolExecutor to minimize scan time. Use `-w` to adjust parallelism based on your API rate limits.
|