feat(automation): generar variables de simulacion desde Terraform
This commit is contained in:
parent
ada0284012
commit
6788d0c3a6
|
|
@ -65,3 +65,14 @@ Elimina las reglas de bloqueo en Network ACL, remueve usuarios y políticas temp
|
||||||
```bash
|
```bash
|
||||||
ansible-playbook ansible/playbooks/simulations/rollback_cleanup.yml
|
ansible-playbook ansible/playbooks/simulations/rollback_cleanup.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Reconstrucción y Sincronización Automática tras Despliegue
|
||||||
|
|
||||||
|
Si la infraestructura en AWS fue recreada con Terraform, regenera las variables del laboratorio y el inventario con:
|
||||||
|
```bash
|
||||||
|
python ansible/scripts/generate_inventory.py
|
||||||
|
python ansible/scripts/generate_simulation_vars.py
|
||||||
|
```
|
||||||
|
Esto leerá las salidas (`outputs`) del nuevo entorno en AWS y sincronizará de forma automática las IPs, buckets, tablas e identificadores de red tanto en el inventario SSM como en `ansible/playbooks/simulations/vars.yml`.
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,17 @@
|
||||||
---
|
---
|
||||||
# Variables centrales para la Suite de Ataques Red Team y Rollback (TIC Tesis)
|
# Variables de simulacion actualizadas automaticamente desde Terraform
|
||||||
# Alineadas con los outputs activos de Terraform en AWS us-east-2
|
|
||||||
|
|
||||||
portal_public_ip: "18.219.62.81"
|
portal_public_ip: 18.219.62.81
|
||||||
portal_url: "http://18.219.62.81"
|
portal_url: http://18.219.62.81
|
||||||
aws_region: "us-east-2"
|
aws_region: us-east-2
|
||||||
vpc_id: "vpc-00cd654d72a84e9f0"
|
vpc_id: vpc-00cd654d72a84e9f0
|
||||||
nacl_id: "acl-0c072d7e12b416874"
|
nacl_id: acl-0c072d7e12b416874
|
||||||
|
sensitive_bucket: tesis-ir-sensitive-data-056176271407-us-east-2
|
||||||
sensitive_bucket: "tesis-ir-sensitive-data-056176271407-us-east-2"
|
evidence_bucket: tesis-ir-evidence-056176271407-us-east-2
|
||||||
evidence_bucket: "tesis-ir-evidence-056176271407-us-east-2"
|
logs_bucket: tesis-ir-logs-056176271407-us-east-2
|
||||||
logs_bucket: "tesis-ir-logs-056176271407-us-east-2"
|
dynamodb_incidents_table: tesis-ir_incidents
|
||||||
|
dynamodb_state_table: tesis-ir_detection_state
|
||||||
dynamodb_incidents_table: "tesis-ir_incidents"
|
portal_instance_id: i-05a276d44211bf7e7
|
||||||
dynamodb_state_table: "tesis-ir_detection_state"
|
test_iam_username: tesis-ir-temp-escalation-test
|
||||||
|
test_escalation_policy_arn: arn:aws:iam::aws:policy/ReadOnlyAccess
|
||||||
portal_instance_id: "i-05a276d44211bf7e7"
|
emergency_deny_policy_name: EmergencyDenyAll
|
||||||
test_iam_username: "tesis-ir-temp-escalation-test"
|
|
||||||
test_escalation_policy_arn: "arn:aws:iam::aws:policy/ReadOnlyAccess"
|
|
||||||
emergency_deny_policy_name: "EmergencyDenyAll"
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
"""Genera ansible/playbooks/simulations/vars.yml desde outputs de Terraform."""
|
||||||
|
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
root = Path(__file__).resolve().parents[2]
|
||||||
|
tf_dir = root / "terraform-tesis-ir-secure-portal"
|
||||||
|
out_file = root / "ansible/playbooks/simulations/vars.yml"
|
||||||
|
try:
|
||||||
|
raw = subprocess.run(
|
||||||
|
["terraform", f"-chdir={tf_dir}", "output", "-json"],
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
data = json.loads(raw.stdout)
|
||||||
|
vars_content = {
|
||||||
|
"portal_public_ip": data["portal_public_ip"]["value"],
|
||||||
|
"portal_url": data["portal_url"]["value"],
|
||||||
|
"aws_region": data["region"]["value"],
|
||||||
|
"vpc_id": data["vpc_id"]["value"],
|
||||||
|
"nacl_id": data["mitigation_network_acl_id"]["value"],
|
||||||
|
"sensitive_bucket": data["sensitive_bucket"]["value"],
|
||||||
|
"evidence_bucket": data["evidence_bucket"]["value"],
|
||||||
|
"logs_bucket": data["logs_bucket"]["value"],
|
||||||
|
"dynamodb_incidents_table": data["dynamodb_incidents_table"]["value"],
|
||||||
|
"dynamodb_state_table": data["dynamodb_state_table"]["value"],
|
||||||
|
"portal_instance_id": data["portal_instance_id"]["value"],
|
||||||
|
"test_iam_username": "tesis-ir-temp-escalation-test",
|
||||||
|
"test_escalation_policy_arn": "arn:aws:iam::aws:policy/ReadOnlyAccess",
|
||||||
|
"emergency_deny_policy_name": "EmergencyDenyAll",
|
||||||
|
}
|
||||||
|
with open(out_file, "w", encoding="utf-8") as f:
|
||||||
|
f.write("---\n# Variables de simulacion actualizadas automaticamente desde Terraform\n\n")
|
||||||
|
yaml.dump(vars_content, f, default_flow_style=False, sort_keys=False)
|
||||||
|
print(f"Variables de simulacion actualizadas: {out_file}")
|
||||||
|
except (OSError, ValueError, subprocess.CalledProcessError) as exc:
|
||||||
|
print(f"Error generando vars.yml: {exc}", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
Loading…
Reference in New Issue