cdk-factory 0.14.1__py3-none-any.whl → 0.15.1__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 cdk-factory might be problematic. Click here for more details.
- cdk_factory/configurations/resources/rds.py +5 -0
- cdk_factory/configurations/resources/route53.py +7 -2
- cdk_factory/configurations/resources/security_group_full_stack.py +5 -0
- cdk_factory/constructs/cloudfront/cloudfront_distribution_construct.py +2 -1
- cdk_factory/lambdas/edge/ip_gate/handler.py +56 -1
- cdk_factory/stack_library/cloudfront/cloudfront_stack.py +278 -150
- cdk_factory/stack_library/rds/rds_stack.py +110 -28
- cdk_factory/stack_library/security_group/security_group_full_stack.py +57 -4
- cdk_factory/version.py +1 -1
- {cdk_factory-0.14.1.dist-info → cdk_factory-0.15.1.dist-info}/METADATA +1 -1
- {cdk_factory-0.14.1.dist-info → cdk_factory-0.15.1.dist-info}/RECORD +14 -14
- {cdk_factory-0.14.1.dist-info → cdk_factory-0.15.1.dist-info}/WHEEL +0 -0
- {cdk_factory-0.14.1.dist-info → cdk_factory-0.15.1.dist-info}/entry_points.txt +0 -0
- {cdk_factory-0.14.1.dist-info → cdk_factory-0.15.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -130,3 +130,8 @@ class RdsConfig(EnhancedBaseConfig):
|
|
|
130
130
|
def vpc_id(self, value: str):
|
|
131
131
|
"""Sets the VPC ID for the Security Group"""
|
|
132
132
|
self.__config["vpc_id"] = value
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def ssm_imports(self) -> Dict[str, str]:
|
|
136
|
+
"""SSM parameter imports for the RDS instance"""
|
|
137
|
+
return self.__config.get("ssm_imports", {})
|
|
@@ -26,11 +26,16 @@ class Route53Config:
|
|
|
26
26
|
def hosted_zone_id(self) -> Optional[str]:
|
|
27
27
|
"""Hosted zone ID"""
|
|
28
28
|
return self.__config.get("hosted_zone_id")
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def existing_hosted_zone_id(self) -> Optional[str]:
|
|
32
|
+
"""Existing hosted zone ID (alias for hosted_zone_id)"""
|
|
33
|
+
return self.__config.get("existing_hosted_zone_id") or self.__config.get("hosted_zone_id")
|
|
29
34
|
|
|
30
35
|
@property
|
|
31
36
|
def domain_name(self) -> Optional[str]:
|
|
32
|
-
"""Domain name"""
|
|
33
|
-
return self.__config.get("domain_name")
|
|
37
|
+
"""Domain name (also checks hosted_zone_name)"""
|
|
38
|
+
return self.__config.get("domain_name") or self.__config.get("hosted_zone_name")
|
|
34
39
|
|
|
35
40
|
@property
|
|
36
41
|
def record_names(self) -> List[str]:
|
|
@@ -61,3 +61,8 @@ class SecurityGroupFullStackConfig:
|
|
|
61
61
|
def tags(self) -> Dict[str, str]:
|
|
62
62
|
"""Tags to apply to the Security Group"""
|
|
63
63
|
return self.__config.get("tags", {})
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def ssm_imports(self) -> Dict[str, str]:
|
|
67
|
+
"""SSM parameter imports for the Security Group"""
|
|
68
|
+
return self.__config.get("ssm_imports", {})
|
|
@@ -292,8 +292,9 @@ class CloudFrontDistributionConstruct(Construct):
|
|
|
292
292
|
logger.info(f"Using IP gate Lambda ARN from SSM: {ip_gate_ssm_path}")
|
|
293
293
|
|
|
294
294
|
# Add the IP gating Lambda@Edge association
|
|
295
|
+
# MUST use viewer-request to run BEFORE cache check!
|
|
295
296
|
lambda_edge_associations = [{
|
|
296
|
-
"event_type": "
|
|
297
|
+
"event_type": "viewer-request",
|
|
297
298
|
"lambda_arn": f"{{{{ssm:{ip_gate_ssm_path}}}}}",
|
|
298
299
|
"include_body": False
|
|
299
300
|
}]
|
|
@@ -178,7 +178,58 @@ def lambda_handler(event, context):
|
|
|
178
178
|
print(f"IP {client_ip} is allowed")
|
|
179
179
|
return request
|
|
180
180
|
|
|
181
|
-
# IP not allowed - redirect
|
|
181
|
+
# IP not allowed - either redirect or proxy maintenance page
|
|
182
|
+
# Check response mode from SSM (default: redirect for backward compatibility)
|
|
183
|
+
response_mode_param = f"/{function_name}/response-mode"
|
|
184
|
+
response_mode = get_ssm_parameter(response_mode_param, default='redirect')
|
|
185
|
+
|
|
186
|
+
if response_mode == 'proxy':
|
|
187
|
+
# Proxy mode: Fetch and return maintenance content (keeps URL the same)
|
|
188
|
+
print(f"IP {client_ip} is NOT allowed, proxying content from {maint_cf_host}")
|
|
189
|
+
|
|
190
|
+
try:
|
|
191
|
+
import urllib3
|
|
192
|
+
http = urllib3.PoolManager()
|
|
193
|
+
|
|
194
|
+
# Fetch the maintenance page
|
|
195
|
+
maint_response = http.request(
|
|
196
|
+
'GET',
|
|
197
|
+
f'https://{maint_cf_host}',
|
|
198
|
+
headers={'User-Agent': 'CloudFront-IP-Gate-Proxy'},
|
|
199
|
+
timeout=3.0
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
# Return the maintenance content
|
|
203
|
+
response = {
|
|
204
|
+
'status': str(maint_response.status),
|
|
205
|
+
'statusDescription': 'OK' if maint_response.status == 200 else 'Service Unavailable',
|
|
206
|
+
'headers': {
|
|
207
|
+
'content-type': [{
|
|
208
|
+
'key': 'Content-Type',
|
|
209
|
+
'value': maint_response.headers.get('Content-Type', 'text/html')
|
|
210
|
+
}],
|
|
211
|
+
'cache-control': [{
|
|
212
|
+
'key': 'Cache-Control',
|
|
213
|
+
'value': 'no-cache, no-store, must-revalidate, max-age=0'
|
|
214
|
+
}],
|
|
215
|
+
'x-ip-gate-mode': [{
|
|
216
|
+
'key': 'X-IP-Gate-Mode',
|
|
217
|
+
'value': 'proxy'
|
|
218
|
+
}]
|
|
219
|
+
},
|
|
220
|
+
'body': maint_response.data.decode('utf-8')
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
print(f"Successfully proxied maintenance page (status {maint_response.status})")
|
|
224
|
+
return response
|
|
225
|
+
|
|
226
|
+
except Exception as proxy_error:
|
|
227
|
+
print(f"Error proxying maintenance content: {str(proxy_error)}")
|
|
228
|
+
# Fall back to redirect if proxy fails
|
|
229
|
+
print(f"Falling back to redirect mode")
|
|
230
|
+
response_mode = 'redirect'
|
|
231
|
+
|
|
232
|
+
# Redirect mode (default): HTTP 302 redirect to maintenance site
|
|
182
233
|
print(f"IP {client_ip} is NOT allowed, redirecting to {maint_cf_host}")
|
|
183
234
|
|
|
184
235
|
response = {
|
|
@@ -192,6 +243,10 @@ def lambda_handler(event, context):
|
|
|
192
243
|
'cache-control': [{
|
|
193
244
|
'key': 'Cache-Control',
|
|
194
245
|
'value': 'no-cache, no-store, must-revalidate'
|
|
246
|
+
}],
|
|
247
|
+
'x-ip-gate-mode': [{
|
|
248
|
+
'key': 'X-IP-Gate-Mode',
|
|
249
|
+
'value': 'redirect'
|
|
195
250
|
}]
|
|
196
251
|
}
|
|
197
252
|
}
|