Mục tiêu buổi học
- Hiểu các lớp bảo mật trong vSphere: Physical → Network → Hypervisor → vCenter → VM → Data
- Thực hiện ESXi Hardening theo CIS Benchmark
- Cấu hình SSO và tích hợp Active Directory
- Thiết kế RBAC Least Privilege cho môi trường enterprise
- Triển khai VM Encryption với vSphere Native Key Provider
Lý Thuyết
vSphere Security Layers
Layer 1: Physical security (rack, datacenter access control) Layer 2: Network security (firewall, VLAN isolation, microsegmentation) Layer 3: Hypervisor security (ESXi hardening, Lockdown Mode) Layer 4: vCenter security (RBAC, SSO, audit logging) Layer 5: VM security (guest OS hardening, vTPM, encryption) Layer 6: Data security (VM Encryption, vSAN Encryption, TLS) Defense in Depth: Mỗi layer phải độc lập → Compromise 1 layer không đủ để access data
ESXi Lockdown Modes
| Mode | SSH | DCUI | vCenter API | ESXi Shell |
|---|---|---|---|---|
| Normal | Có (nếu bật) | Có | Có | Có (nếu bật) |
| Lockdown Normal | Không | Có (local admin) | Có | Không |
| Lockdown Strict | Không | Không | Có | Không |
Exception Users: Danh sách users được phép local access dù Lockdown bật — dùng cho break-glass account, monitoring agents.
vSphere SSO Architecture
Identity Sources (hỗ trợ):
1. vsphere.local — local SSO domain (built-in, luôn có)
2. Active Directory — LDAP / Integrated Windows Authentication
3. OpenLDAP — generic LDAP directory
4. SAML 2.0 — Azure AD, Okta, ADFS
Authentication Flow:
User → vSphere Client (HTTPS 443)
→ vCenter SSO Service
→ Validate credentials vs Identity Source
→ Issue SAML token (short-lived)
→ vCenter checks Permissions (Authorization)
→ Access granted to specific objects
Token lifetime: 300 giây (default, configurable)
VM Encryption & vTPM
VM Encryption requires Key Provider:
Option A: External KMS (HashiCorp Vault, HyTrust, Thales)
Option B: vSphere Native Key Provider (vNKP) — built-in vCenter 7+
Không cần external KMS server
Yêu cầu: ESXi host phải có TPM 2.0 chip
Encryption scope:
VM Encryption: VMDK files encrypted at datastore level
Keys per-VM, managed by vCenter
vSAN Encryption: Toàn bộ vSAN datastore encrypted
(thay vì per-VM)
vTPM (Virtual Trusted Platform Module):
Hardware v14+
Yêu cầu: VM Encryption hoặc vNKP
Enables: Windows Secure Boot, BitLocker, Windows 11
vTPM state encrypted → di chuyển VM giữa hosts an toàn
ESXi Firewall Management
# Liệt kê tất cả firewall rulesets esxcli network firewall ruleset list # Bật/tắt ruleset cụ thể esxcli network firewall ruleset set --ruleset-id syslog --enabled true esxcli network firewall ruleset set --ruleset-id CIM-HTTPS --enabled false # Kiểm tra trạng thái firewall esxcli network firewall get # Refresh sau khi thay đổi esxcli network firewall refresh
RBAC — Permission Model
Permission = Role + User/Group + Object + Propagate
Object hierarchy (permissions propagate down):
vCenter
└── Datacenter
└── Cluster
└── Host
└── VM Folder
└── VM
Built-in Roles:
No Access / Read-Only / Administrator
Virtual Machine User / Virtual Machine Power User
Resource Pool Administrator
Datastore Consumer / Network Administrator
Custom Role example "VM-Operator":
Virtual Machine → Interaction → Power On/Off, Console
Virtual Machine → Snapshot → Create, Delete, Revert
(Không có: Edit Settings, Delete VM)
Lab Thực Hành
Lab 12.1 — ESXi Hardening (CIS Benchmark)
1. Bật Lockdown Mode Normal: Host → Configure → Security Profile → Lockdown Mode → Edit → Normal 2. Vô hiệu hóa SSH (sau khi dùng xong): Host → Configure → Services → SSH → Stop Startup Policy: Start and stop manually 3. ESXi Firewall — chỉ bật dịch vụ cần thiết: Host → Configure → Security Profile → Firewall ✓ Bật: vSphere Web Client, vMotion, iSCSI, syslog ✗ Tắt: CIM, NFC (nếu không dùng) 4. SSH timeout (auto-disconnect idle sessions): Advanced System Settings: UserVars.ESXiShellInteractiveTimeOut = 900 (15 phút) UserVars.ESXiShellTimeOut = 600 (10 phút) 5. Account lockout policy: Security.AccountLockFailures = 5 Security.AccountUnlockTime = 900 6. Disable weak ciphers: Advanced Settings → UserVars.SuppressShellWarning = 0 7. NTP đồng bộ (quan trọng cho SSO ticket validation): System → Time Configuration → NTP: time.google.com 8. Syslog forwarding: Advanced Settings → Syslog.global.logHost = udp://siem.hoatranlab.io.local:514 Security Profile → Firewall → syslog: Enable
Lab 12.2 — SSO và Active Directory Integration
Bước 1: Join VCSA vào AD Domain vSphere Client → Administration → Single Sign On → Configuration → Active Directory → Join AD Domain: hoatranlab.io.local OU: OU=Servers,DC=corp,DC=company,DC=com User: [email protected] Password: **** → Join Domain → Reboot VCSA appliance Bước 2: Add AD như Identity Source Administration → SSO → Configuration → Identity Sources → Add Type: Active Directory (Integrated Windows Authentication) Domain: hoatranlab.io.local → Test Connection → Add Bước 3: Gán quyền cho AD Groups (Least Privilege) Administration → Access Control → Global Permissions → Add AD Group: corp\GG-VMware-Admins Role: Administrator ✓ Propagate to children AD Group: corp\GG-VMware-ReadOnly Role: Read-Only ✓ Propagate to children AD Group: corp\GG-VMware-Ops Role: VM-Operator (custom role) Object: Folder "Production" only (limited scope) Bước 4: Test đăng nhập AD Logout → Login: [email protected] ✓ Thấy chỉ Production folder ✗ Không thấy cluster settings, datastore management
Lab 12.3 — vSphere Native Key Provider & VM Encryption
Bước 1: Tạo vSphere Native Key Provider vSphere Client → vCenter → Configure → Key Providers → Add → Native Key Provider Name: vNKP-Production → Add Key Provider Backup vNKP (BẮT BUỘC — mất backup = mất access data!): → Back Up → Download .p12 file Lưu: offline storage + encrypted vault (LastPass, CyberArk) Bước 2: Encrypt VM Right-click VM → VM Policies → Edit VM Storage Policies Policy: VM Encryption Policy → Apply Hoặc khi tạo VM mới: VM Storage Policy → VM Encryption Policy Bước 3: Kiểm tra encryption status VM → Summary → VM Hardware → Encrypted: Yes ✓ Bước 4: Encrypt existing VM (in-place) VM phải ở Powered Off Right-click → VM Policies → Edit VM Storage Policies → VM Encryption Policy → Apply to all disks Bước 5: Add vTPM cho Windows 11 VM VM Edit Settings → Add New Device → Trusted Platform Module (Yêu cầu: VM Encryption đã bật, HW version ≥ 14)
Lab 12.4 — vCenter Audit & Syslog Forwarding
1. Syslog từ vCenter (VAMI): https://vcsa-01.lab.local:5480 → Syslog → New Forwarding Configuration Protocol: UDP Host: 10.100.100.50 (Splunk/ELK) Port: 514 2. Syslog từ ESXi (mỗi host): Host → Advanced Settings Syslog.global.logHost = udp://10.100.100.50:514 Host → Security Profile → Firewall → syslog: Enable 3. ESXi Audit Logs (ESXi 8.0+): /var/log/audit/ Audit Events cần monitor trong SIEM: - Login/Logout events (cả thành công và thất bại) - Permission changes (thêm/xóa quyền) - VM power operations (shutdown, restart) - ESXi host configuration changes - Datastore modifications (create, delete, resize) - Snapshot operations - VM migration (vMotion) - SSH login to ESXi 4. Splunk/ELK query examples: # Failed logins vCenter: source=vcenter "Login failure" | stats count by user # VM deletions: source=vcenter "Deleted virtual machine" | table time, user, vm
ỨNG DỤNG DOANH NGHIỆP — MODULE 12
vSphere Security Hardening thực chiến tại doanh nghiệp — CIS benchmark compliance, Lockdown Mode, VM Encryption, vNKP, audit logging đến SIEM và certificate management với VMCA.
1. CIS VMware ESXi Benchmark Compliance — Level 1 & Level 2
CIS (Center for Internet Security) benchmark là tiêu chuẩn hardening được chấp nhận rộng rãi — Level 1 bắt buộc cho mọi production, Level 2 cho môi trường sensitive.
| Control ID | CIS Control | Level | Cấu hình | Verify |
|---|---|---|---|---|
| 1.1 | ESXi patch up-to-date | L1 | VUM/LCM monthly patch cycle | esxcli software vib list |
| 2.1 | Configure NTP | L1 | esxcli system ntp set -e yes -s ntp.corp.com | esxcli system time get |
| 3.1 | SSH disabled | L1 | Get-VMHostService | Stop-VMHostService | Running: False |
| 3.2 | Lockdown Mode | L1 | Normal Lockdown (DCUI still works) | LockdownMode = lockdownNormal |
| 4.1 | Syslog to SIEM | L1 | esxcli system syslog config set --loghost | Logs appearing in SIEM |
| 5.1 | VM Encryption at rest | L2 | vNKP + Encrypted VM Storage Policy | VM.Config.Settings encrypted |
| 5.2 | FIPS 140-2 mode | L2 | esxcli system security fips140 update -e true | Reboot required |
### PowerCLI — CIS Hardening Automation (Level 1)
Connect-VIServer vcsa-01.lab.local
Get-VMHost | ForEach-Object {
$host = $_
# 1. Disable SSH & Shell
Get-VMHostService -VMHost $host | Where-Object {$_.Key -in "TSM","TSM-SSH"} |
Set-VMHostService -Policy Off | Stop-VMHostService -Confirm:$false
# 2. Enable Lockdown Mode (Normal)
($host | Get-View).EnterLockdownMode()
# 3. Configure Syslog
Set-VMHostAdvancedConfiguration -VMHost $host `
-Name "Syslog.global.logHost" -Value "tcp://siem.hoatranlab.io.local:514"
# 4. Account lockout: max 5 failed logins, 15 min lockout
Set-VMHostAdvancedConfiguration -VMHost $host `
-Name "Security.AccountLockFailures" -Value 5
Set-VMHostAdvancedConfiguration -VMHost $host `
-Name "Security.AccountUnlockTime" -Value 900
Write-Host "$($host.Name): Hardening applied"
}
2. ESXi Lockdown Mode — Normal vs Strict
Lockdown Mode buộc mọi thao tác phải đi qua vCenter — ngăn admin dùng SSH/DCUI bypass audit trail. Cần hiểu rõ sự khác nhau giữa Normal và Strict.
### So sánh Lockdown Mode ┌─────────────────────────────────────────────────────────────────┐ │ LOCKDOWN MODE COMPARISON │ ├──────────────────────┬──────────────────┬───────────────────────┤ │ Access Method │ Normal Lockdown │ Strict Lockdown │ ├──────────────────────┼──────────────────┼───────────────────────┤ │ vCenter API │ ✓ Allowed │ ✓ Allowed │ │ SSH (Exception Users)│ ✓ Allowed │ ✗ BLOCKED │ │ DCUI │ ✓ Allowed │ ✗ BLOCKED │ │ Direct API (non-vC) │ ✗ Blocked │ ✗ Blocked │ │ Exception Users list │ ✓ Can SSH │ ✓ DCUI only │ └──────────────────────┴──────────────────┴───────────────────────┘ ### Exception Users — Ai được phép khi Lockdown enabled # Thêm break-glass account vào Exception Users list: # vSphere Client → Host → Configure → Security Profile → Lockdown Mode # → Exception Users → Add: [email protected] ### Bật Lockdown Mode qua PowerCLI $vmhost = Get-VMHost "esxi-hn-r01-01.hoatranlab.io.local" ($vmhost | Get-View).EnterLockdownMode() # Normal Lockdown # Strict: cần set qua API: # ($vmhost | Get-View).EnterStrictLockdownMode() ### Kiểm tra Lockdown Mode status Get-VMHost | Select-Object Name, @{N='LockdownMode';E={($_ | Get-View).Config.LockdownMode}}
Cẩn thận khi bật Strict Lockdown
- Strict Mode block DCUI — nếu vCenter down, không có cách nào access host trực tiếp
- Chỉ dùng Strict cho môi trường có vCenter HA và uptime cao >99.9%
- Luôn test với 1 host trước khi rollout toàn cluster
- Đảm bảo Exception Users list có ít nhất 1 break-glass account
3. VM Encryption & vSphere Native Key Provider (vNKP) Setup
vNKP (vSphere Native Key Provider) là Key Management Server built-in vCenter từ vSphere 7.0U2 — không cần KMS bên ngoài, phù hợp với hầu hết doanh nghiệp.
### BƯỚC 1: Tạo vSphere Native Key Provider
# vSphere Client → Menu → Administration → Key Providers
# → Add → Native Key Provider
# Name: vNKP-Production
# → Add Key Provider
# → Lần đầu: "Back Up" để export key provider data → lưu an toàn
### BƯỚC 2: Tạo VM Encryption Storage Policy
# vSphere Client → Policies and Profiles → VM Storage Policies
# → Create → VM Encryption Policy
# Name: Policy-VM-Encrypted
# Rules: Encryption = Required
# Key Provider: vNKP-Production
### BƯỚC 3: Enable encryption cho VM mới
# Khi tạo VM: VM Storage Policy → chọn "Policy-VM-Encrypted"
# → vNKP tự động generate DEK (Data Encryption Key) per VM
### BƯỚC 4: Encrypt VM đang chạy (in-place)
# Right-click VM → VM Policies → Edit VM Storage Policy
# → Đổi sang Policy-VM-Encrypted
# → Apply: "Encrypt" — VM tiếp tục chạy trong khi encrypt
### Kiểm tra trạng thái encryption
Get-VM | Where-Object {$_.ExtensionData.Config.KeyId} | Select-Object Name,
@{N='EncryptionKeyId';E={$_.ExtensionData.Config.KeyId.KeyId}},
@{N='KMS';E={$_.ExtensionData.Config.KeyId.ProviderId.Id}}
vNKP vs External KMS — Khi nào dùng gì
Dùng vNKP khi:
- - Không có compliance yêu cầu external KMS
- - Môi trường SMB đến mid-enterprise
- - Muốn đơn giản, không manage KMS riêng
- - vSphere 7.0 U2+ trở lên
Dùng External KMS (Thales/Fortanix) khi:
- - FIPS 140-2 Level 3 hardware HSM yêu cầu
- - PCI-DSS, HIPAA compliance
- - Separation of duties: key mgmt ≠ infra team
- - Multi-cloud key management
4. Audit Logging đến SIEM — syslog-ng / Splunk Integration
Centralized logging là bắt buộc trong môi trường có compliance — ESXi và vCenter logs phải được forward realtime đến SIEM.
### ESXi → SIEM (Splunk/ELK) — Cấu hình
# 1. ESXi Syslog via esxcli (per host)
esxcli system syslog config set \
--loghost="ssl://splunk.hoatranlab.io.local:6514" \
--logdir=/scratch/log \
--default-rotate=10 \
--default-size=1024
esxcli system syslog reload
esxcli network firewall ruleset set --ruleset-id syslog --enabled true
esxcli network firewall refresh
# Verify: kiểm tra syslog gửi đi
esxcli system syslog config get | grep loghost
# 2. PowerCLI — Apply cho tất cả hosts trong cluster
Get-VMHost -Location (Get-Cluster "CL-HN-Prod-01") | ForEach-Object {
Set-VMHostSysLogServer -VMHost $_ -SysLogServer "ssl://splunk.hoatranlab.io.local:6514"
}
# 3. vCenter syslog (VAMI)
# Truy cập https://vcsa:5480 → Syslog → New Forwarding
# Protocol: TLS, Host: splunk.hoatranlab.io.local, Port: 6514
### Events quan trọng cần alert trong SIEM
# vim.event.UserLoginSessionEvent → mọi login vCenter
# vim.event.UserLogoutSessionEvent → logout
# vim.event.PermissionAddedEvent → thêm permission
# vim.event.PermissionRemovedEvent → xóa permission
# vim.event.VmPoweredOffEvent → VM bị tắt
# vim.event.HostDisconnectedEvent → host disconnect
| SIEM Rule | Event Pattern | Severity | Response |
|---|---|---|---|
| Brute Force Login | >5 UserLogin failures / 5 phút | HIGH | Block IP, notify SOC |
| Privilege Escalation | PermissionAdded + Administrator role | CRITICAL | PagerDuty P1, review immediately |
| Mass VM Deletion | >3 VmRemovedEvent / 10 phút | CRITICAL | Freeze account, incident response |
| Off-hours Admin Login | Admin login ngoài giờ làm | MEDIUM | Verify với admin qua call |
5. Host Certificate Management — VMCA & Custom CA
VMware Certificate Authority (VMCA) tự động quản lý certificate cho ESXi hosts và vCenter services — tích hợp Enterprise CA cho môi trường có PKI.
### Certificate Management Modes MODE 1: VMCA as Root CA (mặc định) - VMCA tự ký cert cho tất cả components - Simple, zero config - Phù hợp: Lab, non-regulated environments MODE 2: VMCA as Subordinate CA (recommended production) - Enterprise CA (Active Directory CA) sign VMCA cert - VMCA sau đó sign component certs - Browser trust chain: Enterprise CA → VMCA → ESXi cert - Phù hợp: Production doanh nghiệp có AD PKI MODE 3: Custom Certificates (mỗi component riêng) - Enterprise CA sign trực tiếp từng cert - Phức tạp nhất, tốn công nhất - Phù hợp: PCI-DSS yêu cầu cert riêng từng node ### Subordinate CA Setup (Mode 2) — Recommended # 1. Export VMCA CSR # vSphere Client → Administration → Certificate Management → VMCA Root # → "Generate CSR" → Save vmca.csr # 2. Sign bởi Enterprise CA (Active Directory) certreq -submit -attrib "CertificateTemplate:SubCA" vmca.csr vmca-signed.cer # 3. Import VMCA Subordinate cert # Certificate Management → "Replace" → Upload vmca-signed.cer + root chain # 4. Renew tất cả component certs # Certificate Management → "Renew" → tất cả hosts sẽ nhận cert mới từ VMCA
6. Security Hardening Checklist — Production Deployment
Checklist hoàn chỉnh khi hardening vSphere environment — chạy theo thứ tự để không bỏ sót control quan trọng.
ESXi Host Hardening
vCenter & VM Security