container-audit 0.1.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.
- container_audit-0.1.0/LICENSE +21 -0
- container_audit-0.1.0/PKG-INFO +287 -0
- container_audit-0.1.0/README.md +254 -0
- container_audit-0.1.0/container_audit/__init__.py +4 -0
- container_audit-0.1.0/container_audit/checks/__init__.py +0 -0
- container_audit-0.1.0/container_audit/checks/docker.py +376 -0
- container_audit-0.1.0/container_audit/checks/kubernetes.py +352 -0
- container_audit-0.1.0/container_audit/checks/network.py +91 -0
- container_audit-0.1.0/container_audit/checks/secrets.py +109 -0
- container_audit-0.1.0/container_audit/cli.py +0 -0
- container_audit-0.1.0/container_audit/models.py +122 -0
- container_audit-0.1.0/container_audit/reporters/__init__.py +7 -0
- container_audit-0.1.0/container_audit/reporters/console.py +112 -0
- container_audit-0.1.0/container_audit/reporters/html_out.py +122 -0
- container_audit-0.1.0/container_audit/reporters/json_out.py +31 -0
- container_audit-0.1.0/container_audit/scanner.py +0 -0
- container_audit-0.1.0/container_audit/utils.py +37 -0
- container_audit-0.1.0/container_audit.egg-info/PKG-INFO +287 -0
- container_audit-0.1.0/container_audit.egg-info/SOURCES.txt +26 -0
- container_audit-0.1.0/container_audit.egg-info/dependency_links.txt +1 -0
- container_audit-0.1.0/container_audit.egg-info/entry_points.txt +2 -0
- container_audit-0.1.0/container_audit.egg-info/requires.txt +7 -0
- container_audit-0.1.0/container_audit.egg-info/top_level.txt +1 -0
- container_audit-0.1.0/pyproject.toml +52 -0
- container_audit-0.1.0/setup.cfg +4 -0
- container_audit-0.1.0/tests/test_docker.py +0 -0
- container_audit-0.1.0/tests/test_k8s.py +121 -0
- container_audit-0.1.0/tests/test_scanner.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HYMichellexdd
|
|
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,287 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: container-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight container security auditor for Docker and Kubernetes
|
|
5
|
+
Author-email: HYMichellexdd <contact@hyichellexdd.dev>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/HYMichellelxdd/container-audit
|
|
8
|
+
Project-URL: Repository, https://github.com/HYMichellelxdd/container-audit
|
|
9
|
+
Project-URL: Issues, https://github.com/HYMichellelxdd/container-audit/issues
|
|
10
|
+
Keywords: security,docker,kubernetes,container,audit,scanner,devsecops
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Classifier: Topic :: System :: Systems Administration
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: pyyaml>=6.0
|
|
27
|
+
Requires-Dist: rich>=13.0
|
|
28
|
+
Requires-Dist: jinja2>=3.1
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="https://img.shields.io/badge/🔒-Container%20Audit-blueviolet?style=for-the-badge" alt="Container Audit"/>
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
<h1 align="center">Container Audit</h1>
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<strong>Lightweight container security auditor for Docker and Kubernetes</strong>
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
<p align="center">
|
|
45
|
+
<a href="https://github.com/HYMichellexdd/container-audit/actions/workflows/ci.yml"><img src="https://github.com/HYMichellexdd/container-audit/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
46
|
+
<a href="https://github.com/HYMichellexdd/container-audit/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License: MIT"></a>
|
|
47
|
+
<a href="https://pypi.org/project/container-audit/"><img src="https://img.shields.io/pypi/v/container-audit.svg" alt="PyPI"></a>
|
|
48
|
+
<a href="https://pypi.org/project/container-audit/"><img src="https://img.shields.io/pypi/pyversions/container-audit.svg" alt="Python"></a>
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## ✨ Features
|
|
54
|
+
|
|
55
|
+
**Container Audit** is a fast, lightweight security scanner that helps developers and DevSecOps teams identify misconfigurations in Docker and Kubernetes environments before they become vulnerabilities.
|
|
56
|
+
|
|
57
|
+
- 🐳 **Docker Security** — 14 checks covering privileged mode, capabilities, secrets, network exposure, and more
|
|
58
|
+
- ☸️ **Kubernetes Compliance** — Pod Security, RBAC, NetworkPolicy, and manifest best practices
|
|
59
|
+
- 🔍 **Secret Detection** — Scan files for leaked API keys, private keys, passwords, and connection strings
|
|
60
|
+
- 📊 **Multiple Reports** — Terminal (Rich), JSON, and HTML output with dark theme
|
|
61
|
+
- ⚡ **Security Score** — 0-100 score based on severity-weighted findings
|
|
62
|
+
- 🔌 **CI/CD Ready** — Exit codes and JSON output for pipeline integration
|
|
63
|
+
|
|
64
|
+
## 🚀 Quick Start
|
|
65
|
+
|
|
66
|
+
### Installation
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install container-audit
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or from source:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/HYMichellexdd/container-audit.git
|
|
76
|
+
cd container-audit
|
|
77
|
+
pip install -e ".[dev]"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Basic Usage
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Scan a running Docker container
|
|
84
|
+
container-audit docker my-container
|
|
85
|
+
|
|
86
|
+
# Scan a docker-compose file
|
|
87
|
+
container-audit compose docker-compose.yml
|
|
88
|
+
|
|
89
|
+
# Scan Kubernetes manifests
|
|
90
|
+
container-audit k8s ./k8s-manifests/
|
|
91
|
+
|
|
92
|
+
# Scan for secrets in source code
|
|
93
|
+
container-audit secrets ./src/
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Output Formats
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# JSON output (for CI/CD pipelines)
|
|
100
|
+
container-audit docker my-container -f json -o report.json
|
|
101
|
+
|
|
102
|
+
# HTML report (dark theme, great for sharing)
|
|
103
|
+
container-audit docker my-container -f html -o report.html
|
|
104
|
+
|
|
105
|
+
# Verbose terminal output with evidence
|
|
106
|
+
container-audit docker my-container -v
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 📋 Security Checks
|
|
110
|
+
|
|
111
|
+
### Docker (14 checks)
|
|
112
|
+
|
|
113
|
+
| Check | Severity | Description |
|
|
114
|
+
|-------|----------|-------------|
|
|
115
|
+
| `DOCKER-001` | 🔴 CRITICAL | Privileged container detection |
|
|
116
|
+
| `DOCKER-002` | 🔴 CRITICAL | Docker socket mount detection |
|
|
117
|
+
| `DOCKER-003` | 🟡 MEDIUM | Running as root user |
|
|
118
|
+
| `DOCKER-004` | 🔴 HIGH | Dangerous capabilities (SYS_ADMIN, NET_ADMIN, etc.) |
|
|
119
|
+
| `DOCKER-005` | 🟡 MEDIUM | Ports exposed on 0.0.0.0 |
|
|
120
|
+
| `DOCKER-006` | 🔴 HIGH | Secrets in environment variables |
|
|
121
|
+
| `DOCKER-007` | 🔵 LOW | Writable root filesystem |
|
|
122
|
+
| `DOCKER-008` | 🟡 MEDIUM | Missing resource limits (memory/CPU/PIDs) |
|
|
123
|
+
| `DOCKER-009` | 🔵 LOW | No healthcheck configured |
|
|
124
|
+
| `DOCKER-010` | 🔵 LOW | AppArmor profile status |
|
|
125
|
+
| `DOCKER-011` | 🔵 LOW | Seccomp profile status |
|
|
126
|
+
| `DOCKER-012` | 🔴 HIGH | Host PID namespace sharing |
|
|
127
|
+
| `DOCKER-013` | 🟡 MEDIUM | Host IPC namespace sharing |
|
|
128
|
+
| `DOCKER-014` | 🔴 HIGH | Host network mode |
|
|
129
|
+
|
|
130
|
+
### Kubernetes
|
|
131
|
+
|
|
132
|
+
| Check | Severity | Description |
|
|
133
|
+
|-------|----------|-------------|
|
|
134
|
+
| `K8S-PRIV-*` | 🔴 CRITICAL | Privileged containers in workloads |
|
|
135
|
+
| `K8S-ROOT-*` | 🟡 MEDIUM | Containers running as root |
|
|
136
|
+
| `K8S-CAPS-*` | 🔴 HIGH | Dangerous capabilities added |
|
|
137
|
+
| `K8S-SA-TOKEN` | 🟡 MEDIUM | ServiceAccount token auto-mounting |
|
|
138
|
+
| `K8S-HNET` | 🔴 HIGH | Host network enabled |
|
|
139
|
+
| `K8S-HPID` | 🔴 HIGH | Host PID namespace |
|
|
140
|
+
| `K8S-HOSTPATH` | 🔴 HIGH | HostPath volumes mounted |
|
|
141
|
+
| `K8S-RBAC-*` | 🔴 HIGH | Overprivileged RBAC rules |
|
|
142
|
+
| `K8S-NS-*` | 🟡 MEDIUM | Namespace configuration checks |
|
|
143
|
+
| `K8S-ING-TLS-*` | 🔴 HIGH | Ingress without TLS |
|
|
144
|
+
| `K8S-NP-*` | 🟡 MEDIUM | NetworkPolicy validation |
|
|
145
|
+
|
|
146
|
+
### Secrets Detection
|
|
147
|
+
|
|
148
|
+
| Pattern | Severity | Description |
|
|
149
|
+
|---------|----------|-------------|
|
|
150
|
+
| API Keys | 🔴 CRITICAL | Generic API key patterns |
|
|
151
|
+
| AWS Keys | 🔴 CRITICAL | AWS access/secret keys |
|
|
152
|
+
| GitHub Tokens | 🔴 CRITICAL | GitHub PATs and tokens |
|
|
153
|
+
| Private Keys | 🔴 CRITICAL | RSA/EC/DSA private keys |
|
|
154
|
+
| Passwords | 🔴 CRITICAL | Hardcoded passwords |
|
|
155
|
+
| Connection Strings | 🔴 CRITICAL | Database/message broker URIs |
|
|
156
|
+
| JWT Tokens | 🔴 CRITICAL | JSON Web Tokens |
|
|
157
|
+
| GCP/Azure | 🔴 CRITICAL | Cloud provider credentials |
|
|
158
|
+
|
|
159
|
+
## 📊 Report Example
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
╭──────────── Security Report ────────────╮
|
|
163
|
+
│ Container Audit Report │
|
|
164
|
+
│ Target: my-container │
|
|
165
|
+
│ Scan Type: docker │
|
|
166
|
+
│ Score: 35/100 │
|
|
167
|
+
╰─────────────────────────────────────────╯
|
|
168
|
+
|
|
169
|
+
┌──────────────────────────────────────────────┐
|
|
170
|
+
│ Summary │
|
|
171
|
+
├──────────┬────────┬────────┬─────────────────┤
|
|
172
|
+
│ Severity │ Failed │ Passed │ Warnings │
|
|
173
|
+
├──────────┼────────┼────────┼─────────────────┤
|
|
174
|
+
│ CRITICAL │ 2 │ 0 │ 0 │
|
|
175
|
+
│ HIGH │ 3 │ 1 │ 0 │
|
|
176
|
+
│ MEDIUM │ 2 │ 1 │ 1 │
|
|
177
|
+
│ LOW │ 1 │ 2 │ 2 │
|
|
178
|
+
└──────────┴────────┴────────┴─────────────────┘
|
|
179
|
+
|
|
180
|
+
Findings:
|
|
181
|
+
✗ CRITICAL Privileged container
|
|
182
|
+
→ Remove --privileged flag. Use specific capabilities instead.
|
|
183
|
+
✗ CRITICAL Docker socket mounted
|
|
184
|
+
→ Avoid mounting Docker socket.
|
|
185
|
+
✗ HIGH Dangerous capabilities added
|
|
186
|
+
→ Remove unnecessary capabilities.
|
|
187
|
+
✓ HIGH Host PID namespace
|
|
188
|
+
✗ MEDIUM Running as root
|
|
189
|
+
→ Set USER directive in Dockerfile.
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 🔧 CI/CD Integration
|
|
193
|
+
|
|
194
|
+
### GitHub Actions
|
|
195
|
+
|
|
196
|
+
```yaml
|
|
197
|
+
- name: Container Security Scan
|
|
198
|
+
run: |
|
|
199
|
+
pip install container-audit
|
|
200
|
+
container-audit docker ${{ env.IMAGE }} -f json -o scan-results.json
|
|
201
|
+
# Fail CI on critical findings
|
|
202
|
+
container-audit docker ${{ env.IMAGE }}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### GitLab CI
|
|
206
|
+
|
|
207
|
+
```yaml
|
|
208
|
+
security_scan:
|
|
209
|
+
image: python:3.12-slim
|
|
210
|
+
script:
|
|
211
|
+
- pip install container-audit
|
|
212
|
+
- container-audit k8s ./k8s/ -f json -o report.json
|
|
213
|
+
artifacts:
|
|
214
|
+
reports:
|
|
215
|
+
container_scanning: report.json
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Exit Codes
|
|
219
|
+
|
|
220
|
+
| Code | Meaning |
|
|
221
|
+
|------|---------|
|
|
222
|
+
| `0` | No critical or high findings |
|
|
223
|
+
| `1` | High severity findings present |
|
|
224
|
+
| `2` | Critical severity findings present |
|
|
225
|
+
|
|
226
|
+
## 🛡️ Why Container Audit?
|
|
227
|
+
|
|
228
|
+
| Feature | Container Audit | Trivy | Grype | Snyk |
|
|
229
|
+
|---------|----------------|-------|-------|------|
|
|
230
|
+
| Docker config audit | ✅ | ❌ | ❌ | ❌ |
|
|
231
|
+
| Compose file scan | ✅ | ❌ | ❌ | ❌ |
|
|
232
|
+
| K8s manifest check | ✅ | ⚠️ Limited | ❌ | ⚠️ Limited |
|
|
233
|
+
| Secret detection | ✅ | ✅ | ❌ | ✅ |
|
|
234
|
+
| CI/CD friendly | ✅ | ✅ | ✅ | ✅ |
|
|
235
|
+
| Zero dependencies | ✅ | ❌ | ❌ | ❌ |
|
|
236
|
+
| Lightweight (<1s) | ✅ | ⚠️ | ✅ | ❌ |
|
|
237
|
+
|
|
238
|
+
## 📁 Project Structure
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
container-audit/
|
|
242
|
+
├── container_audit/
|
|
243
|
+
│ ├── __init__.py
|
|
244
|
+
│ ├── cli.py # CLI entry point
|
|
245
|
+
│ ├── scanner.py # Core scanning engine
|
|
246
|
+
│ ├── utils.py # Shared utilities
|
|
247
|
+
│ ├── checks/
|
|
248
|
+
│ │ ├── docker.py # Docker security checks
|
|
249
|
+
│ │ ├── kubernetes.py # K8s manifest checks
|
|
250
|
+
│ │ ├── network.py # Network exposure checks
|
|
251
|
+
│ │ └── secrets.py # Secret detection
|
|
252
|
+
│ └── reporters/
|
|
253
|
+
│ ├── console.py # Rich terminal output
|
|
254
|
+
│ ├── json_out.py # JSON report
|
|
255
|
+
│ └── html_out.py # HTML report
|
|
256
|
+
├── tests/
|
|
257
|
+
├── .github/workflows/ci.yml
|
|
258
|
+
├── pyproject.toml
|
|
259
|
+
├── LICENSE
|
|
260
|
+
└── README.md
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## 🤝 Contributing
|
|
264
|
+
|
|
265
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
266
|
+
|
|
267
|
+
1. Fork the repository
|
|
268
|
+
2. Create your feature branch (`git checkout -b feature/amazing-check`)
|
|
269
|
+
3. Commit your changes (`git commit -m 'Add amazing security check'`)
|
|
270
|
+
4. Push to the branch (`git push origin feature/amazing-check`)
|
|
271
|
+
5. Open a Pull Request
|
|
272
|
+
|
|
273
|
+
## 📄 License
|
|
274
|
+
|
|
275
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
276
|
+
|
|
277
|
+
## 🔗 Links
|
|
278
|
+
|
|
279
|
+
- [GitHub Repository](https://github.com/HYMichellexdd/container-audit)
|
|
280
|
+
- [Issue Tracker](https://github.com/HYMichellexdd/container-audit/issues)
|
|
281
|
+
- [PyPI Package](https://pypi.org/project/container-audit/)
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
<p align="center">
|
|
286
|
+
Made with ❤️ by <a href="https://github.com/HYMichellexdd">HYMichellexdd</a>
|
|
287
|
+
</p>
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://img.shields.io/badge/🔒-Container%20Audit-blueviolet?style=for-the-badge" alt="Container Audit"/>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Container Audit</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<strong>Lightweight container security auditor for Docker and Kubernetes</strong>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://github.com/HYMichellexdd/container-audit/actions/workflows/ci.yml"><img src="https://github.com/HYMichellexdd/container-audit/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
13
|
+
<a href="https://github.com/HYMichellexdd/container-audit/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-green.svg" alt="License: MIT"></a>
|
|
14
|
+
<a href="https://pypi.org/project/container-audit/"><img src="https://img.shields.io/pypi/v/container-audit.svg" alt="PyPI"></a>
|
|
15
|
+
<a href="https://pypi.org/project/container-audit/"><img src="https://img.shields.io/pypi/pyversions/container-audit.svg" alt="Python"></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## ✨ Features
|
|
21
|
+
|
|
22
|
+
**Container Audit** is a fast, lightweight security scanner that helps developers and DevSecOps teams identify misconfigurations in Docker and Kubernetes environments before they become vulnerabilities.
|
|
23
|
+
|
|
24
|
+
- 🐳 **Docker Security** — 14 checks covering privileged mode, capabilities, secrets, network exposure, and more
|
|
25
|
+
- ☸️ **Kubernetes Compliance** — Pod Security, RBAC, NetworkPolicy, and manifest best practices
|
|
26
|
+
- 🔍 **Secret Detection** — Scan files for leaked API keys, private keys, passwords, and connection strings
|
|
27
|
+
- 📊 **Multiple Reports** — Terminal (Rich), JSON, and HTML output with dark theme
|
|
28
|
+
- ⚡ **Security Score** — 0-100 score based on severity-weighted findings
|
|
29
|
+
- 🔌 **CI/CD Ready** — Exit codes and JSON output for pipeline integration
|
|
30
|
+
|
|
31
|
+
## 🚀 Quick Start
|
|
32
|
+
|
|
33
|
+
### Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install container-audit
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or from source:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git clone https://github.com/HYMichellexdd/container-audit.git
|
|
43
|
+
cd container-audit
|
|
44
|
+
pip install -e ".[dev]"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Basic Usage
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Scan a running Docker container
|
|
51
|
+
container-audit docker my-container
|
|
52
|
+
|
|
53
|
+
# Scan a docker-compose file
|
|
54
|
+
container-audit compose docker-compose.yml
|
|
55
|
+
|
|
56
|
+
# Scan Kubernetes manifests
|
|
57
|
+
container-audit k8s ./k8s-manifests/
|
|
58
|
+
|
|
59
|
+
# Scan for secrets in source code
|
|
60
|
+
container-audit secrets ./src/
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Output Formats
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# JSON output (for CI/CD pipelines)
|
|
67
|
+
container-audit docker my-container -f json -o report.json
|
|
68
|
+
|
|
69
|
+
# HTML report (dark theme, great for sharing)
|
|
70
|
+
container-audit docker my-container -f html -o report.html
|
|
71
|
+
|
|
72
|
+
# Verbose terminal output with evidence
|
|
73
|
+
container-audit docker my-container -v
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 📋 Security Checks
|
|
77
|
+
|
|
78
|
+
### Docker (14 checks)
|
|
79
|
+
|
|
80
|
+
| Check | Severity | Description |
|
|
81
|
+
|-------|----------|-------------|
|
|
82
|
+
| `DOCKER-001` | 🔴 CRITICAL | Privileged container detection |
|
|
83
|
+
| `DOCKER-002` | 🔴 CRITICAL | Docker socket mount detection |
|
|
84
|
+
| `DOCKER-003` | 🟡 MEDIUM | Running as root user |
|
|
85
|
+
| `DOCKER-004` | 🔴 HIGH | Dangerous capabilities (SYS_ADMIN, NET_ADMIN, etc.) |
|
|
86
|
+
| `DOCKER-005` | 🟡 MEDIUM | Ports exposed on 0.0.0.0 |
|
|
87
|
+
| `DOCKER-006` | 🔴 HIGH | Secrets in environment variables |
|
|
88
|
+
| `DOCKER-007` | 🔵 LOW | Writable root filesystem |
|
|
89
|
+
| `DOCKER-008` | 🟡 MEDIUM | Missing resource limits (memory/CPU/PIDs) |
|
|
90
|
+
| `DOCKER-009` | 🔵 LOW | No healthcheck configured |
|
|
91
|
+
| `DOCKER-010` | 🔵 LOW | AppArmor profile status |
|
|
92
|
+
| `DOCKER-011` | 🔵 LOW | Seccomp profile status |
|
|
93
|
+
| `DOCKER-012` | 🔴 HIGH | Host PID namespace sharing |
|
|
94
|
+
| `DOCKER-013` | 🟡 MEDIUM | Host IPC namespace sharing |
|
|
95
|
+
| `DOCKER-014` | 🔴 HIGH | Host network mode |
|
|
96
|
+
|
|
97
|
+
### Kubernetes
|
|
98
|
+
|
|
99
|
+
| Check | Severity | Description |
|
|
100
|
+
|-------|----------|-------------|
|
|
101
|
+
| `K8S-PRIV-*` | 🔴 CRITICAL | Privileged containers in workloads |
|
|
102
|
+
| `K8S-ROOT-*` | 🟡 MEDIUM | Containers running as root |
|
|
103
|
+
| `K8S-CAPS-*` | 🔴 HIGH | Dangerous capabilities added |
|
|
104
|
+
| `K8S-SA-TOKEN` | 🟡 MEDIUM | ServiceAccount token auto-mounting |
|
|
105
|
+
| `K8S-HNET` | 🔴 HIGH | Host network enabled |
|
|
106
|
+
| `K8S-HPID` | 🔴 HIGH | Host PID namespace |
|
|
107
|
+
| `K8S-HOSTPATH` | 🔴 HIGH | HostPath volumes mounted |
|
|
108
|
+
| `K8S-RBAC-*` | 🔴 HIGH | Overprivileged RBAC rules |
|
|
109
|
+
| `K8S-NS-*` | 🟡 MEDIUM | Namespace configuration checks |
|
|
110
|
+
| `K8S-ING-TLS-*` | 🔴 HIGH | Ingress without TLS |
|
|
111
|
+
| `K8S-NP-*` | 🟡 MEDIUM | NetworkPolicy validation |
|
|
112
|
+
|
|
113
|
+
### Secrets Detection
|
|
114
|
+
|
|
115
|
+
| Pattern | Severity | Description |
|
|
116
|
+
|---------|----------|-------------|
|
|
117
|
+
| API Keys | 🔴 CRITICAL | Generic API key patterns |
|
|
118
|
+
| AWS Keys | 🔴 CRITICAL | AWS access/secret keys |
|
|
119
|
+
| GitHub Tokens | 🔴 CRITICAL | GitHub PATs and tokens |
|
|
120
|
+
| Private Keys | 🔴 CRITICAL | RSA/EC/DSA private keys |
|
|
121
|
+
| Passwords | 🔴 CRITICAL | Hardcoded passwords |
|
|
122
|
+
| Connection Strings | 🔴 CRITICAL | Database/message broker URIs |
|
|
123
|
+
| JWT Tokens | 🔴 CRITICAL | JSON Web Tokens |
|
|
124
|
+
| GCP/Azure | 🔴 CRITICAL | Cloud provider credentials |
|
|
125
|
+
|
|
126
|
+
## 📊 Report Example
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
╭──────────── Security Report ────────────╮
|
|
130
|
+
│ Container Audit Report │
|
|
131
|
+
│ Target: my-container │
|
|
132
|
+
│ Scan Type: docker │
|
|
133
|
+
│ Score: 35/100 │
|
|
134
|
+
╰─────────────────────────────────────────╯
|
|
135
|
+
|
|
136
|
+
┌──────────────────────────────────────────────┐
|
|
137
|
+
│ Summary │
|
|
138
|
+
├──────────┬────────┬────────┬─────────────────┤
|
|
139
|
+
│ Severity │ Failed │ Passed │ Warnings │
|
|
140
|
+
├──────────┼────────┼────────┼─────────────────┤
|
|
141
|
+
│ CRITICAL │ 2 │ 0 │ 0 │
|
|
142
|
+
│ HIGH │ 3 │ 1 │ 0 │
|
|
143
|
+
│ MEDIUM │ 2 │ 1 │ 1 │
|
|
144
|
+
│ LOW │ 1 │ 2 │ 2 │
|
|
145
|
+
└──────────┴────────┴────────┴─────────────────┘
|
|
146
|
+
|
|
147
|
+
Findings:
|
|
148
|
+
✗ CRITICAL Privileged container
|
|
149
|
+
→ Remove --privileged flag. Use specific capabilities instead.
|
|
150
|
+
✗ CRITICAL Docker socket mounted
|
|
151
|
+
→ Avoid mounting Docker socket.
|
|
152
|
+
✗ HIGH Dangerous capabilities added
|
|
153
|
+
→ Remove unnecessary capabilities.
|
|
154
|
+
✓ HIGH Host PID namespace
|
|
155
|
+
✗ MEDIUM Running as root
|
|
156
|
+
→ Set USER directive in Dockerfile.
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## 🔧 CI/CD Integration
|
|
160
|
+
|
|
161
|
+
### GitHub Actions
|
|
162
|
+
|
|
163
|
+
```yaml
|
|
164
|
+
- name: Container Security Scan
|
|
165
|
+
run: |
|
|
166
|
+
pip install container-audit
|
|
167
|
+
container-audit docker ${{ env.IMAGE }} -f json -o scan-results.json
|
|
168
|
+
# Fail CI on critical findings
|
|
169
|
+
container-audit docker ${{ env.IMAGE }}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### GitLab CI
|
|
173
|
+
|
|
174
|
+
```yaml
|
|
175
|
+
security_scan:
|
|
176
|
+
image: python:3.12-slim
|
|
177
|
+
script:
|
|
178
|
+
- pip install container-audit
|
|
179
|
+
- container-audit k8s ./k8s/ -f json -o report.json
|
|
180
|
+
artifacts:
|
|
181
|
+
reports:
|
|
182
|
+
container_scanning: report.json
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Exit Codes
|
|
186
|
+
|
|
187
|
+
| Code | Meaning |
|
|
188
|
+
|------|---------|
|
|
189
|
+
| `0` | No critical or high findings |
|
|
190
|
+
| `1` | High severity findings present |
|
|
191
|
+
| `2` | Critical severity findings present |
|
|
192
|
+
|
|
193
|
+
## 🛡️ Why Container Audit?
|
|
194
|
+
|
|
195
|
+
| Feature | Container Audit | Trivy | Grype | Snyk |
|
|
196
|
+
|---------|----------------|-------|-------|------|
|
|
197
|
+
| Docker config audit | ✅ | ❌ | ❌ | ❌ |
|
|
198
|
+
| Compose file scan | ✅ | ❌ | ❌ | ❌ |
|
|
199
|
+
| K8s manifest check | ✅ | ⚠️ Limited | ❌ | ⚠️ Limited |
|
|
200
|
+
| Secret detection | ✅ | ✅ | ❌ | ✅ |
|
|
201
|
+
| CI/CD friendly | ✅ | ✅ | ✅ | ✅ |
|
|
202
|
+
| Zero dependencies | ✅ | ❌ | ❌ | ❌ |
|
|
203
|
+
| Lightweight (<1s) | ✅ | ⚠️ | ✅ | ❌ |
|
|
204
|
+
|
|
205
|
+
## 📁 Project Structure
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
container-audit/
|
|
209
|
+
├── container_audit/
|
|
210
|
+
│ ├── __init__.py
|
|
211
|
+
│ ├── cli.py # CLI entry point
|
|
212
|
+
│ ├── scanner.py # Core scanning engine
|
|
213
|
+
│ ├── utils.py # Shared utilities
|
|
214
|
+
│ ├── checks/
|
|
215
|
+
│ │ ├── docker.py # Docker security checks
|
|
216
|
+
│ │ ├── kubernetes.py # K8s manifest checks
|
|
217
|
+
│ │ ├── network.py # Network exposure checks
|
|
218
|
+
│ │ └── secrets.py # Secret detection
|
|
219
|
+
│ └── reporters/
|
|
220
|
+
│ ├── console.py # Rich terminal output
|
|
221
|
+
│ ├── json_out.py # JSON report
|
|
222
|
+
│ └── html_out.py # HTML report
|
|
223
|
+
├── tests/
|
|
224
|
+
├── .github/workflows/ci.yml
|
|
225
|
+
├── pyproject.toml
|
|
226
|
+
├── LICENSE
|
|
227
|
+
└── README.md
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## 🤝 Contributing
|
|
231
|
+
|
|
232
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
233
|
+
|
|
234
|
+
1. Fork the repository
|
|
235
|
+
2. Create your feature branch (`git checkout -b feature/amazing-check`)
|
|
236
|
+
3. Commit your changes (`git commit -m 'Add amazing security check'`)
|
|
237
|
+
4. Push to the branch (`git push origin feature/amazing-check`)
|
|
238
|
+
5. Open a Pull Request
|
|
239
|
+
|
|
240
|
+
## 📄 License
|
|
241
|
+
|
|
242
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
243
|
+
|
|
244
|
+
## 🔗 Links
|
|
245
|
+
|
|
246
|
+
- [GitHub Repository](https://github.com/HYMichellexdd/container-audit)
|
|
247
|
+
- [Issue Tracker](https://github.com/HYMichellexdd/container-audit/issues)
|
|
248
|
+
- [PyPI Package](https://pypi.org/project/container-audit/)
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
<p align="center">
|
|
253
|
+
Made with ❤️ by <a href="https://github.com/HYMichellexdd">HYMichellexdd</a>
|
|
254
|
+
</p>
|
|
File without changes
|