-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.sh
More file actions
181 lines (153 loc) · 8.34 KB
/
commands.sh
File metadata and controls
181 lines (153 loc) · 8.34 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
# Commands executed during the lab
# ========================================================================
# Environment Setup / Install Required Tools
# ========================================================================
sudo apt update
sudo apt install -y python3 python3-pip python3-venv
sudo apt install -y curl jq git
# ========================================================================
# Environment Setup / Create Project Directory
# ========================================================================
mkdir -p ~/policy-gate-lab
cd ~/policy-gate-lab
# ========================================================================
# Environment Setup / Create Python Virtual Environment
# ========================================================================
python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install pyyaml requests
# ========================================================================
# Task 1: Build the Multi-Profile Policy Engine / Step 1: Create Policy Configuration Files
# ========================================================================
mkdir -p config/profiles
# ========================================================================
# Task 1: Build the Multi-Profile Policy Engine / Step 1: Create Policy Configuration Files / Healthcare Profile (`config/profiles/healthcare.yaml`)
# ========================================================================
nano config/profiles/healthcare.yaml
# ========================================================================
# Task 1: Build the Multi-Profile Policy Engine / Step 1: Create Policy Configuration Files / Finance Profile (`config/profiles/finance.yaml`)
# ========================================================================
nano config/profiles/finance.yaml
# ========================================================================
# Task 1: Build the Multi-Profile Policy Engine / Step 1: Create Policy Configuration Files / Retail Profile (`config/profiles/retail.yaml`)
# ========================================================================
nano config/profiles/retail.yaml
# ========================================================================
# Task 1: Build the Multi-Profile Policy Engine / Step 2: Create the Policy Gate Engine
# ========================================================================
nano policy_gate.py
# ========================================================================
# Task 1: Build the Multi-Profile Policy Engine / Step 2: Create the Policy Gate Engine / Make it executable:
# ========================================================================
chmod +x policy_gate.py
# ========================================================================
# Task 2: Dynamic Policy Enforcement System / Step 1: Create Configuration Switcher
# ========================================================================
nano config_manager.py
# ========================================================================
# Task 2: Dynamic Policy Enforcement System / Step 1: Create Configuration Switcher / Make it executable:
# ========================================================================
chmod +x config_manager.py
# ========================================================================
# Task 2: Dynamic Policy Enforcement System / Step 2: Build the API Gateway
# ========================================================================
nano api_gateway.py
# ========================================================================
# Task 2: Dynamic Policy Enforcement System / Step 2: Build the API Gateway / Make it executable:
# ========================================================================
chmod +x api_gateway.py
# ========================================================================
# Task 2: Dynamic Policy Enforcement System / Step 3: Create Test Client
# ========================================================================
nano test_client.py
# ========================================================================
# Task 2: Dynamic Policy Enforcement System / Step 3: Create Test Client / Make it executable:
# ========================================================================
chmod +x test_client.py
# ========================================================================
# Verification / Step 1: Start the Policy Gate Server / In terminal 1
# ========================================================================
cd ~/policy-gate-lab
source venv/bin/activate
python3 api_gateway.py
# ========================================================================
# Verification / Step 2: Test Profile Switching / In terminal 2
# ========================================================================
cd ~/policy-gate-lab
source venv/bin/activate
curl http://localhost:8080/profiles
curl -X POST http://localhost:8080/switch-profile \
-H "Content-Type: application/json" \
-d '{"profile": "healthcare"}'
curl http://localhost:8080/status
# ========================================================================
# Step 3: Test Policy Enforcement / Test Healthcare Compliance / Non-compliant request (no encryption)
# ========================================================================
curl -X POST http://localhost:8080/enforce \
-H "Content-Type: application/json" \
-d '{
"data_type": "PHI",
"encrypted": false,
"access_logged": true
}'
# ========================================================================
# Step 3: Test Policy Enforcement / Test Healthcare Compliance / Compliant request
# ========================================================================
curl -X POST http://localhost:8080/enforce \
-H "Content-Type: application/json" \
-d '{
"data_type": "PHI",
"encrypted": true,
"access_logged": true
}'
# ========================================================================
# Step 3: Test Policy Enforcement / Test Finance Profile / Switch profile
# ========================================================================
curl -X POST http://localhost:8080/switch-profile \
-H "Content-Type: application/json" \
-d '{"profile": "finance"}'
# ========================================================================
# Step 3: Test Policy Enforcement / Test Finance Profile / Test enforcement
# ========================================================================
curl -X POST http://localhost:8080/enforce \
-H "Content-Type: application/json" \
-d '{
"data_type": "cardholder_data",
"encrypted": true,
"network_segmented": true,
"password_length": 14
}'
# ========================================================================
# Verification / Additional Validation Using `test_client.py`
# ========================================================================
python3 test_client.py
# ========================================================================
# Verification / Step 4: Verify Dynamic Switching
# ========================================================================
nano verify_switching.sh
# ========================================================================
# Verification / Step 4: Verify Dynamic Switching / Run verification:
# ========================================================================
chmod +x verify_switching.sh
./verify_switching.sh
# ========================================================================
# Troubleshooting Tips / YAML parsing errors
# ========================================================================
python3 -c "import yaml; yaml.safe_load(open('config/profiles/healthcare.yaml'))"
python3 -c "import yaml; yaml.safe_load(open('config/profiles/finance.yaml'))"
python3 -c "import yaml; yaml.safe_load(open('config/profiles/retail.yaml'))"
# ========================================================================
# Troubleshooting Tips / Profile not switching
# ========================================================================
ls -la config/profiles/
# ========================================================================
# Troubleshooting Tips / Enforcement not working
# ========================================================================
curl http://localhost:8080/status
# ========================================================================
# Troubleshooting Tips / Port already in use
# ========================================================================
sudo lsof -ti:8080
sudo lsof -ti:8080 | xargs -r kill -9