Skip to content

Commit becbfa3

Browse files
fix: streamline discovery targeting and live catalog loading (#55)
* fix: streamline discovery targeting and live catalog loading * fix(sdk): avoid duplicate single-region debug logs * fix(cli): list supported regions in validation errors * fix(sdk): restore discovery target compatibility * fix(sdk): avoid ambient region lookup for explicit discovery targets
1 parent 642391d commit becbfa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2206
-489
lines changed

.changeset/nice-trains-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cloudburn": patch
3+
---
4+
5+
Restore `cloudburn discover --region` as a single-region CLI flag while keeping SDK-backed debug output streamed from the SDK and provider layers.

.changeset/small-bottles-laugh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudburn/rules": patch
3+
---
4+
5+
Redesign `CLDBRN-AWS-CLOUDWATCH-2` to flag inactive CloudWatch log groups from latest stream activity summaries instead of enumerating every log stream.

.changeset/tame-lions-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudburn/sdk": patch
3+
---
4+
5+
Reduce live discovery fan-out with batched Resource Explorer queries, add throttling-aware retries and debug tracing, and add log-group-level CloudWatch activity hydration to avoid full log-stream enumeration for stale log group checks.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,18 @@ cloudburn --format json scan ./iac
118118

119119
### Discover
120120

121-
`discover` runs the same rules against live AWS resources. Initialize AWS Resource Explorer first, then run against one region or all of them.
121+
`discover` runs the same rules against live AWS resources. Initialize AWS Resource Explorer first, then run against the current AWS region or one explicit region.
122122

123123
```bash
124124
cloudburn discover init
125125
cloudburn discover
126126
cloudburn discover --region eu-central-1
127-
cloudburn discover --region all
128127
cloudburn discover --service ec2,s3
128+
cloudburn --debug discover --region eu-central-1
129129
```
130130

131-
`--region all` requires an AWS Resource Explorer aggregator index.
131+
The CLI targets one region at a time. Multi-region discovery remains available through the SDK.
132+
Use `--debug` to relay SDK and provider execution trace details to `stderr` while keeping normal command output on `stdout`.
132133

133134
Generate a starter config with `cloudburn config --init`. Full details in the [config reference](docs/reference/config-schema.md).
134135

docs/TESTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Mock at the SDK boundary — do not run real scans.
6868
- `--config`, `--enabled-rules`, and `--disabled-rules` pass the expected runtime overrides to the SDK
6969
- `--exit-code` sets `process.exitCode = 1` when findings exist
7070
- `--exit-code` without findings sets `process.exitCode = 0`
71-
- `discover list-enabled-regions`, `discover supported-resource-types`, `discover init`, `config`, `rules list`, and `estimate` all go through the shared formatter system
71+
- `discover supported-resource-types`, `discover init`, `discover status`, `config`, `rules list`, and `estimate` all go through the shared formatter system
7272
- `table` output stays human-readable and `json` output stays machine-readable
7373
- Runtime errors remain structured JSON on `stderr` regardless of stdout format
7474

docs/architecture/cli.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ graph TD
1111
Root --> Estimate["estimate"]
1212
Root --> Completion["completion"]
1313
Rules --> RulesList["list"]
14-
Discover --> DiscoverRegions["list-enabled-regions"]
1514
Discover --> DiscoverInit["init"]
1615
Discover --> DiscoverTypes["supported-resource-types"]
1716
Completion --> CompletionBash["bash"]
1817
Completion --> CompletionFish["fish"]
1918
Completion --> CompletionZsh["zsh"]
2019
21-
Root -.- RootFlags["--format json|table"]
20+
Root -.- RootFlags["--debug\n--format json|table"]
2221
Scan -.- ScanFlags["--config path\n--enabled-rules ids\n--disabled-rules ids\n--exit-code"]
23-
Discover -.- DiscoverFlags["--region <region|all>\n--config path\n--enabled-rules ids\n--disabled-rules ids\n--exit-code"]
22+
Discover -.- DiscoverFlags["--region region\n--config path\n--enabled-rules ids\n--disabled-rules ids\n--exit-code"]
2423
Estimate -.- EstimateFlags["--server url"]
2524
```
2625

@@ -38,9 +37,9 @@ graph LR
3837

3938
All stdout-producing commands return a typed `CliResponse` and share the same format resolver.
4039

41-
| Format | Output |
42-
| ------- | ---------------------------------------------------------------------------------------------------------------------------------- |
43-
| `json` | Pretty JSON for the underlying response payload |
40+
| Format | Output |
41+
| ------- | --------------------------------------------------------------------------------------------- |
42+
| `json` | Pretty JSON for the underlying response payload |
4443
| `table` | ASCII tables for scans, record lists, string lists, key/value status output, and `rules list` |
4544

4645
## Command Behavior
@@ -50,16 +49,17 @@ All stdout-producing commands return a typed `CliResponse` and share the same fo
5049
- `discover` runs live AWS discovery and rule evaluation through `CloudBurnClient.discover({ target, config?, configPath? })`.
5150
- `discover` accepts `--config`, `--enabled-rules`, `--disabled-rules`, and `--service` for one-off overrides of discovery config.
5251
- `discover --region <region>` overrides the current AWS region resolved from `AWS_REGION`, `AWS_DEFAULT_REGION`, `aws_region`, then the AWS SDK region provider chain.
53-
- `discover --region all` requires a Resource Explorer aggregator index.
54-
- `discover --region <region>` targets one enabled Resource Explorer index region.
55-
- `discover list-enabled-regions` and `discover supported-resource-types` use the shared `json|table` renderer.
52+
- The CLI targets one explicit AWS region per discover run.
53+
- Multi-region discovery remains an SDK capability through `target: { mode: 'regions', regions: [...] }` and requires a Resource Explorer aggregator index.
54+
- `discover supported-resource-types` uses the shared `json|table` renderer.
5655
- `discover init` bootstraps Resource Explorer through the SDK, defaults to the current AWS region, accepts `--region <region>` as an override, and falls back to local-only setup when cross-region bootstrap is denied.
5756
- `discover init` status output includes the resolved setup `indexType` so users can distinguish local-only setup from aggregator setup.
5857
- `config --init` creates `.cloudburn.yml` in the git root (or current directory when no git root exists), unless a config file already exists there.
5958
- `config --print` prints the current discovered config file as raw YAML by default and can render table or JSON when `--format` is provided.
6059
- `config --print-template` prints the starter template without writing a file.
6160
- `rules list`, `config`, and `estimate` all use the shared formatter system instead of ad hoc string output.
6261
- `completion` is a structural parent command. `completion bash|fish|zsh` prints shell completion scripts for the selected shell.
62+
- `--debug` is a global flag that relays SDK and provider execution tracing to `stderr` without changing normal command output on `stdout`.
6363
- `--format` is documented as a global option and defaults to `table`, except `config --print` and `config --print-template`, which preserve raw YAML by default for redirection workflows.
6464
- `scan` and `discover` can also source their default format from `.cloudburn.yml`; explicit `--format` still wins.
6565
- The hidden `__complete` command exists only as the runtime hook for generated shell scripts.
@@ -78,10 +78,8 @@ cloudburn scan ./iac --enabled-rules CLDBRN-AWS-EBS-1,CLDBRN-AWS-EC2-1
7878
cloudburn scan ./iac --service ec2,s3
7979
cloudburn discover
8080
cloudburn discover --region eu-central-1
81-
cloudburn discover --region all
8281
cloudburn discover --config .cloudburn.yml --disabled-rules CLDBRN-AWS-S3-1
8382
cloudburn discover --service ec2,s3
84-
cloudburn discover list-enabled-regions
8583
cloudburn discover init
8684
cloudburn config --init
8785
cloudburn config --print

docs/architecture/rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Rule evaluators consume static and live datasets through `context.resources.get(
9696
| `CLDBRN-AWS-CLOUDTRAIL-1` | CloudTrail Redundant Global Trails | cloudtrail | discovery | Implemented |
9797
| `CLDBRN-AWS-CLOUDTRAIL-2` | CloudTrail Redundant Regional Trails | cloudtrail | discovery | Implemented |
9898
| `CLDBRN-AWS-CLOUDWATCH-1` | CloudWatch Log Group Missing Retention | cloudwatch | discovery | Implemented |
99-
| `CLDBRN-AWS-CLOUDWATCH-2` | CloudWatch Unused Log Streams | cloudwatch | discovery | Implemented |
99+
| `CLDBRN-AWS-CLOUDWATCH-2` | CloudWatch Log Group Inactive | cloudwatch | discovery | Implemented |
100100
| `CLDBRN-AWS-EC2-1` | EC2 Instance Type Not Preferred | ec2 | iac, discovery | Implemented |
101101
| `CLDBRN-AWS-EC2-2` | S3 Interface VPC Endpoint Used | ec2 | iac | Implemented |
102102
| `CLDBRN-AWS-EC2-3` | Elastic IP Address Unassociated | ec2 | discovery | Implemented |

docs/architecture/sdk.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
class CloudBurnClient {
88
+scanStatic(path: string, config?: Partial~CloudBurnConfig~, options?: { configPath?: string }) Promise~ScanResult~
99
+discover(options?: { target?: AwsDiscoveryTarget, config?: Partial~CloudBurnConfig~, configPath?: string }) Promise~ScanResult~
10-
+listEnabledDiscoveryRegions() Promise~AwsDiscoveryRegion[]~
1110
+initializeDiscovery(options?: { region?: string }) Promise~AwsDiscoveryInitialization~
1211
+listSupportedDiscoveryResourceTypes() Promise~AwsSupportedResourceType[]~
1312
+loadConfig(path?: string) Promise~CloudBurnConfig~
@@ -72,11 +71,13 @@ Current live-discovery behavior:
7271
- `discover` is the live entrypoint for both the CLI and direct SDK callers.
7372
- `discoverAwsResources` in `src/providers/aws/discovery.ts` is the AWS live orchestration entrypoint.
7473
- Default discovery target is the current region, resolved from `AWS_REGION`, then `AWS_DEFAULT_REGION`, then `aws_region`, then the AWS SDK region provider chain.
74+
- Explicit discovery uses `target: { mode: 'regions', regions: [...] }`.
7575
- Explicit single-region discovery uses the selected region as the Resource Explorer control plane instead of the ambient current region.
76-
- `--region all` requires an aggregator index and fails fast when one is not enabled.
76+
- Explicit multi-region discovery requires an aggregator index and fails fast when one is not enabled.
7777
- Discovery resolves the explicit default Resource Explorer view in the chosen search region and fails if no default view exists or if that default view applies additional filters.
7878
- Discovery setup returns existing local indexes without forcing aggregator creation, and `discover init` retries as local-only setup when cross-region aggregator creation is denied.
7979
- Catalog collection uses Resource Explorer `ListResources` with filter strings instead of `Search`, which avoids the 1,000-result ceiling on filter-only queries.
80+
- Resource Explorer catalog seeding batches `resourcetype:` and `region:` filters into the smallest possible query set, raises `MaxResults` to `1000`, and retries throttled `ListResources` calls before failing.
8081
- Account-scoped or fallback-backed datasets can bypass Resource Explorer seeding entirely by declaring no `resourceTypes`; the loader then receives `[]` and owns the account-level API call.
8182
- Resource Explorer inventory failures and dataset loader failures are fatal. The SDK does not degrade to partial live results.
8283
- Missing Lambda `Architectures` values from AWS are normalized to `['x86_64']`, matching the AWS default architecture.

docs/reference/config-schema.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ Source of truth: `packages/sdk/src/types.ts` (type), `packages/sdk/src/config/de
1111

1212
Each mode uses the same fields:
1313

14-
| Field | Type | Default | Description |
15-
| ---------------- | ---------------------------- | ------- | --------------------------------------------------------------------------- |
16-
| `enabled-rules` | `string[]` | unset | If present, only the listed rule IDs remain active for that mode. |
17-
| `disabled-rules` | `string[]` | unset | Rule IDs to remove from the active set after `enabled-rules` is applied. |
18-
| `services` | `string[]` | unset | Service allowlist applied before `enabled-rules` and `disabled-rules`. |
19-
| `format` | `'json' \| 'table'` | unset | Default CLI output format for that mode when `--format` is not passed. |
14+
| Field | Type | Default | Description |
15+
| ---------------- | ------------------- | ------- | ------------------------------------------------------------------------ |
16+
| `enabled-rules` | `string[]` | unset | If present, only the listed rule IDs remain active for that mode. |
17+
| `disabled-rules` | `string[]` | unset | Rule IDs to remove from the active set after `enabled-rules` is applied. |
18+
| `services` | `string[]` | unset | Service allowlist applied before `enabled-rules` and `disabled-rules`. |
19+
| `format` | `'json' \| 'table'` | unset | Default CLI output format for that mode when `--format` is not passed. |
2020

2121
## Merge Behavior
2222

@@ -89,7 +89,8 @@ discovery:
8989
9090
- `cloudburn discover` defaults to the current region.
9191
- Current region resolution order is `AWS_REGION`, `AWS_DEFAULT_REGION`, `aws_region`, then the AWS SDK region provider chain.
92-
- Passing `--region <region>` overrides the current region and queries Resource Explorer from that selected region.
92+
- Passing `--region <region>` overrides the current region for the CLI discover command.
9393
- `discover({ target })` is the SDK live-discovery entrypoint.
94-
- `--region all` requires an aggregator index and an unfiltered default Resource Explorer view in the aggregator region.
94+
- `discover({ target: { mode: 'regions', regions: [...] } })` is the SDK shape for explicit discovery regions.
95+
- Multi-region SDK discovery requires an aggregator index and an unfiltered default Resource Explorer view in the aggregator region.
9596
- `cloudburn discover init` defaults to the current region, accepts `--region <region>` as an override, and falls back to local-only setup in that region when cross-region aggregator setup is denied.

docs/reference/rule-ids.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Format: `CLDBRN-{PROVIDER}-{SERVICE}-{N}`
2222
| `CLDBRN-AWS-CLOUDTRAIL-1` | CloudTrail Redundant Global Trails | cloudtrail | discovery | Implemented |
2323
| `CLDBRN-AWS-CLOUDTRAIL-2` | CloudTrail Redundant Regional Trails | cloudtrail | discovery | Implemented |
2424
| `CLDBRN-AWS-CLOUDWATCH-1` | CloudWatch Log Group Missing Retention | cloudwatch | discovery, iac | Implemented |
25-
| `CLDBRN-AWS-CLOUDWATCH-2` | CloudWatch Unused Log Streams | cloudwatch | discovery | Implemented |
25+
| `CLDBRN-AWS-CLOUDWATCH-2` | CloudWatch Log Group Inactive | cloudwatch | discovery | Implemented |
2626
| `CLDBRN-AWS-CLOUDWATCH-3` | CloudWatch Log Group No Metric Filters | cloudwatch | discovery | Implemented |
2727
| `CLDBRN-AWS-COSTGUARDRAILS-1` | AWS Budgets Missing | costguardrails | discovery | Implemented |
2828
| `CLDBRN-AWS-COSTGUARDRAILS-2` | Cost Anomaly Detection Missing | costguardrails | discovery | Implemented |
@@ -108,7 +108,7 @@ Format: `CLDBRN-{PROVIDER}-{SERVICE}-{N}`
108108

109109
`CLDBRN-AWS-EBS-7` flags only `completed` snapshots with a parsed `StartTime` older than `90` days.
110110

111-
`CLDBRN-AWS-CLOUDWATCH-2` flags log streams with no observed event history and log streams whose `lastIngestionTime` is more than 90 days old. Delivery-managed log groups remain exempt.
111+
`CLDBRN-AWS-CLOUDWATCH-2` flags log groups whose most recent observed stream activity is missing or older than 90 days. Delivery-managed log groups remain exempt.
112112

113113
`CLDBRN-AWS-CLOUDWATCH-3` reviews only log groups storing at least `1 GiB` and flags them when no metric filters are configured.
114114

0 commit comments

Comments
 (0)