kekkai-cli 1.1.0__py3-none-any.whl → 2.0.0__py3-none-any.whl
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.
- kekkai/cli.py +238 -36
- kekkai/dojo_import.py +9 -1
- kekkai/output.py +2 -3
- kekkai/report/unified.py +226 -0
- kekkai/triage/__init__.py +54 -1
- kekkai/triage/fix_screen.py +232 -0
- kekkai/triage/loader.py +196 -0
- kekkai/triage/screens.py +1 -0
- kekkai_cli-2.0.0.dist-info/METADATA +317 -0
- {kekkai_cli-1.1.0.dist-info → kekkai_cli-2.0.0.dist-info}/RECORD +13 -28
- {kekkai_cli-1.1.0.dist-info → kekkai_cli-2.0.0.dist-info}/entry_points.txt +0 -1
- {kekkai_cli-1.1.0.dist-info → kekkai_cli-2.0.0.dist-info}/top_level.txt +0 -1
- kekkai_cli-1.1.0.dist-info/METADATA +0 -359
- portal/__init__.py +0 -19
- portal/api.py +0 -155
- portal/auth.py +0 -103
- portal/enterprise/__init__.py +0 -45
- portal/enterprise/audit.py +0 -435
- portal/enterprise/licensing.py +0 -408
- portal/enterprise/rbac.py +0 -276
- portal/enterprise/saml.py +0 -595
- portal/ops/__init__.py +0 -53
- portal/ops/backup.py +0 -553
- portal/ops/log_shipper.py +0 -469
- portal/ops/monitoring.py +0 -517
- portal/ops/restore.py +0 -469
- portal/ops/secrets.py +0 -408
- portal/ops/upgrade.py +0 -591
- portal/tenants.py +0 -340
- portal/uploads.py +0 -259
- portal/web.py +0 -393
- {kekkai_cli-1.1.0.dist-info → kekkai_cli-2.0.0.dist-info}/WHEEL +0 -0
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: kekkai-cli
|
|
3
|
-
Version: 1.1.0
|
|
4
|
-
Summary: Kekkai monorepo (local-first AppSec orchestration + compliance checker)
|
|
5
|
-
Requires-Python: >=3.12
|
|
6
|
-
Description-Content-Type: text/markdown
|
|
7
|
-
Requires-Dist: rich>=13.0.0
|
|
8
|
-
Requires-Dist: jsonschema>=4.20.0
|
|
9
|
-
Requires-Dist: textual>=0.50.0
|
|
10
|
-
Requires-Dist: httpx>=0.24.0
|
|
11
|
-
|
|
12
|
-
<p align="center">
|
|
13
|
-
<img src="https://raw.githubusercontent.com/kademoslabs/assets/main/logos/kekkai-slim.png" alt="Kekkai CLI Logo" width="250"/>
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
<p align="center"><strong>Security orchestration at developer speed.</strong></p>
|
|
17
|
-
<p align="center"><i>One tool for the entire AppSec lifecycle: Predict, Detect, Triage, Manage.</i></p>
|
|
18
|
-
|
|
19
|
-
<p align="center">
|
|
20
|
-
<img src="https://img.shields.io/github/actions/workflow/status/kademoslabs/kekkai/docker-publish.yml?logo=github"/>
|
|
21
|
-
<img src="https://img.shields.io/circleci/build/github/kademoslabs/kekkai?logo=circleci"/>
|
|
22
|
-
<img src="https://img.shields.io/pypi/v/kekkai-cli?pypiBaseUrl=https%3A%2F%2Fpypi.org&logo=pypi"/>
|
|
23
|
-
</p>
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
# Kekkai
|
|
28
|
-
|
|
29
|
-
Stop juggling security tools. **Kekkai orchestrates your entire AppSec lifecycle** — from AI-powered threat modeling to vulnerability management — in a single CLI.
|
|
30
|
-
|
|
31
|
-

|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## The Five Pillars
|
|
36
|
-
|
|
37
|
-
| Pillar | Feature | Command | Description |
|
|
38
|
-
|--------|---------|---------|-------------|
|
|
39
|
-
| 🔮 **Predict** | AI Threat Modeling | `kekkai threatflow` | Generate STRIDE threat models before writing code |
|
|
40
|
-
| 🔍 **Detect** | Unified Scanning | `kekkai scan` | Run Trivy, Semgrep, Gitleaks in isolated containers |
|
|
41
|
-
| ✅ **Triage** | Interactive Review | `kekkai triage` | Review findings in a terminal UI, mark false positives |
|
|
42
|
-
| 🚦 **Gate** | CI/CD Policy | `kekkai scan --ci` | Break builds on severity thresholds |
|
|
43
|
-
| 📊 **Manage** | DefectDojo | `kekkai dojo up` | Spin up vulnerability management in 60 seconds |
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## Quick Start (60 Seconds)
|
|
48
|
-
|
|
49
|
-
### 1. Install
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
pipx install kekkai-cli
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### 2. Predict (Threat Model)
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
kekkai threatflow --repo . --model-mode local
|
|
59
|
-
# Generates THREATS.md with STRIDE analysis and Data Flow Diagram
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### 3. Detect (Scan)
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
kekkai scan
|
|
66
|
-
# Runs Trivy (CVEs), Semgrep (code), Gitleaks (secrets)
|
|
67
|
-
# Outputs unified kekkai-report.json
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### 4. Triage (Review)
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
kekkai triage
|
|
74
|
-
# Interactive TUI to accept, reject, or ignore findings
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### 5. Manage (DefectDojo)
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
kekkai dojo up --wait
|
|
81
|
-
kekkai upload
|
|
82
|
-
# Full vulnerability management platform + automated import
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Why Kekkai?
|
|
88
|
-
|
|
89
|
-
| Capability | Manual Approach | Kekkai |
|
|
90
|
-
|------------|-----------------|--------|
|
|
91
|
-
| **Tooling** | Install/update 5+ tools individually | One binary, auto-pulls scanner containers |
|
|
92
|
-
| **Output** | Parse 5 different JSON formats | Unified `kekkai-report.json` |
|
|
93
|
-
| **Threat Modeling** | Expensive consultants or whiteboarding | AI-generated `THREATS.md` locally |
|
|
94
|
-
| **DefectDojo** | 200-line docker-compose + debugging | `kekkai dojo up` (one command) |
|
|
95
|
-
| **Triage** | Read JSON files manually | Interactive terminal UI |
|
|
96
|
-
| **CI/CD** | Complex bash scripts | `kekkai scan --ci --fail-on high` |
|
|
97
|
-
| **PR Feedback** | Manual security review comments | Auto-comments on GitHub PRs |
|
|
98
|
-
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
## Feature Deep Dives
|
|
102
|
-
|
|
103
|
-
### 🔮 ThreatFlow — AI-Powered Threat Modeling
|
|
104
|
-
|
|
105
|
-
Generate STRIDE-aligned threat models and Mermaid.js Data Flow Diagrams from your codebase.
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
# Ollama (recommended - easy setup, privacy-preserving)
|
|
109
|
-
ollama pull mistral
|
|
110
|
-
kekkai threatflow --repo . --model-mode ollama --model-name mistral
|
|
111
|
-
|
|
112
|
-
# Local GGUF model (requires llama-cpp-python)
|
|
113
|
-
kekkai threatflow --repo . --model-mode local --model-path ./mistral-7b.gguf
|
|
114
|
-
|
|
115
|
-
# Remote API (faster, requires API key)
|
|
116
|
-
export KEKKAI_THREATFLOW_API_KEY="sk-..."
|
|
117
|
-
kekkai threatflow --repo . --model-mode openai
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
**Output:** `THREATS.md` containing:
|
|
121
|
-
- Attack surface analysis
|
|
122
|
-
- STRIDE threat classification
|
|
123
|
-
- Mermaid.js architecture diagram
|
|
124
|
-
- Recommended mitigations
|
|
125
|
-
|
|
126
|
-
[Full ThreatFlow Documentation →](docs/threatflow/README.md)
|
|
127
|
-
|
|
128
|
-
---
|
|
129
|
-
|
|
130
|
-
### 🔍 Unified Scanning
|
|
131
|
-
|
|
132
|
-
Run industry-standard scanners without installing them individually. Each scanner runs in an isolated Docker container with security hardening.
|
|
133
|
-
|
|
134
|
-
```bash
|
|
135
|
-
kekkai scan # Scan current directory
|
|
136
|
-
kekkai scan --repo /path/to/project # Scan specific path
|
|
137
|
-
kekkai scan --output results.json # Custom output path
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
**Scanners Included:**
|
|
141
|
-
| Scanner | Finds | Image |
|
|
142
|
-
|---------|-------|-------|
|
|
143
|
-
| Trivy | CVEs in dependencies | `aquasec/trivy:latest` |
|
|
144
|
-
| Semgrep | Code vulnerabilities | `semgrep/semgrep:latest` |
|
|
145
|
-
| Gitleaks | Hardcoded secrets | `zricethezav/gitleaks:latest` |
|
|
146
|
-
|
|
147
|
-
**Container Security:**
|
|
148
|
-
- Read-only filesystem
|
|
149
|
-
- No network access
|
|
150
|
-
- Memory limited (2GB)
|
|
151
|
-
- No privilege escalation
|
|
152
|
-
|
|
153
|
-
---
|
|
154
|
-
|
|
155
|
-
### ✅ Interactive Triage TUI
|
|
156
|
-
|
|
157
|
-
Stop reading JSON. Review security findings in your terminal.
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
kekkai triage
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
**Features:**
|
|
164
|
-
- Navigate findings with keyboard
|
|
165
|
-
- Mark as: Accept, Reject, False Positive, Ignore
|
|
166
|
-
- Filter by severity, scanner, or status
|
|
167
|
-
- Persist decisions in `.kekkai-ignore`
|
|
168
|
-
- Export triaged results
|
|
169
|
-
|
|
170
|
-
<!-- Screenshot placeholder:  -->
|
|
171
|
-
|
|
172
|
-
[Full Triage Documentation →](docs/triage/README.md)
|
|
173
|
-
|
|
174
|
-
---
|
|
175
|
-
|
|
176
|
-
### 🚦 CI/CD Policy Gate
|
|
177
|
-
|
|
178
|
-
Automate security enforcement in your pipelines.
|
|
179
|
-
|
|
180
|
-
```bash
|
|
181
|
-
# Fail on any critical or high findings
|
|
182
|
-
kekkai scan --ci --fail-on high
|
|
183
|
-
|
|
184
|
-
# Fail only on critical
|
|
185
|
-
kekkai scan --ci --fail-on critical
|
|
186
|
-
|
|
187
|
-
# Custom threshold: fail on 5+ medium findings
|
|
188
|
-
kekkai scan --ci --fail-on medium --max-findings 5
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
**Exit Codes:**
|
|
192
|
-
| Code | Meaning |
|
|
193
|
-
|------|---------|
|
|
194
|
-
| 0 | No findings above threshold |
|
|
195
|
-
| 1 | Findings exceed threshold |
|
|
196
|
-
| 2 | Scanner error |
|
|
197
|
-
|
|
198
|
-
**GitHub Actions Example:**
|
|
199
|
-
|
|
200
|
-
```yaml
|
|
201
|
-
- name: Security Scan
|
|
202
|
-
run: |
|
|
203
|
-
pipx install kekkai-cli
|
|
204
|
-
kekkai scan --ci --fail-on high
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
[Full CI Documentation →](docs/ci/ci-mode.md)
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
### 📊 DefectDojo Integration
|
|
212
|
-
|
|
213
|
-
Spin up a complete vulnerability management platform locally.
|
|
214
|
-
|
|
215
|
-
```bash
|
|
216
|
-
kekkai dojo up --wait # Start DefectDojo (Nginx, Postgres, Redis, Celery)
|
|
217
|
-
kekkai dojo status # Check service health
|
|
218
|
-
kekkai upload # Import scan results
|
|
219
|
-
kekkai dojo down # Stop and clean up (removes volumes)
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
**What You Get:**
|
|
223
|
-
- DefectDojo web UI at `http://localhost:8080`
|
|
224
|
-
- Automatic credential generation
|
|
225
|
-
- Pre-configured for Kekkai imports
|
|
226
|
-
- Clean teardown (no orphaned volumes)
|
|
227
|
-
|
|
228
|
-
[Full Dojo Documentation →](docs/dojo/dojo.md)
|
|
229
|
-
|
|
230
|
-
---
|
|
231
|
-
|
|
232
|
-
### 🔔 GitHub PR Comments
|
|
233
|
-
|
|
234
|
-
Get security feedback directly in pull requests.
|
|
235
|
-
|
|
236
|
-
```bash
|
|
237
|
-
export GITHUB_TOKEN="ghp_..."
|
|
238
|
-
kekkai scan --github-comment
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
Kekkai will:
|
|
242
|
-
1. Run all scanners
|
|
243
|
-
2. Post findings as PR review comments
|
|
244
|
-
3. Annotate specific lines with inline comments
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
|
-
## Installation
|
|
249
|
-
|
|
250
|
-
### pipx (Recommended)
|
|
251
|
-
|
|
252
|
-
Isolated environment, no conflicts with system Python.
|
|
253
|
-
|
|
254
|
-
```bash
|
|
255
|
-
pipx install kekkai-cli
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
### Homebrew (macOS/Linux)
|
|
259
|
-
|
|
260
|
-
```bash
|
|
261
|
-
brew install kademoslabs/tap/kekkai
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Scoop (Windows)
|
|
265
|
-
|
|
266
|
-
```bash
|
|
267
|
-
scoop bucket add kademoslabs https://github.com/kademoslabs/scoop-bucket
|
|
268
|
-
scoop install kekkai
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
### Docker (No Python Required)
|
|
272
|
-
|
|
273
|
-
```bash
|
|
274
|
-
docker pull kademoslabs/kekkai:latest
|
|
275
|
-
alias kekkai='docker run --rm -v "$(pwd):/repo" kademoslabs/kekkai:latest'
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
### pip (Traditional)
|
|
279
|
-
|
|
280
|
-
```bash
|
|
281
|
-
pip install kekkai-cli
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
---
|
|
285
|
-
|
|
286
|
-
## Enterprise Features — Kekkai Portal
|
|
287
|
-
|
|
288
|
-
For teams that need centralized management, **Kekkai Portal** provides:
|
|
289
|
-
|
|
290
|
-
| Feature | Description |
|
|
291
|
-
|---------|-------------|
|
|
292
|
-
| **SAML 2.0 SSO** | Integrate with Okta, Azure AD, Google Workspace ([Setup Guide](docs/portal/saml-setup.md)) |
|
|
293
|
-
| **Role-Based Access Control** | Fine-grained permissions per team/project ([RBAC Guide](docs/portal/rbac.md)) |
|
|
294
|
-
| **Multi-Tenant Architecture** | Isolated environments per organization ([Architecture](docs/portal/multi-tenant.md)) |
|
|
295
|
-
| **Aggregated Dashboards** | Centralized view of all CLI scan results |
|
|
296
|
-
| **Audit Logging** | Cryptographically signed compliance trails |
|
|
297
|
-
|
|
298
|
-
**Upgrade Path:**
|
|
299
|
-
- CLI users can sync results to Portal: `kekkai upload` ([Sync Guide](docs/portal/cli-sync.md))
|
|
300
|
-
- Portal provides dashboards for security managers
|
|
301
|
-
- Self-hosted or Kademos-managed options ([Deployment Guide](docs/portal/deployment.md))
|
|
302
|
-
|
|
303
|
-
[Contact us for Portal access →](mailto:sales@kademos.org)
|
|
304
|
-
|
|
305
|
-
---
|
|
306
|
-
|
|
307
|
-
## Security
|
|
308
|
-
|
|
309
|
-
Kekkai is designed with security as a core principle:
|
|
310
|
-
|
|
311
|
-
- **Container Isolation**: Scanners run in hardened Docker containers
|
|
312
|
-
- **No Network Access**: Containers cannot reach external networks
|
|
313
|
-
- **Local-First AI**: ThreatFlow can run entirely on your machine
|
|
314
|
-
- **SLSA Level 3**: Release artifacts include provenance attestations
|
|
315
|
-
- **Signed Images**: Docker images are Cosign-signed
|
|
316
|
-
|
|
317
|
-
For vulnerability reports, see [SECURITY.md](SECURITY.md).
|
|
318
|
-
|
|
319
|
-
---
|
|
320
|
-
|
|
321
|
-
## Documentation
|
|
322
|
-
|
|
323
|
-
| Guide | Description |
|
|
324
|
-
|-------|-------------|
|
|
325
|
-
| [Installation](docs/README.md#installation-methods) | All installation methods |
|
|
326
|
-
| [ThreatFlow](docs/threatflow/README.md) | AI threat modeling setup |
|
|
327
|
-
| [Dojo Quick Start](docs/dojo/dojo-quickstart.md) | DefectDojo in 5 minutes |
|
|
328
|
-
| [CI Mode](docs/ci/ci-mode.md) | Pipeline integration |
|
|
329
|
-
| [Portal](docs/portal/README.md) | Enterprise features overview |
|
|
330
|
-
| [Portal SSO](docs/portal/saml-setup.md) | SAML 2.0 SSO configuration |
|
|
331
|
-
| [Portal RBAC](docs/portal/rbac.md) | Role-based access control |
|
|
332
|
-
| [Portal Deployment](docs/portal/deployment.md) | Self-hosted deployment |
|
|
333
|
-
| [Security](docs/security/slsa-provenance.md) | SLSA provenance verification |
|
|
334
|
-
|
|
335
|
-
---
|
|
336
|
-
|
|
337
|
-
## CI/CD Status
|
|
338
|
-
|
|
339
|
-
[](https://github.com/kademoslabs/kekkai/actions/workflows/kekkai-pr-scan.yml)
|
|
340
|
-
[](https://github.com/kademoslabs/kekkai/actions/workflows/docker-publish.yml)
|
|
341
|
-
[](https://github.com/kademoslabs/kekkai/actions/workflows/docker-security-scan.yml)
|
|
342
|
-
[](https://github.com/kademoslabs/kekkai/actions/workflows/test-cross-platform.yml)
|
|
343
|
-
[](https://github.com/kademoslabs/kekkai/actions/workflows/release-slsa.yml)
|
|
344
|
-
|
|
345
|
-
---
|
|
346
|
-
|
|
347
|
-
## Contributing
|
|
348
|
-
|
|
349
|
-
We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
350
|
-
|
|
351
|
-
---
|
|
352
|
-
|
|
353
|
-
## License
|
|
354
|
-
|
|
355
|
-
Apache-2.0 — See [LICENSE](LICENSE) for details.
|
|
356
|
-
|
|
357
|
-
---
|
|
358
|
-
|
|
359
|
-
<p align="center"><i>Built by <a href="https://kademos.org">Kademos Labs</a></i></p>
|
portal/__init__.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"""Kekkai Hosted Portal - DefectDojo-backed multi-tenant security dashboard."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
__all__ = [
|
|
6
|
-
"AuthMethod",
|
|
7
|
-
"AuthResult",
|
|
8
|
-
"SAMLTenantConfig",
|
|
9
|
-
"Tenant",
|
|
10
|
-
"TenantStore",
|
|
11
|
-
"UploadResult",
|
|
12
|
-
"authenticate_request",
|
|
13
|
-
"process_upload",
|
|
14
|
-
"validate_upload",
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
from .auth import AuthResult, authenticate_request
|
|
18
|
-
from .tenants import AuthMethod, SAMLTenantConfig, Tenant, TenantStore
|
|
19
|
-
from .uploads import UploadResult, process_upload, validate_upload
|
portal/api.py
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"""Portal API endpoints for programmatic access.
|
|
2
|
-
|
|
3
|
-
Provides REST API endpoints that expose the same data visible in the UI.
|
|
4
|
-
All endpoints require authentication and enforce tenant isolation.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
import json
|
|
10
|
-
import logging
|
|
11
|
-
import os
|
|
12
|
-
from dataclasses import dataclass
|
|
13
|
-
from pathlib import Path
|
|
14
|
-
from typing import Any
|
|
15
|
-
|
|
16
|
-
from .tenants import Tenant
|
|
17
|
-
|
|
18
|
-
logger = logging.getLogger(__name__)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@dataclass(frozen=True)
|
|
22
|
-
class UploadInfo:
|
|
23
|
-
"""Information about an upload."""
|
|
24
|
-
|
|
25
|
-
upload_id: str
|
|
26
|
-
filename: str
|
|
27
|
-
timestamp: str
|
|
28
|
-
file_hash: str
|
|
29
|
-
size_bytes: int
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
@dataclass(frozen=True)
|
|
33
|
-
class TenantStats:
|
|
34
|
-
"""Statistics for a tenant."""
|
|
35
|
-
|
|
36
|
-
total_uploads: int
|
|
37
|
-
total_size_bytes: int
|
|
38
|
-
last_upload_time: str | None
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def get_tenant_info(tenant: Tenant) -> dict[str, Any]:
|
|
42
|
-
"""Get tenant information for API response.
|
|
43
|
-
|
|
44
|
-
Args:
|
|
45
|
-
tenant: The authenticated tenant
|
|
46
|
-
|
|
47
|
-
Returns:
|
|
48
|
-
Dictionary containing tenant metadata
|
|
49
|
-
"""
|
|
50
|
-
return {
|
|
51
|
-
"id": tenant.id,
|
|
52
|
-
"name": tenant.name,
|
|
53
|
-
"dojo_product_id": tenant.dojo_product_id,
|
|
54
|
-
"dojo_engagement_id": tenant.dojo_engagement_id,
|
|
55
|
-
"enabled": tenant.enabled,
|
|
56
|
-
"max_upload_size_mb": tenant.max_upload_size_mb,
|
|
57
|
-
"auth_method": tenant.auth_method.value,
|
|
58
|
-
"default_role": tenant.default_role,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def list_uploads(tenant: Tenant, limit: int = 50) -> list[dict[str, Any]]:
|
|
63
|
-
"""List recent uploads for a tenant.
|
|
64
|
-
|
|
65
|
-
Args:
|
|
66
|
-
tenant: The authenticated tenant
|
|
67
|
-
limit: Maximum number of uploads to return
|
|
68
|
-
|
|
69
|
-
Returns:
|
|
70
|
-
List of upload metadata dictionaries
|
|
71
|
-
"""
|
|
72
|
-
upload_dir = Path(os.environ.get("PORTAL_UPLOAD_DIR", "/var/lib/kekkai-portal/uploads"))
|
|
73
|
-
tenant_dir = upload_dir / tenant.id
|
|
74
|
-
|
|
75
|
-
if not tenant_dir.exists():
|
|
76
|
-
return []
|
|
77
|
-
|
|
78
|
-
uploads: list[dict[str, Any]] = []
|
|
79
|
-
|
|
80
|
-
# Get all upload files for this tenant
|
|
81
|
-
try:
|
|
82
|
-
upload_files = sorted(
|
|
83
|
-
tenant_dir.glob("*.json"),
|
|
84
|
-
key=lambda p: p.stat().st_mtime,
|
|
85
|
-
reverse=True,
|
|
86
|
-
)[:limit]
|
|
87
|
-
|
|
88
|
-
for upload_file in upload_files:
|
|
89
|
-
stat = upload_file.stat()
|
|
90
|
-
uploads.append(
|
|
91
|
-
{
|
|
92
|
-
"upload_id": upload_file.stem,
|
|
93
|
-
"filename": upload_file.name,
|
|
94
|
-
"timestamp": str(int(stat.st_mtime)),
|
|
95
|
-
"size_bytes": stat.st_size,
|
|
96
|
-
}
|
|
97
|
-
)
|
|
98
|
-
except (OSError, PermissionError) as e:
|
|
99
|
-
logger.warning("Failed to list uploads for tenant %s: %s", tenant.id, e)
|
|
100
|
-
|
|
101
|
-
return uploads
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def get_tenant_stats(tenant: Tenant) -> dict[str, Any]:
|
|
105
|
-
"""Get statistics for a tenant.
|
|
106
|
-
|
|
107
|
-
Args:
|
|
108
|
-
tenant: The authenticated tenant
|
|
109
|
-
|
|
110
|
-
Returns:
|
|
111
|
-
Dictionary containing tenant statistics
|
|
112
|
-
"""
|
|
113
|
-
upload_dir = Path(os.environ.get("PORTAL_UPLOAD_DIR", "/var/lib/kekkai-portal/uploads"))
|
|
114
|
-
tenant_dir = upload_dir / tenant.id
|
|
115
|
-
|
|
116
|
-
if not tenant_dir.exists():
|
|
117
|
-
return {
|
|
118
|
-
"total_uploads": 0,
|
|
119
|
-
"total_size_bytes": 0,
|
|
120
|
-
"last_upload_time": None,
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
total_uploads = 0
|
|
124
|
-
total_size_bytes = 0
|
|
125
|
-
last_upload_time: int | None = None
|
|
126
|
-
|
|
127
|
-
try:
|
|
128
|
-
for upload_file in tenant_dir.glob("*.json"):
|
|
129
|
-
stat = upload_file.stat()
|
|
130
|
-
total_uploads += 1
|
|
131
|
-
total_size_bytes += stat.st_size
|
|
132
|
-
|
|
133
|
-
if last_upload_time is None or stat.st_mtime > last_upload_time:
|
|
134
|
-
last_upload_time = int(stat.st_mtime)
|
|
135
|
-
|
|
136
|
-
except (OSError, PermissionError) as e:
|
|
137
|
-
logger.warning("Failed to get stats for tenant %s: %s", tenant.id, e)
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
"total_uploads": total_uploads,
|
|
141
|
-
"total_size_bytes": total_size_bytes,
|
|
142
|
-
"last_upload_time": str(last_upload_time) if last_upload_time else None,
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def serialize_api_response(data: dict[str, Any]) -> bytes:
|
|
147
|
-
"""Serialize API response to JSON bytes.
|
|
148
|
-
|
|
149
|
-
Args:
|
|
150
|
-
data: Response data dictionary
|
|
151
|
-
|
|
152
|
-
Returns:
|
|
153
|
-
JSON-encoded bytes
|
|
154
|
-
"""
|
|
155
|
-
return json.dumps(data, indent=2).encode("utf-8")
|
portal/auth.py
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"""Authentication middleware for portal API.
|
|
2
|
-
|
|
3
|
-
Security controls:
|
|
4
|
-
- ASVS V16.3.2: Log failed authorization attempts
|
|
5
|
-
- Constant-time API key comparison to prevent timing attacks
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from __future__ import annotations
|
|
9
|
-
|
|
10
|
-
import logging
|
|
11
|
-
import re
|
|
12
|
-
from dataclasses import dataclass
|
|
13
|
-
from typing import TYPE_CHECKING
|
|
14
|
-
|
|
15
|
-
from kekkai_core import redact
|
|
16
|
-
|
|
17
|
-
from .tenants import Tenant, TenantStore
|
|
18
|
-
|
|
19
|
-
if TYPE_CHECKING:
|
|
20
|
-
from collections.abc import Mapping
|
|
21
|
-
|
|
22
|
-
logger = logging.getLogger(__name__)
|
|
23
|
-
|
|
24
|
-
BEARER_PATTERN = re.compile(r"^Bearer\s+(\S+)$", re.IGNORECASE)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@dataclass(frozen=True)
|
|
28
|
-
class AuthResult:
|
|
29
|
-
"""Result of authentication attempt."""
|
|
30
|
-
|
|
31
|
-
authenticated: bool
|
|
32
|
-
tenant: Tenant | None = None
|
|
33
|
-
error: str | None = None
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def authenticate_request(
|
|
37
|
-
headers: Mapping[str, str],
|
|
38
|
-
tenant_store: TenantStore,
|
|
39
|
-
client_ip: str = "unknown",
|
|
40
|
-
) -> AuthResult:
|
|
41
|
-
"""Authenticate a request using Bearer token.
|
|
42
|
-
|
|
43
|
-
Args:
|
|
44
|
-
headers: Request headers (case-insensitive lookup)
|
|
45
|
-
tenant_store: Tenant storage for API key verification
|
|
46
|
-
client_ip: Client IP for logging failed attempts
|
|
47
|
-
|
|
48
|
-
Returns:
|
|
49
|
-
AuthResult with tenant if authenticated, error otherwise
|
|
50
|
-
"""
|
|
51
|
-
auth_header = _get_header(headers, "Authorization")
|
|
52
|
-
if not auth_header:
|
|
53
|
-
_log_auth_failure(client_ip, "missing_header")
|
|
54
|
-
return AuthResult(authenticated=False, error="Missing Authorization header")
|
|
55
|
-
|
|
56
|
-
match = BEARER_PATTERN.match(auth_header)
|
|
57
|
-
if not match:
|
|
58
|
-
_log_auth_failure(client_ip, "invalid_format")
|
|
59
|
-
return AuthResult(authenticated=False, error="Invalid Authorization format")
|
|
60
|
-
|
|
61
|
-
api_key = match.group(1)
|
|
62
|
-
if not api_key:
|
|
63
|
-
_log_auth_failure(client_ip, "empty_token")
|
|
64
|
-
return AuthResult(authenticated=False, error="Empty API token")
|
|
65
|
-
|
|
66
|
-
tenant = tenant_store.get_by_api_key(api_key)
|
|
67
|
-
if not tenant:
|
|
68
|
-
_log_auth_failure(client_ip, "invalid_token", api_key_prefix=api_key[:8])
|
|
69
|
-
return AuthResult(authenticated=False, error="Invalid API key")
|
|
70
|
-
|
|
71
|
-
if not tenant.enabled:
|
|
72
|
-
_log_auth_failure(client_ip, "tenant_disabled", tenant_id=tenant.id)
|
|
73
|
-
return AuthResult(authenticated=False, error="Tenant is disabled")
|
|
74
|
-
|
|
75
|
-
logger.info(
|
|
76
|
-
"auth.success client_ip=%s tenant_id=%s",
|
|
77
|
-
redact(client_ip),
|
|
78
|
-
tenant.id,
|
|
79
|
-
)
|
|
80
|
-
return AuthResult(authenticated=True, tenant=tenant)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
def _get_header(headers: Mapping[str, str], name: str) -> str | None:
|
|
84
|
-
"""Get header value with case-insensitive lookup."""
|
|
85
|
-
for key, value in headers.items():
|
|
86
|
-
if key.lower() == name.lower():
|
|
87
|
-
return value
|
|
88
|
-
return None
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def _log_auth_failure(
|
|
92
|
-
client_ip: str,
|
|
93
|
-
reason: str,
|
|
94
|
-
tenant_id: str | None = None,
|
|
95
|
-
api_key_prefix: str | None = None,
|
|
96
|
-
) -> None:
|
|
97
|
-
"""Log authentication failure for security monitoring (ASVS V16.3.2)."""
|
|
98
|
-
parts = [f"auth.failure reason={reason}", f"client_ip={redact(client_ip)}"]
|
|
99
|
-
if tenant_id:
|
|
100
|
-
parts.append(f"tenant_id={tenant_id}")
|
|
101
|
-
if api_key_prefix:
|
|
102
|
-
parts.append(f"api_key_prefix={api_key_prefix}...")
|
|
103
|
-
logger.warning(" ".join(parts))
|
portal/enterprise/__init__.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"""Enterprise features for Kekkai Portal.
|
|
2
|
-
|
|
3
|
-
Provides:
|
|
4
|
-
- RBAC (Role-Based Access Control)
|
|
5
|
-
- SAML 2.0 SSO integration
|
|
6
|
-
- Audit logging
|
|
7
|
-
- Enterprise license gating (ECDSA asymmetric signing)
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
from __future__ import annotations
|
|
11
|
-
|
|
12
|
-
from .audit import AuditEvent, AuditEventType, AuditLog
|
|
13
|
-
from .licensing import (
|
|
14
|
-
EnterpriseLicense,
|
|
15
|
-
LicenseCheckResult,
|
|
16
|
-
LicenseSigner,
|
|
17
|
-
LicenseStatus,
|
|
18
|
-
LicenseValidator,
|
|
19
|
-
generate_keypair,
|
|
20
|
-
)
|
|
21
|
-
from .rbac import AuthorizationResult, Permission, RBACManager, Role
|
|
22
|
-
from .saml import SAMLAssertion, SAMLConfig, SAMLError, SAMLProcessor
|
|
23
|
-
|
|
24
|
-
ENTERPRISE_AVAILABLE = True
|
|
25
|
-
|
|
26
|
-
__all__ = [
|
|
27
|
-
"ENTERPRISE_AVAILABLE",
|
|
28
|
-
"AuditEvent",
|
|
29
|
-
"AuditEventType",
|
|
30
|
-
"AuditLog",
|
|
31
|
-
"AuthorizationResult",
|
|
32
|
-
"EnterpriseLicense",
|
|
33
|
-
"LicenseCheckResult",
|
|
34
|
-
"LicenseSigner",
|
|
35
|
-
"LicenseStatus",
|
|
36
|
-
"LicenseValidator",
|
|
37
|
-
"Permission",
|
|
38
|
-
"RBACManager",
|
|
39
|
-
"Role",
|
|
40
|
-
"SAMLAssertion",
|
|
41
|
-
"SAMLConfig",
|
|
42
|
-
"SAMLError",
|
|
43
|
-
"SAMLProcessor",
|
|
44
|
-
"generate_keypair",
|
|
45
|
-
]
|