-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
118 lines (100 loc) · 4.5 KB
/
Copy pathMakefile
File metadata and controls
118 lines (100 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# ── Azure Security Baseline — Makefile ───────────────────────────────────────────
# Usage: make <target>
# All targets that interact with Azure require: az login
.PHONY: help init plan apply destroy audit report lint fmt validate clean
SHELL := /bin/bash
TF_DIR := terraform
SCRIPTS_DIR := scripts
REPORTS_DIR := reports
RG ?= azsec-lab-rg
# Default: print help
help:
@echo ""
@echo " Azure Security Baseline"
@echo " ──────────────────────────────────────────────────────"
@echo ""
@echo " Infrastructure:"
@echo " make init Terraform init (no backend — local state)"
@echo " make plan Terraform plan (review before apply)"
@echo " make apply Terraform apply (provisions Azure resources)"
@echo " make destroy Tear down all provisioned resources"
@echo ""
@echo " Audit:"
@echo " make audit Run NSG security audit against RG (RG=<name>)"
@echo " make report Generate Markdown report from last audit"
@echo " make full-audit Provision → audit → report in one command"
@echo ""
@echo " Code Quality:"
@echo " make lint Lint Python scripts with ruff"
@echo " make fmt Format Python with ruff"
@echo " make validate Validate Terraform configuration"
@echo ""
@echo " Variables:"
@echo " RG=<name> Resource group to audit (default: azsec-lab-rg)"
@echo ""
# ── Infrastructure ────────────────────────────────────────────────────────────────
init:
@echo "→ Terraform init..."
cd $(TF_DIR) && terraform init
plan:
@echo "→ Terraform plan..."
cd $(TF_DIR) && terraform plan
apply:
@echo "→ Terraform apply..."
cd $(TF_DIR) && terraform apply -auto-approve
@echo ""
@echo "→ Provisioning complete. Run 'make audit' to audit the environment."
destroy:
@echo "→ Destroying all resources in resource group..."
cd $(TF_DIR) && terraform destroy -auto-approve
# ── Audit ─────────────────────────────────────────────────────────────────────────
audit:
@echo "→ Running NSG security audit against resource group: $(RG)"
@mkdir -p $(REPORTS_DIR)
python $(SCRIPTS_DIR)/nsg_analyzer.py \
--resource-group $(RG) \
--output-json $(REPORTS_DIR)/findings.json \
--fail-on HIGH; \
EXIT=$$?; \
echo ""; \
if [ $$EXIT -ne 0 ]; then \
echo " Findings require remediation. Run 'make report' to generate the report."; \
else \
echo " Audit passed. Run 'make report' to generate the report."; \
fi; \
exit $$EXIT
report:
@if [ ! -f $(REPORTS_DIR)/findings.json ]; then \
echo "ERROR: No findings.json found. Run 'make audit' first."; \
exit 1; \
fi
@echo "→ Generating Markdown report..."
python $(SCRIPTS_DIR)/generate_report.py \
--input $(REPORTS_DIR)/findings.json \
--output $(REPORTS_DIR)/AUDIT-$(shell date +%Y%m%d).md
@echo "→ Report generated: $(REPORTS_DIR)/AUDIT-$(shell date +%Y%m%d).md"
full-audit: apply audit report
@echo "→ Full audit cycle complete."
# ── Code Quality ──────────────────────────────────────────────────────────────────
lint:
@echo "→ Linting Python..."
ruff check $(SCRIPTS_DIR)/
@echo "→ Checking Terraform format..."
cd $(TF_DIR) && terraform fmt -check -recursive
fmt:
@echo "→ Formatting Python..."
ruff format $(SCRIPTS_DIR)/
@echo "→ Formatting Terraform..."
cd $(TF_DIR) && terraform fmt -recursive
validate:
@echo "→ Validating Terraform configuration..."
cd $(TF_DIR) && terraform init -backend=false -reconfigure && terraform validate
# ── Cleanup ───────────────────────────────────────────────────────────────────────
clean:
@echo "→ Cleaning generated files..."
rm -f $(REPORTS_DIR)/findings.json
rm -f $(REPORTS_DIR)/AUDIT-*.md
rm -rf $(TF_DIR)/.terraform
rm -f $(TF_DIR)/.terraform.lock.hcl
rm -f $(TF_DIR)/terraform.tfstate
rm -f $(TF_DIR)/terraform.tfstate.backup