<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NSG &#8211; Haikos Blog</title>
	<atom:link href="https://www.hertes.net/tag/nsg/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.hertes.net</link>
	<description>Blog von Haiko Hertes zu allen Themen rund um Microsoft, Cloud und Datacenter</description>
	<lastBuildDate>Wed, 07 Feb 2024 14:18:42 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Mitglieder einer Azure Application Security Group auslesen</title>
		<link>https://www.hertes.net/2024/02/mitglieder-einer-azure-application-security-group-auslesen/</link>
					<comments>https://www.hertes.net/2024/02/mitglieder-einer-azure-application-security-group-auslesen/#respond</comments>
		
		<dc:creator><![CDATA[Haiko]]></dc:creator>
		<pubDate>Thu, 08 Feb 2024 06:30:00 +0000</pubDate>
				<category><![CDATA[Arbeit]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[KQL]]></category>
		<category><![CDATA[Network Security Group]]></category>
		<category><![CDATA[NSG]]></category>
		<category><![CDATA[Query]]></category>
		<category><![CDATA[Resource Graph]]></category>
		<guid isPermaLink="false">https://www.hertes.net/?p=4294</guid>

					<description><![CDATA[Immer wieder begegnet mir von Kunden die Frage, ob und wie man die Server, die Mitglieder einer Azure Application Security Group sind, auslesen kann. Im Portal selber müsste man dazu nämlich alles VMs einzelne abklappern. Und das geht natürlich auch einfacher per PowerShell: Das könnte man jetzt noch schöner machen &#8211; ist aber ohnehin keine wirklich gute Lösung, weil man hierzu alle Subscriptions &#8222;abklappern&#8220; müsste. Besser ist hier dann der Resource Graph geeignet: Die Query fragt alle NICs (und damit auch alle Private Endpoints, die ja auch eine ASG haben könnten) ab und bereitet die Daten dann noch etwas schöner&#8230;]]></description>
										<content:encoded><![CDATA[
<p>Immer wieder begegnet mir von Kunden die Frage, ob und wie man die Server, die Mitglieder einer Azure Application Security Group sind, auslesen kann. Im Portal selber müsste man dazu nämlich alles VMs einzelne abklappern.</p>



<p>Und das geht natürlich auch einfacher per PowerShell:</p>



<pre class="wp-block-code"><code>Get-AzNetworkInterface | Select-Object -Property Name, IpConfigurations | Select -Property Name,@{label="ASG";expression={$_.ipConfigurations.ApplicationSecurityGroupsText}} | Where ASG -ne "&#91;]" | fl *</code></pre>



<figure class="wp-block-image size-large"><a href="https://www.hertes.net/wp-content/uploads/2024/02/image.png"><img fetchpriority="high" decoding="async" width="1024" height="359" src="https://www.hertes.net/wp-content/uploads/2024/02/image-1024x359.png" alt="" class="wp-image-4295" srcset="https://www.hertes.net/wp-content/uploads/2024/02/image-1024x359.png 1024w, https://www.hertes.net/wp-content/uploads/2024/02/image-300x105.png 300w, https://www.hertes.net/wp-content/uploads/2024/02/image-768x269.png 768w, https://www.hertes.net/wp-content/uploads/2024/02/image-1536x538.png 1536w, https://www.hertes.net/wp-content/uploads/2024/02/image.png 1775w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Das könnte man jetzt noch schöner machen &#8211; ist aber ohnehin keine wirklich gute Lösung, weil man hierzu alle Subscriptions &#8222;abklappern&#8220; müsste. Besser ist hier dann der Resource Graph geeignet:</p>



<figure class="wp-block-image size-large"><a href="https://www.hertes.net/wp-content/uploads/2024/02/image-1.png"><img decoding="async" width="1024" height="359" src="https://www.hertes.net/wp-content/uploads/2024/02/image-1-1024x359.png" alt="" class="wp-image-4296" srcset="https://www.hertes.net/wp-content/uploads/2024/02/image-1-1024x359.png 1024w, https://www.hertes.net/wp-content/uploads/2024/02/image-1-300x105.png 300w, https://www.hertes.net/wp-content/uploads/2024/02/image-1-768x269.png 768w, https://www.hertes.net/wp-content/uploads/2024/02/image-1-1536x539.png 1536w, https://www.hertes.net/wp-content/uploads/2024/02/image-1.png 1845w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Die Query fragt alle NICs (und damit auch alle Private Endpoints, die ja auch eine ASG haben könnten) ab und bereitet die Daten dann noch etwas schöner auf. Das Ganze liefert in weniger als einer Sekunde die Informationen über alle Subscriptions! </p>



<p>Die dafür von mir geschriebene Query lautet:</p>



<pre class="wp-block-code"><code>resources<br>| where type =~ "microsoft.network/networkinterfaces"<br>| mv-expand properties.ipConfigurations<br>| mv-expand applicationSecurityGroupId=properties_ipConfigurations.properties.applicationSecurityGroups<br>| parse applicationSecurityGroupId with * "/applicationSecurityGroups/" applicationSecurityGroup '"' *<br>| extend vmId = properties.virtualMachine.id<br>| parse vmId with * "/virtualMachines/" vmName<br>| extend peId = properties.privateEndpoint.id<br>| parse peId with * "/privateEndpoints/" peName<br>| where isnotnull(applicationSecurityGroupId)<br>| extend endpointName = iff(isnotnull(vmId),vmName, peName)<br>| extend endpointId = iff(isnotnull(vmId),vmId, peId)<br>| extend endpointType = iff(isnotnull(vmId),"Virtual Machine","Private Endpoint")<br>| project applicationSecurityGroup,applicationSecurityGroupId=applicationSecurityGroupId.id,endpointName,endpointId,endpointType<br>| order by applicationSecurityGroup</code></pre>



<p>Optional kann man noch ein </p>



<pre class="wp-block-code"><code>| summarize make_list(endpointName) by tostring(applicationSecurityGroupId),applicationSecurityGroup</code></pre>



<p>anhängen, wenn man nicht mehr jede VM einzeln sehen will&#8230;</p>



<figure class="wp-block-image size-large"><a href="https://www.hertes.net/wp-content/uploads/2024/02/image-2.png"><img decoding="async" width="1024" height="129" src="https://www.hertes.net/wp-content/uploads/2024/02/image-2-1024x129.png" alt="" class="wp-image-4297" srcset="https://www.hertes.net/wp-content/uploads/2024/02/image-2-1024x129.png 1024w, https://www.hertes.net/wp-content/uploads/2024/02/image-2-300x38.png 300w, https://www.hertes.net/wp-content/uploads/2024/02/image-2-768x97.png 768w, https://www.hertes.net/wp-content/uploads/2024/02/image-2.png 1313w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure>



<p>Die Query findet ihr auch auf meinem GitHub Repository:</p>



<p><a href="https://github.com/HaikoHertes/scripts/blob/master/Azure/ResourceGraph/ApplicationSecurityGroupQuery.kql">scripts/Azure/ResourceGraph/ApplicationSecurityGroupQuery.kql at master · HaikoHertes/scripts (github.com)</a></p>



<p>Viel Spaß damit!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.hertes.net/2024/02/mitglieder-einer-azure-application-security-group-auslesen/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
