@softspark/ai-toolkit 1.5.1 → 1.6.0

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.
@@ -0,0 +1,1166 @@
1
+ ---
2
+ title: "Plan: Cloud Security Pack — Multi-Cloud Audit (GCP/AWS/Azure)"
3
+ category: planning
4
+ service: ai-toolkit
5
+ tags:
6
+ - cloud-security
7
+ - gcp
8
+ - aws
9
+ - azure
10
+ - firebase
11
+ - plugin-pack
12
+ - security-audit
13
+ - credentials
14
+ doc_type: plan
15
+ status: proposed
16
+ created: "2026-04-10"
17
+ last_updated: "2026-04-10"
18
+ completion: "0%"
19
+ council_review: "2026-04-10 — conditional FOR, scope reduction recommended"
20
+ description: "Plugin pack for deterministic, read-only security auditing of GCP (Firebase/Cloud Functions), AWS (S3/Lambda/IAM), and Azure (NSG/Functions/CosmosDB). Includes CLI credential management, static+live modes, false positive resolution, SARIF output, incremental scanning, and CI integration."
21
+ ---
22
+
23
+ # Plan: Cloud Security Pack — Multi-Cloud Audit
24
+
25
+ **Status:** Proposed
26
+ **Completion:** 0%
27
+ **Created:** 2026-04-10
28
+ **Origin:** Firebase RTDB/Firestore rules audit, Cloud Functions public exposure, false positive resolution for App Check/Gateway patterns
29
+ **Estimated Effort:** 5-6 weeks (council-revised from original 3-4 weeks)
30
+
31
+ ---
32
+
33
+ ## 1. Objective
34
+
35
+ Create `cloud-security-pack` plugin pack that provides deterministic, read-only security auditing for three major cloud providers. All scripts are stdlib-only Python with zero external dependencies. The pack includes a dedicated agent, multiple scan scripts, CLI credential management, and CI pipeline integration.
36
+
37
+ **Key design principles:**
38
+ - **Read-only** — never modifies cloud resources, only reads state
39
+ - **Deterministic** — reproducible results, no LLM-driven regex (same pattern as `hipaa_scan.py`)
40
+ - **False positive aware** — context graph resolves "public endpoint behind gateway/App Check/WAF"
41
+ - **CI-ready** — `--output json` + `--output sarif` (SARIF v2.1.0 for GitHub Advanced Security), exit code 1 on HIGH, 0 otherwise
42
+ - **Credential isolation** — keys stored in `~/.ai-toolkit/credentials/`, accessible only by this pack's scripts
43
+ - **Static-first** — static mode (no credentials) is the default, live mode is opt-in upgrade
44
+ - **Incremental** — `--changed` flag scans only files modified since last commit (PR workflow)
45
+ - **IaC via `terraform show -json`** — wraps Terraform's own JSON output instead of parsing HCL directly
46
+
47
+ ---
48
+
49
+ ## 2. Architecture Overview
50
+
51
+ ```
52
+ ai-toolkit credentials add gcp --file ~/sa-viewer.json
53
+ ai-toolkit credentials add aws --profile my-audit-profile
54
+ ai-toolkit credentials add azure --subscription abc-123
55
+
56
+ ┌──────────────────────────────────────────────────────┐
57
+ │ cloud-security-pack │
58
+ │ │
59
+ │ Agent: cloud-security-auditor │
60
+ │ Tools: Read, Grep, Glob, Bash (read-only commands) │
61
+ │ │
62
+ │ Skills: │
63
+ │ /cloud-security-audit (orchestrator) │
64
+ │ /firebase-rules-audit (GCP: rules) │
65
+ │ /cloud-functions-audit (GCP: CF + IAM) │
66
+ │ /aws-security-audit (AWS: S3/Lambda) │
67
+ │ /azure-security-audit (Azure: NSG/Fn) │
68
+ │ │
69
+ │ Scripts (stdlib Python, zero deps): │
70
+ │ gcp_auth.py (credential helper)│
71
+ │ firebase_rules_scan.py (static parser) │
72
+ │ cloud_functions_audit.py (CF IAM + context) │
73
+ │ aws_security_scan.py (S3/Lambda/IAM) │
74
+ │ azure_security_scan.py (NSG/Fn/RBAC) │
75
+ │ false_positive_resolver.py (context graph) │
76
+ │ sarif_formatter.py (SARIF v2.1.0) │
77
+ │ incremental.py (git diff filter) │
78
+ │ │
79
+ │ Modes: │
80
+ │ --static (no credentials, parse IaC/source) │
81
+ │ --live (credentials, deployed state) │
82
+ │ --output json|sarif (CI pipeline) │
83
+ │ --changed <ref> (incremental, static only) │
84
+ │ --explain <id> (remediation lookup) │
85
+ └──────────────────────────────────────────────────────┘
86
+
87
+ ### YAML Parsing Constraint (BLOCKER)
88
+
89
+ Python stdlib has NO YAML parser. This affects AWS static mode:
90
+ - CloudFormation templates (`.yaml`) — YAML
91
+ - `serverless.yml` — YAML
92
+ - SAM templates (`template.yaml`) — YAML
93
+
94
+ **Decision: JSON-only for static IaC parsing.** Rationale:
95
+ 1. CloudFormation supports both JSON and YAML — JSON variant parseable with `json` module
96
+ 2. `terraform show -json` outputs JSON — the primary Terraform path
97
+ 3. `serverless.yml` → recommend users run `sls print --format json` to convert
98
+ 4. Adding `pyyaml` breaks the stdlib-only constraint for the entire toolkit
99
+
100
+ **Practical impact:** ~30% of CloudFormation users use JSON, ~70% YAML. For YAML users, live mode (`--mode live`) still works (queries APIs directly, no file parsing needed). The `--explain` output will suggest `sls print --format json` conversion.
101
+
102
+ **v2 option:** Ship a vendored minimal YAML subset parser (~150 LOC, handles flat key-value and simple nested maps — enough for security-relevant fields like `Principal`, `Effect`, `authLevel`).
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 3. Progress Tracking
108
+
109
+ | # | Feature | Priority | Status | Est. Time | Notes |
110
+ |---|---------|----------|--------|-----------|-------|
111
+ | 1.1 | CLI `credentials` command (add/list/remove/test) | P0 | Proposed | 2d | 0600 perms, allowlist wrapper |
112
+ | 1.1b | `credentials init` interactive wizard | P1 | Proposed | 1.5d | **Deferred to Milestone 2** (orchestration-review: saves 1.5d in M1 critical path) |
113
+ | 1.2 | `cloud-security-auditor` agent | P0 | Proposed | 1d | Agent definition |
114
+ | 1.3 | SARIF + incremental scan infrastructure | P0 | Proposed | 2d | `--output sarif`, `--changed` flag |
115
+ | 2.1 | `firebase-rules-audit` skill + script | P0 | Proposed | 4-5d | Recursive descent parser (orchestration-review: +1d vs regex) |
116
+ | 2.2 | `cloud-functions-audit` skill + script | P0 | Proposed | 3-4d | CF IAM + App Check context |
117
+ | 2.3 | False positive resolver (GCP context) | P0 | Proposed | 3-4d | Context graph engine — GCP only (~8 code paths). **+2d per provider** in later milestones (orchestration-review) |
118
+ | 3.1 | `aws-security-audit` skill + script | P1 | Proposed | 4-5d | S3/Lambda/IAM/SG, `terraform show -json` |
119
+ | 3.2 | `/cloud-security-audit` orchestrator + plugin.json | P1 | Proposed | 3d | Multi-provider orchestration + pack |
120
+ | 4.1 | `azure-security-audit` skill + script | P1 | Proposed | 4-5d | NSG/Functions/RBAC |
121
+ | 5.1 | Tests + CI integration docs | P1 | Proposed | 3d | Tests + SARIF + pipeline examples |
122
+ | 5.2 | Documentation (kb/) | P2 | Proposed | 1d | Checklists, patterns, KB |
123
+
124
+ **Phasing (full delivery, all 3 providers):**
125
+ - **Phase 1 (week 1-2):** Foundation + GCP — credentials CLI, agent, SARIF/incremental infra, firebase-rules, cloud-functions, false positive resolver (GCP context)
126
+ - **Phase 2 (week 3-4):** AWS + orchestrator — AWS security audit, `terraform show -json`, orchestrator skill, plugin pack, `credentials init`
127
+ - **Phase 3 (week 5-6):** Azure + polish — Azure security audit, false positive resolver (Azure context), full test suite, documentation
128
+
129
+ ---
130
+
131
+ ## 4. Dependency Graph
132
+
133
+ ```
134
+ Phase 1: Foundation + GCP (week 1-2)
135
+ ====================================
136
+ credentials CLI (1.1) ─────┐
137
+ ├──► firebase-rules-audit (2.1)
138
+ SARIF + incremental (1.3) ──┤
139
+ ├──► cloud-functions-audit (2.2) ──► false-positive-resolver (2.3)
140
+ agent definition (1.2) ─────┘
141
+
142
+ Phase 2: AWS + Orchestrator (week 3-4)
143
+ ======================================
144
+ credentials init (1.1b) ───┐
145
+ ├──► aws-security-audit (3.1) ─────► false-positive-resolver (+AWS context)
146
+ └──► orchestrator skill + plugin.json (3.2)
147
+
148
+ Phase 3: Azure + Polish (week 5-6)
149
+ ==================================
150
+ ├──► azure-security-audit (4.1) ───► false-positive-resolver (+Azure context)
151
+ └──► tests + docs (5.1, 5.2)
152
+ ```
153
+
154
+ **All 3 providers ship.** No conditional gates — full delivery in 6 weeks.
155
+
156
+ ---
157
+
158
+ ## 5. Detailed Implementation
159
+
160
+ ### Faza 1: Foundation (tydzien 1)
161
+
162
+ #### 1.1 CLI `credentials` Command
163
+
164
+ **Purpose:** Secure credential storage for cloud provider API access. Credentials live outside any project directory and are only accessible by this pack's scripts.
165
+
166
+ **CLI interface:**
167
+ ```bash
168
+ # GCP — Service Account JSON
169
+ ai-toolkit credentials add gcp --file ~/sa-viewer.json
170
+ ai-toolkit credentials add gcp --file ~/sa-viewer.json --project my-project-id
171
+
172
+ # GCP — use existing gcloud session (no file needed)
173
+ ai-toolkit credentials add gcp --gcloud --project my-project-id
174
+
175
+ # AWS — named profile (reads from ~/.aws/credentials)
176
+ ai-toolkit credentials add aws --profile audit-readonly
177
+ ai-toolkit credentials add aws --profile audit-readonly --region eu-west-1
178
+
179
+ # AWS — explicit keys (interactive, never on CLI args)
180
+ ai-toolkit credentials add aws --interactive
181
+
182
+ # Azure — subscription
183
+ ai-toolkit credentials add azure --subscription abc-123-def
184
+
185
+ # Azure — use existing az login session
186
+ ai-toolkit credentials add azure --az-cli
187
+
188
+ # Interactive guided setup (reduces onboarding from 4 steps to 1)
189
+ ai-toolkit credentials init # auto-detect provider, interactive wizard
190
+ ai-toolkit credentials init --provider gcp # skip auto-detect, go straight to GCP setup
191
+
192
+ # Management
193
+ ai-toolkit credentials list
194
+ ai-toolkit credentials remove gcp
195
+ ai-toolkit credentials remove aws
196
+ ai-toolkit credentials remove azure
197
+ ai-toolkit credentials test gcp # verify read-only access works
198
+ ai-toolkit credentials test aws
199
+ ```
200
+
201
+ **Storage structure:**
202
+ ```
203
+ ~/.ai-toolkit/
204
+ credentials/
205
+ gcp.json # SA key file (copied, chmod 0600)
206
+ gcp.meta.json # { project_id, added_at, method: "file"|"gcloud" }
207
+ aws.json # { profile, region, method: "profile"|"keys" }
208
+ azure.json # { subscription_id, method: "subscription"|"az-cli" }
209
+ ```
210
+
211
+ **`credentials init` interactive flow:**
212
+ 1. Auto-detect providers from project files (`firebase.json` → GCP, `*.tf` with `provider "aws"` → AWS, etc.)
213
+ 2. If multiple detected → ask user: "Found GCP and AWS markers. Which provider to configure first? [gcp/aws/both]"
214
+ 3. Per provider:
215
+ - GCP: "Do you have a Service Account JSON file? [y/n]" → if yes: ask path → if no: "Run `gcloud auth application-default login` and we'll use that"
216
+ - AWS: "Do you have a named profile in ~/.aws/credentials? [y/n]" → if yes: ask profile name → if no: "Run `aws configure` first"
217
+ - Azure: "Do you have an active `az login` session? [y/n]" → if yes: ask subscription ID → if no: "Run `az login` first"
218
+ 4. Run `credentials test` automatically after setup
219
+ 5. Generate `.cloud-security.json` scaffold with detected context
220
+
221
+ **Security requirements:**
222
+ - All credential files: `chmod 0600` (owner read/write only)
223
+ - Never log credential contents to stdout/stderr
224
+ - `credentials test` validates:
225
+ - Connection works (GCP: `gcloud auth list`, AWS: `aws sts get-caller-identity`, Azure: `az account show`)
226
+ - SA/role has **only read permissions** — **REFUSE to store** if write access detected (orchestration-review: warn-only is ignored by users). Override: `--force` flag with explicit acknowledgment
227
+ - Project/subscription exists
228
+ - `.gitignore`-proof — lives in `~/.ai-toolkit/`, never in project directory
229
+ - Scripts access credentials via `gcp_auth.py` helper — single entry point, no direct file reads
230
+
231
+ **Files to create/modify:**
232
+
233
+ | File | Action | Description |
234
+ |------|--------|-------------|
235
+ | `scripts/credentials_cli.py` | CREATE | CLI: add/list/remove/test credentials |
236
+ | `bin/ai-toolkit.js` | EDIT | Register `credentials` subcommand |
237
+ | `tests/test_credentials.bats` | CREATE | Tests: add, remove, permissions, test |
238
+
239
+ **Success Criteria:**
240
+ - [ ] `credentials add gcp --file` copies and secures SA key
241
+ - [ ] `credentials add aws --profile` stores profile reference
242
+ - [ ] `credentials add azure --subscription` stores subscription
243
+ - [ ] `credentials test` validates read access + warns on write perms
244
+ - [ ] `credentials list` shows providers without exposing secrets
245
+ - [ ] `credentials remove` cleans up securely
246
+ - [ ] All files created with 0600 permissions
247
+ - [ ] Tests: >= 8
248
+
249
+ ---
250
+
251
+ #### 1.3 SARIF Output + Incremental Scanning (Council addition)
252
+
253
+ **SARIF v2.1.0 output** — industry standard consumed by GitHub Advanced Security (inline PR annotations), VS Code SARIF Viewer, Azure DevOps, and SonarQube.
254
+
255
+ ```bash
256
+ /cloud-security-audit --output sarif > results.sarif
257
+
258
+ # GitHub Actions: upload SARIF for inline PR annotations
259
+ - uses: github/codeql-action/upload-sarif@v3
260
+ with:
261
+ sarif_file: results.sarif
262
+ ```
263
+
264
+ **SARIF structure (per finding):**
265
+ ```json
266
+ {
267
+ "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json",
268
+ "version": "2.1.0",
269
+ "runs": [{
270
+ "tool": { "driver": {
271
+ "name": "cloud-security-audit", "version": "1.0.0",
272
+ "rules": [{ "id": "GCP-CF-001", "shortDescription": { "text": "Public Cloud Function invoker" }, "helpUri": "https://cloud.google.com/functions/docs/securing" }]
273
+ } },
274
+ "results": [{
275
+ "ruleId": "GCP-CF-001",
276
+ "level": "error",
277
+ "message": { "text": "Cloud Function 'adminEndpoint' has allUsers invoker with no protection layer" },
278
+ "locations": [{ "physicalLocation": { "artifactLocation": { "uri": "functions/src/admin.ts" }, "region": { "startLine": 42 } } }],
279
+ "properties": { "resolved_severity": "HIGH", "context_chain": [], "provider": "gcp" }
280
+ }]
281
+ }]
282
+ }
283
+ ```
284
+
285
+ **Incremental scan mode** — scan only changed files since last commit:
286
+
287
+ ```bash
288
+ /cloud-security-audit --changed # files changed vs HEAD~1
289
+ /cloud-security-audit --changed HEAD~5 # files changed in last 5 commits
290
+ /cloud-security-audit --changed main # files changed vs main branch (PR workflow)
291
+ ```
292
+
293
+ Implementation: use `git diff --name-only <ref>` to get changed files, filter to relevant extensions (.rules, .tf, .json, .ts, .py, .bicep), scan only those. Falls back to full scan if no git repo detected.
294
+
295
+ **`--changed` applies to static mode ONLY.** Live mode always scans all deployed resources (it queries cloud APIs, not files). If user passes `--changed` with `--mode live`, emit warning: "Incremental scan applies to static analysis only. Live mode will scan all resources." and proceed with full live scan.
296
+
297
+ **`--explain` flag** — detailed remediation for a specific finding:
298
+
299
+ ```bash
300
+ /cloud-security-audit --explain GCP-CF-001
301
+ # Output: what the finding means, why it matters, exact fix steps,
302
+ # links to GCP documentation, CIS Benchmark reference
303
+ ```
304
+
305
+ **Files:**
306
+
307
+ | File | Action | Description |
308
+ |------|--------|-------------|
309
+ | `app/skills/cloud-security-audit/scripts/sarif_formatter.py` | CREATE | SARIF v2.1.0 output |
310
+ | `app/skills/cloud-security-audit/scripts/incremental.py` | CREATE | Git diff + file filter |
311
+ | `app/skills/cloud-security-audit/reference/rule-explanations.json` | CREATE | Per-rule remediation guides |
312
+
313
+ **Success Criteria:**
314
+ - [ ] `--output sarif` produces valid SARIF v2.1.0 JSON with `driver.rules[]` array (orchestration-review: GitHub silently drops annotations without rule metadata)
315
+ - [ ] SARIF upload to GitHub Advanced Security works (inline PR annotations)
316
+ - [ ] SARIF `level` mapping: HIGH→`error`, WARN→`warning`, INFO→`note`
317
+ - [ ] `--changed main` scans only PR-changed files
318
+ - [ ] `--explain <rule-id>` shows detailed remediation
319
+ - [ ] Tests: >= 6
320
+
321
+ ---
322
+
323
+ #### 1.2 Agent Definition: `cloud-security-auditor`
324
+
325
+ **File:** `app/agents/cloud-security-auditor.md`
326
+
327
+ ```markdown
328
+ ---
329
+ name: cloud-security-auditor
330
+ description: "Multi-cloud security auditor (GCP/AWS/Azure). Read-only deterministic scans
331
+ for IAM, network, storage, serverless, and compliance. False positive resolution
332
+ via security context graph."
333
+ model: opus
334
+ color: red
335
+ tools: Read, Grep, Glob, Bash
336
+ skills: security-patterns, cloud-security-audit
337
+ ---
338
+
339
+ # Cloud Security Auditor Agent
340
+
341
+ You are the **Cloud Security Auditor**. You perform read-only security assessments
342
+ across GCP, AWS, and Azure. You never modify cloud resources.
343
+
344
+ ## Core Philosophy
345
+ **"Read everything, change nothing. Context before verdict."**
346
+
347
+ ## Mandatory Protocol
348
+ Before any audit:
349
+ 1. Check credentials: `ai-toolkit credentials test <provider>`
350
+ 2. Determine mode: `--static` (IaC/source only) or `--live` (deployed state)
351
+ 3. Run deterministic scripts first, then interpret results
352
+
353
+ ## Responsibilities
354
+
355
+ ### 1. Static Analysis (no credentials needed)
356
+ - Parse IaC: Terraform (.tf), CloudFormation (.yaml/.json), Bicep (.bicep)
357
+ - Parse Firebase rules: firestore.rules, database.rules.json
358
+ - Parse source: Cloud Functions (onCall vs onRequest), Lambda handlers, Azure Functions
359
+ - Parse configs: firebase.json, serverless.yml, sam-template.yaml
360
+
361
+ ### 2. Live Analysis (credentials required, READ-ONLY)
362
+ - GCP: `gcloud` CLI commands (list, describe, get-iam-policy)
363
+ - AWS: `aws` CLI commands (s3api, lambda, iam, ec2 — get/list/describe only)
364
+ - Azure: `az` CLI commands (network nsg, functionapp, cosmosdb — list/show only)
365
+
366
+ ### 3. False Positive Resolution
367
+ Build security context graph before rendering verdict:
368
+ - Public endpoint → check: API Gateway? WAF? App Check? CDN?
369
+ - Open port → check: behind Load Balancer? VPN? private subnet?
370
+ - Broad IAM role → check: scoped to specific resource? temporary?
371
+
372
+ ## Allowed CLI Commands (WHITELIST — read-only only)
373
+
374
+ ### GCP
375
+ - gcloud functions list / describe / get-iam-policy
376
+ - gcloud projects get-iam-policy
377
+ - gcloud app-check services list
378
+ - gcloud firestore indexes list
379
+ - gcloud compute firewall-rules list
380
+ - gcloud run services list / describe
381
+ - firebase apps:list
382
+
383
+ ### AWS
384
+ - aws s3api get-bucket-policy / get-bucket-acl / get-public-access-block
385
+ - aws lambda get-policy / get-function-configuration / list-functions
386
+ - aws iam list-roles / list-policies / get-role / get-policy-version
387
+ - aws ec2 describe-security-groups / describe-network-acls
388
+ - aws apigateway get-rest-apis / get-resources
389
+ - aws elbv2 describe-load-balancers / describe-listeners
390
+
391
+ ### Azure
392
+ - az network nsg list / show / rule list
393
+ - az functionapp list / show / config show
394
+ - az cosmosdb list / show / keys list
395
+ - az role assignment list
396
+ - az webapp show / config show
397
+ - az network application-gateway list
398
+
399
+ ### NEVER ALLOWED
400
+ - Any create/update/delete/put/set/deploy/push command
401
+ - Any command that modifies state
402
+ - `gcloud auth activate-service-account` (credential pivot)
403
+ - `aws sts assume-role` (lateral movement)
404
+ - `az login` (session hijack)
405
+ - `terraform apply` / `terraform destroy`
406
+
407
+ ## Output Format
408
+ (see skill SKILL.md for detailed format)
409
+ ```
410
+
411
+ **SECURITY: Programmatic Bash Allowlist (orchestration-review P0 BLOCKER)**
412
+
413
+ The read-only whitelist above lives in the agent's system prompt. An LLM can be prompt-injected via malicious IaC files or source code comments. **The prompt-only approach is insufficient.**
414
+
415
+ **Required:** A shell wrapper script (`scripts/cloud_security_allowlist.sh`) that validates every CLI invocation against a compiled allowlist regex BEFORE execution, independent of the LLM:
416
+
417
+ ```bash
418
+ #!/bin/bash
419
+ # cloud_security_allowlist.sh — wraps Bash calls from cloud-security-auditor
420
+ # Rejects any command not matching read-only patterns
421
+
422
+ ALLOWED_PATTERNS=(
423
+ '^gcloud (functions|projects|app-check|firestore|compute|run) (list|describe|get-iam-policy|indexes)'
424
+ '^gcloud auth list$'
425
+ '^firebase apps:list'
426
+ '^aws (s3api|lambda|iam|ec2|apigateway|elbv2|sts|cloudfront) (get-|list-|describe-|generate-credential-report)'
427
+ '^aws sts get-caller-identity$'
428
+ '^az (network|functionapp|cosmosdb|role|webapp|storage) (list|show|rule list|config show|assignment list|account show)'
429
+ '^az account show$'
430
+ '^terraform show -json'
431
+ '^git diff --name-only'
432
+ '^python3 .*/scripts/.*\.(py)$'
433
+ )
434
+
435
+ CMD="$*"
436
+ for pattern in "${ALLOWED_PATTERNS[@]}"; do
437
+ if [[ "$CMD" =~ $pattern ]]; then
438
+ exec $CMD
439
+ fi
440
+ done
441
+
442
+ echo "BLOCKED: Command not in read-only allowlist: $CMD" >&2
443
+ exit 1
444
+ ```
445
+
446
+ The agent's `allowed-tools` in SKILL.md references this wrapper instead of raw Bash. All cloud CLI calls go through the allowlist.
447
+
448
+ **`terraform plan` risk (orchestration-review):** `terraform plan -json` executes providers and provisioners. A malicious `.tf` file with `local-exec` provisioner runs arbitrary code during plan. **Decision: use `terraform show -json` ONLY (reads existing state), NOT `terraform plan -json`.** Document this prominently.
449
+
450
+ **Files:**
451
+
452
+ | File | Action | Description |
453
+ |------|--------|-------------|
454
+ | `app/skills/cloud-security-audit/scripts/cloud_security_allowlist.sh` | CREATE | Bash allowlist wrapper |
455
+
456
+ **Success Criteria:**
457
+ - [ ] Agent file created in `app/agents/`
458
+ - [ ] Read-only command whitelist documented
459
+ - [ ] NEVER ALLOWED section explicit
460
+ - [ ] Programmatic Bash allowlist enforced (not just prompt)
461
+ - [ ] `terraform plan` excluded — only `terraform show -json` allowed
462
+ - [ ] Allowlist tested: blocked commands return exit 1
463
+
464
+ ---
465
+
466
+ ### Faza 2: GCP / Firebase (Phase 1, tydzien 1-2)
467
+
468
+ #### 2.1 Skill: `firebase-rules-audit`
469
+
470
+ **Purpose:** Static analysis of Firestore rules and RTDB rules. No credentials needed.
471
+
472
+ **What it scans:**
473
+
474
+ | Check | Severity | Description |
475
+ |-------|----------|-------------|
476
+ | `allow read, write: if true` | HIGH | World-readable/writable collection |
477
+ | `allow read: if true` without `write` guard | WARN | Public read — may be intentional |
478
+ | `allow write: if request.auth != null` without field validation | WARN | Authenticated but no field-level validation |
479
+ | Missing `request.resource.data` validation on writes | WARN | No schema enforcement |
480
+ | Wildcard collection `/{document=**}` with broad permissions | HIGH | Recursive wildcard + open access |
481
+ | RTDB `.read: true` or `.write: true` at root | HIGH | Entire database public |
482
+ | RTDB `.read: "auth != null"` without path scoping | WARN | All authenticated users can read everything |
483
+ | Timestamp/TTL rules missing for sensitive collections | WARN | No data lifecycle enforcement |
484
+ | `get()` / `exists()` cross-collection reads without auth check | WARN | Privilege escalation via rule chaining |
485
+ | Rules file > 256KB (approaching Firebase limit) | WARN | May hit deployment limit |
486
+
487
+ **Script:** `scripts/firebase_rules_scan.py`
488
+ - Parses `firestore.rules` via **recursive descent parser** (not regex — orchestration-review P1)
489
+ - Grammar: ~8 production rules (service, match, allow, function, condition)
490
+ - Tracks: brace depth, current match path, accumulated allow blocks
491
+ - Handles: nested `match` blocks, multi-line conditions with `&&`/`||`, custom `function` declarations
492
+ - Estimated: 550-650 LOC for parser + check logic
493
+ - Unsupported (documented): CEL ternary expressions, complex `get()`/`exists()` chains with computed paths
494
+ - Parses `database.rules.json` (JSON rules — stdlib `json` module)
495
+ - Outputs findings as JSON or text
496
+ - Exit code 1 on HIGH, 0 otherwise
497
+ - Supports `.cloud-security-ignore` for suppressions
498
+
499
+ **Reference file:** `reference/firebase-rules-patterns.md` — safe/unsafe patterns with examples
500
+
501
+ **Files:**
502
+
503
+ | File | Action | Description |
504
+ |------|--------|-------------|
505
+ | `app/skills/firebase-rules-audit/SKILL.md` | CREATE | Skill definition |
506
+ | `app/skills/firebase-rules-audit/scripts/firebase_rules_scan.py` | CREATE | Deterministic scanner |
507
+ | `app/skills/firebase-rules-audit/reference/firebase-rules-patterns.md` | CREATE | Safe/unsafe patterns |
508
+
509
+ **Success Criteria:**
510
+ - [ ] Parses `firestore.rules` — detects 10+ check patterns
511
+ - [ ] Parses `database.rules.json` — detects root-level open access
512
+ - [ ] `--output json` for CI
513
+ - [ ] `.cloud-security-ignore` support
514
+ - [ ] Tests: >= 10 (one per check pattern + edge cases)
515
+
516
+ ---
517
+
518
+ #### 2.2 Skill: `cloud-functions-audit`
519
+
520
+ **Purpose:** Audit Cloud Functions permissions and detect false positives.
521
+
522
+ **Static mode (no credentials):**
523
+
524
+ | Check | Severity | Description |
525
+ |-------|----------|-------------|
526
+ | `onRequest` handler without auth middleware | WARN | Potentially public — needs context |
527
+ | `onCall` handler (inherently authenticated) | INFO | Informational — callable is auth'd |
528
+ | Hardcoded API keys / secrets in source | HIGH | Secrets in code |
529
+ | CORS `origin: '*'` in CF handler | WARN | Unrestricted CORS |
530
+ | Missing rate limiting patterns | WARN | No throttling on public endpoint |
531
+ | `functions.https.onRequest` + no `validateFirebaseIdToken` | WARN | HTTP function without Firebase Auth check |
532
+
533
+ **Live mode (credentials required):**
534
+
535
+ | Check | Severity | CLI Command | Description |
536
+ |-------|----------|-------------|-------------|
537
+ | `allUsers` invoker on CF | CONTEXT | `gcloud functions get-iam-policy` | Public — resolve with context graph |
538
+ | `allAuthenticatedUsers` invoker | WARN | `gcloud functions get-iam-policy` | Any Google account can invoke |
539
+ | App Check enforcement status | CONTEXT | `gcloud app-check services list` | Feeds into false positive resolution |
540
+ | Deployed rules vs local rules diff | WARN | `gcloud firestore indexes` + local | Rules drift detection |
541
+ | Cloud Run public ingress | CONTEXT | `gcloud run services describe` | Public — resolve with context graph |
542
+ | Overly broad IAM roles on SA | HIGH | `gcloud projects get-iam-policy` | CF service account with editor/owner |
543
+
544
+ **Script:** `scripts/cloud_functions_audit.py`
545
+
546
+ **Files:**
547
+
548
+ | File | Action | Description |
549
+ |------|--------|-------------|
550
+ | `app/skills/cloud-functions-audit/SKILL.md` | CREATE | Skill definition |
551
+ | `app/skills/cloud-functions-audit/scripts/cloud_functions_audit.py` | CREATE | Scanner |
552
+ | `app/skills/cloud-functions-audit/scripts/gcp_auth.py` | CREATE | Credential loader |
553
+ | `app/skills/cloud-functions-audit/reference/false-positives-gcp.md` | CREATE | False positive patterns |
554
+
555
+ **Success Criteria:**
556
+ - [ ] Static: parses CF source for auth patterns
557
+ - [ ] Live: checks IAM bindings via `gcloud`
558
+ - [ ] False positive resolution for App Check + Gateway patterns
559
+ - [ ] Tests: >= 8
560
+
561
+ ---
562
+
563
+ #### 2.3 False Positive Resolver
564
+
565
+ **Purpose:** Central engine that resolves "is this actually a problem?" by building a security context graph.
566
+
567
+ **How it works:**
568
+ ```
569
+ Input: Finding { resource, severity, type }
570
+
571
+ Step 1: Gather context
572
+ ├── Check API Gateway routes (firebase.json rewrites, API Gateway configs)
573
+ ├── Check WAF/CDN (Cloudflare, CloudFront, Azure Front Door)
574
+ ├── Check App Check / AppArmor / Shield
575
+ ├── Check callable vs HTTP function type
576
+ ├── Check VPC / private subnet placement
577
+ └── Check Load Balancer + auth middleware
578
+
579
+ Step 2: Apply resolution rules
580
+ ├── Public CF + App Check ENFORCED → SUPPRESSED (protected)
581
+ ├── Public CF + API Gateway route → SUPPRESSED (gateway handles auth)
582
+ ├── Public CF + onCall() → SUPPRESSED (callable is auth'd by SDK)
583
+ ├── Public S3 + CloudFront OAI → SUPPRESSED (not directly accessible)
584
+ ├── Open SG port + ALB → SUPPRESSED (ALB handles TLS + auth)
585
+ ├── Open NSG + Application Gateway → SUPPRESSED (WAF handles filtering)
586
+ └── No context found → KEEP ORIGINAL SEVERITY
587
+
588
+ Step 3: Output
589
+ ├── Original severity
590
+ ├── Resolved severity (SUPPRESSED / DOWNGRADED / CONFIRMED)
591
+ ├── Context chain (what protections were found)
592
+ └── Confidence (high if multiple protections, low if single)
593
+ ```
594
+
595
+ **Output example:**
596
+ ```json
597
+ {
598
+ "resource": "processPayment",
599
+ "provider": "gcp",
600
+ "type": "cloud-function-public-invoker",
601
+ "original_severity": "HIGH",
602
+ "resolved_severity": "SUPPRESSED",
603
+ "confidence": "high",
604
+ "context_chain": [
605
+ { "layer": "app_check", "status": "ENFORCED", "source": "gcloud app-check services list" },
606
+ { "layer": "function_type", "status": "onCall", "source": "source:index.ts:42" },
607
+ { "layer": "api_gateway", "status": "ROUTED", "source": "firebase.json:rewrites" }
608
+ ],
609
+ "verdict": "3/3 protection layers active. Suppressing finding."
610
+ }
611
+ ```
612
+
613
+ **Script:** `scripts/false_positive_resolver.py`
614
+
615
+ **Resolution rules stored in:** `reference/resolution-rules.json`
616
+ ```json
617
+ {
618
+ "rules": [
619
+ {
620
+ "id": "gcp-cf-appcheck",
621
+ "finding_type": "cloud-function-public-invoker",
622
+ "provider": "gcp",
623
+ "context_required": ["app_check:ENFORCED"],
624
+ "action": "SUPPRESS",
625
+ "reason": "App Check enforced — only verified app instances can invoke"
626
+ },
627
+ {
628
+ "id": "gcp-cf-callable",
629
+ "finding_type": "cloud-function-public-invoker",
630
+ "provider": "gcp",
631
+ "context_required": ["function_type:onCall"],
632
+ "action": "SUPPRESS",
633
+ "reason": "onCall functions require Firebase Auth token from client SDK"
634
+ },
635
+ {
636
+ "id": "aws-s3-cloudfront-oai",
637
+ "finding_type": "s3-bucket-public-access",
638
+ "provider": "aws",
639
+ "context_required": ["cloudfront_oai:ACTIVE"],
640
+ "action": "SUPPRESS",
641
+ "reason": "Bucket accessed only via CloudFront Origin Access Identity"
642
+ },
643
+ {
644
+ "id": "azure-func-apigw",
645
+ "finding_type": "function-app-public",
646
+ "provider": "azure",
647
+ "context_required": ["application_gateway:ACTIVE"],
648
+ "action": "SUPPRESS",
649
+ "reason": "Function behind Application Gateway with WAF"
650
+ }
651
+ ]
652
+ }
653
+ ```
654
+
655
+ **Files:**
656
+
657
+ | File | Action | Description |
658
+ |------|--------|-------------|
659
+ | `app/skills/cloud-security-audit/scripts/false_positive_resolver.py` | CREATE | Context graph engine |
660
+ | `app/skills/cloud-security-audit/reference/resolution-rules.json` | CREATE | Configurable rules |
661
+
662
+ **Success Criteria:**
663
+ - [ ] Resolves GCP: App Check, Gateway, callable patterns
664
+ - [ ] Resolves AWS: CloudFront OAI, ALB, WAF patterns
665
+ - [ ] Resolves Azure: App Gateway, Front Door, VNET patterns
666
+ - [ ] JSON output with context chain
667
+ - [ ] User can add custom rules to `.cloud-security.json` `context` section
668
+ - [ ] Tests: >= 12 (4 per provider)
669
+
670
+ ---
671
+
672
+ ### Faza 3: AWS (Phase 2, tydzien 3-4)
673
+
674
+ #### 3.1 Skill: `aws-security-audit`
675
+
676
+ **Static mode (IaC parsing):**
677
+
678
+ | Check | Severity | Source | Description |
679
+ |-------|----------|--------|-------------|
680
+ | S3 bucket `"Effect": "Allow", "Principal": "*"` | HIGH | .tf / .json | Public bucket policy |
681
+ | S3 `BlockPublicAccess` all false | HIGH | .tf / .json | Public access not blocked |
682
+ | Lambda `resource-based policy` with `Principal: "*"` | HIGH | .tf / .json | Public Lambda |
683
+ | Security Group `0.0.0.0/0` ingress on non-80/443 | HIGH | .tf / .json | Open port to world |
684
+ | IAM policy with `Action: "*"` | HIGH | .tf / .json | God-mode IAM |
685
+ | IAM policy with `Resource: "*"` + sensitive actions | WARN | .tf / .json | Broad resource scope |
686
+ | Unencrypted RDS/DynamoDB | WARN | .tf / .json | Missing encryption at rest |
687
+ | CloudTrail disabled | HIGH | .tf / .json | No audit logging |
688
+ | Missing VPC Flow Logs | WARN | .tf / .json | No network monitoring |
689
+
690
+ **Live mode:**
691
+
692
+ | Check | CLI Command | Description |
693
+ |-------|-------------|-------------|
694
+ | S3 public buckets | `aws s3api get-public-access-block` | Per-bucket public access |
695
+ | Lambda public policies | `aws lambda get-policy` | Resource-based policies |
696
+ | Open Security Groups | `aws ec2 describe-security-groups` | Ingress from 0.0.0.0/0 |
697
+ | Overly permissive IAM | `aws iam list-roles` + `get-role` | Roles with admin/broad access |
698
+ | Unused IAM credentials | `aws iam generate-credential-report` | Stale access keys |
699
+ | API Gateway without auth | `aws apigateway get-rest-apis` | Endpoints without authorizer |
700
+
701
+ **Script:** `scripts/aws_security_scan.py`
702
+
703
+ **Files:**
704
+
705
+ | File | Action | Description |
706
+ |------|--------|-------------|
707
+ | `app/skills/aws-security-audit/SKILL.md` | CREATE | Skill definition |
708
+ | `app/skills/aws-security-audit/scripts/aws_security_scan.py` | CREATE | Scanner |
709
+ | `app/skills/aws-security-audit/scripts/aws_auth.py` | CREATE | Credential loader |
710
+ | `app/skills/aws-security-audit/reference/aws-security-checklist.md` | CREATE | CIS Benchmark mapping |
711
+ | `app/skills/aws-security-audit/reference/false-positives-aws.md` | CREATE | ALB/CloudFront/WAF patterns |
712
+
713
+ **Terraform approach (council revision):** Do NOT parse HCL directly (stdlib-only Python cannot handle heredocs, variable interpolation, modules, `for_each`). Instead wrap `terraform show -json` / `terraform plan -json` which outputs clean JSON. Fallback to flat-resource regex for projects without `terraform` CLI.
714
+
715
+ **Success Criteria:**
716
+ - [ ] Static: `terraform show -json` wrapper + CloudFormation/SAM JSON parsing
717
+ - [ ] Live: checks S3, Lambda, IAM, SG via `aws` CLI
718
+ - [ ] False positive resolution for CloudFront/ALB/WAF
719
+ - [ ] CIS Benchmark mapping in reference
720
+ - [ ] Tests: >= 10
721
+
722
+ ---
723
+
724
+ ### Faza 4: Azure (Phase 3, tydzien 5-6)
725
+
726
+ #### 4.1 Skill: `azure-security-audit`
727
+
728
+ **Static mode (IaC parsing):**
729
+
730
+ | Check | Severity | Source | Description |
731
+ |-------|----------|--------|-------------|
732
+ | NSG rule `0.0.0.0/0` source on management ports | HIGH | .tf / .bicep | Open RDP/SSH to world |
733
+ | Function App `authLevel: "anonymous"` | WARN | source / .tf | Public Azure Function |
734
+ | Cosmos DB `publicNetworkAccess: enabled` | WARN | .tf / .bicep | Public database access |
735
+ | Storage Account `allowBlobPublicAccess: true` | HIGH | .tf / .bicep | Public blob storage |
736
+ | Missing Key Vault references (hardcoded secrets) | HIGH | source | Secrets not in Key Vault |
737
+ | Missing RBAC (classic co-admin model) | WARN | .tf | Legacy access model |
738
+
739
+ **Live mode:**
740
+
741
+ | Check | CLI Command | Description |
742
+ |-------|-------------|-------------|
743
+ | Open NSG rules | `az network nsg rule list` | Broad inbound rules |
744
+ | Function App auth | `az functionapp show` + `config` | Auth level and provider |
745
+ | Cosmos DB access | `az cosmosdb show` | Network access settings |
746
+ | RBAC assignments | `az role assignment list` | Owner/Contributor sprawl |
747
+ | Storage public access | `az storage account show` | Blob public access |
748
+ | App Service auth | `az webapp auth show` | Auth configuration |
749
+
750
+ **Script:** `scripts/azure_security_scan.py`
751
+
752
+ **Files:**
753
+
754
+ | File | Action | Description |
755
+ |------|--------|-------------|
756
+ | `app/skills/azure-security-audit/SKILL.md` | CREATE | Skill definition |
757
+ | `app/skills/azure-security-audit/scripts/azure_security_scan.py` | CREATE | Scanner |
758
+ | `app/skills/azure-security-audit/scripts/azure_auth.py` | CREATE | Credential loader |
759
+ | `app/skills/azure-security-audit/reference/azure-security-checklist.md` | CREATE | CIS Benchmark mapping |
760
+ | `app/skills/azure-security-audit/reference/false-positives-azure.md` | CREATE | App Gateway/Front Door patterns |
761
+
762
+ **Success Criteria:**
763
+ - [ ] Static: parses Terraform, Bicep, ARM templates
764
+ - [ ] Live: checks NSG, Functions, CosmosDB, RBAC via `az` CLI
765
+ - [ ] False positive resolution for App Gateway/Front Door/VNET
766
+ - [ ] Tests: >= 10
767
+
768
+ ---
769
+
770
+ ### Faza 3 (cont.): Orchestration + Pack Integration (Phase 2, tydzien 3-4)
771
+
772
+ #### 3.2 Orchestrator Skill: `/cloud-security-audit`
773
+
774
+ **Purpose:** Single entry point that runs all provider audits detected in the project.
775
+
776
+ **Behavior:**
777
+ 1. Auto-detect providers from project files:
778
+ - `firebase.json` / `firestore.rules` / `.firebaserc` → GCP
779
+ - `serverless.yml` / `template.yaml` / `*.tf` with `provider "aws"` → AWS
780
+ - `*.bicep` / `*.tf` with `provider "azurerm"` / `azure-pipelines.yml` → Azure
781
+ 2. Check available credentials: `ai-toolkit credentials list`
782
+ 3. Run detected provider scans in parallel
783
+ 4. Merge results through false positive resolver
784
+ 5. Output unified report
785
+
786
+ **Skill frontmatter:**
787
+ ```yaml
788
+ ---
789
+ name: cloud-security-audit
790
+ description: "Multi-cloud security audit — auto-detects GCP/AWS/Azure and runs
791
+ deterministic scans with false positive resolution"
792
+ user-invocable: true
793
+ effort: high
794
+ disable-model-invocation: true
795
+ context: fork
796
+ agent: cloud-security-auditor
797
+ argument-hint: "[path] [--provider gcp|aws|azure|auto] [--mode static|live] [--severity high|warn] [--output json]"
798
+ allowed-tools: Read, Grep, Glob, Bash
799
+ ---
800
+ ```
801
+
802
+ **CLI usage:**
803
+ ```bash
804
+ /cloud-security-audit # auto-detect providers, static mode (default)
805
+ /cloud-security-audit --provider gcp # GCP only
806
+ /cloud-security-audit --provider aws,azure # AWS + Azure
807
+ /cloud-security-audit --mode static # no credentials, IaC/source only (DEFAULT)
808
+ /cloud-security-audit --mode live # deployed state (requires credentials)
809
+ /cloud-security-audit --severity high # HIGH findings only
810
+ /cloud-security-audit --output json # CI pipeline output
811
+ /cloud-security-audit --output sarif # SARIF v2.1.0 for GitHub Advanced Security
812
+ /cloud-security-audit --changed main # incremental: only files changed vs main
813
+ /cloud-security-audit --explain GCP-CF-001 # detailed remediation for specific rule
814
+ /cloud-security-audit src/functions/ # scan specific path
815
+ ```
816
+
817
+ **Unified report format:**
818
+ ```markdown
819
+ ## Cloud Security Audit Report
820
+
821
+ ### Summary
822
+ | Metric | GCP | AWS | Azure | Total |
823
+ |--------|-----|-----|-------|-------|
824
+ | Mode | live | static | n/a | — |
825
+ | Resources scanned | 12 | 8 | 0 | 20 |
826
+ | HIGH | 2 | 1 | 0 | 3 |
827
+ | WARN | 4 | 3 | 0 | 7 |
828
+ | SUPPRESSED (false positive) | 3 | 1 | 0 | 4 |
829
+
830
+ ### Findings (sorted by severity)
831
+
832
+ #### [HIGH] GCP: Cloud Function "adminEndpoint" — public invoker, no protection
833
+ ...
834
+
835
+ #### [SUPPRESSED] GCP: Cloud Function "processPayment" — public invoker
836
+ Context: App Check ENFORCED + onCall + API Gateway routed (3/3 layers)
837
+ ...
838
+ ```
839
+
840
+ ---
841
+
842
+ #### 3.2.1 Plugin Pack Manifest
843
+
844
+ **File:** `app/plugins/cloud-security-pack/plugin.json`
845
+
846
+ ```json
847
+ {
848
+ "name": "cloud-security-pack",
849
+ "description": "Multi-cloud security auditing for GCP, AWS, and Azure",
850
+ "version": "1.0.0",
851
+ "domain": "cloud-security",
852
+ "type": "plugin-pack",
853
+ "status": "experimental",
854
+ "requires": [],
855
+ "includes": {
856
+ "agents": ["cloud-security-auditor"],
857
+ "skills": [
858
+ "cloud-security-audit",
859
+ "firebase-rules-audit",
860
+ "cloud-functions-audit",
861
+ "aws-security-audit",
862
+ "azure-security-audit"
863
+ ],
864
+ "rules": [],
865
+ "hooks": []
866
+ },
867
+ "credentials": {
868
+ "supported_providers": ["gcp", "aws", "azure"],
869
+ "setup_command": "ai-toolkit credentials add <provider>"
870
+ }
871
+ }
872
+ ```
873
+
874
+ **Directory structure:**
875
+ ```
876
+ app/plugins/cloud-security-pack/
877
+ ├── plugin.json
878
+ ├── README.md
879
+ └── (skills and agent live in core app/ dirs, referenced by name)
880
+ ```
881
+
882
+ ---
883
+
884
+ ### Faza 5: Tests + Documentation (ongoing, ships with each milestone)
885
+
886
+ #### 5.1 Tests
887
+
888
+ | Test file | Count | Description |
889
+ |-----------|-------|-------------|
890
+ | `tests/test_credentials.bats` | 8+ | CLI credentials management |
891
+ | `tests/test_firebase_rules_scan.py` | 10+ | Firestore/RTDB rules patterns |
892
+ | `tests/test_cloud_functions_audit.py` | 8+ | CF static + live checks |
893
+ | `tests/test_aws_security_scan.py` | 10+ | S3/Lambda/IAM/SG checks |
894
+ | `tests/test_azure_security_scan.py` | 10+ | NSG/Functions/CosmosDB checks |
895
+ | `tests/test_false_positive_resolver.py` | 12+ | Context graph resolution |
896
+ | `tests/test_sarif_formatter.py` | 4+ | SARIF v2.1.0 output validation |
897
+ | `tests/test_incremental.py` | 4+ | Git diff filtering, fallback |
898
+ | `tests/test_credentials_init.py` | 4+ | Interactive wizard, auto-detect |
899
+ | **Total** | **70+** | |
900
+
901
+ #### 5.2 Documentation
902
+
903
+ | File | Description |
904
+ |------|-------------|
905
+ | `kb/planning/cloud-security-pack-plan.md` | This document |
906
+ | `kb/reference/cloud-security-checklist.md` | Unified multi-cloud checklist (created when Milestone 1 ships) |
907
+ | Skills `reference/` dirs | Per-provider patterns and false positives |
908
+
909
+ ---
910
+
911
+ ## 6. Configuration & Suppression (Unified)
912
+
913
+ **Council revision:** merged `.cloud-security-ignore` + `.cloud-security-config` into a single `.cloud-security.json`. Two config files is one too many — developers expect one file.
914
+
915
+ Scaffold interactively: `ai-toolkit credentials init` generates this file.
916
+
917
+ **Suppression Governance (orchestration-review P0):**
918
+ - **Wildcard ignores** (e.g., `GCP-CF-*`) REQUIRE a `justification` field — scanner refuses to suppress without one
919
+ - **All ignore entries** require `justification` — enforced by schema validation
920
+ - **CI diff detection:** When `.cloud-security.json` is modified in a PR, scanner emits a `SUPPRESSION_CHANGED` finding (severity: WARN) listing added/removed/modified ignore rules. This prevents silent suppression of vulnerabilities via committed config changes.
921
+ - **In live mode:** context claims (e.g., `app_check_enforced: true`) are verified against actual cloud state. If claim doesn't match reality, emit `CONTEXT_MISMATCH` finding (severity: HIGH)
922
+
923
+ ```json
924
+ {
925
+ "$schema": "https://softspark.github.io/ai-toolkit/schemas/cloud-security.json",
926
+
927
+ "ignore": [
928
+ { "rule": "GCP-CF-001:processPayment", "justification": "Behind App Check + API Gateway, verified 2026-04-10" },
929
+ { "rule": "AWS-S3-001:static-assets", "justification": "Intentionally public static bucket, CloudFront OAI active" },
930
+ { "rule": "GCP-CF-*", "justification": "REQUIRED for wildcard suppression — reviewed by @jacek in PR #142" }
931
+ ],
932
+
933
+ "context": {
934
+ "gcp": {
935
+ "app_check_enforced": true,
936
+ "api_gateway": "projects/my-proj/locations/us-central1/gateways/main",
937
+ "known_public_functions": ["healthCheck", "webhookReceiver"]
938
+ },
939
+ "aws": {
940
+ "waf_enabled": true,
941
+ "cloudfront_distributions": ["E1234567890"],
942
+ "known_public_buckets": ["static-assets-prod"]
943
+ },
944
+ "azure": {
945
+ "front_door_enabled": true,
946
+ "application_gateway": "my-app-gw",
947
+ "known_public_functions": ["webhookHandler"]
948
+ }
949
+ }
950
+ }
951
+ ```
952
+
953
+ ---
954
+
955
+ ## 7. CI Pipeline Integration
956
+
957
+ ### Basic: JSON output + fail on HIGH
958
+
959
+ ```yaml
960
+ - name: Cloud Security Audit
961
+ run: |
962
+ python3 scripts/cloud_security_audit.py \
963
+ --mode static --output json --severity high \
964
+ > security-report.json
965
+ # Exit code 1 = HIGH findings → fail pipeline
966
+ ```
967
+
968
+ ### Recommended: SARIF + GitHub Advanced Security (inline PR annotations)
969
+
970
+ ```yaml
971
+ - name: Cloud Security Audit
972
+ run: |
973
+ python3 scripts/cloud_security_audit.py \
974
+ --mode static --output sarif --changed ${{ github.event.pull_request.base.sha }} \
975
+ > results.sarif
976
+ continue-on-error: true
977
+
978
+ - name: Upload SARIF
979
+ uses: github/codeql-action/upload-sarif@v3
980
+ with:
981
+ sarif_file: results.sarif
982
+ ```
983
+
984
+ ### Live mode with credentials (hardened — orchestration-review P0)
985
+
986
+ ```yaml
987
+ - name: Cloud Security Audit (Live)
988
+ env:
989
+ GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
990
+ run: |
991
+ TMPFILE=$(mktemp -m 0600)
992
+ trap 'rm -f "$TMPFILE"' EXIT
993
+ echo "$GCP_SA_KEY" > "$TMPFILE"
994
+ ai-toolkit credentials add gcp --file "$TMPFILE"
995
+ python3 scripts/cloud_security_audit.py \
996
+ --mode live --output sarif --changed "${{ github.event.pull_request.base.sha }}" \
997
+ > results.sarif
998
+
999
+ - name: Validate & Upload SARIF
1000
+ if: always()
1001
+ run: python3 -c "import json; d=json.load(open('results.sarif')); assert d.get('version')=='2.1.0', 'Invalid SARIF'"
1002
+ continue-on-error: false
1003
+
1004
+ - name: Upload SARIF
1005
+ uses: github/codeql-action/upload-sarif@v3
1006
+ with:
1007
+ sarif_file: results.sarif
1008
+ ```
1009
+
1010
+ **CI Security Notes (orchestration-review):**
1011
+ - `mktemp -m 0600` creates file with owner-only permissions (not world-readable `/tmp/sa.json`)
1012
+ - `trap 'rm -f' EXIT` ensures cleanup even on script failure
1013
+ - SARIF schema validated before upload to prevent injected/corrupted annotations
1014
+ - `${{ github.event.pull_request.base.sha }}` quoted to prevent shell injection via crafted refs
1015
+ - Consider GitHub OIDC workload identity federation instead of long-lived SA keys for production
1016
+
1017
+ ---
1018
+
1019
+ ## 8. Success Criteria (Overall)
1020
+
1021
+ | Metric | Target |
1022
+ |--------|--------|
1023
+ | Providers supported | 3 (GCP, AWS, Azure) |
1024
+ | Check patterns (total) | 40+ (GCP: 16, AWS: 15, Azure: 12) |
1025
+ | False positive rules | 10+ |
1026
+ | Output formats | 3 (text, JSON, SARIF v2.1.0) |
1027
+ | CLI commands | 7 (add, list, remove, test, init per provider) |
1028
+ | Scripts (stdlib Python) | 9 (auth + scanners + resolver + sarif + incremental) |
1029
+ | Tests | 70+ |
1030
+ | External dependencies | 0 (stdlib only, CLI tools: gcloud/aws/az/terraform) |
1031
+ | CI exit codes | 0=clean, 1=HIGH findings, 2=credential error |
1032
+ | Incremental scan | `--changed` flag works with git refs |
1033
+ | GitHub integration | SARIF upload → inline PR annotations |
1034
+
1035
+ ---
1036
+
1037
+ ## 9. Fix Strategy
1038
+
1039
+ **Same approach as HIPAA scanner v1: No auto-fix. Agent interprets and suggests.**
1040
+
1041
+ The deterministic scripts produce findings. The `cloud-security-auditor` agent then:
1042
+ 1. **Reads** the flagged file/resource to understand actual context
1043
+ 2. **Suggests** a specific fix (not generic advice — concrete code/config change)
1044
+ 3. **Never** auto-applies changes — the user reviews and applies manually
1045
+
1046
+ Examples:
1047
+ - Firestore rules finding → agent suggests the exact `allow read: if request.auth != null` rule change
1048
+ - Public CF finding → agent suggests adding `validateFirebaseIdToken` middleware with code snippet
1049
+ - Open S3 bucket → agent suggests the exact bucket policy JSON to add `BlockPublicAccess`
1050
+ - Broad IAM role → agent suggests the minimal policy document with only required permissions
1051
+
1052
+ **Why no auto-fix in v1:**
1053
+ - Cloud security fixes require project-specific knowledge (which SA, which bucket, which auth flow)
1054
+ - Wrong auto-fix on IAM can lock out real users
1055
+ - Firestore rules changes can break client apps
1056
+ - The agent's context-aware suggestion is more valuable than a blind auto-fix
1057
+
1058
+ **v2 option:** `--fix-mode suggest` generates a `.cloud-security-fixes.patch` file that users can review and apply with `git apply`.
1059
+
1060
+ ---
1061
+
1062
+ ## 10. Risks and Mitigation (updated)
1063
+
1064
+ | Risk | Probability | Impact | Mitigation |
1065
+ |------|-------------|--------|------------|
1066
+ | CLI tools (gcloud/aws/az) not installed | Medium | Medium | Graceful fallback to static-only mode, clear error message |
1067
+ | Cloud APIs change breaking audit commands | Low | Medium | Version-pin CLI output format parsing, test with CI |
1068
+ | False positive rules too aggressive (suppress real issues) | Low | High | Default to WARN not SUPPRESS, require `.cloud-security-config` for suppression |
1069
+ | Credential leakage in logs | Low | Critical | Never log credentials, 0600 perms, `/tmp` cleanup in CI |
1070
+ | Scope creep (too many checks) | Medium | Medium | Start with top-10 per provider, expand based on feedback |
1071
+ | YAML IaC not parseable (stdlib-only) | High | Medium | JSON-only for static IaC; live mode unaffected; v2: vendored YAML subset parser |
1072
+ | `--changed` confused with live mode | Low | Low | Explicit warning: incremental applies to static only |
1073
+
1074
+ ---
1075
+
1076
+ ## 11. Pre-Mortem
1077
+
1078
+ 1. **Firebase rules parser too simplistic** — Firestore rules use CEL-like syntax with nested `match` blocks. Parser needs proper recursive descent, not just regex. Mitigation: build minimal CEL parser or use line-by-line pattern matching with scope tracking.
1079
+ 2. **False positive resolver gives false confidence** — Users may trust SUPPRESSED status and miss real issues. Mitigation: always show context chain, require explicit `.cloud-security-config` for auto-suppression, default to WARN.
1080
+ 3. **AWS credential scope too broad** — User provides admin-level AWS profile. Mitigation: `credentials test` checks actual permissions, WARN if write access detected, suggest read-only IAM policy in docs.
1081
+ 4. **Three providers = 3x maintenance** — Each provider's CLI evolves independently. Mitigation: abstract provider interface, single test matrix, version tracking per provider.
1082
+ 5. **Terraform parsing incomplete** — HCL syntax is complex (modules, variables, conditionals). Mitigation: wrap `terraform show -json` instead of parsing HCL. Fallback to flat regex for projects without `terraform` CLI.
1083
+ 6. **SARIF adoption low** — Users may not know how to use SARIF with GitHub. Mitigation: provide copy-paste GitHub Actions workflow in docs and `--explain` for onboarding.
1084
+
1085
+ ---
1086
+
1087
+ ## 12. Council Review Summary (2026-04-10)
1088
+
1089
+ **Verdict:** CONDITIONAL FOR — implement with scope reduction.
1090
+ **Confidence:** MEDIUM (weighted score: FOR 3.1 vs AGAINST 2.9)
1091
+
1092
+ **Key insights applied to this plan:**
1093
+ - [x] Timeline revised from 3-4 → 5-6 weeks
1094
+ - [x] ~~Azure deferred to Milestone 3~~ → **reinstated: full 3-provider delivery**
1095
+ - [x] SARIF v2.1.0 output added — essential for GitHub Advanced Security integration
1096
+ - [x] Incremental scan mode added (`--changed`) — how developers actually use security tools
1097
+ - [x] `terraform show -json` wrapper instead of HCL parsing — realistic path
1098
+ - [x] Single config file `.cloud-security.json` (merged ignore + context)
1099
+ - [x] `credentials init` interactive wizard — reduce onboarding friction
1100
+ - [x] `--explain <rule-id>` for on-demand remediation guidance
1101
+ - [x] Static mode as default — zero-setup first experience
1102
+
1103
+ **Deferred to v2:**
1104
+ - Kubernetes/container security (separate pack candidate)
1105
+ - Secret scanning with entropy detection
1106
+ - Compliance framework mapping (SOC2, PCI-DSS, NIST 800-53)
1107
+ - Visual security dashboard in browser
1108
+ - GitHub PR comment integration beyond SARIF
1109
+ - Vendored YAML subset parser for CloudFormation YAML static scanning
1110
+
1111
+ **Council strongest agreement:** False positive resolver is the killer feature and primary differentiator vs Checkov/Trivy/Prowler. No existing tool combines deterministic scanning with context-aware resolution.
1112
+
1113
+ ---
1114
+
1115
+ ## 13. Orchestration Review Summary (2026-04-10)
1116
+
1117
+ **Agents:** tech-lead, security-architect, product-manager, code-reviewer (4 parallel)
1118
+
1119
+ **Verdict:** Plan structurally complete (14/14 elements). Three P0 security blockers identified and resolved.
1120
+
1121
+ **Applied changes:**
1122
+
1123
+ | # | Action | Source | Priority | Applied? |
1124
+ |---|--------|--------|----------|----------|
1125
+ | 1 | Programmatic Bash allowlist | security-architect | P0 | Yes — allowlist.sh + agent integration |
1126
+ | 2 | CI hardening (mktemp/trap/SARIF validation) | security-architect | P0 | Yes — CI examples rewritten |
1127
+ | 3 | Suppression governance (justification + diff detection) | security-architect | P0 | Yes — schema + SUPPRESSION_CHANGED finding |
1128
+ | 4 | Recursive descent parser for Firestore | code-reviewer | P1 | Yes — replaced regex approach, +1d estimate |
1129
+ | 5 | SARIF `driver.rules[]` for GitHub annotations | code-reviewer | P1 | Yes — schema + success criteria |
1130
+ | 6 | Task 4.1→3.2 numbering fix | tech-lead | P1 | Yes — renumbered |
1131
+ | 7 | `terraform plan` execution risk documented | security-architect | P1 | Yes — only `show -json` allowed |
1132
+ | 8 | `credentials init` deferred to M2 | code-reviewer | P2 | Yes — saves 1.5d in M1 |
1133
+ | 9 | False positive resolver budgeted +2d/provider | code-reviewer | P2 | Yes — estimate updated |
1134
+ | 10 | `SUPPRESSION_CHANGED` finding type | security-architect | P2 | Yes — in governance section |
1135
+
1136
+ **Market positioning (product-manager):**
1137
+ - Not competing with Checkov on check count (40 vs 3000)
1138
+ - Competing on: zero-noise (false positive resolver), zero-setup (static-first), IDE-native (10 platforms), AI interpretation
1139
+ - Target: developers in ai-toolkit ecosystem, not enterprise security teams
1140
+ - Value as ecosystem feature, not standalone product
1141
+
1142
+ **Timeline revision (code-reviewer):**
1143
+ - 1 person: 6-7 weeks realistic (was 5-6)
1144
+ - 2 people: 4-5 weeks (parallel GCP + AWS tracks)
1145
+ - All 3 providers ship in 6 weeks — no conditional gates
1146
+
1147
+ ---
1148
+
1149
+ ## 14. Next Actions
1150
+
1151
+ 1. [ ] Approve plan
1152
+ 2. [ ] Implement `credentials` CLI command (1.1) + Bash allowlist
1153
+ 3. [ ] Create `cloud-security-auditor` agent (1.2)
1154
+ 4. [ ] Implement SARIF formatter + incremental scan (1.3)
1155
+ 5. [ ] Implement `firebase-rules-audit` — recursive descent parser (2.1)
1156
+ 6. [ ] Implement `cloud-functions-audit` + false positive resolver GCP (2.2, 2.3)
1157
+ 7. [ ] Implement `aws-security-audit` + `terraform show -json` wrapper (3.1)
1158
+ 8. [ ] Implement orchestrator + plugin pack + `credentials init` (3.2, 1.1b)
1159
+ 9. [ ] Implement `azure-security-audit` + false positive resolver Azure (4.1)
1160
+ 10. [ ] Full test suite (70+) + documentation + release
1161
+
1162
+ ---
1163
+
1164
+ **Last Updated:** 2026-04-10
1165
+ **Council Reviewed:** 2026-04-10
1166
+ **Orchestration Reviewed:** 2026-04-10 (4 agents: tech-lead, security-architect, product-manager, code-reviewer)