🎯 Mục Tiêu Lab
Tạo security group GRP-AZ500-PrivilegedAdmins và thêm admin lab
Tạo Conditional Access policy yêu cầu MFA khi truy cập Azure Portal
Chạy policy ở chế độ Report-only và phân tích sign-in log
Loại trừ break-glass account khỏi policy để tránh bị khóa
Kiểm tra policy bằng What If tool trước khi bật thật
Bật policy On và xác minh admin bị yêu cầu MFA khi đăng nhập
📋 Chuẩn Bị
- Azure subscription đang hoạt động
- Quyền Global Administrator hoặc Conditional Access Administrator
- Đã hoàn thành Lab 01–04 (có user và group lab)
- Microsoft Entra ID P1 hoặc P2 license (cần cho Conditional Access)
- Luôn loại trừ break-glass account trước khi bật policy
- Dùng Report-only mode để test trước khi bật thật
- Nếu trial tenant không có P2 license, dùng Security Defaults tham khảo
- Break-glass account KHÔNG nên gán bất kỳ CA policy nào
🏗️ Kịch Bản
Công ty HoaTranLab Corp vừa bị tấn công credential stuffing vào tài khoản admin. Security team yêu cầu bắt buộc MFA cho tất cả thành viên nhóm GRP-AZ500-PrivilegedAdmins khi truy cập Azure Portal. Bạn là Azure Security Engineer cần triển khai Conditional Access policy, chạy thử Report-only 24h, dùng What If để mô phỏng tác động, sau đó bật policy chính thức.
🧪 Các Bước Thực Hiện
Tạo Group GRP-AZ500-PrivilegedAdmins và Break-glass Account
- 1.1Vào Entra ID → Groups → New group
- 1.2Group type: Security, Name:
GRP-AZ500-PrivilegedAdmins - 1.3Thêm các admin user vào group → Create
- 1.4Tạo user break-glass:
[email protected]— mật khẩu dài 20+ ký tự, lưu vault ngoại tuyến
# Tạo security group cho privileged admins
az ad group create \
--display-name "GRP-AZ500-PrivilegedAdmins" \
--mail-nickname "GRP-AZ500-PrivilegedAdmins"
# Lấy Object ID của group vừa tạo
GROUP_ID=$(az ad group show \
--group "GRP-AZ500-PrivilegedAdmins" \
--query id -o tsv)
echo "Group ID: $GROUP_ID"
# Lấy Object ID user admin lab và thêm vào group
USER_ID=$(az ad user show \
--id "[email protected]" \
--query id -o tsv)
az ad group member add \
--group "GRP-AZ500-PrivilegedAdmins" \
--member-id $USER_ID
# Xác nhận membership
az ad group member list \
--group "GRP-AZ500-PrivilegedAdmins" \
--query "[].{Name:displayName, UPN:userPrincipalName}" \
--output table
GRP-AZ500-PrivilegedAdmins xuất hiện trong Entra ID Groups. Break-glass user tạo thành công, chưa gán bất kỳ role hay policy nào.
Tạo Conditional Access Policy — Report-only Mode
- 2.1Entra ID → Security → Conditional Access → New policy
- 2.2Name:
CA-AZ500-RequireMFA-PrivilegedAdmins - 2.3Users: Include → Groups → chọn
GRP-AZ500-PrivilegedAdmins - 2.4Exclude: Users and groups → chọn break-glass account
az500-breakglass - 2.5Target resources: Cloud apps → Select apps → Microsoft Azure Management
- 2.6Grant: Grant access → Require multifactor authentication → Select
- 2.7Enable policy: chọn Report-only → Save
# Kết nối Graph với quyền cần thiết
Connect-MgGraph -Scopes "Policy.ReadWrite.ConditionalAccess","Group.Read.All"
# Lấy Group Object ID
$groupId = (Get-MgGroup -Filter "DisplayName eq 'GRP-AZ500-PrivilegedAdmins'").Id
$breakGlassId = (Get-MgUser -Filter "UserPrincipalName eq '[email protected]'").Id
# Tạo CA policy ở chế độ Report-only
$params = @{
displayName = "CA-AZ500-RequireMFA-PrivilegedAdmins"
state = "enabledForReportingButNotEnforced" # Report-only mode
conditions = @{
users = @{
includeGroups = @($groupId)
excludeUsers = @($breakGlassId) # Exclude break-glass
}
applications = @{
includeApplications = @("797f4846-ba00-4fd7-ba43-dac1f8f63013") # Azure Management
}
}
grantControls = @{
operator = "OR"
builtInControls = @("mfa")
}
}
New-MgIdentityConditionalAccessPolicy -BodyParameter $params
Write-Host "CA policy created in Report-only mode"
CA-AZ500-RequireMFA-PrivilegedAdmins xuất hiện trong danh sách CA policies với trạng thái Report-only. Break-glass account đã được loại trừ.
Kiểm Tra Sign-in Log và Sử Dụng What If Tool
- 3.1Đăng nhập bằng
az500-admin01vào portal.azure.com - 3.2Entra ID → Monitoring → Sign-in logs → tìm đăng nhập của admin01
- 3.3Click vào sign-in event → tab Conditional Access → xem policy report: Success / Failure / Not applied
- 3.4What If: Conditional Access → What If → nhập User = az500-admin01, App = Microsoft Azure Management → run
- 3.5Xác nhận policy hiển thị trong kết quả What If với Grant = Require MFA
# Xem sign-in logs gần nhất của admin user
Connect-MgGraph -Scopes "AuditLog.Read.All"
$userId = (Get-MgUser -Filter "UserPrincipalName eq '[email protected]'").Id
Get-MgAuditLogSignIn `
-Filter "userId eq '$userId'" `
-Top 5 |
Select-Object CreatedDateTime, UserPrincipalName,
@{N="AppDisplayName";E={$_.AppDisplayName}},
@{N="CAResult";E={$_.ConditionalAccessStatus}} |
Format-Table -AutoSize
Bật Policy — Chuyển từ Report-only sang On
- 4.1Conditional Access → chọn policy
CA-AZ500-RequireMFA-PrivilegedAdmins - 4.2Enable policy → chuyển từ Report-only sang On → Save
- 4.3Đăng nhập bằng az500-admin01 → xác nhận bị prompt MFA
- 4.4Đăng nhập bằng break-glass account → xác nhận KHÔNG bị yêu cầu MFA
# Bật policy từ Report-only sang On
$policyId = (Get-MgIdentityConditionalAccessPolicy `
-Filter "displayName eq 'CA-AZ500-RequireMFA-PrivilegedAdmins'").Id
Update-MgIdentityConditionalAccessPolicy `
-ConditionalAccessPolicyId $policyId `
-State "enabled" # "enabled" = On | "disabled" = Off | "enabledForReportingButNotEnforced" = Report-only
Write-Host "Policy state updated to: enabled (On)"
# Xác nhận trạng thái
Get-MgIdentityConditionalAccessPolicy -ConditionalAccessPolicyId $policyId |
Select-Object DisplayName, State
📊 Kết Quả Đầu Ra
GRP-AZ500-PrivilegedAdmins có admin01, hiển thị trong Entra ID Groups
Policy CA-AZ500-RequireMFA-PrivilegedAdmins trạng thái Enabled
Sign-in log: Conditional Access = Success, MFA được enforce
az500-breakglass đăng nhập thành công không cần MFA nhờ Exclude
What If cho admin01 + Azure Management → policy matched, Grant = MFA
Trước khi bật On, sign-in log hiển thị policy would have applied
🧹 Dọn Dẹp
Giữ lại policy nếu muốn dùng cho các lab tiếp theo. Nếu cần tắt để tránh ảnh hưởng lab khác:
# Tắt policy (không xóa — giữ lại để tham khảo)
# PowerShell:
Update-MgIdentityConditionalAccessPolicy `
-ConditionalAccessPolicyId $policyId `
-State "disabled"
# Hoặc Portal: Conditional Access → policy → Enable policy → Off → Save
❓ Câu Hỏi Ôn Tập
1. Report-only mode khác gì với mode Off và On trong Conditional Access?
Gợi ý: Report-only ghi log như thể policy đang chạy nhưng không enforce thật — giúp đánh giá tác động trước khi bật thật
2. Tại sao break-glass account phải được loại trừ khỏi tất cả Conditional Access policies?
Gợi ý: Dùng khi tenant bị khóa, MFA hỏng hoặc admin không đăng nhập được — break-glass là tài khoản khẩn cấp cuối cùng
3. What If tool trong Conditional Access dùng để làm gì?
Gợi ý: Mô phỏng kết quả CA policy sẽ áp dụng cho một user + app + điều kiện cụ thể mà không cần đăng nhập thật
4. Khi tạo CA policy yêu cầu MFA cho admin, nên target resource là gì để bao gồm Azure Portal?
Gợi ý: Microsoft Azure Management (App ID: 797f4846-ba00-4fd7-ba43-dac1f8f63013) hoặc chọn All cloud apps
5. Sau khi bật policy On, admin chưa đăng ký MFA thì điều gì xảy ra?
Gợi ý: Admin sẽ bị redirect đến trang đăng ký MFA (Combined Security Registration) trước khi được cấp quyền truy cập