Mục Tiêu Lab
Tạo Storage Account với chuẩn bảo mật: TLS 1.2, HTTPS-only, disable anonymous access
Tạo Blob container, upload files, quản lý access tiers (Hot/Cool/Archive)
Tạo SAS (Shared Access Signature) token có thời hạn để chia sẻ file an toàn
Thiết lập Azure Files share và mount vào Windows/Linux như network drive
Sử dụng AzCopy để bulk transfer dữ liệu hiệu suất cao
Cấu hình Lifecycle Management tự động chuyển blob sang tier rẻ hơn
Yêu Cầu Chuẩn Bị
- Hoàn thành Lab 01 + Lab 02
- Azure CLI 2.50+ đã đăng nhập
- AzCopy đã cài: aka.ms/downloadazcopy
- Một vài files test (ảnh, PDF, txt) để upload
- Storage LRS: ~$0.018/GB/tháng (Hot tier)
- Archive tier: ~$0.002/GB/tháng nhưng rehydrate mất giờ
- Azure Files: ~$0.06/GB/tháng (Standard)
- Xóa RG sau lab để tránh chi phí nhỏ tích lũy
Kịch Bản & Tài Nguyên
Bạn cần thiết lập storage cho ứng dụng HoaTranLab Corp: Blob cho static assets của web app, Azure Files cho shared network drive của team, và SAS để chia sẻ báo cáo với đối tác bên ngoài.
Standard LRS
TLS 1.2 + HTTPS
reports (Cool)
backup (Archive)
100 GiB quota
SMB 3.0
Các Bước Thực Hiện
Tạo Storage Account Bảo Mật
Storage Account name phải globally unique, lowercase, 3–24 ký tự, không có dấu gạch ngang. Chuẩn 2026: bắt buộc TLS 1.2, HTTPS-only, tắt anonymous blob access.
sthoatranlab2026 + số ngẫu nhiên (e.g. sthoatranlab20261234).
- 1.Portal → Storage accounts → + Create
- 2.RG: tạo mới
rg-hoatranlab-lab04| Name: sthoatranlab2026xxxx - 3.Region: Southeast Asia | Performance: Standard | Redundancy: LRS
- 4.Tab Advanced: Minimum TLS version: TLS 1.2 | tick Require secure transfer (HTTPS)
- 5.Untick Allow Blob anonymous access (tắt hoàn toàn)
- 6.Review + Create → Create
# Tạo Resource Group
az group create \
--name rg-hoatranlab-lab04 \
--location southeastasia
# Tạo Storage Account với bảo mật chuẩn 2026
# Đặt suffix ngẫu nhiên để tránh name conflict
SUFFIX=$RANDOM
SA_NAME="sthoatranlab${SUFFIX}"
az storage account create \
--name $SA_NAME \
--resource-group rg-hoatranlab-lab04 \
--location southeastasia \
--sku Standard_LRS \
--kind StorageV2 \
--min-tls-version TLS1_2 \
--https-only true \
--allow-blob-public-access false \
--tags env=lab module=az104
echo "Storage Account: $SA_NAME"
# Lấy connection string (dùng cho AzCopy và CLI)
az storage account show-connection-string \
--name $SA_NAME \
--resource-group rg-hoatranlab-lab04 \
--output tsv
Tạo Blob Container & Upload Files
Blob container tương tự như folder cấp cao nhất. Access level: Private (mặc định, bắt buộc auth), Blob (anonymous read từng blob), Container (anonymous list + read). Luôn dùng Private khi có thể.
- 1.Vào Storage Account → Containers (left menu) → + Container
- 2.Name:
assets| Access level: Private → Create - 3.Tạo thêm container
reportsvàbackup(cùng Private) - 4.Click vào container
assets→ Upload → chọn file → Upload - 5.Click vào blob đã upload → xem Properties: URL, Content-Type, Size, Access tier
- 6.Tab Change tier: thay đổi blob sang Cool tier để xem
# Lấy storage key để auth CLI
SA_KEY=$(az storage account keys list \
--account-name $SA_NAME \
--resource-group rg-hoatranlab-lab04 \
--query "[0].value" -o tsv)
# Tạo 3 containers
for CONTAINER in assets reports backup; do
az storage container create \
--name $CONTAINER \
--account-name $SA_NAME \
--account-key $SA_KEY \
--public-access off
done
# Tạo file test để upload
echo "HoaTranLab Azure Storage Lab 04" > testfile.txt
date >> testfile.txt
# Upload file vào container assets (Hot tier mặc định)
az storage blob upload \
--account-name $SA_NAME \
--account-key $SA_KEY \
--container-name assets \
--name "docs/testfile.txt" \
--file testfile.txt \
--tier Hot
# Upload file vào reports (Cool tier)
az storage blob upload \
--account-name $SA_NAME \
--account-key $SA_KEY \
--container-name reports \
--name "2026/report-q1.txt" \
--file testfile.txt \
--tier Cool
# Liệt kê blobs trong container assets
az storage blob list \
--account-name $SA_NAME \
--account-key $SA_KEY \
--container-name assets \
--output table
Name Blob Type Blob Tier Length Content Type -------------------- ----------- ----------- -------- ------------ docs/testfile.txt BlockBlob Hot 42 text/plain
Tạo SAS Token — Chia Sẻ An Toàn Có Thời Hạn
SAS (Shared Access Signature) cho phép chia sẻ access có kiểm soát: chỉ định resource cụ thể, permissions (read/write/delete), IP range, thời gian hết hạn. Không cần chia sẻ account key.
- 1.Storage Account → Containers → assets → click vào file
docs/testfile.txt - 2.Tab Generate SAS → Permissions: Read only
- 3.Expiry: đặt +1 giờ từ hiện tại | Allowed protocols: HTTPS only
- 4.Click Generate SAS token and URL → copy Blob SAS URL
- 5.Paste URL vào trình duyệt → file download thành công mà không cần đăng nhập
- 6.Sửa URL: xóa token → thấy lỗi 403 Forbidden (confirm private)
# Tính thời gian hết hạn: 2 giờ từ hiện tại
END_TIME=$(date -u -d '+2 hours' '+%Y-%m-%dT%H:%MZ' 2>/dev/null \
|| date -u -v+2H '+%Y-%m-%dT%H:%MZ')
# Tạo SAS token cho 1 blob cụ thể (Read only, HTTPS)
SAS_TOKEN=$(az storage blob generate-sas \
--account-name $SA_NAME \
--account-key $SA_KEY \
--container-name assets \
--name "docs/testfile.txt" \
--permissions r \
--expiry $END_TIME \
--https-only \
--output tsv)
# Tạo full URL để chia sẻ
BLOB_URL="https://${SA_NAME}.blob.core.windows.net/assets/docs/testfile.txt?${SAS_TOKEN}"
echo "SAS URL (valid 2 hours):"
echo $BLOB_URL
# Test download qua curl (không cần auth)
curl -s "$BLOB_URL"
# Tạo Account-level SAS (toàn storage account)
az storage account generate-sas \
--account-name $SA_NAME \
--account-key $SA_KEY \
--resource-types sco \
--services bfqt \
--permissions rl \
--expiry $END_TIME \
--https-only \
--output tsv
Azure Files Share — Network Drive Trên Cloud
Azure Files cung cấp SMB/NFS file share có thể mount vào Windows/Linux/macOS như ổ đĩa mạng. Phù hợp cho shared config, legacy apps cần network drive, và lift-and-shift.
- 1.Storage Account → File shares → + File share
- 2.Name:
share-team| Tier: Transaction optimized | Quota: 100 GiB - 3.Create → click vào share-team → Upload → upload file test
- 4.Click Connect → chọn OS: Windows → copy PowerShell script
- 5.Chạy script trong PowerShell → ổ Z: xuất hiện trong File Explorer
- 6.Thử tạo file trong Z: → file xuất hiện trên Portal File share
# Tạo Azure File share az storage share create \ --name share-team \ --account-name $SA_NAME \ --account-key $SA_KEY \ --quota 100 # Upload file vào file share az storage file upload \ --account-name $SA_NAME \ --account-key $SA_KEY \ --share-name share-team \ --source testfile.txt \ --path "shared/testfile.txt" # Liệt kê files trong share az storage file list \ --account-name $SA_NAME \ --account-key $SA_KEY \ --share-name share-team \ --output table
# (Portal sinh ra script này tự động)
$connectTestResult = Test-NetConnection `
-ComputerName "${SA_NAME}.file.core.windows.net" `
-Port 445
if ($connectTestResult.TcpTestSucceeded) {
$storageKey = ConvertTo-SecureString `
-String "$SA_KEY" -AsPlainText -Force
$credential = New-Object `
System.Management.Automation.PSCredential `
-ArgumentList "Azure\$SA_NAME", $storageKey
New-PSDrive -Name Z -PSProvider FileSystem `
-Root "\\${SA_NAME}.file.core.windows.net\share-team" `
-Credential $credential -Persist
}
AzCopy — Transfer Dữ Liệu Hiệu Suất Cao
AzCopy là CLI tool tối ưu cho bulk transfer: parallel uploads, resume interrupted transfers, copy giữa storage accounts. Nhanh hơn azure-cli cho batch operations.
- 1.Tải Azure Storage Explorer và đăng nhập
- 2.Browse tới container → drag & drop files để upload/download
- 3.Right-click container → Get Shared Access Signature để tạo SAS từ GUI
- 4.Snapshot: right-click blob → Create Snapshot
# Đăng nhập AzCopy bằng Microsoft Entra ID
azcopy login
# Tạo thư mục test với nhiều files
mkdir azcopy-test
for i in 1 2 3 4 5; do
echo "File $i - $(date)" > azcopy-test/file${i}.txt
done
# Upload cả thư mục lên container (recursive)
azcopy copy \
"azcopy-test/*" \
"https://${SA_NAME}.blob.core.windows.net/assets/" \
--recursive
# Xem kết quả upload
azcopy list \
"https://${SA_NAME}.blob.core.windows.net/assets/"
# Copy giữa 2 containers trong cùng storage account
azcopy copy \
"https://${SA_NAME}.blob.core.windows.net/assets/" \
"https://${SA_NAME}.blob.core.windows.net/backup/" \
--recursive
# Download container về local
azcopy copy \
"https://${SA_NAME}.blob.core.windows.net/assets/" \
"./download-test/" \
--recursive
Lifecycle Management — Tự Động Chuyển Access Tier
Lifecycle policies tự động chuyển blob sang tier rẻ hơn theo thời gian, giúp tối ưu chi phí mà không cần can thiệp thủ công. Hot → Cool (30 ngày) → Archive (90 ngày) → Delete (365 ngày).
- 1.Storage Account → Lifecycle management → + Add a rule
- 2.Rule name:
tier-down-old-blobs| Apply to all blobs - 3.Base blobs → nếu last modified > 30 ngày: Move to cool
- 4.Nếu last modified > 90 ngày: Move to archive
- 5.Nếu last modified > 365 ngày: Delete blob
- 6.Add → Save
# Tạo lifecycle policy (JSON inline)
az storage account management-policy create \
--account-name $SA_NAME \
--resource-group rg-hoatranlab-lab04 \
--policy '{
"rules": [{
"name": "tier-down-old-blobs",
"enabled": true,
"type": "Lifecycle",
"definition": {
"filters": {
"blobTypes": ["blockBlob"]
},
"actions": {
"baseBlob": {
"tierToCool": {
"daysAfterModificationGreaterThan": 30
},
"tierToArchive": {
"daysAfterModificationGreaterThan": 90
},
"delete": {
"daysAfterModificationGreaterThan": 365
}
}
}
}
}]
}'
# Verify policy
az storage account management-policy show \
--account-name $SA_NAME \
--resource-group rg-hoatranlab-lab04
Kết Quả Đầu Ra Lab 04
TLS 1.2, HTTPS-only, anonymous access disabled — confirm trong Portal → Configuration
assets (Hot), reports (Cool), backup — az storage blob list trả về files đã upload
URL với token → download OK; URL không có token → HTTP 403 Forbidden
Ổ Z: hiển thị trong Windows Explorer, file tạo từ local xuất hiện trên Portal
5 files upload parallel, azcopy list hiển thị đầy đủ trong container assets
Policy visible trong Lifecycle management, JSON rule đúng với 3 actions (Cool/Archive/Delete)
Dọn Dẹp Tài Nguyên
# Xóa Resource Group chứa toàn bộ storage resources az group delete \ --name rg-hoatranlab-lab04 \ --yes \ --no-wait # Xóa files local đã tạo rm -rf testfile.txt azcopy-test download-test
Câu Hỏi Ôn Tập
1. So sánh 4 access tiers của Blob Storage: Hot, Cool, Cold, Archive. Khi nào nên dùng mỗi tier?
Gợi ý: Hot = truy cập thường xuyên (chi phí storage cao, access rẻ); Cool = 30+ ngày (storage rẻ hơn, access đắt hơn); Cold = 90+ ngày; Archive = 180+ ngày, rehydrate mất 1–15 giờ. Chi phí nghịch: storage thấp dần, retrieval cao dần.
2. Sự khác biệt giữa LRS, ZRS, GRS, GZRS là gì? Cho production critical data, nên chọn loại nào?
Gợi ý: LRS = 3 copies trong 1 datacenter; ZRS = 3 zones trong 1 region; GRS = LRS + region thứ hai; GZRS = ZRS + region thứ hai. Critical data: GZRS (SLA 99.99999999999999% - 16 nines).
3. Tại sao User Delegation SAS được coi là bảo mật hơn Account Key SAS? Khi nào KHÔNG nên dùng Account Key?
Gợi ý: User Delegation SAS dùng Microsoft Entra ID credential (có thể revoke qua Entra, không cần rotate key); Account Key = master key, nếu lộ phải rotate ngay. Không dùng Account Key trong code/CI-CD — dùng Managed Identity thay thế.
4. Azure Blob Storage và Azure Files khác nhau như thế nào? Ứng dụng phù hợp cho mỗi loại?
Gợi ý: Blob = object storage (HTTP/REST), tối ưu cho unstructured data, static web, backup; Files = SMB/NFS file system, mount như network drive, lift-and-shift legacy apps cần network share, shared config giữa VMs.
5. Lifecycle Management policy có thể áp dụng cho blob đang ở Archive tier để delete không? Cần làm gì trước?
Gợi ý: Có, delete action hoạt động trực tiếp trên Archive blob. Nhưng nếu muốn READ blob Archive → phải rehydrate sang Hot/Cool trước (mất 1–15 giờ, tùy priority). Rehydrate = copy to new tier, original vẫn ở Archive.