Open Candelit opened 2 years ago
network
Hi: @Candelit As the error info shows that CLI does not support the resources from different subscriptions now, "nsg-vn-devtest-sn-internal-default should be in the same subscription as flow log resource d52ec4e6-3349-XXXX-XXXXXXXXXX-cf3". Best wishes.
Hi: @Candelit As the error info shows that CLI does not support the resources from different subscriptions now, "nsg-vn-devtest-sn-internal-default should be in the same subscription as flow log resource d52ec4e6-3349-XXXX-XXXXXXXXXX-cf3". Best wishes.
Hi, an accurate observation. But why should CLI support less than what can be done in the portal or using PowerShell? There is not any article that states this, I had to spend a lot of time trying before I got to this error message, maybe I should just drop it there and let everyone else make the same journey, but I'm still hopeful, that Microsoft can fix it for us as it is possible in both the portal and PowerShell... In a 'real' environement, it is in my experience not often that these types of resources are in the same subscription. You would if nothing else want separation of the network logs for forensics...
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @aznetsuppgithub.
Author: | Candelit |
---|---|
Assignees: | necusjz, kairu-ms |
Labels: | `Network`, `Service Attention`, `customer-reported`, `Auto-Assign`, `Traiged` |
Milestone: | Backlog |
![image](https://user-images.githubusercontent.com/95396631/163325321-3f76314f-6c6a-439b-b231-501aa2ae3a76.png Hi, @Candelit we have reproduced this issue and routing this to service team, thank you for your reporting. Best wishes.
Hi, is there any update on this? I am facing the same issue in Terraform for both the azurerm and azapi providers.
I can now report that it works fine when deployed using bicep and ARM templates.
Hi,
Is there any update on this? I am still facing the same issue in Terraform. We have log analytics workspace in a separate subscription than NSGs and when deploying NSG Flow logs I get this error even the workspace and resource group exist.
Error: log analytics workspaces "log-xxxxxxxx" (Resource Group "rg-yyyyyyyy") was not found
When I deploy NSG flow logs to a log analytics workspace that is in the same subscription it succeeds.
See similar errors using Terraform azurerm provider:
│ Error: creating "Flow Log: (Name \"nsg-flowlogsdbx_workspace_nsg_eastusprod\" / Network Watcher Name \"NetworkWatcher_aaaaaaa\" / Resource Group \"gggggggggggg\")": network.FlowLogsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="FlowLogTargetResourceIsInDifferentSubscription" Message="Target resource /subscriptions/xxxxxxxxxx/resourceGroups/dbx_workspace_eastusprod_rg/providers/Microsoft.Network/networkSecurityGroups/dbx_workspace_nsg_eastusprod should be in the same subscription as flow log resource yyyyyyyyyy." Details=[]
@zshao9 , @efd7887 I'm from the NSG flow log product group. The behavior mentioned in product documentation is accurate - User can create an NSG flow log and select a storage account in in a subscription that is different from the subscription of NSG. However, user cannot create an NSG flow log where the flow log resource is in a subscription different from the NSG itself. This is likely the case of your error, further details below.
Considerations for NSG flow logs Storage account Location: The storage account must be in the same region as the network security group. Subscription: The storage account must be in the same subscription of the network security group or in a subscription associated with the same Microsoft Entra tenant of the network security group's subscription. Performance tier: The storage account must be standard. Premium storage accounts aren't supported. Self-managed key rotation: If you change or rotate the access keys to your storage account, NSG flow logs stop working. To fix this problem, you must disable and then re-enable NSG flow logs.
Here is the validated creation that succeeded:
Set context to same as NSG subscription
Set-AzContext -Subscription ********-****-****-****-********9379
Create NSG flow log
New-AzNetworkWatcherFlowLog -Location eastus2euap -Name enabledtestfl -TargetResourceId "/subscriptions/********-****-****-****-********9379/resourceGroups/****test3/providers/Microsoft.Network/networkSecurityGroups/enabledCatetgoriesTest-nsg" -StorageId "/subscriptions/********-****-****-****-********5a16/resourceGroups/****test2/providers/Microsoft.Storage/storageAccounts/**********" -Enabled $true
Success message
ResourceGroupName Name Location ProvisioningState TargetResourceId TargetResourceGuid StorageId
----------------- ---- -------- ----------------- ---------------- ------------------ ---------
enabledtestfl eastus2euap Succeeded /subscriptions/********-****-****-****-********9379/resourceGroups/****test3/providers/Microsoft.Network/networkSecurityGroups/enabledCatetgoriesTest-nsg ********-****-****-****-********a963 /subscriptions/********-****…
Validation with failure:
Set context to different subscription other than NSG subscription, in this case we are using the subscription of storage account as an example
Set-AzContext -Subscription ********-****-****-****-********5a16
Create NSG flow log, notice the command is same as before, the only difference being the subscription context
New-AzNetworkWatcherFlowLog -Location eastus2euap -Name enabledtestfl -TargetResourceId "/subscriptions/********-****-****-****-********9379/resourceGroups/****test3/providers/Microsoft.Network/networkSecurityGroups/enabledCatetgoriesTest-nsg" -StorageId "/subscriptions/********-****-****-****-********5a16/resourceGroups/****test2/providers/Microsoft.Storage/storageAccounts/**********" -Enabled $true
Failure message
New-AzNetworkWatcherFlowLog: Operation returned an invalid status code 'BadRequest'
StatusCode: 400
ReasonPhrase:
ErrorCode: FlowLogTargetResourceIsInDifferentSubscription
ErrorMessage: Target resource /subscriptions/********-****-****-****-********9379/resourceGroups/****test3/providers/Microsoft.Network/networkSecurityGroups/enabledCatetgoriesTest-nsg should be in the same subscription as flow log resource ********-****-****-****-************.
Hi. I'm building CLI code to create our network as code, using cli as our default. Now, I have been struggeling all day to get it to work.
This is, we have a centralized storage and log analytics workspace in a separate subscription that we want to use for every NSG on the network.
Tis article from 2018 states that it is possible, it is if done using the portal. https://azure.microsoft.com/es-es/blog/new-azure-network-watcher-integrations-and-network-security-group-flow-logging-updates/
But, using CLI and az network watcher flow-log create it is not possible. Now I finally got this:
(FlowLogTargetResourceIsInDifferentSubscription) Target resource /subscriptions/123e3418-XXXXXXXXXX--XXXX-a1d9a0dc/resourceGroups/rg-dev-infra/providers/Microsoft.Network/networkSecurityGroups/nsg-vn-devtest-sn-internal-default should be in the same subscription as flow log resource d52ec4e6-XXXX-XXXXXXXXXX-cf3. Code: FlowLogTargetResourceIsInDifferentSubscription Message: Target resource /subscriptions/123e3418-XXXXXXXXXX--XXXX-a1d9a0dc/resourceGroups/rg-dev-infra/providers/Microsoft.Network/networkSecurityGroups/nsg-vn-devtest-sn-internal-default should be in the same subscription as flow log resource d52ec4e6-3349-XXXX-XXXXXXXXXX-cf3.
This totally contradicts what the article says and also what can be done using the portal.
The code I use: NSG_ID=$(az network nsg show --resource-group $RESOURCE_GROUP --name $NSG --query "id" --output tsv) FLOWLOG_STORAGE_ID=$(az storage account show --subscription $FLOWLOG_SUBSCRIPTION --resource-group $FLOWLOG_RESOURCE_GROUP --name $FLOWLOG_STORAGE --query "id" --output tsv) WORKSPACE_ID=$(az monitor log-analytics workspace show --subscription $FLOWLOG_SUBSCRIPTION --resource-group $FLOWLOG_RESOURCE_GROUP --workspace-name $FLOWLOG_WORKSPACE --query "id" --output tsv)
az network watcher flow-log create \ --location $LOCATION \ --name ${NSG}-flowlog \ --nsg $NSG_ID \ --subscription $FLOWLOG_SUBSCRIPTION \ --storage-account $FLOWLOG_STORAGE_ID --workspace $WORKSPACE_ID \ --log-version 2 \ --retention 30
Thanks // Thomas
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.