我已经准备好Azure PowerShell脚本,用于从Azure活动日志中捕获RBAC更改信息。当我在测试订阅上测试此脚本时,脚本可以正常工作。问题是当我使用connect-azurermaccount -subscription
命令并切换到prod订阅时。在Azure活动日志刀片中,我看到有一些与RBAC更改相关的日志,如“创建角色分配”之类的日志名称。我正在使用以下命令进行测试:
Get-AzureRmLog -StartTime (Get-Date).AddDays(-10) |
Where-Object {$_.Authorization.Action -like
"Microsoft.Authorization/roleAssignments/*"}
和
Get-AzureRmLog -StartTime 2019-09-01T10:30 | Where-Object {$_.Authorization.Action -like "*Microsoft.Authorization/*"}
我没有在控制台中看到任何输出。当我登录到Azure门户并打开活动日志时,我能够看到与RBAC更改相关的日志,日志名称->“删除角色分配”,“创建角色分配”。我正在测试提到的带有字符串“ Microsoft.Compute”的命令:
Get-AzureRmLog -StartTime (Get-Date).AddDays(-10) |
Where-Object {$_.Authorization.Action -like
""*Microsoft.Compute/*""}
和
Get-AzureRmLog -StartTime 2019-09-01T10:30 | Where-Object {$_.Authorization.Action -like "*Microsoft.Compute/*"}`
我可以在输出中看到日志信息。我不确定什么是错误的,我应该纠正什么。为什么我不能在产品订阅->“ Microsoft.Authorization / ”中使用此筛选器,我想强调一下,在我的测试订阅脚本上工作得很好。
答案 0 :(得分:2)
如果要获取与RBAC更改相关的日志,可以使用以下脚本来获取它。
Connect-AzureRmAccount
Get-AzureRmLog -ResourceProvider Microsoft.Authorization -StartTime (Get-Date).AddMonths(-1)
有关更多详细信息,请参阅 https://docs.microsoft.com/en-us/powershell/module/azurerm.insights/get-azurermlog?view=azurermps-6.13.0
更新
如果要使用Azure Rest API获取与RBAC更改相关的日志,则需要使用rest api,如下所示:
Method : GET
URL:https://management.azure.com/subscriptions/<subscription id>/providers/microsoft.insights/eventtypes/management/values
Params:
api-version = 2017-03-01-preview
$filter = eventTimestamp ge 'your strat time' and resourceTypes eq 'microsoft.authorization/roleassignments'
Header:
Authorization : Bearer access_token
根据我的测试,如果您的日志数太大,将分页结果。如果要获取其他页面的结果,我们需要将请求发送到nextlink,这是结果中的一个参数。