Bagikan melalui


Mengonversi log audit ke daftar yang diizinkan

Dengan Metadata Security Protocol (MSP), Anda dapat menentukan daftar izin kontrol akses berbasis peran (RBAC) kustom untuk membantu mengamankan titik akhir layanan metadata. Konten daftar yang diizinkan berasal dari log audit. Jenis sumber daya baru di Azure Compute Gallery, InVMAccessControlProfile, mengaktifkan daftar yang diizinkan.

Untuk mempelajari selengkapnya tentang RBAC dan InVMAccessControlProfile jenis sumber daya, lihat Konfigurasi tingkat lanjut untuk MSP.

Struktur daftar yang diizinkan

Daftar yang diizinkan terdiri dari:

  • Identitas: Proses pada komputer.
  • Hak istimewa: Endpoint yang diakses oleh berbagai identitas.
  • Peran: Pengelompokan hak istimewa.
  • Penetapan peran: Peran dan daftar identitas yang diberikan akses untuk peran tersebut.

Mengumpul log audit

Jika Mengaktifkan MSP dalam audit mode atau enforce , Anda dapat mengumpulkan data log dari klien komputer virtual melalui Azure Monitor.

  • Windows: Agen pemantauan Azure mengumpulkan Peristiwa Windows melalui Custom XPath Windows Azure!*[System[Provider[@Name=`GuestProxyAgent`]]]

  • Linux: Mengumpulkan peristiwa Syslog dengan Agen Azure Monitor dengan memilih Log_DAEMON dan LOG_DEBUG

Mengkueri log audit

Setelah log audit dikumpulkan seperti yang dijelaskan di bagian sebelumnya, Anda dapat memverifikasi log:

Kueri Kusto Windows: Buka Log Analytics dan jalankan kueri

/// Windows VMs
Event
| where TimeGenerated >ago(1d)
| where EventLog == "Windows Azure" and Source == "GuestProxyAgent"
| where _ResourceId startswith "/subscriptions/<your subscription id>/resourcegroups/<your recrouce group>" 
| where RenderedDescription  has  "processFullPath" and RenderedDescription  has "runAsElevated" and RenderedDescription has "processCmdLine"
| extend json = parse_json(RenderedDescription)
| extend method = json.method, url = json.url, processFullPath = json.processFullPath, username = json.userName, runAsElevated = json.runAsElevated 
| extend userGroups = json.userGroups, ip = json.ip, port = json.port, processCmdLine = json.processCmdLine 
| project TimeGenerated, _ResourceId, url, ip, port, processFullPath, method, username, runAsElevated, processCmdLine

Kueri Kusto Linux: Buka Log Analytics dan jalankan kueri

/// Linux VMs
Syslog
| where TimeGenerated >ago(1d)
| where  ProcessName == "azure-proxy-agent"
| where _ResourceId startswith "/subscriptions/<your subscription id>/resourcegroups/<your recrouce group>" 
| where SyslogMessage  has  "processFullPath" and SyslogMessage  has "runAsElevated" and SyslogMessage has "processCmdLine"
| extend message = substring(SyslogMessage, indexof(SyslogMessage, "{"))
| extend json = parse_json(message)
| extend method = json.method, url = json.url, processFullPath = json.processFullPath, username = json.userName, runAsElevated = json.runAsElevated 
| extend userGroups = json.userGroups, ip = json.ip, port = json.port, processCmdLine = json.processCmdLine 
| project TimeGenerated, _ResourceId, url, ip, port, processFullPath, method, username, runAsElevated, processCmdLine

Jika Anda memiliki Azure VM, Anda bisa mendapatkan log file di dalam Azure VM dengan mengikuti langkah-langkah ini

  1. Temukan berkas konfigurasi json untuk Agen Perantara.

    • Windows VM: GuestProxyAgent.json dalam folder dengan nama GuestProxyAgent windows service
    • Linux VM: etc/azure/proxy-agent.json file
  2. Aktifkan log file dengan memperbarui pengaturan logFolder dalam file konfigurasi json. Atur ke

    • %SYSTEMDRIVE%\\WindowsAzure\\ProxyAgent\\Logs untuk VM Windows
    • /var/log/azure-proxy-agent untuk VM Linux.
  3. Mulai ulang Layanan

  • GuestProxyAgent untuk VM Windows
  • azure-proxy-agent untuk Linux VMs4
  1. Tunggu ProxyAgent.Connection.log hingga terisi ketika layanan pelanggan aktif.
  2. Menarik log file koneksi ProxyAgent dari Azure VM
    • Windows: C:\WindowsAzure\ProxyAgent\Logs\ProxyAgent.Connection.log

    • Linux: /var/log/azure-proxy-agent/ProxyAgent.Connection.log

Mengonversi log ke aturan

Untuk membuat daftar izin, Anda dapat menggunakan metode otomatis atau metode manual.

Membuat daftar yang diizinkan secara otomatis

Anda dapat menggunakan alat generator daftar izin untuk menghasilkan aturan kontrol akses. Alat ini membantu mengurai log audit dan menyediakan UI untuk menghasilkan aturan.

  1. Unduh dan jalankan alat generator daftar izin. Pada halaman rilis terbaru, di bawah Aset, pilih allowListTool.exe.

    Alat ini mengurai ProxyAgentConnection log dan menampilkan hak istimewa dan identitas saat ini pada VM.

  2. Membuat peran dan penugasan peran

    • Untuk membuat peran, pilih pengelompokan hak istimewa dan beri peran nama deskriptif.
    • Untuk membuat penetapan peran, pilih peran dan kelompok identitas. Identitas ini dapat mengakses hak istimewa yang termasuk dalam peran tersebut. Beri nama deskriptif pada penetapan peran.

Membuat daftar izin secara manual

Setelah Anda mengaktifkan VM dengan MSP dalam mode Audit atau Enforce, agen proksi menangkap semua permintaan yang dibuat ke titik akhir host.

Dalam log koneksi, Anda dapat menganalisis aplikasi yang membuat permintaan ke Azure Instance Metadata Service atau titik akhir WireServer.

Cuplikan layar log koneksi.

Contoh berikut menunjukkan format JSON yang diambil.

Cuplikan layar log audit dengan JSON yang diambil.

Dalam file log, Anda dapat mengidentifikasi titik akhir yang ingin Anda amankan. Titik akhir ini muncul di privileges pada instans InVMAccessControlProfile yang akhir. Anda juga dapat mengidentifikasi identitas (identities) yang harus memiliki akses.

Skema aturan sederhana mungkin terlihat seperti contoh berikut.

Cuplikan layar skema aturan sederhana.

Membuat instans InVMAccessControlProfile dengan menggunakan templat ARM

  1. Buat galeri privat baru di Azure Compute Gallery.

  2. Buat InVMAccessControlProfile definisi dengan parameter untuk:

    • Nama galeri untuk disimpan di (dari langkah 1)
    • Nama profil
    • Jenis OS
    • Jenis titik akhir host (WireServer atau Instance Metadata Service)
  3. Buat versi tertentu.

Contoh InVMAccessControlProfile

Berikut contoh InVMAccessControlProfile instansnya:

"properties": {
    "mode": "Enforce",
    "defaultAccess": "Allow",
    "rules": {
      "privileges": [
        {
          "name": "GoalState",
          "path": "/machine",
          "queryParameters": {
            "comp": "goalstate"
          }
        }
      ],
      "roles": [
        {
          "name": "Provisioning",
          "privileges": [
            "GoalState"
          ]
        },
        {
          "name": "ManageGuestExtensions",
          "privileges": [
            "GoalState"
          ]
        },
        {
          "name": "MonitoringAndSecret",
          "privileges": [
            "GoalState"
          ]
        }
      ],
      "identities": [
        {
          "name": "WinPA",
          "userName": "SYSTEM",
          "exePath": "C:\\Windows\\System32\\cscript.exe"
        },
        {
          "name": "GuestAgent",
          "userName": "SYSTEM",
          "processName": "WindowsAzureGuestAgent.exe"
        },
        {
          "name": "WaAppAgent",
          "userName": "SYSTEM",
          "processName": "WaAppAgent.exe"
        },
        {
          "name": "CollectGuestLogs",
          "userName": "SYSTEM",
          "processName": "CollectGuestLogs.exe"
        },
        {
          "name": "AzureProfileExtension",
          "userName": "SYSTEM",
          "processName": "AzureProfileExtension.exe"
        },
        {
          "name": "AzurePerfCollectorExtension",
          "userName": "SYSTEM",
          "processName": "AzurePerfCollectorExtension.exe"
        },
        {
          "name": "WaSecAgentProv",
          "userName": "SYSTEM",
          "processName": "WaSecAgentProv.exe"
        }
      ],
      "roleAssignments": [
        {
          "role": "Provisioning",
          "identities": [
            "WinPA"
          ]
        },
        {
          "role": "ManageGuestExtensions",
          "identities": [
            "GuestAgent",
            "WaAppAgent",
            "CollectGuestLogs"
          ]
        },
        {
          "role": "MonitoringAndSecret",
          "identities": [
            "AzureProfileExtension",
            "AzurePerfCollectorExtension",
            "WaSecAgentProv"
          ]
        }
      ]
    },

Menggunakan PowerShell

Jika Anda menggunakan PowerShell untuk menghasilkan InVMAccessControlProfile, pastikan Anda memiliki versi minimum 10.1.0 PowerShell

Ikuti panduan langkah demi langkah di bawah ini untuk menghasilkan InVMAccessControlProfile:

  1. Masuk ke Akun Azure Anda
Connect-AzAccount 
  1. Buat Grup Sumber Daya tempat galeri pribadi dibuat. Anda dapat melewati langkah ini jika Anda sudah membuat Grup Sumber Daya.
$resourceGroup = "MyResourceGroup4" 
$location = "EastUS2EUAP" 
New-AzResourceGroup -Name $resourceGroup -Location $location 
  1. Buat galeri privat. Galeri ini digunakan sebagai kontainer untuk InVMAccessControlProfile artefak
$galleryName = "MyGallery4" 
New-AzGallery -ResourceGroupName $resourceGroup -GalleryName $galleryName -Location $location -Description "My custom image gallery" 
  1. InVMAccessControlProfile Buat artefak di galeri privat yang dibuat di langkah sebelumnya. Klik di sini untuk mempelajari selengkapnya tentang berbagai parameter untuk artefak ini.
$InVMAccessControlProfileName= "testInVMAccessControlProfileP"  

New-AzGalleryInVMAccessControlProfile -ResourceGroupName  $resourceGroup  -GalleryName $galleryName   -GalleryInVMAccessControlProfileName $InVMAccessControlProfileName -Location $location -OsType "Windows" -ApplicableHostEndPoint "WireServer" -Description "this test1" 
  1. Dapatkan Galeri InVMAccessControlProfile
$inVMAccessCP=Get-AzGalleryInVMAccessControlProfile -ResourceGroupName  $resourceGroup  -GalleryName $galleryName   -GalleryInVMAccessControlProfileName $InVMAccessControlProfileName 

![Cuplikan layar output untuk perintah Get untuk InVMAccessControlProfile.](../gambar/)

  1. Perbarui Galeri InVMAccessControlProfile Setelah InVMAccessControlProfile dibuat, satu-satunya atribut yang dapat diedit adalah deskripsi. Untuk perubahan lainnya, buat artefak baru.

Untuk memperbarui deskripsi:

Update-AzGalleryInVMAccessControlProfile -ResourceGroupName  $resourceGroup  -GalleryName $galleryName   -GalleryInVMAccessControlProfileName $InVMAccessControlProfileName -Location $location -Description "this test2"

Cuplikan layar deskripsi Update InVMAccessControlProfile.

  7. Buat InVMAccessControlProfileVersion

Untuk membuat InVMAccessControlProfileVersion, payload diperlukan. Karena payload ini bisa besar, terutama karena properti aturan, tidak praktis untuk menggunakan satu perintah PowerShell untuk membuat seluruh sumber daya dalam sekali jalan. Properti aturan dalam payload dari versi apa pun terdiri dari empat array: hak istimewa, peran, identitas, dan penugasan peran. Array-array ini dapat membuat payload menjadi besar dan kompleks. Untuk menyederhanakan proses ini, kami memperkenalkan objek PowerShell GalleryInVMAccessControlProfileVersionConfig. Anda dapat mempelajari lebih lanjut tentang hal itu di sini.

Objek ini memungkinkan Anda untuk secara bertahap membangun konfigurasi menggunakan berbagai perintah untuk menambahkan atau menghapus properti aturan. Setelah objek konfigurasi siap, Anda dapat menggunakannya untuk membuat InVMAccessControlProfileVersion, yang dijelaskan di bagian yang akan datang.

Atau, jika Anda sudah memiliki properti aturan sebagai string JSON dan lebih suka tidak menggunakan objek konfigurasi, Anda dapat melewati langkah-langkah ini dan membuat InVMAccessControlProfileVersion menggunakan penyebaran templat ARM, yang juga dibahas nanti di bagian .

Payload sebagai referensi:

{
  "name": "1.0.0",
  "location": "East US 2 EUAP",
  "properties": {
    "mode": "Audit", 
    "defaultAccess": "Deny", 
    "rules": { 
      "privileges": [
        {
          "name": "GoalState",
          "path": "/machine",
          "queryParameters": {
            "comp": "goalstate"
          }
        }
      ],
      "roles": [
        {
          "name": "Provisioning",
          "privileges": [
            "GoalState"
          ]
        }
      ],
      "identities": [
        {
          "name": "WinPA",
          "userName": "SYSTEM",
          "groupName": "Administrators",
          "exePath": "C:\\Windows\\System32\\cscript.exe",
          "processName": "cscript"
        }
      ],
      "roleAssignments": [
        {
          "role": "Provisioning",
          "identities": [
            "WinPA"
          ]
        }
      ]
    },
    "targetLocations": [
      {
        "name": "East US 2 EUAP"
      }
    ],
    "excludeFromLatest": false 
  }
}
  1. Buat InVMAccessControlProfileVersion Konfigurasi
$inVMAccessControlProfileVersionName= "1.0.0"
$targetRegions= @("EastUS2EUAP", "CentralUSEUAP")
$inVMAccessConrolProfileVersion = New-AzGalleryInVMAccessControlProfileVersionConfig `
 -Name $inVMAccessControlProfileVersionName  `
-Location $location  `
-Mode "Audit"  `
-DefaultAccess "Deny" -TargetLocation $targetRegions  -ExcludeFromLatest

Cuplikan layar konfigurasi pembuatan versi profil.

Jalankan perintah ini untuk menambahkan setiap hak istimewa:

Add-AzGalleryInVMAccessControlProfileVersionRulesPrivilege `
  -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion `
  -PrivilegeName "GoalState" `
  -Path "/machine" `
  -QueryParameter @{ comp = "goalstate" }

Untuk menghapus hak istimewa:

Remove-AzGalleryInVMAccessControlProfileVersionRulesPrivilege `
 -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion `
 -PrivilegeName "GoalState2"

Jalankan perintah ini untuk menambahkan setiap peran:

Add-AzGalleryInVMAccessControlProfileVersionRulesRole `
 -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion `
 -RoleName "Provisioning" `
 -Privilege @("GoalState")

Jalankan perintah ini untuk menghapus peran:

Remove-AzGalleryInVMAccessControlProfileVersionRulesRole `
 -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion `
 -RoleName "Provisioning2" 

Tambahkan RulesIdentity:

Add-AzGalleryInVMAccessControlProfileVersionRulesIdentity `
  -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion `
  -IdentityName "WinPA" `
  -UserName "SYSTEM" `
  -GroupName "Administrators" `
  -ExePath "C:\Windows\System32\cscript.exe" `
  -ProcessName "cscript"

Hapus RulesIdentity:

Remove-AzGalleryInVMAccessControlProfileVersionRulesIdentity `
  -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion `
  -IdentityName "WinPA2" 

Jalankan perintah ini untuk menambahkan setiap Penetapan Peran:

Add-AzGalleryInVMAccessControlProfileVersionRulesRoleAssignment `
  -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion `
  -Role "Provisioning" `
  -Identity @("WinPA")

Hapus Penetapan Peran:

Remove-AzGalleryInVMAccessControlProfileVersionRulesRoleAssignment `
  -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion `
  -Role "Provisioning2" 
  1. Buat Galeri InVMAccessControlProfileVersion
New-AzGalleryInVMAccessControlProfileVersion -ResourceGroupName $resourceGroup -GalleryName $galleryName -GalleryInVMAccessControlProfileName   $InVMAccessControlProfileName   -GalleryInVmAccessControlProfileVersion $inVMAccessConrolProfileVersion 

Cuplikan layar pembuatan InVMAccessControlProfileVersion.

  1. Dapatkan InVMAccessControlProfileVersion
$ver = Get-AzGalleryInVMAccessControlProfileVersion -ResourceGroupName $resourceGroup -GalleryName $galleryName -GalleryInVMAccessControlProfileName   $InVMAccessControlProfileName `
 -GalleryInVMAccessControlProfileVersionName  $inVMAccessControlProfileVersionName
 $ver | ConvertTo-Json -Depth 10
  1. Pembaruan InVMAccessControlProfileVersion

Disarankan untuk membuat baru InVMAccessControlProfileVersion karena sebagian besar parameter tidak dapat diperbarui. Berikut adalah sebuah contoh:

$targetRegions= @("EastUS2EUAP")
 
$ver = Get-AzGalleryInVMAccessControlProfileVersion -ResourceGroupName $resourceGroup -GalleryName $galleryName -GalleryInVMAccessControlProfileName   $InVMAccessControlProfileName `
 -GalleryInVMAccessControlProfileVersionName  $inVMAccessControlProfileVersionName
 
 
Update-AzGalleryInVMAccessControlProfileVersion `
  -GalleryInVmAccessControlProfileVersion $ver `
-TargetLocation $targetRegions -ExcludeFromLatest $true

Cuplikan layar pembaruan InVMAccessControlProfileVersion.

  1. Menghapus InVMAccessControlProfileVersion
Remove-AzGalleryInVMAccessControlProfileVersion -ResourceGroupName $resourceGroup -GalleryName $galleryName -GalleryInVMAccessControlProfileName   $InVMAccessControlProfileName `
 -GalleryInVMAccessControlProfileVersionName  $inVMAccessControlProfileVersionName

Cuplikan layar contoh hapus InVMAccessControlProfileVersion.

  1. Mencantumkan semua galeri InVMAccessControlProfile
Get-AzGalleryInVMAccessControlProfile -ResourceGroupName "myResourceGroup" -GalleryName "myGallery"

Cuplikan layar Daftar semua InVMAccessControlProfiles.

Menggunakan CLI

Ikuti panduan langkah demi langkah di bawah ini untuk menghasilkan InVMAccessControlProfile:

  1. Masuk ke Akun Azure Anda
az login
  1. Membuat grup sumber daya di lokasi yang Anda inginkan
az group create  --resource-group ResourceGroupForINVM  --location eastus
  1. Membuat galeri yang akan menampung InVMAccessControlProfile sumber daya
 az sig create --resource-group ResourceGroupForINVM --gallery-name MyGallery67 --location eastus 
  1. Buat sebuah InVMAccessControlProfile di bawah galeri yang telah dibuat di langkah sebelumnya. Untuk detail perintah tambahan: az sig in-vm-access-control-profile | Microsoft Learn
 az sig in-vm-access-control-profile create --resource-group ResourceGroupForINVM --gallery-name MyGallery67 --name myInVMAccessControlProfileName --location eastus --os-type Linux  --applicable-host-endpoint WireServer 

Jalankan perintah ini untuk melihat detail tambahan tentang perintah dan properti

az sig in-vm-access-control-profile create --help 

Tangkapan layar untuk mengambil detail properti InVMAccessControlProfile

  1. Anda hanya dapat memperbarui deskripsi dari InVMAccessControlProfile. Jika perubahan tambahan diperlukan, hapus saat ini InVMAccessControlProfile dan buat yang baru
az sig in-vm-access-control-profile update --resource-group ResourceGroupForINVM --gallery-name MyGallery67 --name myInVMAccessControlProfileName  --description test 

Cuplikan layar tentang pembaruan deskripsi InVMAccessControlProfile

  1. Dapatkan operasi untuk InVMAccessControlProfile
az sig in-vm-access-control-profile show --resource-group ResourceGroupForINVM --gallery-name MyGallery67 --name myInVMAccessControlProfileName 

Cuplikan layar operasi 'get' untuk profil InVMAccessControl

  1. Mencantumkan semua InVMAccessControlProfile artefak

Perintah ini memperlihatkan daftar semua InVMAccessControlProfile di bawah galeri tertentu

az sig in-vm-access-control-profile show --resource-group ResourceGroupForINVM --gallery-name MyGallery67 

Cuplikan layar perintah daftar untuk menampilkan semua artefak InVMAccessControlProfile di bawah galeri tertentu

  1. Menciptakan InVMAccessControlProfileVersion

Anda harus menyediakan payload untuk membuat InVMAccessControlProfileVersion. Payload ini bisa besar, terutama karena properti aturan, yang mungkin berisi konfigurasi yang ekstensif. Alih-alih meneruskan bagian individual dari properti aturan secara langsung, kami telah memperkenalkan parameter aturan yang menerima file JSON sebagai input. Pendekatan ini menyederhanakan proses dan menjaga perintah tetap bersih dan dapat dikelola. Berikut adalah contoh file rules.json:

 1. { 
 2.   "privileges": [
 3. 	{
 4. 	  "name": "GoalState",
 5. 	  "path": "/machine",
 6. 	  "queryParameters": {
 7. 		"comp": "goalstate"
 8. 	  }
 9. 	}
10.   ],
11.   "roles": [
12. 	{
13. 	  "name": "Provisioning",
14. 	  "privileges": [
15. 		"GoalState"
16. 	  ]
17. 	}
18.   ],
19.   "identities": [
20. 	{
21. 	  "name": "WinPA",
22. 	  "userName": "SYSTEM",
23. 	  "groupName": "Administrators",
24. 	  "exePath": "C:\\Windows\\System32\\cscript.exe",
25. 	  "processName": "cscript"
26. 	}
27.   ],
28.   "roleAssignments": [
29. 	{
30. 	  "role": "Provisioning",
31. 	  "identities": [
32. 		"WinPA"
33. 	  ]
34. 	}
35.   ]
36. } 

Lihat detail perintah tambahan di sini: az sig in-vm-access-control-profile-version | Microsoft Learn

Setelah Anda membuat versi file rules.json, gunakan perintah berikut untuk membuat InVMAccessControlProfileVersion

 az sig in-vm-access-control-profile-version create \
   --resource-group ResourceGroupForINVM  \
   --gallery-name MyGallery67  \
   --profile-name myInVMAccessControlProfileName \
   --version-name 1.0.0 \
   --mode Audit \
   --default-access Deny  \
   --target-regions EastUS2EUAP  \
   --exclude-from-latest true \
   --rules @rules.json
  1. Dapatkan InVMAccessControlProfileVersion
az sig in-vm-access-control-profile-version show --resource-group ResourceGroupForINVM --gallery-name MyGallery67 --profile-name myInVMAccessControlProfileName --profile-version 1.0.0

Cuplikan layar perintah get untuk versi profil

  1. Mencantumkan semua InVMAccessControlProfileVersion artefak
az sig in-vm-access-control-profile-version list --resource-group ResourceGroupForINVM --gallery-name MyGallery67 --profile-name myInVMAccessControlProfileName
  1. Menghapus InVMAccessControlProfileVersion

Sebelum Anda menghapus InVMAccessControlProfileVersion, pastikan bahwa InVMAccessControlProfileVersion tidak digunakan oleh pada komputer virtual atau Set Skala Komputer Virtual apa pun.

az sig in-vm-access-control-profile-version delete --resource-group ResourceGroupForINVM --gallery-name MyGallery67 --profile-name myInVMAccessControlProfileName --profile-version 1.0.0
  1. Menghapus InVMAccessControlProfile
az sig in-vm-access-control-profile delete --resource-group ResourceGroupForINVM --gallery-name MyGallery67 --name myInVMAccessControlProfileName