cloudsweep 0.1.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.
- cloudsweep/__init__.py +1 -0
- cloudsweep/cli.py +132 -0
- cloudsweep/demo.py +92 -0
- cloudsweep/engine.py +55 -0
- cloudsweep/licensing.py +136 -0
- cloudsweep/mcp_server.py +107 -0
- cloudsweep/models.py +34 -0
- cloudsweep/output/__init__.py +0 -0
- cloudsweep/output/remediation.py +24 -0
- cloudsweep/output/terminal.py +71 -0
- cloudsweep/scanners/__init__.py +0 -0
- cloudsweep/scanners/aws_ebs.py +51 -0
- cloudsweep/scanners/aws_ipv4.py +30 -0
- cloudsweep/scanners/aws_logs.py +35 -0
- cloudsweep/scanners/aws_nat.py +58 -0
- cloudsweep/scanners/base.py +14 -0
- cloudsweep-0.1.0.dist-info/METADATA +45 -0
- cloudsweep-0.1.0.dist-info/RECORD +20 -0
- cloudsweep-0.1.0.dist-info/WHEEL +4 -0
- cloudsweep-0.1.0.dist-info/entry_points.txt +3 -0
cloudsweep/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
cloudsweep/cli.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import time
|
|
4
|
+
from typing import Annotated
|
|
5
|
+
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from cloudsweep.demo import build_demo_summary
|
|
10
|
+
from cloudsweep.engine import run_scan
|
|
11
|
+
from cloudsweep.licensing import LicenseState, LicenseTier, activate_license, get_license_state
|
|
12
|
+
from cloudsweep.output.remediation import export_cleanup_script
|
|
13
|
+
from cloudsweep.output.terminal import render_summary
|
|
14
|
+
|
|
15
|
+
app = typer.Typer(
|
|
16
|
+
name="cloudsweep",
|
|
17
|
+
help="Find and eliminate zombie AWS resources in seconds.",
|
|
18
|
+
no_args_is_help=True,
|
|
19
|
+
)
|
|
20
|
+
console = Console()
|
|
21
|
+
|
|
22
|
+
READ_ONLY_IAM_POLICY = {
|
|
23
|
+
"Version": "2012-10-17",
|
|
24
|
+
"Statement": [
|
|
25
|
+
{
|
|
26
|
+
"Sid": "CloudSweepReadOnlyAudit",
|
|
27
|
+
"Effect": "Allow",
|
|
28
|
+
"Action": [
|
|
29
|
+
"ec2:DescribeRegions",
|
|
30
|
+
"ec2:DescribeNatGateways",
|
|
31
|
+
"ec2:DescribeVolumes",
|
|
32
|
+
"ec2:DescribeAddresses",
|
|
33
|
+
"cloudwatch:GetMetricStatistics",
|
|
34
|
+
"logs:DescribeLogGroups",
|
|
35
|
+
],
|
|
36
|
+
"Resource": "*",
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@app.command()
|
|
43
|
+
def scan(
|
|
44
|
+
profile: Annotated[str | None, typer.Option("--profile", "-p", help="AWS CLI profile name")] = None,
|
|
45
|
+
region: Annotated[list[str] | None, typer.Option("--region", "-r", help="Specific AWS region(s)")] = None,
|
|
46
|
+
export_fix: Annotated[Path | None, typer.Option("--export-fix", help="Write safe cleanup.sh (Pro)")] = None,
|
|
47
|
+
json_out: Annotated[Path | None, typer.Option("--json-out", help="Export full JSON report (Pro)")] = None,
|
|
48
|
+
) -> None:
|
|
49
|
+
"""Scan AWS account for idle NAT Gateways, unattached EBS volumes, EIPs, and unexpiring logs."""
|
|
50
|
+
license_state = get_license_state()
|
|
51
|
+
|
|
52
|
+
if (export_fix or json_out) and not license_state.is_paid:
|
|
53
|
+
console.print("[bold yellow]Pro license required[/bold yellow] for --export-fix and --json-out.")
|
|
54
|
+
raise typer.Exit(code=2)
|
|
55
|
+
|
|
56
|
+
with console.status("[bold cyan]Scanning AWS regions for zombie resources...[/bold cyan]"):
|
|
57
|
+
summary = run_scan(profile=profile, regions=region)
|
|
58
|
+
|
|
59
|
+
render_summary(summary, license_state, console)
|
|
60
|
+
|
|
61
|
+
if export_fix and summary.findings:
|
|
62
|
+
export_cleanup_script(summary, export_fix)
|
|
63
|
+
console.print(f"[green]Wrote safe remediation script to {export_fix}[/green]")
|
|
64
|
+
|
|
65
|
+
if json_out:
|
|
66
|
+
json_out.write_text(summary.model_dump_json(indent=2), encoding="utf-8")
|
|
67
|
+
console.print(f"[green]Wrote JSON report to {json_out}[/green]")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@app.command()
|
|
71
|
+
def demo(
|
|
72
|
+
pro: Annotated[bool, typer.Option("--pro", help="Preview unlocked Pro output")] = False,
|
|
73
|
+
export_fix: Annotated[Path | None, typer.Option("--export-fix", help="Generate sample cleanup.sh (requires --pro)")] = None,
|
|
74
|
+
fast: Annotated[bool, typer.Option("--fast", help="Skip simulated scan delay")] = False,
|
|
75
|
+
) -> None:
|
|
76
|
+
"""Run a realistic offline demo scan with zero AWS credentials."""
|
|
77
|
+
demo_license = LicenseState(tier=LicenseTier.PRO if pro else LicenseTier.FREE)
|
|
78
|
+
|
|
79
|
+
if export_fix and not demo_license.is_paid:
|
|
80
|
+
console.print("[bold yellow]Pro license required[/bold yellow] for --export-fix. Try adding [bold]--pro[/bold].")
|
|
81
|
+
raise typer.Exit(code=2)
|
|
82
|
+
|
|
83
|
+
if not fast:
|
|
84
|
+
with console.status("[bold cyan]Scanning 3 AWS regions for zombie resources (demo)...[/bold cyan]"):
|
|
85
|
+
time.sleep(1.2)
|
|
86
|
+
|
|
87
|
+
console.print("[dim]DEMO MODE — simulated AWS account (no credentials used)[/dim]")
|
|
88
|
+
summary = build_demo_summary()
|
|
89
|
+
render_summary(summary, demo_license, console)
|
|
90
|
+
|
|
91
|
+
if export_fix:
|
|
92
|
+
export_cleanup_script(summary, export_fix)
|
|
93
|
+
console.print(f"[green]Wrote sample remediation script to {export_fix}[/green]")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@app.command()
|
|
97
|
+
def mcp() -> None:
|
|
98
|
+
"""Start the CloudSweep read-only MCP server over STDIO for AI coding agents."""
|
|
99
|
+
from cloudsweep.mcp_server import run_mcp_server
|
|
100
|
+
|
|
101
|
+
run_mcp_server()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@app.command(name="mcp-config")
|
|
105
|
+
def mcp_config() -> None:
|
|
106
|
+
"""Print the copy-paste MCP client config JSON for Claude Desktop, Cursor, or Gemini CLI."""
|
|
107
|
+
config = {
|
|
108
|
+
"mcpServers": {
|
|
109
|
+
"cloudsweep": {
|
|
110
|
+
"command": "uvx",
|
|
111
|
+
"args": ["cloudsweep", "mcp"],
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
console.print_json(json.dumps(config, indent=2))
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@app.command()
|
|
119
|
+
def activate(key: Annotated[str, typer.Argument(help="Your Polar license key")]) -> None:
|
|
120
|
+
"""Activate a Pro or Guard license key on this machine."""
|
|
121
|
+
try:
|
|
122
|
+
state = activate_license(key)
|
|
123
|
+
console.print(f"[bold green]Activated![/bold green] Tier: [cyan]{state.tier.value.upper()}[/cyan]")
|
|
124
|
+
except Exception as exc:
|
|
125
|
+
console.print(f"[bold red]Activation failed:[/bold red] {exc}")
|
|
126
|
+
raise typer.Exit(code=1)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@app.command()
|
|
130
|
+
def policy() -> None:
|
|
131
|
+
"""Print the minimal read-only IAM policy required to run CloudSweep."""
|
|
132
|
+
console.print_json(json.dumps(READ_ONLY_IAM_POLICY, indent=2))
|
cloudsweep/demo.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from cloudsweep.models import Finding, ScanSummary, ServiceType
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def build_demo_summary() -> ScanSummary:
|
|
5
|
+
"""Returns a realistic synthetic AWS waste audit (~$214.60/mo) with zero credentials."""
|
|
6
|
+
findings = [
|
|
7
|
+
Finding(
|
|
8
|
+
service=ServiceType.EBS,
|
|
9
|
+
region="us-east-1",
|
|
10
|
+
resource_id="vol-0a8f92e14b7c3d102",
|
|
11
|
+
monthly_waste_usd=48.00,
|
|
12
|
+
reason="Unattached 600GB gp3 volume",
|
|
13
|
+
remediation_cmd="aws ec2 delete-volume --volume-id vol-0a8f92e14b7c3d102 --region us-east-1",
|
|
14
|
+
),
|
|
15
|
+
Finding(
|
|
16
|
+
service=ServiceType.EBS,
|
|
17
|
+
region="us-west-2",
|
|
18
|
+
resource_id="vol-0c3d71f95a2e8b441",
|
|
19
|
+
monthly_waste_usd=36.00,
|
|
20
|
+
reason="Unattached 360GB gp2 volume",
|
|
21
|
+
remediation_cmd="aws ec2 delete-volume --volume-id vol-0c3d71f95a2e8b441 --region us-west-2",
|
|
22
|
+
),
|
|
23
|
+
Finding(
|
|
24
|
+
service=ServiceType.NAT_GATEWAY,
|
|
25
|
+
region="us-east-1",
|
|
26
|
+
resource_id="nat-04c1a8b92f3e71d04",
|
|
27
|
+
monthly_waste_usd=32.85,
|
|
28
|
+
reason="Zero outbound bytes over the past 7 days",
|
|
29
|
+
remediation_cmd="aws ec2 delete-nat-gateway --nat-gateway-id nat-04c1a8b92f3e71d04 --region us-east-1",
|
|
30
|
+
),
|
|
31
|
+
Finding(
|
|
32
|
+
service=ServiceType.NAT_GATEWAY,
|
|
33
|
+
region="us-west-2",
|
|
34
|
+
resource_id="nat-09f8d2c17a4b5e310",
|
|
35
|
+
monthly_waste_usd=32.85,
|
|
36
|
+
reason="Zero outbound bytes over the past 7 days",
|
|
37
|
+
remediation_cmd="aws ec2 delete-nat-gateway --nat-gateway-id nat-09f8d2c17a4b5e310 --region us-west-2",
|
|
38
|
+
),
|
|
39
|
+
Finding(
|
|
40
|
+
service=ServiceType.NAT_GATEWAY,
|
|
41
|
+
region="eu-west-1",
|
|
42
|
+
resource_id="nat-02e7b4a81c9d6f205",
|
|
43
|
+
monthly_waste_usd=32.85,
|
|
44
|
+
reason="Zero outbound bytes over the past 7 days",
|
|
45
|
+
remediation_cmd="aws ec2 delete-nat-gateway --nat-gateway-id nat-02e7b4a81c9d6f205 --region eu-west-1",
|
|
46
|
+
),
|
|
47
|
+
Finding(
|
|
48
|
+
service=ServiceType.LOGS,
|
|
49
|
+
region="us-east-1",
|
|
50
|
+
resource_id="/aws/lambda/legacy-checkout-worker",
|
|
51
|
+
monthly_waste_usd=14.75,
|
|
52
|
+
reason="No retention policy configured (491.7GB accumulated)",
|
|
53
|
+
remediation_cmd=(
|
|
54
|
+
"aws logs put-retention-policy "
|
|
55
|
+
"--log-group-name '/aws/lambda/legacy-checkout-worker' "
|
|
56
|
+
"--retention-in-days 30 --region us-east-1"
|
|
57
|
+
),
|
|
58
|
+
),
|
|
59
|
+
Finding(
|
|
60
|
+
service=ServiceType.EBS,
|
|
61
|
+
region="us-east-1",
|
|
62
|
+
resource_id="vol-07e4b2a19d6c5f803",
|
|
63
|
+
monthly_waste_usd=10.00,
|
|
64
|
+
reason="gp2 volume eligible for 20% gp3 upgrade savings (500GB)",
|
|
65
|
+
remediation_cmd="aws ec2 modify-volume --volume-id vol-07e4b2a19d6c5f803 --volume-type gp3 --region us-east-1",
|
|
66
|
+
),
|
|
67
|
+
Finding(
|
|
68
|
+
service=ServiceType.IPV4,
|
|
69
|
+
region="us-east-1",
|
|
70
|
+
resource_id="eipalloc-09f2a1c4b8e7d3612",
|
|
71
|
+
resource_name="54.210.88.142",
|
|
72
|
+
monthly_waste_usd=3.65,
|
|
73
|
+
reason="Unattached Elastic IPv4 (54.210.88.142)",
|
|
74
|
+
remediation_cmd="aws ec2 release-address --allocation-id eipalloc-09f2a1c4b8e7d3612 --region us-east-1",
|
|
75
|
+
),
|
|
76
|
+
Finding(
|
|
77
|
+
service=ServiceType.IPV4,
|
|
78
|
+
region="us-west-2",
|
|
79
|
+
resource_id="eipalloc-03b8c7d1a5f4e9208",
|
|
80
|
+
resource_name="34.219.44.19",
|
|
81
|
+
monthly_waste_usd=3.65,
|
|
82
|
+
reason="Unattached Elastic IPv4 (34.219.44.19)",
|
|
83
|
+
remediation_cmd="aws ec2 release-address --allocation-id eipalloc-03b8c7d1a5f4e9208 --region us-west-2",
|
|
84
|
+
),
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
summary = ScanSummary(
|
|
88
|
+
findings=findings,
|
|
89
|
+
regions_scanned=["us-east-1", "us-west-2", "eu-west-1"],
|
|
90
|
+
)
|
|
91
|
+
summary.calculate_total()
|
|
92
|
+
return summary
|
cloudsweep/engine.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
2
|
+
import boto3
|
|
3
|
+
from botocore.exceptions import ClientError
|
|
4
|
+
|
|
5
|
+
from cloudsweep.models import Finding, ScanSummary
|
|
6
|
+
from cloudsweep.scanners.aws_ebs import EbsVolumeScanner
|
|
7
|
+
from cloudsweep.scanners.aws_ipv4 import ElasticIpScanner
|
|
8
|
+
from cloudsweep.scanners.aws_logs import CloudWatchLogsScanner
|
|
9
|
+
from cloudsweep.scanners.aws_nat import NatGatewayScanner
|
|
10
|
+
|
|
11
|
+
SCANNER_CLASSES = [
|
|
12
|
+
NatGatewayScanner,
|
|
13
|
+
EbsVolumeScanner,
|
|
14
|
+
ElasticIpScanner,
|
|
15
|
+
CloudWatchLogsScanner,
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_enabled_regions(session: boto3.Session) -> list[str]:
|
|
20
|
+
ec2 = session.client("ec2", region_name=session.region_name or "us-east-1")
|
|
21
|
+
resp = ec2.describe_regions(AllRegions=False)
|
|
22
|
+
return [r["RegionName"] for r in resp.get("Regions", [])]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _scan_region(session: boto3.Session, region: str) -> list[Finding]:
|
|
26
|
+
region_findings: list[Finding] = []
|
|
27
|
+
for scanner_cls in SCANNER_CLASSES:
|
|
28
|
+
try:
|
|
29
|
+
scanner = scanner_cls(session=session, region=region)
|
|
30
|
+
region_findings.extend(scanner.scan())
|
|
31
|
+
except ClientError:
|
|
32
|
+
continue
|
|
33
|
+
return region_findings
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def run_scan(
|
|
37
|
+
profile: str | None = None,
|
|
38
|
+
regions: list[str] | None = None,
|
|
39
|
+
max_workers: int = 8,
|
|
40
|
+
) -> ScanSummary:
|
|
41
|
+
session = boto3.Session(profile_name=profile)
|
|
42
|
+
target_regions = regions or get_enabled_regions(session)
|
|
43
|
+
|
|
44
|
+
summary = ScanSummary(regions_scanned=target_regions)
|
|
45
|
+
with ThreadPoolExecutor(max_workers=max_workers) as pool:
|
|
46
|
+
futures = {
|
|
47
|
+
pool.submit(_scan_region, session, region): region
|
|
48
|
+
for region in target_regions
|
|
49
|
+
}
|
|
50
|
+
for future in as_completed(futures):
|
|
51
|
+
summary.findings.extend(future.result())
|
|
52
|
+
|
|
53
|
+
summary.findings.sort(key=lambda f: f.monthly_waste_usd, reverse=True)
|
|
54
|
+
summary.calculate_total()
|
|
55
|
+
return summary
|
cloudsweep/licensing.py
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
from datetime import datetime, timedelta, timezone
|
|
2
|
+
from enum import Enum
|
|
3
|
+
import hashlib
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import platform
|
|
6
|
+
import uuid
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
from pydantic import BaseModel
|
|
10
|
+
|
|
11
|
+
POLAR_API_BASE = "https://api.polar.sh/v1/customer-portal/license-keys"
|
|
12
|
+
POLAR_ORG_ID = "e37309d5-c1d7-46cc-b64e-116ae8a182b0"
|
|
13
|
+
PRO_BENEFIT_ID = "7e83babb-8653-4ddb-b78c-157cd668de33"
|
|
14
|
+
GUARD_BENEFIT_ID = "YOUR_GUARD_BENEFIT_UUID"
|
|
15
|
+
|
|
16
|
+
CACHE_PATH = Path.home() / ".config" / "cloudsweep" / "license.json"
|
|
17
|
+
GRACE_DAYS = 7
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class LicenseTier(str, Enum):
|
|
21
|
+
FREE = "free"
|
|
22
|
+
PRO = "pro"
|
|
23
|
+
GUARD = "guard"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class LicenseState(BaseModel):
|
|
27
|
+
tier: LicenseTier = LicenseTier.FREE
|
|
28
|
+
key: str | None = None
|
|
29
|
+
activation_id: str | None = None
|
|
30
|
+
last_verified_at: datetime | None = None
|
|
31
|
+
expires_at: datetime | None = None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def is_paid(self) -> bool:
|
|
35
|
+
return self.tier in (LicenseTier.PRO, LicenseTier.GUARD)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _machine_fingerprint() -> str:
|
|
39
|
+
raw = f"{platform.node()}-{uuid.getnode()}-{platform.system()}"
|
|
40
|
+
return hashlib.sha256(raw.encode()).hexdigest()[:16]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _save_cache(state: LicenseState) -> None:
|
|
44
|
+
CACHE_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
45
|
+
CACHE_PATH.write_text(state.model_dump_json(indent=2), encoding="utf-8")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _load_cache() -> LicenseState | None:
|
|
49
|
+
if not CACHE_PATH.exists():
|
|
50
|
+
return None
|
|
51
|
+
try:
|
|
52
|
+
return LicenseState.model_validate_json(CACHE_PATH.read_text(encoding="utf-8"))
|
|
53
|
+
except Exception:
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _tier_from_benefit(benefit_id: str | None) -> LicenseTier:
|
|
58
|
+
if benefit_id == GUARD_BENEFIT_ID:
|
|
59
|
+
return LicenseTier.GUARD
|
|
60
|
+
if benefit_id == PRO_BENEFIT_ID:
|
|
61
|
+
return LicenseTier.PRO
|
|
62
|
+
return LicenseTier.PRO
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def activate_license(key: str) -> LicenseState:
|
|
66
|
+
"""Activates a Polar license key on this machine and writes the local cache."""
|
|
67
|
+
payload = {
|
|
68
|
+
"key": key.strip(),
|
|
69
|
+
"organization_id": POLAR_ORG_ID,
|
|
70
|
+
"label": f"{platform.node()} ({_machine_fingerprint()})",
|
|
71
|
+
}
|
|
72
|
+
response = httpx.post(f"{POLAR_API_BASE}/activate", json=payload, timeout=10.0)
|
|
73
|
+
response.raise_for_status()
|
|
74
|
+
data = response.json()
|
|
75
|
+
|
|
76
|
+
license_obj = data.get("license_key", {})
|
|
77
|
+
if license_obj.get("status") != "granted":
|
|
78
|
+
raise ValueError(f"License key is not active (status={license_obj.get('status')}).")
|
|
79
|
+
|
|
80
|
+
state = LicenseState(
|
|
81
|
+
tier=_tier_from_benefit(license_obj.get("benefit_id")),
|
|
82
|
+
key=key.strip(),
|
|
83
|
+
activation_id=data.get("id"),
|
|
84
|
+
last_verified_at=datetime.now(timezone.utc),
|
|
85
|
+
expires_at=license_obj.get("expires_at"),
|
|
86
|
+
)
|
|
87
|
+
_save_cache(state)
|
|
88
|
+
return state
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def get_license_state(force_refresh: bool = False) -> LicenseState:
|
|
92
|
+
"""Returns current tier, revalidating with Polar only after the 7-day cache window."""
|
|
93
|
+
cached = _load_cache()
|
|
94
|
+
if not cached or not cached.key:
|
|
95
|
+
return LicenseState(tier=LicenseTier.FREE)
|
|
96
|
+
|
|
97
|
+
now = datetime.now(timezone.utc)
|
|
98
|
+
if cached.expires_at and cached.expires_at < now:
|
|
99
|
+
return LicenseState(tier=LicenseTier.FREE)
|
|
100
|
+
|
|
101
|
+
cache_fresh = (
|
|
102
|
+
cached.last_verified_at is not None
|
|
103
|
+
and (now - cached.last_verified_at) < timedelta(days=GRACE_DAYS)
|
|
104
|
+
)
|
|
105
|
+
if cache_fresh and not force_refresh:
|
|
106
|
+
return cached
|
|
107
|
+
|
|
108
|
+
payload: dict[str, str] = {
|
|
109
|
+
"key": cached.key,
|
|
110
|
+
"organization_id": POLAR_ORG_ID,
|
|
111
|
+
}
|
|
112
|
+
if cached.activation_id:
|
|
113
|
+
payload["activation_id"] = cached.activation_id
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
response = httpx.post(f"{POLAR_API_BASE}/validate", json=payload, timeout=8.0)
|
|
117
|
+
if response.status_code != 200:
|
|
118
|
+
return LicenseState(tier=LicenseTier.FREE)
|
|
119
|
+
|
|
120
|
+
data = response.json()
|
|
121
|
+
if data.get("status") != "granted":
|
|
122
|
+
return LicenseState(tier=LicenseTier.FREE)
|
|
123
|
+
|
|
124
|
+
refreshed = cached.model_copy(
|
|
125
|
+
update={
|
|
126
|
+
"tier": _tier_from_benefit(data.get("benefit_id")),
|
|
127
|
+
"last_verified_at": now,
|
|
128
|
+
"expires_at": data.get("expires_at"),
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
_save_cache(refreshed)
|
|
132
|
+
return refreshed
|
|
133
|
+
except httpx.HTTPError:
|
|
134
|
+
if cached.last_verified_at and (now - cached.last_verified_at) < timedelta(days=14):
|
|
135
|
+
return cached
|
|
136
|
+
return LicenseState(tier=LicenseTier.FREE)
|
cloudsweep/mcp_server.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from fastmcp import FastMCP
|
|
4
|
+
|
|
5
|
+
from cloudsweep.demo import build_demo_summary
|
|
6
|
+
from cloudsweep.engine import run_scan
|
|
7
|
+
from cloudsweep.licensing import LicenseState, LicenseTier, get_license_state
|
|
8
|
+
from cloudsweep.models import ScanSummary
|
|
9
|
+
from cloudsweep.output.terminal import CHECKOUT_URL
|
|
10
|
+
|
|
11
|
+
mcp = FastMCP(
|
|
12
|
+
name="cloudsweep",
|
|
13
|
+
instructions=(
|
|
14
|
+
"Read-only AWS zombie resource and cloud waste auditor. "
|
|
15
|
+
"Never runs destructive actions; returns estimated monthly waste and safe remediation commands."
|
|
16
|
+
),
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
READ_ONLY_IAM_POLICY: dict[str, Any] = {
|
|
20
|
+
"Version": "2012-10-17",
|
|
21
|
+
"Statement": [
|
|
22
|
+
{
|
|
23
|
+
"Sid": "CloudSweepReadOnlyAudit",
|
|
24
|
+
"Effect": "Allow",
|
|
25
|
+
"Action": [
|
|
26
|
+
"ec2:DescribeRegions",
|
|
27
|
+
"ec2:DescribeNatGateways",
|
|
28
|
+
"ec2:DescribeVolumes",
|
|
29
|
+
"ec2:DescribeAddresses",
|
|
30
|
+
"cloudwatch:GetMetricStatistics",
|
|
31
|
+
"logs:DescribeLogGroups",
|
|
32
|
+
],
|
|
33
|
+
"Resource": "*",
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _serialize_summary(summary: ScanSummary, license_state: LicenseState) -> dict[str, Any]:
|
|
40
|
+
findings_payload: list[dict[str, Any]] = []
|
|
41
|
+
for f in summary.findings:
|
|
42
|
+
if license_state.is_paid:
|
|
43
|
+
findings_payload.append(
|
|
44
|
+
{
|
|
45
|
+
"service": f.service.value,
|
|
46
|
+
"region": f.region,
|
|
47
|
+
"resource_id": f.resource_id,
|
|
48
|
+
"monthly_waste_usd": f.monthly_waste_usd,
|
|
49
|
+
"reason": f.reason,
|
|
50
|
+
"remediation_cmd": f.remediation_cmd,
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
else:
|
|
54
|
+
findings_payload.append(
|
|
55
|
+
{
|
|
56
|
+
"service": f.service.value,
|
|
57
|
+
"region": f.region,
|
|
58
|
+
"resource_id": f.masked_resource_id(),
|
|
59
|
+
"monthly_waste_usd": f.monthly_waste_usd,
|
|
60
|
+
"reason": "Unattached Elastic IPv4 (masked in Free mode)"
|
|
61
|
+
if f.service.value == "Elastic IPv4"
|
|
62
|
+
else f.reason,
|
|
63
|
+
"remediation_cmd": "LOCKED — Upgrade to CloudSweep Pro to unlock cleanup commands",
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
payload: dict[str, Any] = {
|
|
68
|
+
"tier": license_state.tier.value,
|
|
69
|
+
"total_monthly_waste_usd": summary.total_waste_usd,
|
|
70
|
+
"total_annual_waste_usd": round(summary.total_waste_usd * 12, 2),
|
|
71
|
+
"regions_scanned": summary.regions_scanned,
|
|
72
|
+
"finding_count": len(summary.findings),
|
|
73
|
+
"findings": findings_payload,
|
|
74
|
+
}
|
|
75
|
+
if not license_state.is_paid:
|
|
76
|
+
payload["upgrade_url"] = CHECKOUT_URL
|
|
77
|
+
payload["note"] = "Resource IDs and remediation commands are masked in Free Preview mode."
|
|
78
|
+
return payload
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@mcp.tool
|
|
82
|
+
def scan_aws_waste(
|
|
83
|
+
profile: str | None = None,
|
|
84
|
+
regions: list[str] | None = None,
|
|
85
|
+
) -> dict[str, Any]:
|
|
86
|
+
"""Scan an AWS account (read-only) for idle NAT Gateways, unattached EBS volumes, orphaned EIPs, and unexpiring CloudWatch Logs."""
|
|
87
|
+
license_state = get_license_state()
|
|
88
|
+
summary = run_scan(profile=profile, regions=regions)
|
|
89
|
+
return _serialize_summary(summary, license_state)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@mcp.tool
|
|
93
|
+
def demo_aws_waste(pro_preview: bool = False) -> dict[str, Any]:
|
|
94
|
+
"""Run a realistic offline demo AWS waste audit (~$214.60/mo) with zero AWS credentials."""
|
|
95
|
+
demo_license = LicenseState(tier=LicenseTier.PRO if pro_preview else LicenseTier.FREE)
|
|
96
|
+
summary = build_demo_summary()
|
|
97
|
+
return _serialize_summary(summary, demo_license)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@mcp.tool
|
|
101
|
+
def get_iam_policy() -> dict[str, Any]:
|
|
102
|
+
"""Return the minimal read-only AWS IAM policy JSON required to run CloudSweep safely."""
|
|
103
|
+
return READ_ONLY_IAM_POLICY
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def run_mcp_server() -> None:
|
|
107
|
+
mcp.run()
|
cloudsweep/models.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from pydantic import BaseModel, Field
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ServiceType(str, Enum):
|
|
6
|
+
NAT_GATEWAY = "NAT Gateway"
|
|
7
|
+
EBS = "EBS Volume"
|
|
8
|
+
IPV4 = "Elastic IPv4"
|
|
9
|
+
LOGS = "CloudWatch Logs"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Finding(BaseModel):
|
|
13
|
+
service: ServiceType
|
|
14
|
+
region: str
|
|
15
|
+
resource_id: str
|
|
16
|
+
resource_name: str | None = None
|
|
17
|
+
monthly_waste_usd: float = Field(ge=0.0)
|
|
18
|
+
reason: str
|
|
19
|
+
remediation_cmd: str
|
|
20
|
+
|
|
21
|
+
def masked_resource_id(self) -> str:
|
|
22
|
+
"""Masks resource ID for free preview tier."""
|
|
23
|
+
if len(self.resource_id) <= 8:
|
|
24
|
+
return self.resource_id[:3] + "****"
|
|
25
|
+
return f"{self.resource_id[:8]}****"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ScanSummary(BaseModel):
|
|
29
|
+
findings: list[Finding] = []
|
|
30
|
+
total_waste_usd: float = 0.0
|
|
31
|
+
regions_scanned: list[str] = []
|
|
32
|
+
|
|
33
|
+
def calculate_total(self) -> None:
|
|
34
|
+
self.total_waste_usd = round(sum(f.monthly_waste_usd for f in self.findings), 2)
|
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from cloudsweep.models import ScanSummary
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def export_cleanup_script(summary: ScanSummary, output_path: Path) -> Path:
|
|
6
|
+
lines = [
|
|
7
|
+
"#!/usr/bin/env bash",
|
|
8
|
+
"set -euo pipefail",
|
|
9
|
+
"",
|
|
10
|
+
f"# CloudSweep remediation script — Est. savings: ${summary.total_waste_usd:,.2f}/month",
|
|
11
|
+
"# SAFETY: All commands are commented out by default. Review and uncomment lines before running.",
|
|
12
|
+
"",
|
|
13
|
+
]
|
|
14
|
+
for finding in summary.findings:
|
|
15
|
+
lines.append(
|
|
16
|
+
f"# [{finding.service.value}] {finding.region} | "
|
|
17
|
+
f"${finding.monthly_waste_usd:.2f}/mo — {finding.reason}"
|
|
18
|
+
)
|
|
19
|
+
lines.append(f"# {finding.remediation_cmd}")
|
|
20
|
+
lines.append("")
|
|
21
|
+
|
|
22
|
+
output_path.write_text("\n".join(lines), encoding="utf-8")
|
|
23
|
+
output_path.chmod(0o755)
|
|
24
|
+
return output_path
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.panel import Panel
|
|
3
|
+
from rich.table import Table
|
|
4
|
+
|
|
5
|
+
from cloudsweep.licensing import LicenseState
|
|
6
|
+
from cloudsweep.models import ScanSummary, ServiceType
|
|
7
|
+
|
|
8
|
+
CHECKOUT_URL = "https://buy.polar.sh/polar_cl_BnHKRuw1KemJO7NX0p3720fvxZDfjVdjgd4pi3HygFk"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def render_summary(summary: ScanSummary, license_state: LicenseState, console: Console) -> None:
|
|
12
|
+
annual_waste = round(summary.total_waste_usd * 12, 2)
|
|
13
|
+
|
|
14
|
+
if not summary.findings:
|
|
15
|
+
console.print(
|
|
16
|
+
Panel.fit(
|
|
17
|
+
"[bold green]Clean account![/bold green] No zombie resources found across "
|
|
18
|
+
f"{len(summary.regions_scanned)} region(s).",
|
|
19
|
+
border_style="green",
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
header = (
|
|
25
|
+
f"[bold red]${summary.total_waste_usd:,.2f}/month[/bold red] estimated waste "
|
|
26
|
+
f"([bold]${annual_waste:,.2f}/year[/bold])\n"
|
|
27
|
+
f"Found [bold]{len(summary.findings)}[/bold] zombie resources across "
|
|
28
|
+
f"[bold]{len(summary.regions_scanned)}[/bold] region(s)."
|
|
29
|
+
)
|
|
30
|
+
console.print(Panel(header, title="CloudSweep Audit Summary", border_style="red"))
|
|
31
|
+
|
|
32
|
+
table = Table(show_header=True, header_style="bold cyan", expand=True)
|
|
33
|
+
table.add_column("Service", style="bold")
|
|
34
|
+
table.add_column("Region")
|
|
35
|
+
table.add_column("Resource ID")
|
|
36
|
+
table.add_column("Est. Waste / Mo", justify="right", style="red")
|
|
37
|
+
table.add_column("Reason")
|
|
38
|
+
|
|
39
|
+
for finding in summary.findings:
|
|
40
|
+
if license_state.is_paid:
|
|
41
|
+
display_id = finding.resource_id
|
|
42
|
+
display_reason = finding.reason
|
|
43
|
+
else:
|
|
44
|
+
display_id = f"[dim]{finding.masked_resource_id()}[/dim]"
|
|
45
|
+
display_reason = (
|
|
46
|
+
"Unattached Elastic IPv4 (masked in Free mode)"
|
|
47
|
+
if finding.service == ServiceType.IPV4
|
|
48
|
+
else finding.reason
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
table.add_row(
|
|
52
|
+
finding.service.value,
|
|
53
|
+
finding.region,
|
|
54
|
+
display_id,
|
|
55
|
+
f"${finding.monthly_waste_usd:,.2f}",
|
|
56
|
+
display_reason,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
console.print(table)
|
|
60
|
+
|
|
61
|
+
if not license_state.is_paid:
|
|
62
|
+
console.print(
|
|
63
|
+
Panel(
|
|
64
|
+
"Resource IDs are masked in Free Preview mode.\n"
|
|
65
|
+
f"Unlock exact IDs, CSV/JSON export, and safe cleanup scripts for $49 one-time:\n"
|
|
66
|
+
f"[bold cyan]{CHECKOUT_URL}[/bold cyan]\n"
|
|
67
|
+
"Already purchased? Run [bold]cloudsweep activate YOUR-KEY[/bold]",
|
|
68
|
+
title="Unlock Full Report",
|
|
69
|
+
border_style="yellow",
|
|
70
|
+
)
|
|
71
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from cloudsweep.models import Finding, ServiceType
|
|
2
|
+
from cloudsweep.scanners.base import BaseScanner
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class EbsVolumeScanner(BaseScanner):
|
|
6
|
+
def scan(self) -> list[Finding]:
|
|
7
|
+
findings: list[Finding] = []
|
|
8
|
+
ec2 = self.session.client("ec2", region_name=self.region)
|
|
9
|
+
paginator = ec2.get_paginator("describe_volumes")
|
|
10
|
+
|
|
11
|
+
for page in paginator.paginate():
|
|
12
|
+
for vol in page.get("Volumes", []):
|
|
13
|
+
vol_id = vol["VolumeId"]
|
|
14
|
+
size_gb = vol["Size"]
|
|
15
|
+
vol_type = vol["VolumeType"]
|
|
16
|
+
state = vol["State"]
|
|
17
|
+
|
|
18
|
+
if state == "available":
|
|
19
|
+
rate_per_gb = 0.08 if vol_type == "gp3" else 0.10
|
|
20
|
+
waste = round(size_gb * rate_per_gb, 2)
|
|
21
|
+
findings.append(
|
|
22
|
+
Finding(
|
|
23
|
+
service=ServiceType.EBS,
|
|
24
|
+
region=self.region,
|
|
25
|
+
resource_id=vol_id,
|
|
26
|
+
monthly_waste_usd=waste,
|
|
27
|
+
reason=f"Unattached {size_gb}GB {vol_type} volume",
|
|
28
|
+
remediation_cmd=(
|
|
29
|
+
f"aws ec2 delete-volume "
|
|
30
|
+
f"--volume-id {vol_id} --region {self.region}"
|
|
31
|
+
),
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
elif state == "in-use" and vol_type == "gp2" and size_gb <= 1000:
|
|
35
|
+
monthly_savings = round(size_gb * 0.02, 2)
|
|
36
|
+
if monthly_savings >= 1.0:
|
|
37
|
+
findings.append(
|
|
38
|
+
Finding(
|
|
39
|
+
service=ServiceType.EBS,
|
|
40
|
+
region=self.region,
|
|
41
|
+
resource_id=vol_id,
|
|
42
|
+
monthly_waste_usd=monthly_savings,
|
|
43
|
+
reason=f"gp2 volume eligible for 20% gp3 upgrade savings ({size_gb}GB)",
|
|
44
|
+
remediation_cmd=(
|
|
45
|
+
f"aws ec2 modify-volume "
|
|
46
|
+
f"--volume-id {vol_id} --volume-type gp3 --region {self.region}"
|
|
47
|
+
),
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
return findings
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from cloudsweep.models import Finding, ServiceType
|
|
2
|
+
from cloudsweep.scanners.base import BaseScanner
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ElasticIpScanner(BaseScanner):
|
|
6
|
+
def scan(self) -> list[Finding]:
|
|
7
|
+
findings: list[Finding] = []
|
|
8
|
+
ec2 = self.session.client("ec2", region_name=self.region)
|
|
9
|
+
addresses = ec2.describe_addresses().get("Addresses", [])
|
|
10
|
+
|
|
11
|
+
for addr in addresses:
|
|
12
|
+
if "AssociationId" not in addr:
|
|
13
|
+
alloc_id = addr.get("AllocationId", addr.get("PublicIp", "unknown"))
|
|
14
|
+
ip = addr.get("PublicIp", "unknown")
|
|
15
|
+
findings.append(
|
|
16
|
+
Finding(
|
|
17
|
+
service=ServiceType.IPV4,
|
|
18
|
+
region=self.region,
|
|
19
|
+
resource_id=alloc_id,
|
|
20
|
+
resource_name=ip,
|
|
21
|
+
monthly_waste_usd=3.65,
|
|
22
|
+
reason=f"Unattached Elastic IPv4 ({ip})",
|
|
23
|
+
remediation_cmd=(
|
|
24
|
+
f"aws ec2 release-address "
|
|
25
|
+
f"--allocation-id {alloc_id} --region {self.region}"
|
|
26
|
+
),
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return findings
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import shlex
|
|
2
|
+
from cloudsweep.models import Finding, ServiceType
|
|
3
|
+
from cloudsweep.scanners.base import BaseScanner
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CloudWatchLogsScanner(BaseScanner):
|
|
7
|
+
def scan(self) -> list[Finding]:
|
|
8
|
+
findings: list[Finding] = []
|
|
9
|
+
logs = self.session.client("logs", region_name=self.region)
|
|
10
|
+
paginator = logs.get_paginator("describe_log_groups")
|
|
11
|
+
|
|
12
|
+
for page in paginator.paginate():
|
|
13
|
+
for group in page.get("logGroups", []):
|
|
14
|
+
group_name = group["logGroupName"]
|
|
15
|
+
stored_bytes = group.get("storedBytes", 0)
|
|
16
|
+
size_gb = stored_bytes / (1024**3)
|
|
17
|
+
|
|
18
|
+
if "retentionInDays" not in group and size_gb >= 1.0:
|
|
19
|
+
waste = round(size_gb * 0.03, 2)
|
|
20
|
+
findings.append(
|
|
21
|
+
Finding(
|
|
22
|
+
service=ServiceType.LOGS,
|
|
23
|
+
region=self.region,
|
|
24
|
+
resource_id=group_name,
|
|
25
|
+
monthly_waste_usd=waste,
|
|
26
|
+
reason=f"No retention policy configured ({size_gb:.1f}GB accumulated)",
|
|
27
|
+
remediation_cmd=(
|
|
28
|
+
f"aws logs put-retention-policy "
|
|
29
|
+
f"--log-group-name {shlex.quote(group_name)} "
|
|
30
|
+
f"--retention-in-days 30 --region {self.region}"
|
|
31
|
+
),
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return findings
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from datetime import datetime, timedelta, timezone
|
|
2
|
+
from cloudsweep.models import Finding, ServiceType
|
|
3
|
+
from cloudsweep.scanners.base import BaseScanner
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NatGatewayScanner(BaseScanner):
|
|
7
|
+
def __init__(self, session, region: str, min_age_days: int = 7):
|
|
8
|
+
super().__init__(session, region)
|
|
9
|
+
self.min_age_days = min_age_days
|
|
10
|
+
|
|
11
|
+
def scan(self) -> list[Finding]:
|
|
12
|
+
findings: list[Finding] = []
|
|
13
|
+
ec2 = self.session.client("ec2", region_name=self.region)
|
|
14
|
+
cw = self.session.client("cloudwatch", region_name=self.region)
|
|
15
|
+
paginator = ec2.get_paginator("describe_nat_gateways")
|
|
16
|
+
|
|
17
|
+
now = datetime.now(timezone.utc)
|
|
18
|
+
start_time = now - timedelta(days=7)
|
|
19
|
+
min_created_cutoff = now - timedelta(days=self.min_age_days)
|
|
20
|
+
|
|
21
|
+
for page in paginator.paginate(
|
|
22
|
+
Filter=[{"Name": "state", "Values": ["available"]}]
|
|
23
|
+
):
|
|
24
|
+
for gw in page.get("NatGateways", []):
|
|
25
|
+
create_time = gw.get("CreateTime")
|
|
26
|
+
if create_time and create_time > min_created_cutoff:
|
|
27
|
+
continue
|
|
28
|
+
|
|
29
|
+
gw_id = gw["NatGatewayId"]
|
|
30
|
+
stats = cw.get_metric_statistics(
|
|
31
|
+
Namespace="AWS/NATGateway",
|
|
32
|
+
MetricName="BytesOutToDestination",
|
|
33
|
+
Dimensions=[{"Name": "NatGatewayId", "Value": gw_id}],
|
|
34
|
+
StartTime=start_time,
|
|
35
|
+
EndTime=now,
|
|
36
|
+
Period=86400,
|
|
37
|
+
Statistics=["Sum"],
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
datapoints = stats.get("Datapoints", [])
|
|
41
|
+
total_bytes = sum(dp.get("Sum", 0.0) for dp in datapoints)
|
|
42
|
+
|
|
43
|
+
if total_bytes == 0.0:
|
|
44
|
+
findings.append(
|
|
45
|
+
Finding(
|
|
46
|
+
service=ServiceType.NAT_GATEWAY,
|
|
47
|
+
region=self.region,
|
|
48
|
+
resource_id=gw_id,
|
|
49
|
+
monthly_waste_usd=32.85,
|
|
50
|
+
reason="Zero outbound bytes over the past 7 days",
|
|
51
|
+
remediation_cmd=(
|
|
52
|
+
f"aws ec2 delete-nat-gateway "
|
|
53
|
+
f"--nat-gateway-id {gw_id} --region {self.region}"
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
return findings
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
import boto3
|
|
3
|
+
from cloudsweep.models import Finding
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BaseScanner(ABC):
|
|
7
|
+
def __init__(self, session: boto3.Session, region: str):
|
|
8
|
+
self.session = session
|
|
9
|
+
self.region = region
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def scan(self) -> list[Finding]:
|
|
13
|
+
"""Audit the given region and return detected zombie findings."""
|
|
14
|
+
pass
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: cloudsweep
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fast, strictly read-only AWS waste auditor CLI and MCP server.
|
|
5
|
+
Keywords: aws,finops,cloud-cost,cli,mcp,devops
|
|
6
|
+
Requires-Dist: boto3>=1.44.9
|
|
7
|
+
Requires-Dist: fastmcp>=4.2.4
|
|
8
|
+
Requires-Dist: httpx>=0.28.1
|
|
9
|
+
Requires-Dist: pydantic>=2.14.4
|
|
10
|
+
Requires-Dist: rich>=15.0.0
|
|
11
|
+
Requires-Dist: typer>=0.29.2
|
|
12
|
+
Requires-Python: >=3.13
|
|
13
|
+
Project-URL: CloudSweep Pro, https://buy.polar.sh/polar_cl_BnHKRuw1KemJO7NX0p3720fvxZDfjVdjgd4pi3HygFk
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# CloudSweep
|
|
17
|
+
|
|
18
|
+
Fast, strictly read-only CLI and MCP server to find and eliminate zombie AWS waste in seconds.
|
|
19
|
+
|
|
20
|
+
## What It Catches
|
|
21
|
+
- **Idle NAT Gateways** (~$32.85/mo each with zero outbound traffic over 7 days)
|
|
22
|
+
- **Unattached EBS Volumes & `gp2` -> `gp3` Upgrades** ($0.08-$0.10/GB-mo)
|
|
23
|
+
- **Orphaned Elastic IPv4 Addresses** ($3.65/mo each)
|
|
24
|
+
- **Never-Expiring CloudWatch Log Groups** ($0.03/GB-mo accumulated)
|
|
25
|
+
|
|
26
|
+
## Quick Start (Zero Install)
|
|
27
|
+
```bash
|
|
28
|
+
# Preview realistic output offline (no AWS credentials needed)
|
|
29
|
+
uvx cloudsweep demo
|
|
30
|
+
|
|
31
|
+
# Print the minimal read-only IAM policy
|
|
32
|
+
uvx cloudsweep policy
|
|
33
|
+
|
|
34
|
+
# Scan your AWS account
|
|
35
|
+
uvx cloudsweep scan
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## AI Agent / MCP Mode
|
|
39
|
+
Print ready-to-paste JSON config for Claude Desktop, Cursor, or Gemini CLI:
|
|
40
|
+
```bash
|
|
41
|
+
uvx cloudsweep mcp-config
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Safety Guarantee
|
|
45
|
+
CloudSweep **never** executes destructive AWS API calls. Pro remediation exports generate a commented-out `cleanup.sh` script for human review.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
cloudsweep/__init__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
2
|
+
cloudsweep/cli.py,sha256=g4OkFlvHTbG98MWI0wZQrRhvg4CjyAA-hEeonXylnjc,4895
|
|
3
|
+
cloudsweep/demo.py,sha256=i1saTeOGHdomCzfZ_D4OVEsVZ_OPcyfd3fyOOT4gHIg,3888
|
|
4
|
+
cloudsweep/engine.py,sha256=WXi7xzyAOKH3wMM0W1bnk1MDEZAVoR7-oZREBbQ2qCQ,1861
|
|
5
|
+
cloudsweep/licensing.py,sha256=HK6Y8usI3zKBhVUARk_3PYRGpGQkIYBybRnKZXWDPkk,4297
|
|
6
|
+
cloudsweep/mcp_server.py,sha256=rIY-63C8Jr9FK6Fw1liGl3-s3OHW-b9tN6RsiNHH_94,3783
|
|
7
|
+
cloudsweep/models.py,sha256=MU0_5uVzuekTOrFm0TutbVRcT2e1ky4OUz0J8jOQmQ4,908
|
|
8
|
+
cloudsweep/output/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
cloudsweep/output/remediation.py,sha256=W3RdjOzJvd-v3r4_G450jK3Lr8L5OIeUpGyHm1Rzfcw,854
|
|
10
|
+
cloudsweep/output/terminal.py,sha256=jjYKzVM5QKQRTUn7kI_aYVBIHMpQgzJJRCC5OE0HyZg,2596
|
|
11
|
+
cloudsweep/scanners/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
cloudsweep/scanners/aws_ebs.py,sha256=wyxx_OC4XPrOQmLFN2Bp_M_gcdIhYbmZtIq5mHE_-i8,2307
|
|
13
|
+
cloudsweep/scanners/aws_ipv4.py,sha256=uHy_yc3xYrmnUi9XHhga3pUOIPPANmsoOoAlCrIgFIM,1188
|
|
14
|
+
cloudsweep/scanners/aws_logs.py,sha256=Eq6QfcjYCQtrrAkES09DD-3bZEnf2-BIrDdV-Lh9rxs,1494
|
|
15
|
+
cloudsweep/scanners/aws_nat.py,sha256=q5P5h_knKNtqRuDR6Ds5bjHpd1uSCPi36ITrl2S4bDo,2358
|
|
16
|
+
cloudsweep/scanners/base.py,sha256=BokZkdoA_lRdQHSz0Z0MJ7xVHp7pgNHEbVyTMAv9acI,379
|
|
17
|
+
cloudsweep-0.1.0.dist-info/WHEEL,sha256=G_-rrEibZr7OEM7zdH1dSO6s-VdjfnS5PA4CLAdI9Vw,80
|
|
18
|
+
cloudsweep-0.1.0.dist-info/entry_points.txt,sha256=THAPdOaCPzNiqzXEmRanea6Mtv-m0IO6eZA1jTm0Pf0,51
|
|
19
|
+
cloudsweep-0.1.0.dist-info/METADATA,sha256=L4nblR0Yp297udxA-LBoQtLDqhsgVBKo0e4TbStsgHI,1464
|
|
20
|
+
cloudsweep-0.1.0.dist-info/RECORD,,
|