regscale-cli 6.27.3.0__py3-none-any.whl → 6.28.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.

Potentially problematic release.


This version of regscale-cli might be problematic. Click here for more details.

Files changed (113) hide show
  1. regscale/_version.py +1 -1
  2. regscale/core/app/utils/app_utils.py +11 -2
  3. regscale/dev/cli.py +26 -0
  4. regscale/dev/version.py +72 -0
  5. regscale/integrations/commercial/__init__.py +15 -1
  6. regscale/integrations/commercial/amazon/amazon/__init__.py +0 -0
  7. regscale/integrations/commercial/amazon/amazon/common.py +204 -0
  8. regscale/integrations/commercial/amazon/common.py +48 -58
  9. regscale/integrations/commercial/aws/audit_manager_compliance.py +2671 -0
  10. regscale/integrations/commercial/aws/cli.py +3093 -55
  11. regscale/integrations/commercial/aws/cloudtrail_control_mappings.py +333 -0
  12. regscale/integrations/commercial/aws/cloudtrail_evidence.py +501 -0
  13. regscale/integrations/commercial/aws/cloudwatch_control_mappings.py +357 -0
  14. regscale/integrations/commercial/aws/cloudwatch_evidence.py +490 -0
  15. regscale/integrations/commercial/aws/config_compliance.py +914 -0
  16. regscale/integrations/commercial/aws/conformance_pack_mappings.py +198 -0
  17. regscale/integrations/commercial/aws/evidence_generator.py +283 -0
  18. regscale/integrations/commercial/aws/guardduty_control_mappings.py +340 -0
  19. regscale/integrations/commercial/aws/guardduty_evidence.py +1053 -0
  20. regscale/integrations/commercial/aws/iam_control_mappings.py +368 -0
  21. regscale/integrations/commercial/aws/iam_evidence.py +574 -0
  22. regscale/integrations/commercial/aws/inventory/__init__.py +223 -22
  23. regscale/integrations/commercial/aws/inventory/base.py +107 -5
  24. regscale/integrations/commercial/aws/inventory/resources/audit_manager.py +513 -0
  25. regscale/integrations/commercial/aws/inventory/resources/cloudtrail.py +315 -0
  26. regscale/integrations/commercial/aws/inventory/resources/cloudtrail_logs_metadata.py +476 -0
  27. regscale/integrations/commercial/aws/inventory/resources/cloudwatch.py +191 -0
  28. regscale/integrations/commercial/aws/inventory/resources/compute.py +66 -9
  29. regscale/integrations/commercial/aws/inventory/resources/config.py +464 -0
  30. regscale/integrations/commercial/aws/inventory/resources/containers.py +74 -9
  31. regscale/integrations/commercial/aws/inventory/resources/database.py +106 -31
  32. regscale/integrations/commercial/aws/inventory/resources/guardduty.py +286 -0
  33. regscale/integrations/commercial/aws/inventory/resources/iam.py +470 -0
  34. regscale/integrations/commercial/aws/inventory/resources/inspector.py +476 -0
  35. regscale/integrations/commercial/aws/inventory/resources/integration.py +175 -61
  36. regscale/integrations/commercial/aws/inventory/resources/kms.py +447 -0
  37. regscale/integrations/commercial/aws/inventory/resources/networking.py +103 -67
  38. regscale/integrations/commercial/aws/inventory/resources/s3.py +394 -0
  39. regscale/integrations/commercial/aws/inventory/resources/security.py +268 -72
  40. regscale/integrations/commercial/aws/inventory/resources/securityhub.py +473 -0
  41. regscale/integrations/commercial/aws/inventory/resources/storage.py +53 -29
  42. regscale/integrations/commercial/aws/inventory/resources/systems_manager.py +657 -0
  43. regscale/integrations/commercial/aws/inventory/resources/vpc.py +655 -0
  44. regscale/integrations/commercial/aws/kms_control_mappings.py +288 -0
  45. regscale/integrations/commercial/aws/kms_evidence.py +879 -0
  46. regscale/integrations/commercial/aws/ocsf/__init__.py +7 -0
  47. regscale/integrations/commercial/aws/ocsf/constants.py +115 -0
  48. regscale/integrations/commercial/aws/ocsf/mapper.py +435 -0
  49. regscale/integrations/commercial/aws/org_control_mappings.py +286 -0
  50. regscale/integrations/commercial/aws/org_evidence.py +666 -0
  51. regscale/integrations/commercial/aws/s3_control_mappings.py +356 -0
  52. regscale/integrations/commercial/aws/s3_evidence.py +632 -0
  53. regscale/integrations/commercial/aws/scanner.py +851 -206
  54. regscale/integrations/commercial/aws/security_hub.py +319 -0
  55. regscale/integrations/commercial/aws/session_manager.py +282 -0
  56. regscale/integrations/commercial/aws/ssm_control_mappings.py +291 -0
  57. regscale/integrations/commercial/aws/ssm_evidence.py +492 -0
  58. regscale/integrations/commercial/synqly/ticketing.py +27 -0
  59. regscale/integrations/compliance_integration.py +308 -38
  60. regscale/integrations/due_date_handler.py +3 -0
  61. regscale/integrations/scanner_integration.py +399 -84
  62. regscale/models/integration_models/cisa_kev_data.json +65 -5
  63. regscale/models/integration_models/synqly_models/capabilities.json +1 -1
  64. regscale/models/integration_models/synqly_models/connectors/vulnerabilities.py +17 -9
  65. regscale/models/regscale_models/assessment.py +2 -1
  66. regscale/models/regscale_models/control_objective.py +74 -5
  67. regscale/models/regscale_models/file.py +2 -0
  68. regscale/models/regscale_models/issue.py +2 -5
  69. {regscale_cli-6.27.3.0.dist-info → regscale_cli-6.28.1.0.dist-info}/METADATA +1 -1
  70. {regscale_cli-6.27.3.0.dist-info → regscale_cli-6.28.1.0.dist-info}/RECORD +113 -34
  71. tests/regscale/integrations/commercial/aws/__init__.py +0 -0
  72. tests/regscale/integrations/commercial/aws/test_audit_manager_compliance.py +1304 -0
  73. tests/regscale/integrations/commercial/aws/test_audit_manager_evidence_aggregation.py +341 -0
  74. tests/regscale/integrations/commercial/aws/test_aws_audit_manager_collector.py +1155 -0
  75. tests/regscale/integrations/commercial/aws/test_aws_cloudtrail_collector.py +534 -0
  76. tests/regscale/integrations/commercial/aws/test_aws_config_collector.py +400 -0
  77. tests/regscale/integrations/commercial/aws/test_aws_guardduty_collector.py +315 -0
  78. tests/regscale/integrations/commercial/aws/test_aws_iam_collector.py +458 -0
  79. tests/regscale/integrations/commercial/aws/test_aws_inspector_collector.py +353 -0
  80. tests/regscale/integrations/commercial/aws/test_aws_inventory_integration.py +530 -0
  81. tests/regscale/integrations/commercial/aws/test_aws_kms_collector.py +919 -0
  82. tests/regscale/integrations/commercial/aws/test_aws_s3_collector.py +722 -0
  83. tests/regscale/integrations/commercial/aws/test_aws_scanner_integration.py +722 -0
  84. tests/regscale/integrations/commercial/aws/test_aws_securityhub_collector.py +792 -0
  85. tests/regscale/integrations/commercial/aws/test_aws_systems_manager_collector.py +918 -0
  86. tests/regscale/integrations/commercial/aws/test_aws_vpc_collector.py +996 -0
  87. tests/regscale/integrations/commercial/aws/test_cli_evidence.py +431 -0
  88. tests/regscale/integrations/commercial/aws/test_cloudtrail_control_mappings.py +452 -0
  89. tests/regscale/integrations/commercial/aws/test_cloudtrail_evidence.py +788 -0
  90. tests/regscale/integrations/commercial/aws/test_config_compliance.py +298 -0
  91. tests/regscale/integrations/commercial/aws/test_conformance_pack_mappings.py +200 -0
  92. tests/regscale/integrations/commercial/aws/test_evidence_generator.py +386 -0
  93. tests/regscale/integrations/commercial/aws/test_guardduty_control_mappings.py +564 -0
  94. tests/regscale/integrations/commercial/aws/test_guardduty_evidence.py +1041 -0
  95. tests/regscale/integrations/commercial/aws/test_iam_control_mappings.py +718 -0
  96. tests/regscale/integrations/commercial/aws/test_iam_evidence.py +1375 -0
  97. tests/regscale/integrations/commercial/aws/test_kms_control_mappings.py +656 -0
  98. tests/regscale/integrations/commercial/aws/test_kms_evidence.py +1163 -0
  99. tests/regscale/integrations/commercial/aws/test_ocsf_mapper.py +370 -0
  100. tests/regscale/integrations/commercial/aws/test_org_control_mappings.py +546 -0
  101. tests/regscale/integrations/commercial/aws/test_org_evidence.py +1240 -0
  102. tests/regscale/integrations/commercial/aws/test_s3_control_mappings.py +672 -0
  103. tests/regscale/integrations/commercial/aws/test_s3_evidence.py +987 -0
  104. tests/regscale/integrations/commercial/aws/test_scanner_evidence.py +373 -0
  105. tests/regscale/integrations/commercial/aws/test_security_hub_config_filtering.py +539 -0
  106. tests/regscale/integrations/commercial/aws/test_session_manager.py +516 -0
  107. tests/regscale/integrations/commercial/aws/test_ssm_control_mappings.py +588 -0
  108. tests/regscale/integrations/commercial/aws/test_ssm_evidence.py +735 -0
  109. tests/regscale/integrations/commercial/test_aws.py +55 -56
  110. {regscale_cli-6.27.3.0.dist-info → regscale_cli-6.28.1.0.dist-info}/LICENSE +0 -0
  111. {regscale_cli-6.27.3.0.dist-info → regscale_cli-6.28.1.0.dist-info}/WHEEL +0 -0
  112. {regscale_cli-6.27.3.0.dist-info → regscale_cli-6.28.1.0.dist-info}/entry_points.txt +0 -0
  113. {regscale_cli-6.27.3.0.dist-info → regscale_cli-6.28.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,288 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """AWS KMS Control Mappings for RegScale Compliance Integration."""
4
+
5
+ import logging
6
+ from typing import Dict, List, Optional
7
+
8
+ logger = logging.getLogger("regscale")
9
+
10
+ # NIST 800-53 R5 Control Mappings for AWS KMS
11
+ KMS_CONTROL_MAPPINGS = {
12
+ "SC-12": {
13
+ "name": "Cryptographic Key Establishment and Management",
14
+ "description": "Establish and manage cryptographic keys for cryptography employed in organizational systems",
15
+ "checks": {
16
+ "rotation_enabled": {
17
+ "weight": 100,
18
+ "pass_criteria": "Customer-managed key with automatic rotation enabled",
19
+ "fail_criteria": "Customer-managed key with automatic rotation disabled",
20
+ },
21
+ "key_state": {
22
+ "weight": 80,
23
+ "pass_criteria": "Key is in Enabled state",
24
+ "fail_criteria": "Key is PendingDeletion or Disabled",
25
+ },
26
+ "key_manager": {
27
+ "weight": 40,
28
+ "pass_criteria": "Customer-managed key (not AWS-managed)",
29
+ "fail_criteria": "AWS-managed key (limited rotation control)",
30
+ },
31
+ },
32
+ },
33
+ "SC-13": {
34
+ "name": "Cryptographic Protection",
35
+ "description": "Implement FIPS-validated or NSA-approved cryptography",
36
+ "checks": {
37
+ "key_spec": {
38
+ "weight": 100,
39
+ "pass_criteria": "Using approved algorithms (SYMMETRIC_DEFAULT, RSA_*, ECC_*)",
40
+ "fail_criteria": "Using deprecated or non-approved algorithms",
41
+ },
42
+ "key_usage": {
43
+ "weight": 80,
44
+ "pass_criteria": "Key usage appropriate for workload (ENCRYPT_DECRYPT, SIGN_VERIFY)",
45
+ "fail_criteria": "Key usage mismatch or GENERATE_VERIFY_MAC without proper controls",
46
+ },
47
+ "key_origin": {
48
+ "weight": 60,
49
+ "pass_criteria": "Key generated in AWS_KMS (FIPS 140-2 Level 2+)",
50
+ "fail_criteria": "External key material without documented FIPS compliance",
51
+ },
52
+ },
53
+ },
54
+ "SC-28": {
55
+ "name": "Protection of Information at Rest",
56
+ "description": "Protect information at rest using cryptographic mechanisms",
57
+ "checks": {
58
+ "key_exists": {
59
+ "weight": 100,
60
+ "pass_criteria": "KMS key exists and is enabled for data-at-rest encryption",
61
+ "fail_criteria": "No KMS key configured for data-at-rest protection",
62
+ },
63
+ "multi_region": {
64
+ "weight": 60,
65
+ "pass_criteria": "Multi-region key for disaster recovery scenarios",
66
+ "fail_criteria": "Single-region key may impact availability",
67
+ },
68
+ "grants": {
69
+ "weight": 40,
70
+ "pass_criteria": "Grants follow least-privilege principle",
71
+ "fail_criteria": "Excessive grants or overly permissive policies",
72
+ },
73
+ },
74
+ },
75
+ }
76
+
77
+ # ISO 27001 A.10.1 Control Mappings
78
+ ISO_27001_MAPPINGS = {
79
+ "A.10.1.1": {
80
+ "name": "Policy on the use of cryptographic controls",
81
+ "kms_attributes": ["rotation_enabled", "key_policy", "key_manager"],
82
+ },
83
+ "A.10.1.2": {
84
+ "name": "Key management",
85
+ "kms_attributes": ["rotation_enabled", "key_state", "creation_date", "deletion_date"],
86
+ },
87
+ }
88
+
89
+ # Approved KMS key specifications (FIPS-validated algorithms)
90
+ APPROVED_KEY_SPECS = [
91
+ "SYMMETRIC_DEFAULT", # AES-256-GCM
92
+ "RSA_2048",
93
+ "RSA_3072",
94
+ "RSA_4096",
95
+ "ECC_NIST_P256",
96
+ "ECC_NIST_P384",
97
+ "ECC_NIST_P521",
98
+ "ECC_SECG_P256K1",
99
+ "HMAC_224",
100
+ "HMAC_256",
101
+ "HMAC_384",
102
+ "HMAC_512",
103
+ "SM2", # China State Cryptography Administration standard
104
+ ]
105
+
106
+ # Key states that indicate compliance issues
107
+ NON_COMPLIANT_KEY_STATES = [
108
+ "PendingDeletion",
109
+ "PendingImport",
110
+ "Unavailable",
111
+ ]
112
+
113
+
114
+ class KMSControlMapper:
115
+ """Map AWS KMS key attributes to compliance control status."""
116
+
117
+ def __init__(self, framework: str = "NIST800-53R5"):
118
+ """
119
+ Initialize KMS control mapper.
120
+
121
+ :param str framework: Compliance framework (NIST800-53R5 or ISO27001)
122
+ """
123
+ self.framework = framework
124
+ self.mappings = KMS_CONTROL_MAPPINGS if framework == "NIST800-53R5" else ISO_27001_MAPPINGS
125
+
126
+ def assess_key_compliance(self, key_data: Dict) -> Dict[str, str]:
127
+ """
128
+ Assess KMS key compliance against all mapped controls.
129
+
130
+ :param Dict key_data: KMS key metadata and attributes
131
+ :return: Dictionary mapping control IDs to compliance results (PASS/FAIL)
132
+ :rtype: Dict[str, str]
133
+ """
134
+ results = {}
135
+
136
+ if self.framework == "NIST800-53R5":
137
+ results["SC-12"] = self._assess_sc12(key_data)
138
+ results["SC-13"] = self._assess_sc13(key_data)
139
+ results["SC-28"] = self._assess_sc28(key_data)
140
+
141
+ return results
142
+
143
+ def _assess_sc12(self, key_data: Dict) -> str:
144
+ """
145
+ Assess SC-12 (Cryptographic Key Management) compliance.
146
+
147
+ :param Dict key_data: KMS key metadata
148
+ :return: Compliance result (PASS/FAIL)
149
+ :rtype: str
150
+ """
151
+ # Critical: Rotation must be enabled for customer-managed keys
152
+ key_manager = key_data.get("KeyManager", "CUSTOMER")
153
+ rotation_enabled = key_data.get("RotationEnabled", False)
154
+ key_state = key_data.get("KeyState", "Unknown")
155
+
156
+ # AWS-managed keys have automatic rotation, so they pass
157
+ if key_manager == "AWS":
158
+ logger.debug(f"Key {key_data.get('KeyId')} is AWS-managed, auto-passing SC-12")
159
+ return "PASS"
160
+
161
+ # Customer-managed keys MUST have rotation enabled
162
+ if not rotation_enabled:
163
+ logger.debug(f"Key {key_data.get('KeyId')} FAILS SC-12: rotation disabled")
164
+ return "FAIL"
165
+
166
+ # Key must be in enabled state
167
+ if key_state in NON_COMPLIANT_KEY_STATES:
168
+ logger.debug(f"Key {key_data.get('KeyId')} FAILS SC-12: key state is {key_state}")
169
+ return "FAIL"
170
+
171
+ logger.debug(f"Key {key_data.get('KeyId')} PASSES SC-12: rotation enabled, state {key_state}")
172
+ return "PASS"
173
+
174
+ def _assess_sc13(self, key_data: Dict) -> str:
175
+ """
176
+ Assess SC-13 (Cryptographic Protection) compliance.
177
+
178
+ :param Dict key_data: KMS key metadata
179
+ :return: Compliance result (PASS/FAIL)
180
+ :rtype: str
181
+ """
182
+ key_spec = key_data.get("KeySpec", "SYMMETRIC_DEFAULT")
183
+ key_origin = key_data.get("Origin", "AWS_KMS")
184
+
185
+ # Check for approved key specifications
186
+ if key_spec not in APPROVED_KEY_SPECS:
187
+ logger.debug(f"Key {key_data.get('KeyId')} FAILS SC-13: unapproved key spec {key_spec}")
188
+ return "FAIL"
189
+
190
+ # Prefer AWS_KMS origin for FIPS 140-2 Level 2+ compliance
191
+ # EXTERNAL origin requires additional documentation
192
+ if key_origin == "EXTERNAL":
193
+ logger.warning(f"Key {key_data.get('KeyId')} uses EXTERNAL origin - verify FIPS compliance documentation")
194
+
195
+ # AWS_CLOUDHSM origin is acceptable (FIPS 140-2 Level 3)
196
+ # AWS_KMS origin is acceptable (FIPS 140-2 Level 2)
197
+ logger.debug(f"Key {key_data.get('KeyId')} PASSES SC-13: spec {key_spec}, origin {key_origin}")
198
+ return "PASS"
199
+
200
+ def _assess_sc28(self, key_data: Dict) -> str:
201
+ """
202
+ Assess SC-28 (Protection of Information at Rest) compliance.
203
+
204
+ :param Dict key_data: KMS key metadata
205
+ :return: Compliance result (PASS/FAIL)
206
+ :rtype: str
207
+ """
208
+ key_state = key_data.get("KeyState", "Unknown")
209
+ enabled = key_data.get("Enabled", False)
210
+
211
+ # Key must be enabled and available for data-at-rest encryption
212
+ if key_state in NON_COMPLIANT_KEY_STATES:
213
+ logger.debug(f"Key {key_data.get('KeyId')} FAILS SC-28: key state is {key_state}")
214
+ return "FAIL"
215
+
216
+ if not enabled:
217
+ logger.debug(f"Key {key_data.get('KeyId')} FAILS SC-28: key is disabled")
218
+ return "FAIL"
219
+
220
+ # Check for overly permissive policies (simplified check)
221
+ policy = key_data.get("Policy")
222
+ if policy and self._has_overly_permissive_policy(policy):
223
+ logger.warning(f"Key {key_data.get('KeyId')} has overly permissive policy - review required")
224
+
225
+ logger.debug(f"Key {key_data.get('KeyId')} PASSES SC-28: enabled and available")
226
+ return "PASS"
227
+
228
+ def _has_overly_permissive_policy(self, policy: str) -> bool:
229
+ """
230
+ Check if key policy is overly permissive.
231
+
232
+ :param str policy: Key policy JSON string
233
+ :return: True if policy has security concerns
234
+ :rtype: bool
235
+ """
236
+ import json
237
+
238
+ try:
239
+ policy_dict = json.loads(policy)
240
+ statements = policy_dict.get("Statement", [])
241
+
242
+ for statement in statements:
243
+ # Check for wildcard principals
244
+ principal = statement.get("Principal", {})
245
+ if principal == "*" or (isinstance(principal, dict) and principal.get("AWS") == "*"):
246
+ effect = statement.get("Effect", "Deny")
247
+ if effect == "Allow":
248
+ return True
249
+
250
+ except (json.JSONDecodeError, AttributeError):
251
+ logger.debug("Could not parse key policy for security analysis")
252
+
253
+ return False
254
+
255
+ def get_control_description(self, control_id: str) -> Optional[str]:
256
+ """
257
+ Get human-readable description for a control.
258
+
259
+ :param str control_id: Control identifier (e.g., SC-12)
260
+ :return: Control description or None
261
+ :rtype: Optional[str]
262
+ """
263
+ control_data = self.mappings.get(control_id)
264
+ if control_data:
265
+ return f"{control_data.get('name')}: {control_data.get('description', '')}"
266
+ return None
267
+
268
+ def get_mapped_controls(self) -> List[str]:
269
+ """
270
+ Get list of all control IDs mapped for this framework.
271
+
272
+ :return: List of control IDs
273
+ :rtype: List[str]
274
+ """
275
+ return list(self.mappings.keys())
276
+
277
+ def get_check_details(self, control_id: str) -> Optional[Dict]:
278
+ """
279
+ Get detailed check criteria for a control.
280
+
281
+ :param str control_id: Control identifier
282
+ :return: Dictionary of check details or None
283
+ :rtype: Optional[Dict]
284
+ """
285
+ control_data = self.mappings.get(control_id)
286
+ if control_data:
287
+ return control_data.get("checks", {})
288
+ return None