AZ-500 · LAB 04 ~75 phút Chương 01 Yêu cầu Lab 02 Cần Entra P1/P2 Nâng cao

Administrative Unit — Phân Quyền Theo Phạm Vi

Cấu hình Administrative Unit để giới hạn quyền quản trị của helpdesk chỉ trong phòng Security. Người được gán User Administrator trong AU chỉ quản lý được user thuộc AU đó — đây là mô hình least-privilege theo phòng ban của Zero Trust.

🎯 Mục Tiêu Lab

Tạo Administrative Unit AU-AZ500-Security

Thêm az500-admin01 và az500-secops01 vào AU làm thành viên được quản lý

Gán role User Administrator cho az500-helpdesk01 — scoped chỉ trong AU này

Đăng nhập bằng az500-helpdesk01 và xác nhận chỉ thấy user trong AU

Xác nhận helpdesk01 KHÔNG thể quản lý user ngoài AU (az500-dev01, az500-auditor01)

Kiểm tra audit log ghi nhận scoped role assignment

📋 Chuẩn Bị

Yêu cầu:
  • Hoàn thành Lab 02 (5 user az500-* đã tạo)
  • Microsoft Entra ID P1 hoặc P2 license (AU scoped role yêu cầu P1+)
  • Quyền Privileged Role Administrator hoặc Global Administrator
  • Tài khoản az500-helpdesk01 đã đổi password lần đầu (hoặc dùng Global Admin để test)
Khái niệm cần nắm:
  • Administrative Unit (AU) = container logic giới hạn scope của Entra roles
  • AU không ảnh hưởng Azure RBAC — chỉ giới hạn Entra directory roles
  • Global Administrator luôn có quyền vượt scope AU
  • Một user có thể thuộc nhiều AU cùng lúc

🏗️ Kịch bản & Tài Nguyên

Doanh nghiệp có helpdesk riêng cho từng phòng ban. Helpdesk của Security Team chỉ được phép reset password và unlock account cho nhân viên Security — không được đụng đến nhân viên Engineering hay Compliance. Administrative Unit là cơ chế Microsoft Entra ID để thực thi giới hạn này.

Kiến trúc AU Lab
AU-AZ500-Security
├── Members (được quản lý)
├── az500-admin01
└── az500-secops01
└── Role Assignments
└── az500-helpdesk01
→ User Administrator (scoped)
Quyền helpdesk01 sau khi gán
Reset password az500-admin01 ✓
Unlock az500-secops01 ✓
Sửa az500-dev01 ✗ (ngoài AU)
Xem az500-auditor01 ✗ (ngoài AU)
Gán Global Admin role ✗ (không đủ quyền)

🧪 Các Bước Thực Hiện

1

Tạo Administrative Unit AU-AZ500-Security

Cách 1 — Azure Portal
1. Portal → Microsoft Entra ID → Admin centers → Administrative units
   (hoặc tìm kiếm "Administrative units" trong search bar)
2. + Add
3. Name: AU-AZ500-Security
   Description: Administrative Unit for Security department - AZ-500 lab
4. (Tùy chọn) Restricted management:
   - Off = chỉ giới hạn AU-scoped roles
   - On = ngay cả Global Admin cũng bị giới hạn thao tác trực tiếp lên AU members
   → Để Off cho lab này
5. Review + Create → Create
Cách 2 — Microsoft Graph via Azure CLI
# Tạo Administrative Unit
az rest \
  --method POST \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits" \
  --headers "Content-Type=application/json" \
  --body '{
    "displayName": "AU-AZ500-Security",
    "description": "Administrative Unit for Security department - AZ-500 lab",
    "visibility": "HiddenMembership"
  }'

# Lấy AU ID
AU_ID=$(az rest \
  --method GET \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits?\$filter=displayName eq 'AU-AZ500-Security'" \
  --query "value[0].id" -o tsv)
echo "AU ID: $AU_ID"
Kết quả (Output)
{
  "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "displayName": "AU-AZ500-Security",
  "description": "Administrative Unit for Security department - AZ-500 lab",
  "visibility": "HiddenMembership"
}
2

Thêm User vào AU làm Members được Quản Lý

Thêm az500-admin01 và az500-secops01 vào AU. Đây là các user được quản lý bởi AU, không phải người quản lý AU.

Cách 1 — Azure Portal
1. Portal → Microsoft Entra ID → Administrative units → AU-AZ500-Security
2. Menu trái → Members → + Add members
3. Tìm và chọn:
   - az500-admin01
   - az500-secops01
4. Select → xác nhận 2 members xuất hiện trong danh sách
Cách 2 — Microsoft Graph via Azure CLI
DOMAIN=$(az ad signed-in-user show --query userPrincipalName -o tsv | cut -d'@' -f2)

AU_ID=$(az rest \
  --method GET \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits?\$filter=displayName eq 'AU-AZ500-Security'" \
  --query "value[0].id" -o tsv)

USER_ADMIN_ID=$(az ad user show --id "az500-admin01@$DOMAIN" --query id -o tsv)
USER_SECOPS_ID=$(az ad user show --id "az500-secops01@$DOMAIN" --query id -o tsv)

# Thêm az500-admin01 vào AU
az rest \
  --method POST \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits/$AU_ID/members/\$ref" \
  --headers "Content-Type=application/json" \
  --body "{\"@odata.id\": \"https://graph.microsoft.com/v1.0/users/$USER_ADMIN_ID\"}"

# Thêm az500-secops01 vào AU
az rest \
  --method POST \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits/$AU_ID/members/\$ref" \
  --headers "Content-Type=application/json" \
  --body "{\"@odata.id\": \"https://graph.microsoft.com/v1.0/users/$USER_SECOPS_ID\"}"

# Kiểm tra members của AU
az rest \
  --method GET \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits/$AU_ID/members" \
  --query "value[].{Name:displayName, UPN:userPrincipalName}"
Kết quả (Output)
[
  {"Name": "AZ500 Admin 01",  "UPN": "[email protected]"},
  {"Name": "AZ500 SecOps 01", "UPN": "[email protected]"}
]
3

Gán Scoped Role "User Administrator" cho az500-helpdesk01

Đây là bước quan trọng nhất: gán role trong phạm vi AU, không phải toàn bộ tenant. az500-helpdesk01 sẽ là người quản trị — chỉ có thể quản lý user là thành viên của AU-AZ500-Security.

Cách 1 — Azure Portal
1. Portal → Microsoft Entra ID → Administrative units → AU-AZ500-Security
2. Menu trái → Roles and administrators → + Add assignment
3. Role: tìm "User Administrator" → Select
4. Members: tìm az500-helpdesk01 → Select
5. Review → Add

Kết quả xác nhận:
- AU-AZ500-Security → Roles and administrators
  → User Administrator: az500-helpdesk01
- Đây là scoped assignment: CHỈ trong AU này, không toàn tenant
Cách 2 — Microsoft Graph via Azure CLI
DOMAIN=$(az ad signed-in-user show --query userPrincipalName -o tsv | cut -d'@' -f2)

AU_ID=$(az rest \
  --method GET \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits?\$filter=displayName eq 'AU-AZ500-Security'" \
  --query "value[0].id" -o tsv)

USER_HELPDESK_ID=$(az ad user show --id "az500-helpdesk01@$DOMAIN" --query id -o tsv)

# Lấy Role Definition ID cho "User Administrator"
ROLE_ID=$(az rest \
  --method GET \
  --url "https://graph.microsoft.com/v1.0/directoryRoles?\$filter=displayName eq 'User Administrator'" \
  --query "value[0].id" -o tsv)

# Nếu role chưa được kích hoạt, kích hoạt từ roleTemplates
if [ -z "$ROLE_ID" ]; then
  ROLE_TEMPLATE_ID=$(az rest \
    --method GET \
    --url "https://graph.microsoft.com/v1.0/directoryRoleTemplates?\$filter=displayName eq 'User Administrator'" \
    --query "value[0].id" -o tsv)
  az rest --method POST \
    --url "https://graph.microsoft.com/v1.0/directoryRoles" \
    --headers "Content-Type=application/json" \
    --body "{\"roleTemplateId\": \"$ROLE_TEMPLATE_ID\"}"
  ROLE_ID=$(az rest \
    --method GET \
    --url "https://graph.microsoft.com/v1.0/directoryRoles?\$filter=displayName eq 'User Administrator'" \
    --query "value[0].id" -o tsv)
fi

# Gán scoped role trong AU
az rest \
  --method POST \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits/$AU_ID/scopedRoleMembers" \
  --headers "Content-Type=application/json" \
  --body "{
    \"roleId\": \"$ROLE_ID\",
    \"roleMemberInfo\": {
      \"id\": \"$USER_HELPDESK_ID\"
    }
  }"

echo "Scoped role assigned. helpdesk01 is now User Administrator within AU-AZ500-Security only."
4

Kiểm Tra: Đăng Nhập bằng az500-helpdesk01

Dùng tài khoản az500-helpdesk01 để xác nhận phạm vi quyền hạn. Đây là bước xác minh quan trọng nhất của lab.

Cách 1 — Azure Portal (InPrivate/Incognito)
1. Mở browser InPrivate / Incognito
2. Truy cập https://portal.azure.com
3. Đăng nhập: [email protected]
   Password: Az500@Lab2026! (đổi password lần đầu nếu được yêu cầu)

4. TEST 1 — Xem Users: Portal → Microsoft Entra ID → Users
   → Chỉ thấy az500-admin01 và az500-secops01 (2 user trong AU)
   → KHÔNG thấy az500-dev01, az500-auditor01

5. TEST 2 — Reset password az500-admin01:
   → Click vào az500-admin01 → Reset password → OK
   → Thành công ✓ (trong phạm vi AU)

6. TEST 3 — Thử truy cập az500-dev01 (ngoài AU):
   → Tìm kiếm "az500-dev01" → Không thấy kết quả
   → Hoặc nếu thấy, click vào → "You don't have access"
   → Thất bại như mong đợi ✓

7. TEST 4 — Thử gán Global Administrator cho user:
   → Users → az500-admin01 → Assigned roles → + Add assignments
   → Tìm "Global Administrator" → Sẽ không thấy hoặc không có quyền gán
   → Thất bại như mong đợi ✓ (helpdesk không thể leo thang quyền)
Cách 2 — Azure CLI với credential helpdesk01
DOMAIN=$(az ad signed-in-user show --query userPrincipalName -o tsv | cut -d'@' -f2)

# Đăng nhập bằng helpdesk01 trong terminal khác hoặc az login --username
az login --username "az500-helpdesk01@$DOMAIN" \
         --password "Az500@Lab2026!" \
         --allow-no-subscriptions

# Kiểm tra user nào helpdesk01 có thể thấy
az ad user list \
  --query "[].{Name:displayName, UPN:userPrincipalName}" \
  --output table
# Kết quả mong đợi: chỉ thấy user trong AU

# Thử lấy thông tin user ngoài AU (phải thất bại)
az ad user show --id "az500-dev01@$DOMAIN" 2>&1 | head -5
# Kết quả: "Insufficient privileges" hoặc không tìm thấy

# Quay lại admin account
az login
5

Xem Audit Log — Scoped Role Assignment

Cách 1 — Azure Portal
1. Portal → Microsoft Entra ID → Monitoring → Audit logs
2. Filter:
   - Date: Last 1 hour
   - Service: Core Directory
   - Category: RoleManagement
3. Tìm entries:
   - "Add member to role in AU" → az500-helpdesk01 → User Administrator
   - Xem "Modified properties": Scope = AU-AZ500-Security
4. Lưu ý: log cho thấy đây là SCOPED assignment, không phải tenant-wide

Điểm khác nhau trong audit log:
  Tenant-wide role: "Add member to role"
  AU-scoped role:   "Add member to role in administrative unit"
Microsoft Graph — Xem Scoped Role Assignments trong AU
AU_ID=$(az rest \
  --method GET \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits?\$filter=displayName eq 'AU-AZ500-Security'" \
  --query "value[0].id" -o tsv)

# Xem tất cả scoped role assignments trong AU
az rest \
  --method GET \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits/$AU_ID/scopedRoleMembers" \
  --query "value[].{RoleID:roleId, MemberName:roleMemberInfo.displayName, MemberUPN:roleMemberInfo.userPrincipalName}"
Kết quả (Output)
[
  {
    "RoleID": "fe930be7-5e62-47db-91af-98c3a49a38b1",
    "MemberName": "AZ500 Helpdesk 01",
    "MemberUPN": "[email protected]"
  }
]
# Role ID fe930be7-... = User Administrator role template ID

🧹 Dọn Dẹp Tài Nguyên

Giữ lại AU và toàn bộ user cho các lab MFA, Conditional Access, RBAC tiếp theo. Xóa khi kết thúc toàn bộ khóa học.

Microsoft Graph via Azure CLI — Khi kết thúc khóa học
AU_ID=$(az rest \
  --method GET \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits?\$filter=displayName eq 'AU-AZ500-Security'" \
  --query "value[0].id" -o tsv)

# Xóa Administrative Unit (khi kết thúc khóa học)
az rest \
  --method DELETE \
  --url "https://graph.microsoft.com/v1.0/administrativeUnits/$AU_ID"

# Xóa user và group (khi kết thúc khóa học)
# Xem lab01-tao-tenant-lab.html → Bước Dọn dẹp để xóa toàn bộ

📊 Kết Quả Đầu Ra Lab 04

AU-AZ500-Security tạo thành công

Graph API trả về AU ID, Portal hiển thị trong Administrative units list

2 Members trong AU

admin01 và secops01 hiển thị trong AU → Members tab

Scoped Role gán đúng

scopedRoleMembers API trả về helpdesk01 với User Administrator role trong AU scope

helpdesk01 chỉ thấy user trong AU

Đăng nhập bằng helpdesk01 → Users list chỉ hiển thị admin01 và secops01

Least-privilege xác nhận

helpdesk01 không thể truy cập dev01/auditor01, không thể gán Global Admin

Audit log phân biệt scoped vs tenant-wide

Audit log hiển thị "Add member to role in administrative unit" thay vì "Add member to role"

❓ Câu Hỏi Ôn Tập

1. Administrative Unit giới hạn loại quyền nào? Azure RBAC hay Microsoft Entra directory roles?

Gợi ý: AU chỉ giới hạn Entra directory roles (User Administrator, Password Administrator, Helpdesk Administrator...). Azure RBAC (Owner, Contributor, Reader...) vẫn hoạt động độc lập theo resource scope.

2. Global Administrator có bị giới hạn bởi Administrative Unit không?

Gợi ý: Mặc định KHÔNG. Trừ khi AU được bật "Restricted management" — khi đó ngay cả Global Admin cũng bị hạn chế thao tác trực tiếp lên AU members, tăng bảo vệ cho dữ liệu nhạy cảm.

3. Nêu 3 tình huống thực tế doanh nghiệp nên dùng Administrative Unit?

Gợi ý: (1) Multi-geography: IT team mỗi quốc gia chỉ quản lý user nước đó. (2) Multi-department: Helpdesk HR chỉ reset password cho HR. (3) Subsidiary: Admin của công ty con chỉ quản lý user trong công ty đó.

4. Một user có thể thuộc nhiều Administrative Unit cùng lúc không? Nếu có, quyền của helpdesk được tính như thế nào?

Gợi ý: Có, một user có thể thuộc nhiều AU. Helpdesk được gán role trong AU nào thì quản lý được user trong AU đó — các AU độc lập nhau, không tích hợp. Quyền được tính hợp (union) từ tất cả AU assignment.

5. Sự khác nhau giữa "Member" của AU và "Admin" (role assignment) trong AU là gì?

Gợi ý: Member = user ĐƯỢC quản lý (đối tượng bị ảnh hưởng bởi scoped roles). Admin trong AU = người được gán scoped role — chính là người QUẢN LÝ các member. Trong lab: admin01/secops01 là member; helpdesk01 là người quản lý (được gán scoped role).

Lab 03: Dynamic Group Thư viện Labs Lab 05: MFA cho Admin
Zalo