🎯 Mục Tiêu Lab
Tạo Storage Account với TLS 1.2 minimum và anonymous access disabled
Cấu hình Storage firewall chỉ cho phép subnet VNet cụ thể (Service Endpoint)
Whitelist IP cụ thể (IP quản trị) trên Storage firewall
Kiểm tra truy cập blob từ VM trong subnet cho phép vs. nguồn bị chặn
Xem Storage diagnostic logs để xác nhận deny từ nguồn không được phép
Hiểu sự khác biệt giữa Storage firewall, Service Endpoint và Private Endpoint
📋 Chuẩn Bị
- Azure subscription với quyền Contributor
- Azure CLI 2.50+ hoặc Azure Cloud Shell
- VNet và subnet để test Service Endpoint (tạo trong lab)
- Biết IP public hiện tại của máy bạn (whatismyip.com)
- RG: rg-az500-lab37
- Storage: staz500lab37[suffix]
- VNet: vnet-az500-lab37
- Subnet: snet-app-lab37
- Region: southeastasia
🏗️ Kịch Bản
Công ty yêu cầu Storage Account chứa dữ liệu nhạy cảm chỉ được truy cập từ subnet ứng dụng nội bộ và IP quản trị được whitelist. Mọi request từ Internet hay subnet không được phép phải bị chặn và ghi log. Tiêu chuẩn 2026: TLS 1.2 minimum, anonymous access disabled, firewall "Allow selected networks" thay vì "All networks".
Public access: All networks + anonymous blob access
Firewall bật nhưng chưa tắt anonymous access
TLS 1.2 + no anonymous + firewall selected networks
🧪 Các Bước Thực Hiện
Tạo VNet, Subnet và Bật Service Endpoint
- 1.1Portal → Virtual networks → + Create → RG:
rg-az500-lab37→ Name:vnet-az500-lab37→ Region: Southeast Asia - 1.2Tab IP addresses: Address space
10.37.0.0/16→ thêm subnetsnet-app-lab37với range10.37.1.0/24 - 1.3Vào VNet → Subnets → chọn
snet-app-lab37→ Service endpoints → Add → chọn Microsoft.Storage → Save
# Tạo resource group
az group create \
--name rg-az500-lab37 \
--location southeastasia \
--tags "lab=37" "module=az500-ch09"
# Tạo VNet
az network vnet create \
--resource-group rg-az500-lab37 \
--name vnet-az500-lab37 \
--address-prefix 10.37.0.0/16 \
--subnet-name snet-app-lab37 \
--subnet-prefix 10.37.1.0/24
# Bật Service Endpoint cho Microsoft.Storage trên subnet
az network vnet subnet update \
--resource-group rg-az500-lab37 \
--vnet-name vnet-az500-lab37 \
--name snet-app-lab37 \
--service-endpoints Microsoft.Storage
# Xác nhận Service Endpoint đã bật
az network vnet subnet show \
--resource-group rg-az500-lab37 \
--vnet-name vnet-az500-lab37 \
--name snet-app-lab37 \
--query "serviceEndpoints[].service" \
--output tsv
Tạo Storage Account — TLS 1.2 + Tắt Anonymous Access
- 2.1Portal → Storage accounts → + Create → RG:
rg-az500-lab37→ Name:staz500lab37[4 số ngẫu nhiên]→ Region: Southeast Asia → Redundancy: LRS - 2.2Tab Advanced: Minimum TLS version → Version 1.2 → Allow Blob anonymous access → Disabled
- 2.3Tab Networking: Network access → Enable from selected virtual networks and IP addresses
- 2.4Virtual networks → + Add existing virtual network → chọn
vnet-az500-lab37→ subnetsnet-app-lab37→ Add - 2.5Firewall → nhập IP public máy bạn (whatismyip.com) vào ô Add your client IP address → Review + create
# Lấy subnet ID để dùng trong network rule
SUBNET_ID=$(az network vnet subnet show \
--resource-group rg-az500-lab37 \
--vnet-name vnet-az500-lab37 \
--name snet-app-lab37 \
--query id --output tsv)
# Tên storage phải unique, chỉ lowercase + số, 3–24 ký tự
STORAGE_NAME="staz500lab37$(shuf -i 1000-9999 -n 1)"
echo "Storage name: $STORAGE_NAME"
# Tạo Storage Account:
# --min-tls-version TLS1_2 = bắt buộc TLS 1.2
# --allow-blob-public-access false = tắt anonymous access
# --default-action Deny = chặn tất cả, chỉ mở theo rule
az storage account create \
--resource-group rg-az500-lab37 \
--name $STORAGE_NAME \
--location southeastasia \
--sku Standard_LRS \
--kind StorageV2 \
--min-tls-version TLS1_2 \
--allow-blob-public-access false \
--default-action Deny
# Thêm subnet vào network rule (Service Endpoint)
az storage account network-rule add \
--resource-group rg-az500-lab37 \
--account-name $STORAGE_NAME \
--subnet $SUBNET_ID
# Whitelist IP public của bạn (thay YOUR_IP_ADDRESS)
MY_IP=$(curl -s https://api.ipify.org)
az storage account network-rule add \
--resource-group rg-az500-lab37 \
--account-name $STORAGE_NAME \
--ip-address $MY_IP
# Xem network rules hiện tại
az storage account network-rule list \
--resource-group rg-az500-lab37 \
--account-name $STORAGE_NAME \
--output table
Tạo Container và Blob — Upload Dữ Liệu Test
- 3.1Storage account → Containers → + Container → Name:
test-data→ Public access level: Private (no anonymous access) → Create - 3.2Vào container
test-data→ Upload → chọn một file nhỏ bất kỳ → Upload - 3.3Click vào file → copy URL → thử mở URL trong browser → xác nhận nhận lỗi 403 Forbidden (vì không có SAS và anonymous access đã tắt)
# Lấy connection string (dùng account key — chỉ để test từ IP được whitelist)
CONN_STR=$(az storage account show-connection-string \
--resource-group rg-az500-lab37 \
--name $STORAGE_NAME \
--query connectionString --output tsv)
# Tạo container với private access
az storage container create \
--name test-data \
--connection-string "$CONN_STR" \
--public-access off
# Upload file test
echo "AZ-500 Lab 37 - Storage Firewall Test" > /tmp/lab37-test.txt
az storage blob upload \
--container-name test-data \
--name lab37-test.txt \
--file /tmp/lab37-test.txt \
--connection-string "$CONN_STR"
# Thử download từ IP được whitelist (nên thành công)
az storage blob download \
--container-name test-data \
--name lab37-test.txt \
--file /tmp/downloaded.txt \
--connection-string "$CONN_STR"
echo "Download thành công:"
cat /tmp/downloaded.txt
# Xem blob URL (truy cập trực tiếp sẽ bị 403 do anonymous disabled)
az storage blob url \
--container-name test-data \
--name lab37-test.txt \
--connection-string "$CONN_STR"
Kiểm Tra Firewall — Từ Nguồn Được Phép và Bị Chặn
- 4.1Storage account → Networking → xác nhận Firewall = "Enabled from selected virtual networks and IP addresses"
- 4.2Thử xóa IP của bạn khỏi whitelist → Save → đợi 1 phút → thử truy cập blob lại → nhận lỗi AuthorizationFailure hoặc 403
- 4.3Thêm lại IP → Save → thử lại → truy cập thành công
- 4.4Storage → Insights hoặc Monitoring → Metrics → xem biểu đồ transactions
# Xem toàn bộ cấu hình network của Storage Account
az storage account show \
--resource-group rg-az500-lab37 \
--name $STORAGE_NAME \
--query "{
minTlsVersion: minimumTlsVersion,
allowBlobPublicAccess: allowBlobPublicAccess,
defaultAction: networkRuleSet.defaultAction,
bypass: networkRuleSet.bypass
}" \
--output json
# Xem danh sách IP rules
az storage account network-rule list \
--resource-group rg-az500-lab37 \
--account-name $STORAGE_NAME \
--query "ipRules[].{IP:ipAddressOrRange, Action:action}" \
--output table
# Xem danh sách VNet rules
az storage account network-rule list \
--resource-group rg-az500-lab37 \
--account-name $STORAGE_NAME \
--query "virtualNetworkRules[].{VNet:virtualNetworkResourceId, Action:action}" \
--output table
# Thử xóa IP rule (giả lập nguồn bị chặn) — lệnh tiếp theo sẽ fail
az storage account network-rule remove \
--resource-group rg-az500-lab37 \
--account-name $STORAGE_NAME \
--ip-address $MY_IP
# Đợi propagation ~30 giây rồi thử list blobs — sẽ nhận AuthorizationFailure
sleep 30
az storage blob list \
--container-name test-data \
--connection-string "$CONN_STR" \
--output table 2>&1 | head -5
# Thêm lại IP
az storage account network-rule add \
--resource-group rg-az500-lab37 \
--account-name $STORAGE_NAME \
--ip-address $MY_IP
📊 Kết Quả Mong Đợi
minimumTlsVersion: TLS1_2, allowBlobPublicAccess: false, defaultAction: Deny
IP được whitelist → truy cập thành công; IP bị xóa → AuthorizationFailure
Subnet snet-app-lab37 có Microsoft.Storage trong serviceEndpoints
URL blob trực tiếp → 403 ResourceNotFound hoặc AuthenticationFailed
🧹 Dọn Dẹp Tài Nguyên
# Giữ lại RG nếu cần dùng cho Lab 38 (cùng storage)
# Xóa nếu không tiếp tục
az group delete \
--name rg-az500-lab37 \
--yes \
--no-wait
❓ Câu Hỏi Ôn Tập
1. Sự khác biệt chính giữa Storage firewall (Service Endpoint) và Private Endpoint là gì?
Gợi ý: Service Endpoint dùng public IP của storage nhưng traffic đi qua Microsoft backbone; Private Endpoint tạo private IP trong VNet, hoàn toàn không dùng public endpoint
2. Tại sao cần tắt anonymous blob access dù đã bật firewall?
Gợi ý: Nếu anonymous access bật, bất kỳ ai trong subnet hoặc IP được whitelist đều có thể đọc blob công khai mà không cần credential; anonymous access và firewall là hai lớp bảo vệ độc lập
3. Tham số --bypass trong Storage network rule có tác dụng gì?
Gợi ý: Bypass cho phép Azure services (như Backup, Metrics) và/hoặc trusted Microsoft services truy cập storage dù firewall bật; giá trị: None, AzureServices, Logging, Metrics
4. Lệnh CLI nào để xem tất cả network rules của một Storage Account?
Gợi ý: az storage account network-rule list --account-name ...
5. Tại sao cần đặt minimum TLS version là TLS_1_2 cho Storage Account?
Gợi ý: TLS 1.0 và 1.1 có nhiều lỗ hổng bảo mật (POODLE, BEAST). Microsoft Security Benchmark yêu cầu TLS 1.2+ để bảo vệ data in transit