cloudcompliance 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ """
2
+ CloudCompliance — SOC2 Evidence Report Generator
3
+ Reads Terraform state and maps resources to SOC2 Trust Service Criteria
4
+ """
5
+
6
+ __version__ = "1.0.0"
7
+ __author__ = "Kadhiravan E.G."
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ CloudCompliance — SOC2 Evidence Report Generator
4
+ """
5
+
6
+ import json
7
+ import sys
8
+ from datetime import datetime
9
+ from pathlib import Path
10
+ from rich.console import Console
11
+ from rich.table import Table
12
+ from rich.panel import Panel
13
+ from rich import box
14
+
15
+ console = Console()
16
+
17
+ SOC2_CONTROLS = {
18
+ "CC6.1": {
19
+ "title": "Logical Access — Network Isolation",
20
+ "description": "Restrict logical access via private networking and ACLs",
21
+ "resources": ["aws_vpc", "aws_subnet", "aws_default_security_group"],
22
+ },
23
+ "CC6.2": {
24
+ "title": "Logical Access — Authentication Controls",
25
+ "description": "Enforce strong authentication, password policy, least privilege",
26
+ "resources": ["aws_iam_account_password_policy", "aws_iam_role", "aws_iam_policy", "aws_sns_topic"],
27
+ },
28
+ "CC6.7": {
29
+ "title": "Encryption — Data Protection",
30
+ "description": "Encrypt data at rest and in transit using KMS and HTTPS",
31
+ "resources": ["aws_kms_key", "aws_kms_alias", "aws_s3_bucket_server_side_encryption_configuration", "aws_s3_bucket_policy"],
32
+ },
33
+ "CC7.1": {
34
+ "title": "Threat Detection — Continuous Monitoring",
35
+ "description": "Monitor for anomalous activity and compliance drift",
36
+ "resources": ["aws_cloudwatch_metric_alarm", "aws_config_configuration_recorder", "aws_config_config_rule"],
37
+ },
38
+ "CC7.2": {
39
+ "title": "Audit Logging — Tamper-evident Records",
40
+ "description": "Log all activity with integrity validation and retention",
41
+ "resources": ["aws_s3_bucket_versioning", "aws_s3_bucket_public_access_block", "aws_config_delivery_channel", "aws_flow_log", "aws_cloudwatch_log_group"],
42
+ },
43
+ "CC6.6": {
44
+ "title": "Logical Access — Transmission Protection",
45
+ "description": "Protect data in transit — HTTPS only, deny plaintext",
46
+ "resources": ["aws_s3_bucket_policy"],
47
+ },
48
+ "CC8.1": {
49
+ "title": "Change Management — IaC Controlled",
50
+ "description": "All infrastructure changes via version-controlled IaC",
51
+ "resources": ["aws_iam_role", "aws_config_configuration_recorder_status"],
52
+ },
53
+ }
54
+
55
+
56
+ def load_tfstate(path: str) -> dict:
57
+ tfstate_path = Path(path)
58
+ if not tfstate_path.exists():
59
+ console.print(f"[red]Error: tfstate not found at {path}[/red]")
60
+ sys.exit(1)
61
+ with open(tfstate_path) as f:
62
+ return json.load(f)
63
+
64
+
65
+ def extract_resources(tfstate: dict) -> list:
66
+ resources = []
67
+ for resource in tfstate.get("resources", []):
68
+ resources.append({
69
+ "type": resource.get("type"),
70
+ "name": resource.get("name"),
71
+ "module": resource.get("module", "root"),
72
+ "tags": resource.get("instances", [{}])[0]
73
+ .get("attributes", {})
74
+ .get("tags", {}),
75
+ })
76
+ return resources
77
+
78
+
79
+ def evaluate_controls(resources: list) -> dict:
80
+ found_types = set(r["type"] for r in resources)
81
+ results = {}
82
+ for control_id, control in SOC2_CONTROLS.items():
83
+ matched = [t for t in control["resources"] if t in found_types]
84
+ missing = [t for t in control["resources"] if t not in found_types]
85
+ if len(matched) == len(control["resources"]):
86
+ status = "PASS"
87
+ elif len(matched) > 0:
88
+ status = "PARTIAL"
89
+ else:
90
+ status = "FAIL"
91
+ results[control_id] = {
92
+ "title": control["title"],
93
+ "description": control["description"],
94
+ "status": status,
95
+ "matched": matched,
96
+ "missing": missing,
97
+ }
98
+ return results
99
+
100
+
101
+ def print_report(results: dict, resources: list, output_path: Path = None):
102
+ console.print()
103
+ console.print(Panel.fit(
104
+ "[bold cyan]CloudCompliance — SOC2 Evidence Report[/bold cyan]\n"
105
+ f"[dim]Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}[/dim]\n"
106
+ f"[dim]Total resources provisioned: {len(resources)}[/dim]",
107
+ border_style="cyan"
108
+ ))
109
+ console.print()
110
+
111
+ table = Table(box=box.ROUNDED, show_header=True, header_style="bold magenta")
112
+ table.add_column("Control", style="cyan", width=8)
113
+ table.add_column("Title", width=35)
114
+ table.add_column("Status", width=10)
115
+ table.add_column("Matched Resources", width=40)
116
+
117
+ pass_count = 0
118
+ for control_id, result in results.items():
119
+ status = result["status"]
120
+ if status == "PASS":
121
+ status_str = "[green]✅ PASS[/green]"
122
+ pass_count += 1
123
+ elif status == "PARTIAL":
124
+ status_str = "[yellow]⚠️ PARTIAL[/yellow]"
125
+ else:
126
+ status_str = "[red]❌ FAIL[/red]"
127
+ matched_str = ", ".join(result["matched"]) if result["matched"] else "[dim]none[/dim]"
128
+ table.add_row(control_id, result["title"], status_str, matched_str)
129
+
130
+ console.print(table)
131
+ console.print()
132
+
133
+ score = int((pass_count / len(results)) * 100)
134
+ color = "green" if score >= 80 else "yellow" if score >= 50 else "red"
135
+ console.print(Panel.fit(
136
+ f"[bold {color}]SOC2 Compliance Score: {score}% ({pass_count}/{len(results)} controls passing)[/bold {color}]",
137
+ border_style=color
138
+ ))
139
+
140
+ output = {
141
+ "generated_at": datetime.now().isoformat(),
142
+ "total_resources": len(resources),
143
+ "compliance_score": score,
144
+ "controls": results,
145
+ }
146
+
147
+ if output_path is None:
148
+ output_path = Path(__file__).parent.parent / "compliance" / "compliance_report.json"
149
+
150
+ with open(output_path, "w") as f:
151
+ json.dump(output, f, indent=2)
152
+ console.print()
153
+ console.print(f"[dim]Evidence saved → {output_path}[/dim]")
154
+
155
+
156
+ def run(tfstate_path: str = None, output_path: str = None):
157
+ if tfstate_path is None:
158
+ tfstate_path = Path(__file__).parent.parent / "terraform" / "terraform.tfstate"
159
+ console.print(f"[dim]Reading state from: {tfstate_path}[/dim]")
160
+ tfstate = load_tfstate(str(tfstate_path))
161
+ resources = extract_resources(tfstate)
162
+ results = evaluate_controls(resources)
163
+ print_report(results, resources, Path(output_path) if output_path else None)
164
+
165
+
166
+ def main():
167
+ run()
168
+
169
+
170
+ if __name__ == "__main__":
171
+ main()
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: cloudcompliance
3
+ Version: 1.0.0
4
+ Summary: SOC2 compliance evidence generator for Terraform AWS infrastructure
5
+ Author-email: "Kadhiravan E.G." <kadhiravaneg@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/KADHIRAVANEG/terraform-aws-cloudcompliance
8
+ Project-URL: Repository, https://github.com/KADHIRAVANEG/terraform-aws-cloudcompliance
9
+ Keywords: soc2,compliance,terraform,aws,security,iac
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Security
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: rich>=12.0.0
18
+ Dynamic: license-file
19
+
20
+ [![Terraform Registry](https://img.shields.io/badge/Terraform%20Registry-cloudcompliance-7B42BC?logo=terraform)](https://registry.terraform.io/modules/KADHIRAVANEG/cloudcompliance/aws/latest)
21
+ ![SOC2 Compliance](https://github.com/KADHIRAVANEG/Cloud-Compliance/actions/workflows/compliance.yml/badge.svg)
22
+ ![Terraform](https://img.shields.io/badge/Terraform-1.15.6-7B42BC?logo=terraform)
23
+ ![LocalStack](https://img.shields.io/badge/LocalStack-3.4.0-000000?logo=amazon-aws)
24
+ ![Python](https://img.shields.io/badge/Python-3.11-3776AB?logo=python)
25
+ ![License](https://img.shields.io/badge/License-MIT-green)
26
+
27
+ # CloudCompliance — SOC2-Ready AWS IaC
28
+
29
+ > Infrastructure as Code that provisions a SOC2 Type II-aligned AWS environment
30
+ > in one command. Zero manual security configuration required.
31
+
32
+ ## The Problem
33
+
34
+ Startups spend 6–12 months retrofitting SOC2 controls onto infrastructure that
35
+ was never designed to be compliant. Security is an afterthought — CloudTrail
36
+ gets enabled after an incident, encryption gets added before an audit, RBAC
37
+ gets tightened only when required.
38
+
39
+ **This IaC eliminates that retrofit entirely.**
40
+ Every SOC2 control is provisioned automatically at infrastructure creation time.
41
+
42
+ ---
43
+
44
+ ## SOC2 Control Coverage
45
+
46
+ | Control | Title | Resources Enforced |
47
+ |---------|-----------------------------------|-----------------------------------------------------------------|
48
+ | CC6.1 | Network Isolation | VPC, private subnets, deny-all security group |
49
+ | CC6.2 | Authentication Controls | IAM password policy, MFA alert, least-privilege role |
50
+ | CC6.6 | Transmission Protection | HTTPS-only S3 bucket policy, TLS enforcement |
51
+ | CC6.7 | Encryption at Rest | KMS CMK, S3 server-side encryption, encrypted data bucket |
52
+ | CC7.1 | Threat Detection | CloudWatch alarms, AWS Config recorder, Config rules |
53
+ | CC7.2 | Audit Logging | Versioned audit bucket, delete protection, Config delivery |
54
+ | CC8.1 | Change Management | IaC-controlled infra, Config recorder status tracking |
55
+
56
+
57
+ > **Scope note:** This IaC implements the *technical infrastructure controls*
58
+ > mapped to SOC2 Common Criteria CC6-CC8. Full SOC2 Type II certification
59
+ > additionally requires organizational policies, vendor management, employee
60
+ > training, and 6-12 months of evidence collection — which are outside the
61
+ > scope of infrastructure code.
62
+
63
+ ---
64
+
65
+ ## What Gets Provisioned (29 resources)
66
+
67
+ ### Networking — CC6.1
68
+ - Private VPC (`10.0.0.0/16`) with 2 private subnets
69
+ - No public subnets — zero internet exposure by default
70
+ - Default-deny security group — all inbound/outbound blocked
71
+
72
+ ### Logging — CC7.2
73
+ - Dedicated audit S3 bucket with versioning enabled
74
+ - Delete protection policy — no object or bucket deletion allowed
75
+ - HTTPS-only access policy on audit bucket
76
+
77
+ ### Encryption — CC6.7
78
+ - KMS Customer Managed Key (CMK) with automatic key rotation
79
+ - S3 encrypted data bucket with KMS SSE
80
+ - HTTPS-only bucket policy — plaintext requests denied
81
+
82
+ ### IAM — CC6.2
83
+ - Account password policy: 14 chars, complexity, 90-day rotation, 24 history
84
+ - Least-privilege IAM role — S3 read + KMS decrypt only
85
+ - SNS topic for root account usage alerts
86
+
87
+ ### Monitoring — CC7.1
88
+ - CloudWatch alarm: root account login detection
89
+ - CloudWatch alarm: public S3 bucket detection
90
+ - Both wired to SNS alert topic
91
+
92
+ ### Config — CC7.1 + CC7.2
93
+ - AWS Config recorder — all resource types, all regions
94
+ - Config delivery channel → audit S3 bucket
95
+ - Config rules: S3 public read prohibited, S3 encryption required, root MFA
96
+
97
+ ---
98
+
99
+ ## Quick Start
100
+
101
+ **Requirements:** Terraform ≥ 1.15, Docker
102
+
103
+ ```bash
104
+ # 1. Start LocalStack (free local AWS)
105
+ docker run --rm -d -p 4566:4566 localstack/localstack:3.4.0
106
+
107
+ # 2. Deploy all SOC2 controls
108
+ make deploy
109
+
110
+ # 3. Generate compliance evidence report
111
+ make report
112
+ ```
113
+ ## Use as a Terraform Module
114
+
115
+ ```hcl
116
+ module "soc2_baseline" {
117
+ source = "KADHIRAVANEG/cloudcompliance/aws"
118
+ version = "1.0.0"
119
+
120
+ project_name = "my-startup"
121
+ environment = "prod"
122
+ aws_region = "us-east-1"
123
+ }
124
+ ```
125
+
126
+ ```bash
127
+ terraform init
128
+ terraform apply
129
+ ```
130
+
131
+
132
+ **Expected output:**
133
+
134
+ ```
135
+ ╭────────────────────────────────────────╮
136
+ │ CloudCompliance — SOC2 Evidence Report │
137
+ │ Total resources provisioned: 29 │
138
+ ╰────────────────────────────────────────╯
139
+ SOC2 Compliance Score: 100% (7/7 controls passing)
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Project Structure
145
+
146
+ ```
147
+ cloudcompliance/
148
+ ├── terraform/
149
+ │ ├── main.tf # Root — calls all modules
150
+ │ ├── variables.tf # Environment, region, endpoint
151
+ │ ├── backend.tf # Local (dev) / S3 (prod) backend
152
+ │ ├── local.tfvars # LocalStack config
153
+ │ ├── prod.tfvars # Real AWS config
154
+ │ └── modules/
155
+ │ ├── networking/ # CC6.1 — VPC, subnets, SGs
156
+ │ ├── logging/ # CC7.2 — Audit bucket
157
+ │ ├── encryption/ # CC6.7 — KMS, encrypted S3
158
+ │ ├── iam/ # CC6.2 — Password policy, roles
159
+ │ ├── monitoring/ # CC7.1 — CloudWatch alarms
160
+ │ └── config/ # CC7.1/7.2 — Config rules
161
+ ├── compliance/
162
+ │ └── report.py # SOC2 evidence generator
163
+ ├── .github/workflows/
164
+ │ └── compliance.yml # CI gate — blocks non-compliant PRs
165
+ └── Makefile # make deploy / report / destroy
166
+ ```
167
+
168
+ ---
169
+
170
+ ## CI/CD Compliance Gate
171
+
172
+ Every pull request automatically:
173
+ 1. Validates Terraform formatting and syntax
174
+ 2. Deploys to LocalStack
175
+ 3. Runs the compliance report
176
+ 4. **Blocks merge if any SOC2 control is missing**
177
+
178
+ ---
179
+
180
+ ## Deploying to Real AWS
181
+
182
+ ```bash
183
+ # 1. Configure AWS credentials
184
+ aws configure
185
+
186
+ # 2. Deploy to real AWS
187
+ make deploy-prod
188
+ ```
189
+
190
+ For production, uncomment the S3 backend in `terraform/backend.tf`
191
+ to enable remote state with DynamoDB locking.
192
+
193
+ ---
194
+
195
+ ## LocalStack vs Real AWS
196
+
197
+ | Feature | LocalStack (free) | Real AWS |
198
+ |----------------------|-------------------|----------|
199
+ | VPC / Subnets | ✅ | ✅ |
200
+ | S3 + Encryption | ✅ | ✅ |
201
+ | KMS | ✅ | ✅ |
202
+ | IAM | ✅ | ✅ |
203
+ | CloudWatch | ✅ | ✅ |
204
+ | AWS Config | ✅ | ✅ |
205
+ | SNS | ✅ | ✅ |
206
+ | CloudTrail | ⚠️ Pro only | ✅ |
207
+ | GuardDuty | ⚠️ Pro only | ✅ |
208
+
209
+ ---
210
+
211
+ ## Standards Referenced
212
+
213
+ - [AICPA SOC2 Trust Services Criteria 2017](https://www.aicpa.org/resources/landing/system-and-organization-controls-soc-suite-of-services)
214
+ - [CIS AWS Foundations Benchmark v2.0](https://www.cisecurity.org/benchmark/amazon_web_services)
215
+ - [NIST SP 800-53 Rev 5](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-53r5.pdf)
216
+ - [AWS Security Reference Architecture](https://docs.aws.amazon.com/prescriptive-guidance/latest/security-reference-architecture/welcome.html)
217
+
218
+ ---
219
+
220
+ ## Tech Stack
221
+
222
+ `Terraform` · `Python` · `AWS` · `LocalStack` · `GitHub Actions` · `KMS` · `IAM` · `CloudWatch` · `SNS` · `AWS Config`
223
+
224
+ ---
225
+
226
+ ## Author
227
+
228
+ **Kadhiravan E.G.** — 3rd year Cybersecurity student
229
+ GitHub: [@KADHIRAVANEG](https://github.com/KADHIRAVANEG)
@@ -0,0 +1,8 @@
1
+ cloudcompliance/__init__.py,sha256=y5jsn9qPJjblxDPIwEmRrR57G3fkdPts3nuABKKBjc8,185
2
+ cloudcompliance/report.py,sha256=yGmKWiezkUAXoYUXFE3OLhLWpGzWCWiZJYCxQ7yW1jQ,6223
3
+ cloudcompliance-1.0.0.dist-info/licenses/LICENSE,sha256=9BKBy3zyYEzXHSRmGV9dyi04D6iQtPmvVIcPJuBeXy0,1072
4
+ cloudcompliance-1.0.0.dist-info/METADATA,sha256=kWAMXCgAGpetxPSIyIqrLCxGOZfL3x-Pvt5E3bc7DRY,8557
5
+ cloudcompliance-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ cloudcompliance-1.0.0.dist-info/entry_points.txt,sha256=cVo9ou3kxyG2Wrq2AO6bt-ldlIjAXMygS6Y6UpBLuF0,64
7
+ cloudcompliance-1.0.0.dist-info/top_level.txt,sha256=9n0nRDoST8ywe2OfHWO-pdrs_XC4xkyKJJa43LYLuOg,16
8
+ cloudcompliance-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ cloudcompliance = cloudcompliance.report:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kadhiravan E.G.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ cloudcompliance