MODULE 16 Storage 15–20% đề thi ~3 giờ

Cấu hình Storage Accounts

Triển khai Azure Storage, phân biệt các storage services, chọn đúng loại storage account, cấu hình replication (LRS/ZRS/GRS/RA-GRS/GZRS), kiểm soát truy cập và bảo mật service endpoint.

Lý Thuyết Cốt Lõi

1. Azure Storage Services & Loại Storage Account

Azure Storage là nền tảng lưu trữ đám mây có khả năng mở rộng cao, bền vững và bảo mật. Một storage account là container quản lý toàn bộ dịch vụ lưu trữ Azure của bạn.

4 Storage Services
  • Blob Storage: lưu trữ object phi cấu trúc (văn bản, hình ảnh, video, backup)
  • Azure Files: chia sẻ file qua SMB/NFS, thay thế file server on-prem
  • Queue Storage: hàng đợi tin nhắn cho ứng dụng phân tán, tối đa 64 KB/message
  • Table Storage: NoSQL key-value cho dữ liệu phi quan hệ, lược đồ linh hoạt
Loại Storage Account
  • Standard General-Purpose v2 (GPv2): hỗ trợ tất cả 4 services, tất cả replication, khuyên dùng cho hầu hết workload
  • Premium Block Blobs: SSD, độ trễ thấp cho block blob workload I/O cao
  • Premium File Shares: SSD cho Azure Files, cần IOPS cao
  • Premium Page Blobs: SSD cho page blob (VM OS/data disk)
Loại Account Services hỗ trợ Replication Ghi chú
Standard GPv2 Blob, File, Queue, Table LRS, ZRS, GRS, RA-GRS, GZRS, RA-GZRS Khuyên dùng mặc định
Premium Block Blobs Blob only LRS, ZRS Analytics, AI/ML
Premium File Shares Azure Files only LRS, ZRS File server migration
Premium Page Blobs Page blobs only LRS VM disks (managed disk)

2. Chiến Lược Replication — Bền Vững Dữ Liệu

Azure Storage luôn lưu trữ nhiều bản sao dữ liệu. Bạn chọn chiến lược replication dựa trên yêu cầu bền vững (durability), sẵn sàng (availability) và chi phí.

LRS
Locally Redundant Storage
  • • 3 bản sao trong 1 datacenter
  • • Durability: 11 nines (99.999999999%)
  • • Không bảo vệ khỏi thảm hoạ datacenter
  • • Chi phí thấp nhất
ZRS
Zone-Redundant Storage
  • • 3 bản sao trải 3 availability zones trong 1 region
  • • Durability: 12 nines
  • • Bảo vệ khỏi sự cố 1 zone
  • • Phù hợp workload HA trong region
GRS
Geo-Redundant Storage
  • • LRS ở primary region + LRS ở secondary region
  • • Durability: 16 nines
  • • Secondary chỉ đọc được sau failover
  • • Bảo vệ khỏi mất cả region
RA-GRS
Read-Access GRS
  • • GRS + có thể đọc từ secondary bất cứ lúc nào
  • • Secondary endpoint: -secondary.blob.core.windows.net
  • • Phù hợp read-heavy với DR yêu cầu RTO thấp
GZRS
Geo-Zone-Redundant
  • • ZRS ở primary region + LRS ở secondary region
  • • Durability: 16 nines
  • • Bảo vệ khỏi zone failure + region failure
  • • Chi phí cao nhất, HA cao nhất
RA-GZRS
Read-Access GZRS
  • • GZRS + đọc từ secondary bất cứ lúc nào
  • • Tối đa bền vững và sẵn sàng
  • • Cho workload mission-critical toàn cầu
Tip thi AZ-104: GRS và GZRS không cho đọc secondary trừ khi Microsoft khởi động failover. Muốn đọc secondary mọi lúc phải dùng RA-GRS hoặc RA-GZRS. RPO của GRS ≈ 15 phút (async replication).

3. Truy Cập Storage Account

Mỗi storage account có endpoint công khai duy nhất. Azure cung cấp nhiều phương thức xác thực và kiểm soát truy cập.

Public Endpoints (mặc định)
  • • Blob: <account>.blob.core.windows.net
  • • File: <account>.file.core.windows.net
  • • Queue: <account>.queue.core.windows.net
  • • Table: <account>.table.core.windows.net
  • • Cho phép truy cập từ internet, kiểm soát bằng firewall rules
Service Endpoint & Private Endpoint
  • Service Endpoint: traffic từ VNet đi qua Microsoft backbone, không qua internet; chặn public access ngoài VNet
  • Private Endpoint: gán IP private từ VNet subnet trực tiếp; DNS resolve về IP private; bảo mật tối đa
  • • Private Endpoint phù hợp compliance strictest (PHI, PCI-DSS)
Storage Account Keys

2 access keys (key1, key2) — full quyền toàn bộ account. Xoay vòng định kỳ; có thể lưu trong Key Vault.

Microsoft Entra ID (RBAC)

Phân quyền chi tiết theo role: Storage Blob Data Reader, Storage Blob Data Contributor, Storage Account Contributor. Khuyến nghị hơn account key.

Shared Access Signature (SAS)

Cấp quyền tạm thời, giới hạn phạm vi và thời gian cho người dùng/ứng dụng bên ngoài mà không tiết lộ account key.

4. Storage Firewall & Bảo Mật Endpoint

Azure Storage Firewall kiểm soát truy cập mạng vào storage account. Kết hợp với Service/Private Endpoint tạo lớp bảo vệ chuyên sâu.

Storage Firewall Rules
  • • Mặc định: cho phép tất cả mạng (All networks)
  • • Restricted: chỉ cho phép IP cụ thể hoặc VNet/subnet
  • • Chọn Enabled from selected virtual networks and IP addresses để bật firewall
  • • Whitelist IP range (CIDR) cho on-prem hoặc remote office
  • • Exception: Azure services trusted, resource logging, Azure DevOps
Bảo Mật Truyền Tải
  • Secure transfer required: bật mặc định — chỉ chấp nhận HTTPS (TLS 1.2+)
  • Minimum TLS version: thiết lập TLS 1.2 để block TLS 1.0/1.1
  • • SMB 3.x encrypt-in-transit cho Azure Files
  • • Blob Storage mã hoá client-side trước khi upload
Best Practice: Luôn bật Secure transfer requiredMinimum TLS 1.2. Với workload production, dùng Private Endpoint thay Service Endpoint để hoàn toàn không route traffic qua internet. Lưu account key vào Azure Key Vault thay vì hardcode trong code.

Bài Tập Thực Hành (Lab)

Lab 16-A: Tạo Storage Account GPv2 Lab 16-B: Cấu hình Replication Lab 16-C: Storage Firewall & Service Endpoint Lab 16-D: RBAC & Access Keys
1

Tạo Resource Group và Storage Account GPv2 (Standard LRS)

Azure CLI— Chạy được trên PowerShell, CMD, Bash hoặc Azure Cloud Shell
# Tạo Resource Group
az group create \
  --name rg-az104-m16 \
  --location southeastasia \
  --tags Course=AZ-104 Module=16

# Tên storage account phải unique toàn cầu, 3-24 ký tự, viết thường, chỉ a-z 0-9
STORAGE_NAME="staz104m16$(date +%s | tail -c 6)"
echo "Storage Account name: $STORAGE_NAME"

# Tạo storage account Standard GPv2 với LRS
az storage account create \
  --name $STORAGE_NAME \
  --resource-group rg-az104-m16 \
  --location southeastasia \
  --sku Standard_LRS \
  --kind StorageV2 \
  --access-tier Hot \
  --https-only true \
  --min-tls-version TLS1_2 \
  --allow-blob-public-access false \
  --tags Course=AZ-104 Module=16

# Xác nhận storage account đã tạo
az storage account show \
  --name $STORAGE_NAME \
  --resource-group rg-az104-m16 \
  --query '{name:name, sku:sku.name, kind:kind, location:primaryLocation, httpsOnly:enableHttpsTrafficOnly}' \
  -o table
Verify Portal: Azure Portal → Storage accounts → tìm staz104m16XXXXXX → Overview → xác nhận Performance: Standard, Replication: LRS, Kind: StorageV2. Kiểm tra Minimum TLS version: TLS 1.2.
2

Nâng cấp Replication từ LRS lên GRS và tạo thêm account ZRS

Azure CLI— Chạy được trên PowerShell, CMD, Bash hoặc Azure Cloud Shell
# Nâng cấp replication LRS → GRS (có thể làm online không downtime)
az storage account update \
  --name $STORAGE_NAME \
  --resource-group rg-az104-m16 \
  --sku Standard_GRS

# Kiểm tra replication mới
az storage account show \
  --name $STORAGE_NAME \
  --resource-group rg-az104-m16 \
  --query 'sku.name' -o tsv

# Tạo thêm một storage account với ZRS để so sánh
STORAGE_ZRS="stz104m16zrs$(date +%s | tail -c 4)"
az storage account create \
  --name $STORAGE_ZRS \
  --resource-group rg-az104-m16 \
  --location southeastasia \
  --sku Standard_ZRS \
  --kind StorageV2 \
  --https-only true \
  --min-tls-version TLS1_2 \
  --allow-blob-public-access false \
  --tags Course=AZ-104 Module=16 Replication=ZRS

# Liệt kê tất cả storage accounts trong RG
az storage account list \
  --resource-group rg-az104-m16 \
  --query '[].{Name:name, SKU:sku.name, Location:primaryLocation}' \
  -o table
Verify Portal: Portal → Storage account → Configuration → Replication: Geo-redundant storage (GRS). Kéo xuống xem Secondary location (ví dụ: East Asia paired với Southeast Asia). Với ZRS account: Configuration → Replication: Zone-redundant storage (ZRS).
3

Cấu hình Storage Firewall — Chỉ cho phép IP/VNet cụ thể

Bash— Linux/macOS/Cloud Shell, KHÔNG chạy CMD
# Tạo VNet và subnet để test service endpoint
az network vnet create \
  --resource-group rg-az104-m16 \
  --name vnet-m16 \
  --address-prefix 10.16.0.0/16 \
  --subnet-name snet-storage \
  --subnet-prefix 10.16.1.0/24 \
  --location southeastasia

# Bật Microsoft.Storage service endpoint trên subnet
az network vnet subnet update \
  --resource-group rg-az104-m16 \
  --vnet-name vnet-m16 \
  --name snet-storage \
  --service-endpoints Microsoft.Storage

# Lấy subnet resource ID
SUBNET_ID=$(az network vnet subnet show \
  --resource-group rg-az104-m16 \
  --vnet-name vnet-m16 \
  --name snet-storage \
  --query id -o tsv)

# Chuyển storage firewall sang Restricted mode — deny tất cả
az storage account update \
  --name $STORAGE_NAME \
  --resource-group rg-az104-m16 \
  --default-action Deny

# Cho phép subnet truy cập (service endpoint rule)
az storage account network-rule add \
  --resource-group rg-az104-m16 \
  --account-name $STORAGE_NAME \
  --subnet $SUBNET_ID

# Whitelist IP của máy hiện tại (thay bằng IP thực của bạn)
MY_IP=$(curl -s https://api.ipify.org)
echo "My public IP: $MY_IP"
az storage account network-rule add \
  --resource-group rg-az104-m16 \
  --account-name $STORAGE_NAME \
  --ip-address $MY_IP

# Xem tất cả network rules
az storage account network-rule list \
  --resource-group rg-az104-m16 \
  --account-name $STORAGE_NAME \
  -o table
Verify Portal: Portal → Storage account → Networking → Firewalls and virtual networks → Public network access: Enabled from selected virtual networks and IP addresses → xác nhận VNet vnet-m16/snet-storage và IP của bạn được liệt kê. Thử truy cập từ IP khác — phải nhận lỗi 403.
4

Gán RBAC Role cho Storage Account và xoay Account Key

Azure CLI— Chạy được trên PowerShell, CMD, Bash hoặc Azure Cloud Shell
# Lấy storage account resource ID
STORAGE_ID=$(az storage account show \
  --name $STORAGE_NAME \
  --resource-group rg-az104-m16 \
  --query id -o tsv)

# Lấy Object ID của user hiện tại
CURRENT_USER=$(az ad signed-in-user show --query id -o tsv)

# Gán role Storage Blob Data Contributor (quyền đọc/ghi/xóa blob)
az role assignment create \
  --assignee $CURRENT_USER \
  --role "Storage Blob Data Contributor" \
  --scope $STORAGE_ID

# Gán role Storage Queue Data Reader cho một service principal (demo)
# az role assignment create --assignee  --role "Storage Queue Data Reader" --scope $STORAGE_ID

# Liệt kê role assignments trên storage account
az role assignment list \
  --scope $STORAGE_ID \
  --query '[].{Principal:principalName, Role:roleDefinitionName}' \
  -o table

# Xem account keys hiện tại
az storage account keys list \
  --resource-group rg-az104-m16 \
  --account-name $STORAGE_NAME \
  --query '[].{KeyName:keyName, Value:value}' \
  -o table

# Xoay key1 (regenerate) — không ảnh hưởng key2
az storage account keys renew \
  --resource-group rg-az104-m16 \
  --account-name $STORAGE_NAME \
  --key key1

echo "Key1 đã được xoay vòng. Cập nhật connection string trong ứng dụng nếu dùng key1."
Verify Portal: Portal → Storage account → Access Control (IAM) → Role assignments → xác nhận user hiện tại có Storage Blob Data Contributor. Portal → Storage account → Security + networking → Access keys → xác nhận Key1 đã thay đổi (Last rotated time cập nhật).
5

Cleanup — Xóa tài nguyên tránh phát sinh chi phí

Azure CLI— Chạy được trên PowerShell, CMD, Bash hoặc Azure Cloud Shell
# Xóa toàn bộ Resource Group (kéo theo storage accounts, VNet, subnet)
az group delete --name rg-az104-m16 --yes --no-wait

echo "Resource Group rg-az104-m16 đang được xóa nền. Kiểm tra lại sau 2-3 phút."

Kết Quả Đầu Ra

Phân biệt 4 Storage Services

Hiểu rõ Blob, Files, Queue, Table — chọn đúng service cho từng use case (object storage, file share, message queue, NoSQL)

Chọn đúng loại Storage Account

So sánh Standard GPv2 vs Premium (Block Blob, File Shares, Page Blobs) theo workload, IOPS, cost

Cấu hình Replication đúng yêu cầu

Chọn LRS/ZRS/GRS/RA-GRS/GZRS phù hợp SLA, RPO, RTO và ngân sách; nâng cấp online không downtime

Kiểm soát truy cập đa lớp

Kết hợp RBAC + SAS + Account Key; hiểu khi nào dùng phương thức nào theo nguyên tắc least privilege

Storage Firewall & Service Endpoint

Cấu hình network rules whitelist IP/VNet; bật service endpoint trên subnet; chuyển traffic qua Microsoft backbone

Bảo mật truyền tải

Bật Secure transfer required và Minimum TLS 1.2; xoay vòng Account Key định kỳ; lưu key trong Key Vault

Ứng Dụng Thực Tế

Tình huống 1: Ngân hàng Agribank — Lưu trữ hồ sơ tín dụng

Hệ thống xử lý hàng triệu hồ sơ tín dụng, cần lưu trữ bền vững, truy cập nhanh và tuân thủ quy định NHNN về dữ liệu tại Việt Nam.

Giải pháp

Standard GPv2 + GRS tại Southeast Asia (Hà Nội/TP.HCM cluster) với secondary tại East Asia. Private Endpoint cho mọi truy cập từ app servers — không traffic qua internet công cộng.

Triển khai

Blob Storage cho PDF hồ sơ, Table Storage cho index metadata. RBAC: app service identity → Storage Blob Data Reader; DBA team → Storage Blob Data Contributor. Account key trong Key Vault, xoay 90 ngày.

Lợi ích

Dữ liệu lưu trong lãnh thổ VN (Southeast Asia). RTO < 1 giờ nhờ GRS. Zero public internet exposure. Chi phí giảm 60% so với SAN on-prem. Audit log đầy đủ qua Azure Monitor.

Tình huống 2: Shopee Vietnam — Lưu trữ hình ảnh sản phẩm

Nền tảng thương mại điện tử với 50 triệu ảnh sản phẩm, cần tốc độ tải cao cho người dùng trên toàn quốc, chi phí tối ưu.

Giải pháp

Standard GPv2 + RA-GRS. Blob public read access bật cho container ảnh sản phẩm (SAS với expiry dài). Kết hợp Azure CDN trên đầu Blob endpoint để giảm latency toàn quốc.

Triển khai

Storage Firewall: cho phép CDN service tag + IP upload server. Lifecycle policy tự động chuyển ảnh cũ hơn 1 năm sang Cool tier, 3 năm sang Archive. Queue Storage cho upload job queue.

Lợi ích

Latency < 50ms cho người dùng Việt Nam nhờ CDN. RA-GRS đảm bảo đọc từ secondary khi primary bảo trì. Lifecycle rules giảm 40% chi phí storage. Sẵn sàng scale không giới hạn.

Tình huống 3: Bệnh viện Chợ Rẫy — Lưu DICOM hình ảnh y tế

Lưu trữ hình ảnh DICOM (CT, MRI, X-quang) với yêu cầu bảo mật tối cao, không mất mát dữ liệu và truy cập nhanh từ các phòng khám.

Giải pháp

Premium Block Blobs + ZRS (HA trong region) cho DICOM active. Standard GPv2 + GRS cho archive. Private Endpoint — tất cả traffic trong VNet bệnh viện, không bao giờ qua internet.

Triển khai

Immutable Blob Storage (WORM policy) cho hồ sơ lưu trữ pháp lý — không thể xóa trong 10 năm. Customer-managed key trong Key Vault cho mã hóa. RBAC: radiologist → Reader; PACS system → Contributor.

Lợi ích

Tuân thủ Thông tư 46/2018/TT-BYT về lưu trữ hồ sơ y tế điện tử. WORM đảm bảo không ai có thể xóa record trong thời hạn. Latency thấp nhờ Premium SSD cho workload đọc DICOM realtime.

Zalo