[{"content":"Not every project I work on can be made public, but that does not mean I cannot talk about what I learned or built. I wanted a simple way to share approved project descriptions and previews without copying source code or connecting the portfolio to private repositories.\nThe result is a React site built with Vite. It is a static catalog: the browser gets the project records and any approved media included in the portfolio build. There is no backend that reaches into the repositories behind the projects.\nProjects are content, not components Each project is a JSON file in src/content/projects/. A record holds the project title, summary, description, and service labels. Technologies, role, status, period, highlights, links, images, and video are optional. The site loads the records as data, so adding a project does not require writing a new React component.\nMedia, when appropriate, lives under public/media/ and is referenced by the record. Images need meaningful alternative text; video can include captions and a transcript. Before adding anything, I need to review descriptions, metadata, links, screenshots, and recordings for information I am allowed to share.\nBrowse the catalog, then open a project The catalog can be filtered by service and searched by project title, summary, service, or technology. Selecting a project opens a detail page with its description and, when provided, an image gallery or video preview. A sidebar presents metadata such as role, status, period, technologies, highlights, and links.\nProject links use a hash route, for example #/projects/example-service. That keeps navigation compatible with static hosting without requiring server-side rewrites. The trade-off is that search engines and social previews generally cannot treat each hash route as a separate page with its own metadata.\nBuild and publish the site Locally, I can validate the project records, run the tests, and build the static files with the npm scripts. A GitHub Actions workflow runs tests and builds changes; it uploads and deploys the site only for a default-branch push or a manual run targeting that branch. GitHub Pages must be configured to use Actions before the site can be published.\nThe key boundary is that the portfolio itself is public. Keeping a project\u0026rsquo;s source repository private does not make its portfolio entry private: descriptions, metadata, media, Git history, and files under public/ can all be exposed. The site does not connect to or fetch from those private repositories, so I can choose what to present—but I still need to review every item before committing it.\n","permalink":"https://www.errush.org/blogposts/how-my-portfolio-site-works/","summary":"\u003cp\u003eNot every project I work on can be made public, but that does not mean I cannot talk about what I learned or built. I wanted a simple way to share approved project descriptions and previews without copying source code or connecting the portfolio to private repositories.\u003c/p\u003e\n\u003cp\u003eThe result is a React site built with Vite. It is a static catalog: the browser gets the project records and any approved media included in the portfolio build. There is no backend that reaches into the repositories behind the projects.\u003c/p\u003e","title":"Creating a portifolio on GitHub actions for private prjects"},{"content":"In the early days of September 2025, Microsoft announced the general availability for their new v4 SKU family of the Azure App Service Plans. The new plan are based on the new v6 VMs that came GA earlier this year. The SKUs utilize new and better hardware that give big performance benefits. These new SKUs might help you realize some cost savings along the way.\nLike the previous generation of App Serivce Plans (v3), there are both general purpose and memory optimized SKUs. This gives the flexability to get a better right-sizing for your applications needs. The difference now, is that with the new underlying hardware, you will get a lower cost to performance. So, even though the cost is the same per core, you will get a better performance for those cores. This will highly likely result in the possiblity to down-size some plans to a lower SKU tier. For example, from a P3v3 to a P2v4.\nLet\u0026rsquo;s look at the table that Microsoft has released on how much of a difference in performance you might experience with the new v4 SKUs. Microsoft wrote the following about how they conducted the testing: \u0026ldquo;The team ran comparative load tests for Premium v4 and Premium v3 with a classic ASP.NET version of the devshop site that has been used in App Service labs and presentations over the last few years. The application is a simple classic ASP.NET site consisting of a few .aspx pages including a homepage, product category pages, and product detail pages. The site makes no external calls to databases or cache servers. [\u0026hellip;] Load tests were tuned to drive the underlying worker instance to around 80% CPU utilization, a value high enough to provide a good estimate of performance under load while still ensuring sufficient CPU headroom and not overloading the underlying VMs. All tests used a single instance app service plan.\u0026rdquo;\nAnd here are the results: As you can see, the tests show a significant difference in performance. Therefore, you should look at the new App Service Plan v4 SKU family to see if you can reduce you costs by scaling down while still keeping the performance levels that your application requires.\n","permalink":"https://www.errush.org/blogposts/new-asp-v4-ga/","summary":"\u003cp\u003eIn the early days of September 2025, Microsoft announced the general availability for their new v4 SKU family of the Azure App Service Plans. The new plan are based on the new v6 VMs that came GA earlier this year. The SKUs utilize new and better hardware that give big performance benefits. These new SKUs might help you realize some cost savings along the way.\u003c/p\u003e\n\u003cp\u003eLike the previous generation of App Serivce Plans (v3), there are both general purpose and memory optimized SKUs. This gives the flexability to get a better right-sizing for your applications needs. The difference now, is that with the new underlying hardware, you will get a lower cost to performance. So, even though the cost is the same per core, you will get a better performance for those cores. This will highly likely result in the possiblity to down-size some plans to a lower SKU tier. For example, from a P3v3 to a P2v4.\u003c/p\u003e","title":"New App Service Plan v4 SKUs go GA"},{"content":"Insight into your platform can be of huge benefit to both operations, developers and the security team, but logging to much can result in high costs. How can you optimize logging and monitoring to pay for only what you need. There are several ways to save on logging and some patterns and anti-patterns to be aware of to not overspend on logging. Let\u0026rsquo;s look at that now.\nBefore we start, I would like to thank Thomas Thornton and Joe Carlyle who are once again hosting the Azure Spring Clean! And don\u0026rsquo;t forget to check out the other amazing contributions to the community event over at the Azure Spring clean website.\nOne or many workspaces? The first question that you need to take into account when looking at optimizing your loggingstrategy is \u0026ldquo;Do I need all my logs in a central workspace?\u0026rdquo;. There are some benefits to having all your logs in one workspace, and it used to be a recommended best-practice from Microsoft in the Azure Landing zones reference architecture. Having a central workspace makes it easy to have a single pane of glass for all your logs from the whole platform. It was also recommended to use this workspace for Sentinel. There was one big backside to this; it was expensive. When you activate Sentinel on a workspace, you double the cost for ingesting logs. Now, you would get the first 90 days of retention for free, compared to the 30 days with a regular workspace, but luckily there are now other features that can help us keep the first 90 days of retention low, but we will get to that.\nSo you now pay double for ingesting all your logs into the central workspace with Sentinel activated, but at least you can now have your security team simply monitor and query all the logs from the platform. Thats good right? Well, are all Azure logs vital or even related to security? No. Metrics and application insights logs are some of the larger log tables we have and usually they don\u0026rsquo;t really matter for security.\nAnother topic is that for Sentinel, you usually want a longer retention for those logs. Sometimes it\u0026rsquo;s for regulatory reasons, other times for practicality. Do you don\u0026rsquo;t need more than 3 months of metrics from your app service or no need to keep those application exemptions from 6 months ago in your logs? The answer is probably not and therefore it might not be optimal to have all you logs in Sentinel.\nSo now I have given some arguments for why you should use more than 1 workspace, let\u0026rsquo;s have a look at the usual arguments that I have heard for why you should have 1 single workspace:\n\u0026ldquo;We need to have all our logs in the central workspace to break even on our commitment for ignestion per day\u0026rdquo;. This is a fair reason that I can see why someone would make, but it isn\u0026rsquo;t necessary to have all logs in the same workspace to have the commitment. There is something called a dedicated cluster in Azure monitor. A dedicated cluster is just a virtual cluster where you can link all your Log Analytics workspaces and have a single commitment for all the ingestion logs. I must emphesise that a dedicated cluster does not have a Pay-as-you-go pricing, so you should only create a dedicated cluster if you exceeed the break even point of the minimum ingestion commitment tier of 100GB (You need around 70GB ingested per day to break even) or if you need some of the enhanced features like for example encryption using Customer-managed keys or ingesting data directly from Event Hubs.\n\u0026ldquo;We need to join different tables in queries for non-security logs\u0026rdquo;. This used to be a very valid argument, but the product team at Microsoft has created a solution for this as well. You can now do queries cross workspaces. This means that your logs can be located in different workspaces and still be used in the same query. This will make it easier to pay less for ingestion by splitting logs into seperate workspaces and still query them together if you need to. Now, doing cross workspace queries can slow down more advanced KQL queries, but if you have the workspaces linked to a dedicated cluster, you will get better performance for cross workspace queries.\nSo, how many workspaces should you create? That depends! Like the annoying consultant I am, I won\u0026rsquo;t give you an exact number, because it can differ based on your specifications. Do you need granular access control? Probably need more of them to ensure that personel with needs still can access only what they need. Do you want to minimize management? Probably fewer. The only recommendation here is that you need more than 1.\nAnalyzing usage Right, let\u0026rsquo;s move into something more practical. You have a workspace that is costing you loads of money per month, how do you actually get insight into what logs are costing you the most. Here we need to look at some wueries that can help us. We will start to look at a log table called Usage. These logs are like the name implies, logs that tell us something about our usage and mostly ingestion. All logs in LAW have a column called \u0026quot;_IsBillable\u0026quot; and a _BilledSize\u0026quot;. Not all logs ingested into Log Analytics actually costs money and the logs have different sizes depending on the amount of data in them. If we use these logs we can get insight into what we are logging and what is costing us the most amount of money. Have a look at the query below:\nUsage | where StartTime \u0026gt;= startofday(ago(31d)) and EndTime \u0026lt;= startofday(now()) | where IsBillable == true | summarize BillableDataGB = sum(Quantity)/1000. by bin(StartTime, 1d), DataType | render columnchart This query will give a result that looks like this: Here, our usage is broken down into what table have sent how many GBs of data to workspace in the last month, broken down into per day. Getting insights into what tables generate the most logs, we can then drill down into those tables to see what types of logs and what resources send the most logs. Just like the _IsBillable and _BilledSize columns, all logs in Azure also have a column called _ResourceId. And using that column we can create queries to find out which resource have been sending the most logs to our workspace.\nUsing my example above, where there was a table called \u0026ldquo;AVSSyslog\u0026rdquo; that were sending data, I can use the following query to see who the guilty resource is:\nAVSSyslog | summarize count() by _ResourceId When you have the resource that is sending the most, you can dig down into them to find what type of logs and see if there is any way to optimize that logging.\nMove to resource-specific logs Most of the Azure resources have logs have historically used Azure diagnostics to send the logs into Log Analytics workspaces. The Azure diagnostics have therefore been it\u0026rsquo;s log table to make it easier for product teams to create a log schema for all resources. The negative side is that with a standardized schema is that it\u0026rsquo;s not always structured well and some teams have dumped loads of data into a single column. This have lead to the logs being larger than they needed to be. To combat this, Microsoft have created a new collection mode in Azure diagnostics called \u0026ldquo;Resource-specific logs\u0026rdquo;. These are part of a new strategy for all resources to have their own log tables in Log Analytics. By seperating logs into their own log tables, you can optimize each log table by having different retention periods, table-specific RBAC, different table plans and filter ingestion by using table transformation.\nIn addition to giving you more flexibility, some product teams like the Azure Firewall team can brag about reducing the billable size of the logs by 70%! And that is while also making the logs simpler to query and adding new fields with more data. Unfortunately, not all resources support resource-specific logs yet. You should out the documentation from Microsoft to get the newest list of supported log categories.\nFor the logs that you can move to resource-specific, we will now look at what other ways we can utilize them to lower costs even further.\nLog table plans As we have talked about already, not all logs are born equal. Not all logs are as important and therefore, Microsoft has made it possible to have different types of plans for the logs in Log Analytics. The default type is the \u0026ldquo;Analytics\u0026rdquo; logs. These logs are always available in hot storage and have all the features from KQL and Azure Monitor. As of writing this post, there are 2 more table plans with one of them being still in preview. You have the Basic and Auxilliary(preview) table plans. These plans are made for the \u0026ldquo;less important\u0026rdquo; logs. They have more limited features in Log Analytics, but are cheaper to ingest. On the other hand, these plans have a seperate price for actually querying the logs. Meaning like most storage tiers in Azure services, you can chose to have data not as frequently accessed on cheaper storage, but it will cost you to access it. Becuase of this, not all logs should be moved to Basic or Auxilliary table plans, and not all logs can either.\nMicrosoft have these recommendations for what type of data the different plans are best for:\nAnalytics: \u0026ldquo;High-value data used for continuous monitoring, real-time detection, and performance analytics.\u0026rdquo; Basic: \u0026ldquo;Medium-touch data needed for troubleshooting and incident response.\u0026rdquo; Auxilliary: \u0026ldquo;Low-touch data, such as verbose logs, and data required for auditing and compliance.\u0026rdquo; Checkout this link for a full comparison of limitations for the different plans.\nTable Transformation Lastly, we will look at table transformation. This is a feature we can use on some log tables to actually filter and change logs as they are being ingested. Meaning that we can lower the ingestion cost be filtering away logs with specific column values or remove a set of columns we don\u0026rsquo;t need. Again, this is a feature that is limited in supported log tables and therefore not possible to do with all logs. Here is a link to the newest information from Microsoft on supported tables.\nThese transformations rely on KQL to transform the data. Therefore, we will mostly use operators like where, project and project-away. to transform them. But it is also possible to use more advanced operators to create new columns or remove parts of data in a existing column. Today we will only look at filtering away data.\nBy using the where operator, we can select or select away logs that have a specific value. A good example here can be to filter away event logs from VMs that are informational. The Windows event log contain lots of logs and a majority of them are only for information. Therefore, it might be useful to filter them away to prevent them from filling up your workspace. Optionally, you can use the where operator to have an ignore list of certain type of logs. For example, ignoring specific Event IDs from VMs. To do this you can use the following KQL syntax | where column1 != \u0026quot;valueX\u0026quot;.\nAnother alternative is to use project or project-away to select which columns to ingest from the logs. The 2 operators are quite simple, with project you can select which columns you want to include and with project-away you select columns you want to remove. This can be a good way to remove columns that contain duplicate data or data that are not essential for your use.\nYou can transform the table ingestion by going to the tables setting on your log analytics workspace, there you need to find the table you want to transform and press the three dots all the way to the left to bring up the context menu. If the table supports transformations, you should be able to click the Create transformation option.\nHere you need to select or create a data collection rule that will be used to transform the logs. When you have done that, click the button to open the Transformation editor. This is where you can add your KQL operators to edit or filter away logs before they are ingested into your workspace.\nSummary Today we have looked at some ways to cost optimize your logging in Azure. Using this new knowledge, you should now be able to look into why your Log Analytics Workspace is expensive and how to reduce the cost. This was a fair bit longer post as this is a shorter summary of a talk I had some weeks ago. The plan is to have that talk again some time as it will be much better with more demos and more show than tell.\n","permalink":"https://www.errush.org/blogposts/cost-optimizing-azure-monitor/","summary":"\u003cp\u003eInsight into your platform can be of huge benefit to both operations, developers and the security team, but logging to much can result in high costs. How can you optimize logging and monitoring to pay for only what you need. There are several ways to save on logging and some patterns and anti-patterns to be aware of to not overspend on logging. Let\u0026rsquo;s look at that now.\u003c/p\u003e\n\u003cp\u003eBefore we start, I would like to thank Thomas Thornton and Joe Carlyle who are once again hosting the Azure Spring Clean! And don\u0026rsquo;t forget to check out the other amazing contributions to the community event over at the \u003ca href=\"https://azurespringclean.com/\"\u003eAzure Spring clean website.\u003c/a\u003e\u003c/p\u003e","title":"Cost Optimizing Azure Monitor"},{"content":"On the 31st of August 2024, Microsoft will deprecate the Log Analytics VM Agent. This change has been announced years ago, but still many are not prepared. How can you assess your environment and migrate to the Azure Monitor Agent before the agent will stop working. In this 2 part blog service, we will look at how you can find and migrate away from the Log Analytics Agent before the VM extension gets deprecated. In part 1 we will start by finding the affected VMs we will need to migrate.\nBefore we start, I would like to thank Thomas Thornton and Joe Carlyle that are hosting the Azure Spring Clean! And don\u0026rsquo;t forget to check out the other amazing contributions to the community event over at the Azure Spring clean website.\nAffected Services Even though it\u0026rsquo;s the Log Analytics agent that is deprecating, the impact is larger than just monitoring. There are several services that are dependent on the same agent. Here is a list of some of the services that are affected by this deprecation:\nSentinel Azure Automation Update Management Change Tracking/Inventory VM/AVD/Stack HCI Insights Defender for Cloud Network Watcher Container Monitoring Solution Azure Automation Agent-based Hybrid Worker A full list of migration recommendations for the services can be found here.\nOMS? MMA? AMA? WTF? Before we dive into finding the agents, we need to establish the possible versions of VM extension you can find. You will see 2, maybe all 3 different abbreviations for VM extensions that is used for monitoring. First you have the OMS Agent, or the \u0026ldquo;Operations Management Suite Agent for Linux\u0026rdquo; as it\u0026rsquo;s actually called. This is the legacy Log Analytics Agent for Linux VMs and this is one of the VM extensions that are deprecating. The other deprecating extension is the MMA, or Microsoft Monitoring Agent. This is the Log Analytics Agent for Windows. Lastly, we have the AMA. The AMA, or Azure Monitor Agent, is the new extension for both Linux and Windows VMs. Shortly summarized, OMS and MMA bad, AMA good!\nFinding affected VMs So this can be done in a few different ways. I\u0026rsquo;m going to show you 2 different ways with different use-cases. The first way is to find VMs with the agent installed that is sending data to a Log Analytics Workspace. This would require you to know which Log Analytics Workspace the VMs are connected to, and sometimes there can be suprises. The second way will show you all VMs that have the Agent installed. With these 2 ways combined, you will know where you should look closer to prevent any services breaking on the 1st of September.\nLog Analytics query To start, we will use a simple Log Analytics KQL query to find all VMs sending data to a specific workspace using the legacy agent. The query is as simple as this:\nHeartbeat | where Category == \u0026#34;Direct Agent\u0026#34; | summarize by Computer And the result will be just as simple: The query looks for logs in the Heartbeat table that have the Category Direct Agent. The heartbeat table is a log table that is used by the agent to give it\u0026rsquo;s health status. We then use the summarize function to give us a list of only the names of the VMs sending logs to the workspace.\nDefender for Cloud and Resource Graph Queries So this might sound a bit weird, but we can actually find the agents installed in Defender for Cloud. Let me explain, since Defender for Cloud use the Log Analytics Agent, it will give you the recommendation to install it, and it will show you which VMs have the agent installed and which doesn\u0026rsquo;t. We can use this to our advantage. Either you can go into the Defender for Cloud view in the Azure portal and look through the recommendations, but the GUI can be a bit annoying with a lot of scrolling and clicks to get where you need to so you see all VMs with the agent installed. Instead, you can go into the Resource Graph Explorer and paste this query to get the same results:\nsecurityresources | where type == \u0026#34;microsoft.security/assessments\u0026#34; | extend source = trim(\u0026#39; \u0026#39;, tolower(tostring(properties.resourceDetails.Source))) | extend resourceId = trim(\u0026#39; \u0026#39;, tolower(tostring(case( source =~ \u0026#34;azure\u0026#34;, properties.resourceDetails.Id, source =~ \u0026#34;aws\u0026#34; and isnotempty(tostring(properties.resourceDetails.ConnectorId)), properties.resourceDetails.Id, source =~ \u0026#34;gcp\u0026#34; and isnotempty(tostring(properties.resourceDetails.ConnectorId)), properties.resourceDetails.Id, source =~ \u0026#39;aws\u0026#39;, properties.resourceDetails.AzureResourceId, source =~ \u0026#39;gcp\u0026#39;, properties.resourceDetails.AzureResourceId, extract(\u0026#39;^(.+)/providers/Microsoft.Security/assessments/.+$\u0026#39;,1,id) )))) | extend status = trim(\u0026#34; \u0026#34;, tostring(properties.status.code)) | extend cause = trim(\u0026#34; \u0026#34;, tostring(properties.status.cause)) | extend assessmentKey = tostring(name) | where assessmentKey == \u0026#34;d1db3318-01ff-16de-29eb-28b344515626\u0026#34; and status == \u0026#34;Healthy\u0026#34; | extend vmName=split(resourceId,\u0026#34;/\u0026#34;)[-1] | project vmName,resourceGroup,subscriptionId This will give us this nice little list of which VMs have the agent installed: Wrap-up With these two queries, you can find both which VMs are connected to a specific workspace with the legacy agent and all VMs that have the extension installed. In the upcoming part 2 of this blogpost, we will look at what you need to do to migrate over to the Azure Monitor Agent. Thanks again to Thomas and Joe for hosting the Azure Spring Clean this year as well!\n","permalink":"https://www.errush.org/blogposts/log-analytics-agent-deprecation/","summary":"\u003cp\u003eOn the 31st of August 2024, Microsoft will deprecate the Log Analytics VM Agent. This change has been announced years ago, but still many are not prepared. How can you assess your environment and migrate to the Azure Monitor Agent before the agent will stop working. In this 2 part blog service, we will look at how you can find and migrate away from the Log Analytics Agent before the VM extension gets deprecated. In part 1 we will start by finding the affected VMs we will need to migrate.\u003c/p\u003e","title":"Log Analytics Agent deprecation - Prepare for the end"},{"content":"This blogpost is posted in correlation with the Festive Tech Calendar. Festive Tech Calendar is a community event that goes on through the whole of December. The event is raising donations for the Raspberry PI Foundation. The Raspberry PI Foundation is a charity that help children learn to code. Please checkout the Just Giving page and the Festive Tech Calendar.\nSanta\u0026rsquo;s workshop has changed immensely the last 10 years. With kids wanting iPhones, PlayStations or the newest Fortnite battle pass. To adopt to this, half of the elves now work as developers from home, writing code for new cool games and digital toys. In the year 2023, AI is on the rise and Santa wants to capitalize on the hype and produce new cool toys using AI. To innovate new toys, the elves has gotten their own Azure Sandbox subscriptions to play around with the new services.\nAfter 1 month, Santa realised that these AI services were a lot more expensive than he had anticipated. With the economy in recession, Santa needs to be careful with not overspending on development. To prevent the elves from using more than their projects allocated budget, Santa use Azure Cost Management to call automation for cleaning up the sandboxes.\nSo Santa\u0026rsquo;s solution is divided into 2 parts. He has created a budget and an action group that calls an Automation Account that runs a PowerShell script that deletes all resources in the sandbox subscription.\nImportant This demo of a PowerShell script will delete resources! Be very careful if you want to run it in your own environment. Please be sure that you understand and limit the damage it may cause.\nThis demo would require 2 different Azure subscriptions. 1 subscription that hosts the Automation Account and 1 subscription that will have all it\u0026rsquo;s content deleted. A subscription in it self is free and therefore you shouldn\u0026rsquo;t be afraid that cost will increase just because you need 2.\nThe Automation Account Let\u0026rsquo;s start by looking at the Automation Account and the PowerShell script. The Automation Account is placed in a seperate Azure subscription. A management subscription if you like. The Automation Account uses a system-assigned managed identity that has the role Contributor on the sandbox subscription. The Runbbok for the script is using PowerShell 7.1 and I have created a webhook so that we can call it from a action group. But don\u0026rsquo;t think about that, you can set the webhook up when you configure the action group for the budget.\nThe PowerShell script it self is using a logic that I found in a cleanup script in the Azure Bicep CARML GitHub repo. The script is what Microsoft uses in CARML to cleanup resources that are deployed during moudle validation. The script is simple enough, it collects all resources and loops through all of them. It looks through what type the resource is and uses a switch to do special delete actions if they are needed. The default action of the switch is to just delete the resource. This script will only work with a single subscription. If you want to use it for potentially cleanup of several subscriptions based on which has a breached budget, you can use parameters and activate the common alert schema that can feed the info about which subscription has exceeded it\u0026rsquo;s budget.\n## set variables $resources = @() ## Auth Connect-AzAccount -Identity ## Delete resources $resources = get-azresources foreach ($resource in $resources) { $type = $resource.type $ResourceId = $resource.Id switch ($type) { \u0026#39;Microsoft.Insights/diagnosticSettings\u0026#39; { $parentResourceId = $ResourceId.Split(\u0026#39;/providers/{0}\u0026#39; -f $Type)[0] $resourceName = Split-Path $ResourceId -Leaf Remove-AzDiagnosticSetting -ResourceId $parentResourceId -Name $resourceName break } \u0026#39;Microsoft.Authorization/locks\u0026#39; { ## Skipping locks break } \u0026#39;Microsoft.Consumption/budgets\u0026#39; { ## Not deleting budgets break } \u0026#39;Microsoft.Insights/actionGroups\u0026#39; { ## Not deleting Action Group used by budget automation break } \u0026#39;Microsoft.KeyVault/vaults/keys\u0026#39; { $resourceName = Split-Path $ResourceId -Leaf Write-Verbose (\u0026#39;[/] Skipping resource [{0}] of type [{1}]. Reason: It is handled by different logic.\u0026#39; -f $resourceName, $Type) -Verbose # Also, we don\u0026#39;t want to accidently remove keys of the dependency key vault break } \u0026#39;Microsoft.KeyVault/vaults/accessPolicies\u0026#39; { $resourceName = Split-Path $ResourceId -Leaf Write-Verbose (\u0026#39;[/] Skipping resource [{0}] of type [{1}]. Reason: It is handled by different logic.\u0026#39; -f $resourceName, $Type) -Verbose break } \u0026#39;Microsoft.ServiceBus/namespaces/authorizationRules\u0026#39; { if ((Split-Path $ResourceId \u0026#39;/\u0026#39;)[-1] -eq \u0026#39;RootManageSharedAccessKey\u0026#39;) { Write-Verbose (\u0026#39;[/] Skipping resource [RootManageSharedAccessKey] of type [{0}]. Reason: The Service Bus\u0026#39;\u0026#39;s default authorization key cannot be removed\u0026#39; -f $Type) -Verbose } else { Remove-AzResource -ResourceId $ResourceId -Force -ErrorAction \u0026#39;Stop\u0026#39; } break } \u0026#39;Microsoft.Compute/diskEncryptionSets\u0026#39; { # Pre-Removal # ----------- # Remove access policies on key vault $resourceGroupName = $ResourceId.Split(\u0026#39;/\u0026#39;)[4] $resourceName = Split-Path $ResourceId -Leaf $diskEncryptionSet = Get-AzDiskEncryptionSet -Name $resourceName -ResourceGroupName $resourceGroupName $keyVaultResourceId = $diskEncryptionSet.ActiveKey.SourceVault.Id $keyVaultName = Split-Path $keyVaultResourceId -Leaf $objectId = $diskEncryptionSet.Identity.PrincipalId Remove-AzKeyVaultAccessPolicy -VaultName $keyVaultName -ObjectId $objectId # Actual removal # -------------- Remove-AzResource -ResourceId $ResourceId -Force -ErrorAction \u0026#39;Stop\u0026#39; break } \u0026#39;Microsoft.RecoveryServices/vaults/backupstorageconfig\u0026#39; { # Not a \u0026#39;resource\u0026#39; that can be removed, but represents settings on the RSV. The config is deleted with the RSV break } \u0026#39;Microsoft.Authorization/roleAssignments\u0026#39; { ## Don\u0026#39;t want to remove roleAssignments break } \u0026#39;Microsoft.RecoveryServices/vaults\u0026#39; { # Pre-Removal # ----------- # Remove protected VMs if ((Get-AzRecoveryServicesVaultProperty -VaultId $ResourceId).SoftDeleteFeatureState -ne \u0026#39;Disabled\u0026#39;) { Set-AzRecoveryServicesVaultProperty -VaultId $ResourceId -SoftDeleteFeatureState \u0026#39;Disable\u0026#39; } $backupItems = Get-AzRecoveryServicesBackupItem -BackupManagementType \u0026#39;AzureVM\u0026#39; -WorkloadType \u0026#39;AzureVM\u0026#39; -VaultId $ResourceId foreach ($backupItem in $backupItems) { Write-Verbose (\u0026#39;Removing Backup item [{0}] from RSV [{1}]\u0026#39; -f $backupItem.Name, $ResourceId) -Verbose Disable-AzRecoveryServicesBackupProtection -Item $backupItem -VaultId $ResourceId -RemoveRecoveryPoints -Force } # Actual removal # -------------- Remove-AzResource -ResourceId $ResourceId -Force -ErrorAction \u0026#39;Stop\u0026#39; break } \u0026#39;Microsoft.OperationalInsights/workspaces\u0026#39; { $resourceGroupName = $ResourceId.Split(\u0026#39;/\u0026#39;)[4] $resourceName = Split-Path $ResourceId -Leaf # Force delete workspace (cannot be recovered) Write-Verbose (\u0026#39;[*] Purging resource [{0}] of type [{1}]\u0026#39; -f $resourceName, $Type) -Verbose Remove-AzOperationalInsightsWorkspace -ResourceGroupName $resourceGroupName -Name $resourceName -Force -ForceDelete break } \u0026#39;Microsoft.MachineLearningServices/workspaces\u0026#39; { $subscriptionId = $ResourceId.Split(\u0026#39;/\u0026#39;)[2] $resourceGroupName = $ResourceId.Split(\u0026#39;/\u0026#39;)[4] $resourceName = Split-Path $ResourceId -Leaf # Purge service $purgePath = \u0026#39;/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.MachineLearningServices/workspaces/{2}?api-version=2023-06-01-preview\u0026amp;forceToPurge=true\u0026#39; -f $subscriptionId, $resourceGroupName, $resourceName $purgeRequestInputObject = @{ Method = \u0026#39;DELETE\u0026#39; Path = $purgePath } Write-Verbose (\u0026#39;[*] Purging resource [{0}] of type [{1}]\u0026#39; -f $resourceName, $Type) -Verbose $purgeResource = Invoke-AzRestMethod @purgeRequestInputObject if ($purgeResource.StatusCode -notlike \u0026#39;2*\u0026#39;) { $responseContent = $purgeResource.Content | ConvertFrom-Json throw (\u0026#39;{0} : {1}\u0026#39; -f $responseContent.error.code, $responseContent.error.message) } # Wait for workspace to be purged. If it is not purged it has a chance of being soft-deleted via RG deletion (not purged) # The consecutive deployments will fail because it is not purged. $retryCount = 0 $retryLimit = 240 $retryInterval = 15 do { $retryCount++ if ($retryCount -ge $retryLimit) { Write-Warning (\u0026#39; [!] Workspace [{0}] was not purged after {1} seconds. Continuing with resource removal.\u0026#39; -f $resourceName, ($retryCount * $retryInterval)) break } Write-Verbose (\u0026#39; [⏱️] Waiting {0} seconds for workspace to be purged.\u0026#39; -f $retryInterval) -Verbose Start-Sleep -Seconds $retryInterval $workspace = Get-AzMLWorkspace -Name $resourceName -ResourceGroupName $resourceGroupName -SubscriptionId $subscriptionId -ErrorAction SilentlyContinue $workspaceExists = $workspace.count -gt 0 } while ($workspaceExists) break } Default { Remove-AzResource -ResourceId $ResourceId -Force -ErrorAction \u0026#39;Stop\u0026#39; } } } Budget setup Now, on to the budget that we have created to trigger the runbook with the PowerShell script. First we will add a simple budget for 500NOK: In the Set alerts tab we will set that when the actual cost of the subscription exeeds 100% of the configured budget, it will trigger the action group DeleteResources. This action group is calling the webhook of the runbook. To create the action group click the \u0026ldquo;manage action group\u0026rdquo; link right under alert conditions. Create a new action group and give it the basic info such as subscription, resource group and a name. Notice that the Action group need to be in the same subscription as the budget is being configured for. Therefore, I have added functionallity to the script that it should skip action groups. In the Actions tab, chose that the desired action is to run an Azure Automation Runbook. In the dropdown menus that appear in the window, find and chose your Automation Account and Runbook. This will create the webhook that it needs to run the script on demand. That\u0026rsquo;s how simple it is to clean up resources as a budget action. Hopefully this will help Santa to not overspend on the sandbox environments that he has setup for his elves. Again, don\u0026rsquo;t forget to checkout Festive Tech Calendar to see all the awsome content that is being published throughout the whole of December!\n","permalink":"https://www.errush.org/blogposts/santas-magic-cost-management-automation/","summary":"\u003cp\u003eThis blogpost is posted in correlation with the Festive Tech Calendar. Festive Tech Calendar is a community event that goes on through the whole of December. The event is raising donations for the Raspberry PI Foundation. The Raspberry PI Foundation is a charity that help children learn to code. Please checkout the \u003ca href=\"https://www.justgiving.com/page/festive-tech-calendar-2023\"\u003eJust Giving page\u003c/a\u003e and the \u003ca href=\"https://festivetechcalendar.com/\"\u003eFestive Tech Calendar\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eSanta\u0026rsquo;s workshop has changed immensely the last 10 years. With kids wanting iPhones, PlayStations or the newest Fortnite battle pass. To adopt to this, half of the elves now work as developers from home, writing code for new cool games and digital toys. In the year 2023, AI is on the rise and Santa wants to capitalize on the hype and produce new cool toys using AI. To innovate new toys, the elves has gotten their own Azure Sandbox subscriptions to play around with the new services.\u003c/p\u003e","title":"Santa´s Magic Cost Management Automation"},{"content":"Most of the common Azure cost optimizations are quick-fixes. These could include Public IPs that have been forgotten, VM Snapshots that have been lying around for too long or VMs that are stopped, but not deallocated. To have good cost hygiene in your environment, you could automate this using Azure Automation. In this article, I will show you how to automate common cost optimizations. Please check out Azure Back to School for more good content from the Azure Community\nNote: Scripts used in this blogpost will delete resources. Be careful that you understand the consequences of running this in your own environment.\nSecure your environment from accidental deletion Before we get into looking at the script for cleaning up some cost wasting, let\u0026rsquo;s start by talking how we prevent the script from deleting resources that it shouldn\u0026rsquo;t.\nResource locks First, if you haven\u0026rsquo;t secured your production environment with resource locks, this would be a good place to start! Resource locks can be in 2 different modes. Read-Only and Delete. They are quite self explainatory, but Read-Only will prevent you from doing any changes to the resource and Delete will only prevent anyone from deleting a resource, either by accident or with bad intentions. Note that this will note make you 100% secure from someone with bad intentions deleting your production environment, but it will make it harder as they would need Owner role on the resource to remove the lock first.\nYou can find resource locks on both subscriptions, resource groups and on the resources themselves.\nReducing the blast radius For the script we will use Azure Automation with a connected Managed Identity. This Managed Identity will require access to the resources that it is going to check and possible delete. To prevent the script from deleting something it shouldn\u0026rsquo;t, we can use least-privilige access to give the Managed Identity access to only resources that we want it to delete. And more importantly, don\u0026rsquo;t give it access to critical resources that you don\u0026rsquo;t want it to touch at all. This will be easier if you have good segregation of services in your environment, either by resource groups, subscriptions or management groups. Try to keep the access of the Managed Identity at the lowest point possible where the script will still be possible to use and access control is managable.\nExclusion tags Last point for preventing the script from deleting something it shouldn\u0026rsquo;t is to use the exclusion tag. Tags can be put both on specific resources that you want the script to skip, or you can put it on resource group or subscriptions and force inheritence of the tag down to resources. The script will check the resources for the tag, so it will not be enough to just tag a resource group without inheritence. The exclusion tag should also be used for prevention of deleting resources that are false-positive in the checks. An example of this is a public IP that is used by a NAT gateway. Since the NAT gateway isn\u0026rsquo;t directly connecting the public IP to it\u0026rsquo;s network interface, it will look like the public IP is not connected to any resource.\nTo enforce either inheritence or creation of the exclusion tag, I would recommend to use Azure Policy. For inheritence I would recommend either \u0026ldquo;Inherit a tag from the resource group\u0026rdquo; or \u0026ldquo;Inherit a tag from the subscription\u0026rdquo; and for require the creation of the tag I would recommend the \u0026ldquo;Require a tag on resources\u0026rdquo;-policy. For all these policices, you only need to define the name of the tag. For this demo, I have named the exclusion tag \u0026ldquo;ExcludeCostOptimization\u0026rdquo;, but it is defined in a variable in the top of the script so you can change the name of the tag to what ever you need.\nSetting up the Automation Account Let\u0026rsquo;s start by creating an Automation Account. If you are creating the account through the portal, you should be fine with using the default settings and clicking next, next, create. If you are depolying the Automation Account through code, the only thing you need to add in addition to the required properties is the managed identity. Here is what I am using with Bicep to deploy the Automation Account:\nparam location string = resourceGroup().location resource automationAccount \u0026#39;Microsoft.Automation/automationAccounts@2019-06-01\u0026#39; = { name: \u0026#39;CostOptimizationAutomation\u0026#39; location: location identity: { type: \u0026#39;SystemAssigned\u0026#39; } properties: { sku: { name: \u0026#39;Free\u0026#39; } } } Now that you have created the Automation Account, you need to add the role assignment. This is now possible directly from the Automation Account blade, under Identity.\nIn the Azure role assignments window you can both see roles that the Managed Identity has and you can also add new roles directly. Note that adding roles from this blade is currently in preview and may not work 100% of the time.\nAs you can see, I\u0026rsquo;m not following my own recommendation for least-privilege and that is because this is a demo and the subscription I\u0026rsquo;m giving the Managed Identity access to is my Dev subscription.\nFor least-privilige I would recommend these built in roles:\nDisk Snapshot Contributor Desktop Virtualization Power On Off Contributor Network Contributor Or, even better, create a custom role that has only these permissions, as this is all the script needs:\n\u0026ldquo;Microsoft.Compute/virtualMachines/read\u0026rdquo; \u0026ldquo;Microsoft.Compute/virtualMachines/deallocate/action\u0026rdquo; \u0026ldquo;Microsoft.Compute/snapshots/delete\u0026rdquo; \u0026ldquo;Microsoft.Compute/snapshots/read\u0026rdquo; \u0026ldquo;Microsoft.Network/publicIPAdresses/read\u0026rdquo; \u0026ldquo;Microsoft.Network/publicIPAdresses/delete\u0026rdquo; The Script As mentioned, the script checks for 3 things. Public IP addresses that is not connected to any resource, snapshots older than 60 days, and VMs that are stopped but not deallocated.\nAll you have to do is to create a Runbook, paste in the script and connect it to a schedule so that it will run regurarly when you need it to. Note: This script is only tested on Powershell 5.1\n$exclusiontag = \u0026#34;ExcludeCostOptimization\u0026#34; Connect-AzAccount -Identity $subscriptions = Get-AzSubscription foreach($subscription in $subscriptions) { $pips = Get-AzResource -Tag @{$exclusiontag=\u0026#34;false\u0026#34;} -Resourcetype \u0026#34;Microsoft.Network/publicIPAddresses\u0026#34; foreach($pip in $pips){ get-azpublicIPAddress -name $pip.name | Where-Object IpConfiguration -eq $null | Remove-AzPublicIpAddress -Force } $snapshots = Get-AzResource -Tag @{$exclusiontag=\u0026#34;false\u0026#34;} -Resourcetype \u0026#34;Microsoft.Compute/Snapshots\u0026#34; $date = (Get-Date).AddDays(-60) foreach($snapshot in $snapshots) { Get-AzSnapshot -SnapshotName $snapshot.name | Where-Object { $_.TimeCreated -lt $date } | Remove-AzSnapshot -Force } $vms = Get-AzResource -Tag @{$exclusiontag=\u0026#34;false\u0026#34;} -Resourcetype \u0026#34;Microsoft.Compute/VirtualMachines\u0026#34; foreach($vm in $vms) { get-azvm -Status -Name $vm.Name | Where-Object PowerState -eq \u0026#34;VM stopped\u0026#34; | Stop-AzVM -Force } } ","permalink":"https://www.errush.org/blogposts/azurebacktoschool23/","summary":"\u003cp\u003eMost of the common Azure cost optimizations are quick-fixes. These could include Public IPs that have been forgotten, VM Snapshots that have been lying around for too long or VMs that are stopped, but not deallocated. To have good cost hygiene in your environment, you could automate this using Azure Automation. In this article, I will show you how to automate common cost optimizations. Please check out \u003ca href=\"https://azurebacktoschool.github.io/\"\u003eAzure Back to School\u003c/a\u003e for more good content from the Azure Community\u003c/p\u003e","title":"Automate common cost optimizations"},{"content":"Here is a collection of snippets of code used in the \u0026ldquo;Cost Optimization in the wild! - Experiences from reducing costs\u0026rdquo; presentation. If you are missing any snippets of code used in a demo, or if you have any other question, feel free to message me on Twitter or LinkedIn.\nOrphaned disks Old Snapshots App Gateways and Load Balancers Storage v1 App Service Plans Orphaned disks KQL to find disks resources | where type == \u0026#34;microsoft.compute/disks\u0026#34; and properties.managedBy == \u0026#34;\u0026#34; | where not(name endswith \u0026#34;-ASRReplica\u0026#34; or name startswith \u0026#34;ms-asr-\u0026#34; or name startswith \u0026#34;asrseeddisk-\u0026#34;) | project name,location,resourceGroup,subscriptionId,DiskSku=sku.tier,DiskSize=properties.diskSizeGB Old Snapshots KQL to find Old Snapshots resources | where type == \u0026#34;microsoft.compute/snapshots\u0026#34; | where properties.timeCreated \u0026lt;= ago(60d) | project name,location,resourceGroup,subscriptionId,diskSizeGB=properties.diskSizeGB,SKU=sku.name,Timecreated=properties.timeCreated Logic app to notify about Old snapshots { \u0026#34;definition\u0026#34;: { \u0026#34;$schema\u0026#34;: \u0026#34;https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#\u0026#34;, \u0026#34;actions\u0026#34;: { \u0026#34;HTTP_2\u0026#34;: { \u0026#34;inputs\u0026#34;: { \u0026#34;authentication\u0026#34;: { \u0026#34;type\u0026#34;: \u0026#34;ManagedServiceIdentity\u0026#34; }, \u0026#34;body\u0026#34;: { \u0026#34;query\u0026#34;: \u0026#34;resources | where type == \u0026#39;microsoft.compute/snapshots\u0026#39; | where properties.timeCreated \u0026gt;= ago(60d) | project name,location,resourceGroup,subscriptionId,diskSizeGB=properties.diskSizeGB,SKU=sku.name,Timecreated=properties.timeCreated\u0026#34; }, \u0026#34;headers\u0026#34;: { \u0026#34;Content-Type\u0026#34;: \u0026#34;application/json\u0026#34; }, \u0026#34;method\u0026#34;: \u0026#34;POST\u0026#34;, \u0026#34;queries\u0026#34;: { \u0026#34;api-version\u0026#34;: \u0026#34;2021-03-01\u0026#34; }, \u0026#34;uri\u0026#34;: \u0026#34;https://management.azure.com/providers/Microsoft.ResourceGraph/resources\u0026#34; }, \u0026#34;runAfter\u0026#34;: {}, \u0026#34;type\u0026#34;: \u0026#34;Http\u0026#34; } }, \u0026#34;contentVersion\u0026#34;: \u0026#34;1.0.0.0\u0026#34;, \u0026#34;outputs\u0026#34;: {}, \u0026#34;parameters\u0026#34;: {}, \u0026#34;triggers\u0026#34;: { \u0026#34;Recurrence\u0026#34;: { \u0026#34;evaluatedRecurrence\u0026#34;: { \u0026#34;frequency\u0026#34;: \u0026#34;Week\u0026#34;, \u0026#34;interval\u0026#34;: 1 }, \u0026#34;recurrence\u0026#34;: { \u0026#34;frequency\u0026#34;: \u0026#34;Week\u0026#34;, \u0026#34;interval\u0026#34;: 1 }, \u0026#34;type\u0026#34;: \u0026#34;Recurrence\u0026#34; } } }, \u0026#34;parameters\u0026#34;: {} } Load Balancers and App GW KQL to find App Gateways without backend pools resources | where type == \u0026#34;microsoft.network/applicationgateways\u0026#34; | extend backendpool=parse_json(properties.backendAddressPools) | mv-expand backendpool | where backendpool.[\u0026#39;properties.backendAddresses\u0026#39;] == \u0026#34;\u0026#34; | project name,location,resourceGroup,subscriptionId,sku=properties.sku.name KQL to find Load Balancers without backend pools resources | where type == \u0026#34;microsoft.network/loadbalancers\u0026#34; and properties.backendAddressPools == \u0026#34;[]\u0026#34; | extend pipId=parse_json(properties.frontendIPConfigurations[0].properties.publicIPAddress.id) | project name,location,resourceGroup,subscriptionId,sku=sku.name,pipId Storage v1 KQL to find Storage accounts with storage v1 resources | where type == \u0026#34;microsoft.storage/storageaccounts\u0026#34; and [\u0026#39;kind\u0026#39;] == \u0026#34;Storage\u0026#34; | project name,location,resourceGroup,subscriptionId,kind Azure Policy to block storage v1 \u0026#34;policyRule\u0026#34;: { \u0026#34;if\u0026#34;: { \u0026#34;allOf\u0026#34;: [ { \u0026#34;field\u0026#34;: \u0026#34;type\u0026#34;, \u0026#34;equals\u0026#34;: \u0026#34;Microsoft.Storage/storageAccounts\u0026#34; }, { \u0026#34;field\u0026#34;: \u0026#34;kind\u0026#34;, \u0026#34;equals\u0026#34;: \u0026#34;Storage\u0026#34; } ] }, \u0026#34;then\u0026#34;: { \u0026#34;effect\u0026#34;: \u0026#34;deny\u0026#34; } } App service plans KQL to find App Service Plans without apps resources | where type == \u0026#34;microsoft.web/serverfarms\u0026#34; and properties.kind != \u0026#34;functionapp\u0026#34; and properties.numberOfSites == 0 | project name,resourceGroup,location,subscriptionId,SKU=sku.name,kind PowerShell to find stopped web apps $stoppedWAs = Get-AzWebApp | Where-Object {($_.State -EQ \u0026#34;Stopped\u0026#34;) -and ($_.Kind -ne \u0026#34;functionapp\u0026#34;)} foreach($stoppedWA in $stoppedWAs) { $stoppedWAASP = Get-azappserviceplan | Where-Object Id -EQ $stoppedWA.ServerFarmId } ","permalink":"https://www.errush.org/blogposts/cost-optmization-in-the-wild/","summary":"Code snippets from the Cost Optimization in the Wild presentation, covering Azure Resource Graph and cloud cost optimization.","title":"Cost Optmization in the Wild"},{"content":"In Microsoft\u0026rsquo;s Well-Architected Framework there is a pillar for Cost Optimization. Some of the principals for optimizing cost are to continuously look for and clean up orphaned resources like disks and public IPs. In this blog I will show you some KQL queries that will help you find these resources and considerations you should take before cleaning them up. You can then use these queries in an Azure Workbook or dashboard to continuously review your environment. Before I start, I would like to thank Thomas Thornton and Joe Carlyle for organizing the Azure Spring Clean. Please go check out the awesome content that other people in the community have created for the event!\nAzure Well-Architected Framework The Azure Well-Architected Framework is a framework from Microsoft that gives guidance on some key pillars. These pillars are Reliability, Security, Cost, Operational Excellence, and Performance Efficiency. These are also the pillars that you can find recommendations on in Azure Advisor. The framework will give you guidance, checklists, and recommendations on best practices when designing, managing, monitoring, and optimizing Azure Resources.\nIf you have ever done an Azure Well-Architected Review on the Cost pillar, which is an assessment/questionnaire from Microsoft that gives you recommendations on improvements on a specific pillar from WAF, you might have seen a recommendation called \u0026ldquo;Look for Public IPs and orphaned NICs\u0026rdquo;. This recommendation is action is categorized by Microsoft as Critical. And in my experience with helping customers reduce their Azure cost, cleaning up orphaned resources can give a significant cut in cost. In addition to Public IPs and NICs, I will show you some KQL queries that will help you find orphaned disks and load balancers without backend pools.\nHow do resources become orphaned? An orphaned resource is a resource that no longer is connected to another required resource. An example could be a disk that is not connected to a VM or a Public IP not connected to a NIC. These resources are very likely to not being used, but like many Azure resources, they can still have a cost. By cleaning up orphaned resources, you could optimize your Azure cost. Remember, it\u0026rsquo;s not \u0026ldquo;pay for what you use\u0026rdquo;, it\u0026rsquo;s \u0026ldquo;Pay-As-You-Go\u0026rdquo;.\nBut how do these resources become orphaned? If you started working with Azure before the summer of 2022, you might know that it used to be that Azure did not ask if you wanted to delete the connected disks, public IPs and NICs when deleting a VM. This meant that you would need to manually delete all the resources connected to a VM, and this can be error prone. Because of this, a lot of customers are not aware that they have orphaned resources. Let\u0026rsquo;s have a look on how to find them.\nPublic IPs and disks We will start with some simple ones, Public IPs and Disks. To find these resources, we will use the Azure Resource Graph Explorer to create some KQL queries. All the queries will be to the Resources table and all the result will be formatted to get links and friendly names for resource groups and subscriptions. For Public IPs we will look for public IPs where the property \u0026ldquo;ipConfigurations\u0026rdquo; is empty. This will usually indicate that the resource is orphaned. An exemption for this is if the IP is used by a NAT gateway, so remember to double check resources before deleting them! The query for Public IPs looks like this:\nresources | where type == \u0026#34;microsoft.network/publicipaddresses\u0026#34; | where properties[\u0026#39;ipConfiguration\u0026#39;] == \u0026#34;\u0026#34; | project name,location,resourceGroup,subscriptionId,sku.name And will give a result like this: So, we select the Name, Location, Resource group, Subscription, and SKU name. We chose to show the SKU of the public IP because it is only Standard SKU public IP that have a cost when it\u0026rsquo;s not connected to a resource. Basic SKU IPs will not generate a cost when orphaned.\nOn to disks! Here we are looking for disks where the property \u0026ldquo;managedBy\u0026rdquo; is empty. The query looks like this:\nresources | where type == \u0026#34;microsoft.compute/disks\u0026#34; | where managedBy == \u0026#34;\u0026#34; | project name,location,resourceGroup,subscriptionId,sku.tier,properties.diskSizeGB And the results look like this: Here, in addition to the identifying properties, we also show the SKU tier and the Size of the disk. This will help us to see right away which of the disks that have the biggest cost. When looking at orphaned disks, you should try to identify why the disk is left over. Is it by mistake or did someone intend to keep the disk as a backup of a deleted VM? For the latter, you should move the disk to another and cheaper storage solution like cold or archive storage in a Storage Account.\nNetwork Interfaces This one is a bit more complex, but still simple. Now, we could do a simple query and return every NIC that is not connected to a VM, but it\u0026rsquo;s not the NICs that we are interested in. We are interested in NICs that are not connected to a VM and has a public IP. Cause it is that potential Public IP that is costing us money. Let\u0026rsquo;s have a look at the query and explain it before we look at the results:\nresources | where type == \u0026#34;microsoft.network/networkinterfaces\u0026#34; | where properties.virtualMachine == \u0026#34;\u0026#34; | extend p=parse_json(properties.ipConfigurations.[0].properties) | where p.publicIPAddress != \u0026#34;\u0026#34; | extend publicIpSku=p.publicIPAddress.sku.name | project name,location,resourceGroup,subscriptionId,publicIpSku To only get NICs that have a connected public IP we need to dig into the properties. For that we use the Extend operator together with the parse_json function. This makes the query a bit more reader-friendly and keeps us from writing properties.ipConfigurations.[0].properties.publicIPAddress several times over. And we also use it to get a better name for the property of public IP SKU that we want in the results. Speaking of the results, let\u0026rsquo;s have a look at what this query gives us.\nSame as with Public IPs, only Standard SKU Public IPs will create a cost.\nLoad Balancers With load balancers, there are 2 things that can reduce cost. Both the load balancer itself and if the load balancer has a public IP associated. And since the load balancer is always running, we also pay for Basic SKU Public IPs.\nresources | where type == \u0026#34;microsoft.network/loadbalancers\u0026#34; | extend pipId=parse_json(properties.frontendIPConfigurations[0].properties.publicIPAddress.id) | where properties.backendAddressPools == \u0026#34;[]\u0026#34; | project name,location,resourceGroup,subscriptionId,sku.name,pipId Here again, we use the extend operator to make the property of Public IP more reader friendly. And we also get the SKU of the load balancer itself. Both will help give us a potential cost reduction. For the finale time, here is the results of the query:\nAs you can see, the column for pipId isn\u0026rsquo;t user-friendly, but it shows us if the load balancer has a connected Public IP or not. If the load balancer does not have a connected Public IP, the column will be empty.\nCreating a dashboard with the queries So now that you have the queries, you probably want a central place to see them and monitor them. To achieves this, we can add them to an Azure dashboard. To do this, you can press the button for \u0026ldquo;Pin to dashboard\u0026rdquo; that is located right above the results pane.\nLooking at the dashboard after adding all the queries, it looks like this:\nYou could also add these queries to an Azure Workbook and add other queries and graphs to create a more complete Cost management monitoring collection.\n","permalink":"https://www.errush.org/blogposts/finding-orphaned-resources/","summary":"\u003cp\u003eIn Microsoft\u0026rsquo;s Well-Architected Framework there is a pillar for Cost Optimization. Some of the principals for optimizing cost are to continuously look for and clean up orphaned resources like disks and public IPs. In this blog I will show you some KQL queries that will help you find these resources and considerations you should take before cleaning them up. You can then use these queries in an Azure Workbook or dashboard to continuously review your environment. Before I start, I would like to thank \u003ca href=\"https://twitter.com/tamstar1234\"\u003eThomas Thornton\u003c/a\u003e and \u003ca href=\"https://twitter.com/wedoAzure\"\u003eJoe Carlyle\u003c/a\u003e for organizing the \u003ca href=\"https://www.azurespringclean.com/\"\u003eAzure Spring Clean\u003c/a\u003e. Please go check out the awesome content that other people in the community have created for the event!\u003c/p\u003e","title":"Reduce your Azure cost by finding unused resources"},{"content":"Even on the North Pole they must adopt new technologies, and Santa has started using Bicep to deploy his list of this year\u0026rsquo;s presents. Last year, Santa got a huge fine from the North pole Data Protection Authority after he committed the full naughty list into source control in a public repository. This year, Santa needs help with securing his secrets in Bicep templates during deployments!\nBefore I start the blogpost, I want to give a shoutout to the organizers of the Festive Tech Calendar for the amazing work they do! This year\u0026rsquo;s Festive Tech Calendar are raising money for the charity Missing people. A charity that helps find and reconnect missing persons with their loved ones. If you want to help in the fundraising, you can go to this website and donate. Thank you!\nNow, on to helping Santa before Christmas!\nSanta has some Bicep templates that resides in a public repository on Github, because Santa loves Open Source. The templates are deployed to his Azure environment using a Github Actions workflow. The template deploys a vnet, a VM, and then runs Run Commands against the VM with a PowerShell script that creates a file with the names of the naughty children.\nLet\u0026rsquo;s look at how Santa\u0026rsquo;s Bicep template looks like today:\nOh my! This is worse than I imagined! Not only is Santa passing the naughty list into source control, but the admin credentials as well! We\u0026rsquo;ll start by helping Santa secure the admin credentials first!\nSecuring the credentials If we look at the original template, we see that Santa has a module for the VM and passes them into the module as parameters. The best way to secure credentials used in deployments is to not have them in the template at all. How would we do that? The answer is to put the credentials into an Azure Key Vault as secrets and give the Service Principal for the workflow access to get the secret.\nI have now created a Key Vault and added the credentials as secrets: The Key Vault also has an Access Policy that allows the Service Principal to get the secret. So how do we get the credentials from the Key Vault into the Bicep template?\nLuckily, it\u0026rsquo;s simple. We reference the secrets as existing resources like this: Now the credentials are not even shown in the template or deployment! Microsoft handles the reference in the background and the only thing we are pushing to source control is the name of the key vault and the name of the secrets. With that out of the way, let\u0026rsquo;s move on to securing the naughty list.\nSecuring the naughty list! If we look back at the original main template, Santa declared the naughty list as a variable and added the names of naughty children directly into it. We would like to move the secret list out of the template and prevent it from being logged in Azure during deployment. Here\u0026rsquo;s how we would do that.\nFirst, we need to change it from being a variable to being a parameter. But we do not want it as a regular parameter, we want it to be Secure(). When a parameter is defined as secure, it will not be logged during deployment. Unfortunately, you cannot use the secure() function on arrays, so we will have to change it to a string. Here\u0026rsquo;s how it will look:\nAnd now that the naughty list is a parameter, we can define the parameters in the workflow. Now, we are not going to just declare the naughty list in another file that lies in source control. We are going to use Github Actions Secrets. This way we will not show the list to anyone, as it is securely referenced in the workflow in Github just like we did with the Key Vault for credentials.\nAnd the last thing we need to do is to update the workflow with the naughty list parameter that we get from configured secrets:\nSummary We have now helped Santa secure all the secrets in his deployment and he can without a worry prepare for Christmas Eve! For the admin credentials on the VM, we put the securely in a Key Vault, gave the Service Principal access to the secrets and referenced the secrets during deployment as existing resources. And for the naughty list we changed it from being a variable and array to a secure string parameter, then we created a Github Action secret, and finally referenced the secret in the Github Action workflow.\n","permalink":"https://www.errush.org/blogposts/help-santa-secure-his-naughtylist/","summary":"\u003cp\u003eEven on the North Pole they must adopt new technologies, and Santa has started using Bicep to deploy his list of this year\u0026rsquo;s presents. Last year, Santa got a huge fine from the North pole Data Protection Authority after he committed the full naughty list into source control in a public repository. This year, Santa needs help with securing his secrets in Bicep templates during deployments!\u003c/p\u003e\n\u003cp\u003eBefore I start the blogpost, I want to give a shoutout to the organizers of the Festive Tech Calendar for the amazing work they do! This year\u0026rsquo;s Festive Tech Calendar are raising money for the charity \u003ca href=\"https://www.missingpeople.org.uk/\"\u003eMissing people\u003c/a\u003e. A charity that helps find and reconnect missing persons with their loved ones. If you want to help in the fundraising, you can go to this \u003ca href=\"https://www.justgiving.com/fundraising/festivetechcalendar2022\"\u003ewebsite\u003c/a\u003e and donate. Thank you!\u003c/p\u003e","title":"Help Santa Secure His Naughty List"},{"content":"Bicep is an IaC-language which is created by Microsoft for Azure. Therefore, it does not have capabilities to do configuration management of Virtual machines directly. There are however ways to do some level of desired state configuration (DSC) on OS-level of Virtual machines using another Azure service. This service is Run Commands! Note that there is other services like Azure Automation and Azure Automanage that do DSC, but this blogpost is about Run Commands.\nI have written about Run Commands on my blog before, and if you\u0026rsquo;re interested, you can find the post here. In short terms, Run Commands uses the Virtual Machine Agent to run scripts on VMs. These scripts can either be PowerShell or Bash if you have Linux VMs. Today I will demonstrate how to use Run Commands in a Bicep template that will deploy a VM and run a simple script on it post-deployment.\nThe Bicep template First, we need the VM. I won\u0026rsquo;t go into too much detail on this part of the template, but what it does is that it creates a VM, NIC, and a Public IP address.\nparam location string @secure() param adminuser string @secure() param adminpass string resource windowsVM \u0026#39;Microsoft.Compute/virtualMachines@2020-12-01\u0026#39; = { name: \u0026#39;VM-lab2\u0026#39; location: location properties: { diagnosticsProfile: { bootDiagnostics: { enabled: true } } hardwareProfile: { vmSize: \u0026#39;Standard_B2ms\u0026#39; } osProfile: { computerName: \u0026#39;lab2\u0026#39; adminUsername: adminuser adminPassword: adminpass } storageProfile: { imageReference: { publisher: \u0026#39;MicrosoftWindowsServer\u0026#39; offer: \u0026#39;WindowsServer\u0026#39; sku: \u0026#39;2022-Datacenter\u0026#39; version: \u0026#39;latest\u0026#39; } osDisk: { caching: \u0026#39;ReadWrite\u0026#39; createOption: \u0026#39;FromImage\u0026#39; } } networkProfile: { networkInterfaces: [ { id: nic.id } ] } } } resource nic \u0026#39;Microsoft.Network/networkInterfaces@2021-08-01\u0026#39; = { name: \u0026#39;VM-lab2-nic\u0026#39; location: location properties: { ipConfigurations: [ { name: \u0026#39;default\u0026#39; properties: { subnet: { id: vnet.properties.subnets[0].id } privateIPAddress: \u0026#39;10.0.0.10\u0026#39; publicIPAddress: { id: pip.id sku: { name: \u0026#39;Basic\u0026#39; tier: \u0026#39;Regional\u0026#39; } properties: { } } } } ] } } resource pip \u0026#39;Microsoft.Network/publicIPAddresses@2021-08-01\u0026#39; = { name: \u0026#39;pip-lab2\u0026#39; location: location sku: { name: \u0026#39;Basic\u0026#39; tier: \u0026#39;Regional\u0026#39; } properties: { } } resource vnet \u0026#39;Microsoft.Network/virtualNetworks@2022-01-01\u0026#39; existing = { name: \u0026#39;vnet-lab1\u0026#39; } I will then add the Run Commands part to the bottom of the template. For the Run Commands resource, I won\u0026rsquo;t need to specify too much. The resource will of course require the standard name and location that all resources require, but other than that, it only need two properties. Since Run Commands is a child resource of VMs, I will need to specify the parent. The parent is the VM that will run the script. Defining the parent will also create a DepensOn logic in the template. Ensuring that Azure will create the VM before trying to run the script.\nLastly, I need to specify the script I want to run. My script is a PowerShell script that will set some registry keys. These registry keys are a prerequisites for Azure AD Application Proxy. Some of you might know that my script is in fact useless, because on Windows Server 2022 (The OS I have chosen for the VM I\u0026rsquo;m deploying) these registry keys that enable TLS 1.2 are there by default. But this script is for demonstration-purposes only. The only keys that this script will set is the DisabledByDefault ones. And that is how I will confirm that the script ran.\nHere is the part of the template with Run Commands:\nresource deploymentscript \u0026#39;Microsoft.Compute/virtualMachines/runCommands@2022-03-01\u0026#39; = { parent: windowsVM name: \u0026#39;AadAppProxyPrerequisites\u0026#39; location: location properties: { source: { script: \u0026#39;\u0026#39;\u0026#39;Set-ItemProperty \u0026#39;HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\WinHttp\\\u0026#39; -Name EnableDefaultHTTP2 -Value 0 Set-ItemProperty \u0026#39;HKLM:\\SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\SCHANNEL\\Protocols\\TLS 1.2\\Client\\\u0026#39; -Name DisabledByDefault -Value 0 Set-ItemProperty \u0026#39;HKLM:\\SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\SCHANNEL\\Protocols\\TLS 1.2\\Client\\\u0026#39; -Name Enabled -Value 1 Set-ItemProperty \u0026#39;HKLM:\\SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\SCHANNEL\\Protocols\\TLS 1.2\\Server\\\u0026#39; -Name DisabledByDefault -Value 0 Set-ItemProperty \u0026#39;HKLM:\\SYSTEM\\CurrentControlSet\\Control\\SecurityProviders\\SCHANNEL\\Protocols\\TLS 1.2\\Server\\\u0026#39; -Name Enabled -Value 1 Set-ItemProperty \u0026#39;HKLM:\\SOFTWARE\\Microsoft\\.NETFramework\\v4.0.30319\\\u0026#39; -Name SchUseStrongCrypto -Value 1\u0026#39;\u0026#39;\u0026#39; } } } As you can see, the script is written as a multi-line string. It works for this short and simple script, but it\u0026rsquo;s not too good if you want to run a longer script. Fortunately, there is another way to do it. Instead of writing the script into to the template, I can upload the script to a Storage Account and use the property of SciptUri instead of Script in my template. That will look something like this:\nresource deploymentscript \u0026#39;Microsoft.Compute/virtualMachines/runCommands@2022-03-01\u0026#39; = { parent: windowsVM name: \u0026#39;AadAppProxyPrerequisites\u0026#39; location: location properties: { source: { ScriptUri: \u0026#39;https://saerrush832094.blob.core.windows.net/test/AadAppProxyPrerequisites.ps1?sp=r\u0026amp;st=2022-08-04T11:19:33Z\u0026amp;se=2022-08-04T11:19:33Z\u0026amp;spr=https\u0026amp;sv=2021-06-08\u0026amp;sr=b\u0026amp;sig=aDnDOkH78ZI%2FIvZQE4lt0%2FEgQLmTP%2Fq%2BvS\u0026#39; } } } Now this looks a lot better! The URL is a link to the PowerShell script in a blob container, at the end of the URL is a SAS-token that will give the deployment access to the file. The deployment will access the file and run the script.\nThe result Let\u0026rsquo;s deploy the template and look at the results. First, I\u0026rsquo;m using PowerShell and the AZ module to create the deployment: The deployment looks good from the terminal. Let\u0026rsquo;s check the Azure portal to see if all the resources were created.\nAll looks good! I see that all the resources were created, even the Run Commands resource. That should mean that my script ran on the VM, but let\u0026rsquo;s check if that was the case.\nTo verify that the script ran, I RDP into the VM and check the registry for one of the keys that was not there by default.\nAnd there it is, the DisabledByDefault key is present. Meaning that my script ran as intended and I can now install Azure AD Application Proxy on it without problems!\n","permalink":"https://www.errush.org/blogposts/deploymentscripts-in-bicep/","summary":"\u003cp\u003eBicep is an IaC-language which is created by Microsoft for Azure. Therefore, it does not have capabilities to do configuration management of Virtual machines directly. There are however ways to do some level of desired state configuration (DSC) on OS-level of Virtual machines using another Azure service. This service is Run Commands! \u003cstrong\u003eNote\u003c/strong\u003e that there is other services like \u003ca href=\"https://docs.microsoft.com/nb-no/azure/automation/automation-dsc-overview\"\u003eAzure Automation\u003c/a\u003e and \u003ca href=\"https://docs.microsoft.com/nb-no/azure/automanage/automanage-virtual-machines#participating-services\"\u003eAzure Automanage\u003c/a\u003e that do DSC, but this blogpost is about Run Commands.\u003c/p\u003e","title":"Run scripts on VMs after deployment with Bicep"},{"content":"Last blogpost I showed you an Azure Policy that checked for a SQL server firewall rule. The results would be a compliance view in Azure Policy. After the blogpost, me and Dennes Torres had a chat about the results you get in the compliance view. The problem: you don\u0026rsquo;t get the resource ID or resource name for the SQL server with the setting on. This isn\u0026rsquo;t really a problem if you have only one not-compliant resource, but if you have several, it becomes tedious.\nThe problem occours because the firewall rule is its own resource. That makes the firewall rule and not the SQL server non-compliant. Therefore, in the Azure policy compliance view, you only see the firewall rules. You also see the resource group that the resource is in, but again you could have several SQL servers in a single resource group.\nLet\u0026rsquo;s look at what I would need to do to find the SQL server name which has the non-compliant firewall rule:\nIn this scenario I have three different SQL servers in a single resource group. Two of them are non-compliant and one is compliant. The hard way to find the name of the SQL servers is to click into each one of these non-compliant resources in this view. Here I can find the resource ID of the non-compliant resource, but it\u0026rsquo;s the firewall rule that is non-compliant. So, I have to hover my mouse over or copy the resource ID to see that somewhere in that string, there is the SQL server name.\nI wouldn\u0026rsquo;t want to do this for all the non-compliant resources, even if it is just the two of them. So, what is the alternative? The title of this blogpost has already spoiled the answer, but it\u0026rsquo;s to query the Azure Resource Graph. Don\u0026rsquo;t be alarmed, even if you haven\u0026rsquo;t done this before, it is very simple.\nA great way to query the resource graph if you aren\u0026rsquo;t a champion in KQL, is to use the Azure Resource Graph Explorer. In the Graph Explorer you get several prewritten queries you can run. And you also get a visual way to explore the API\u0026rsquo;s on the side. Here you can search for what you are looking for or start clicking your way through the APIs.\nWe need to query the collection of API\u0026rsquo;s called policyresources. And the type we are looking for is \u0026ldquo;microsoft.policyinsights/policystates\u0026rdquo; This will return all resources that is check by at least one compliance policy. Next, we specify which policy and compliance state we want. Finally, we chose to only show the property of resourceId. The query will end up looking like this:\npolicyresources | where type == \u0026#34;microsoft.policyinsights/policystates\u0026#34; | where properties[\u0026#39;policyAssignmentName\u0026#39;] == \u0026#34;Assign Audit AllowAllAzureIps Policy\u0026#34; | where properties[\u0026#39;complianceState\u0026#39;] == \u0026#34;NonCompliant\u0026#34; | project properties[\u0026#39;resourceId\u0026#39;] And this is the result that we got: And there right between /servers/ and /firewallrules/ we see the name of the non-compliant server. You can now either note the server names or you could click \u0026ldquo;Download as CSV\u0026rdquo; to work with the results in Excel.\n","permalink":"https://www.errush.org/blogposts/query-azure-policy-compliance/","summary":"\u003cp\u003eLast blogpost I showed you an Azure Policy that checked for a SQL server firewall rule. The results would be a compliance view in Azure Policy. After the blogpost, me and Dennes Torres had a chat about the results you get in the compliance view. The problem: you don\u0026rsquo;t get the resource ID or resource name for the SQL server with the setting on. This isn\u0026rsquo;t really a problem if you have only one not-compliant resource, but if you have several, it becomes tedious.\u003c/p\u003e","title":"Query Azure Policy Compliance results using KQL"},{"content":"This is going to be a longer one. You have been warned! This adventure started last week when I attended the Azure User Group Norway with a session on Azure SQL networking secrets by Dennes Torres.\nDennes showed a setting in the firewall rules on Azure SQL server that said, \u0026ldquo;Allow Azure services and resources to access this server\u0026rdquo;. Now you might think \u0026ldquo;Yeah, I need that for my App Service to access the database\u0026rdquo;, but in reality, this setting will allow ALL Azure IPs to access the SQL server! Both me and the other attendees at the session was in shock and thought \u0026ldquo;How do I prevent this from being turned on?\u0026rdquo;. This got me diving down the rabbit hole of firewall rules on Azure SQL server and how this setting worked.\nIn this blogpost I will go through my path from learning about this setting to creating a Bicep file for deploying a policy definition and assignment on subscriptions.\nWhere to start? My first thought in all of this was: \u0026ldquo;There\u0026rsquo;s got to be a built-in Azure Policy for this\u0026rdquo;. I searched through Azure Policy and found nothing. I went through all Azure Security Center recommendations to see if there were a policy definition there. Not a single mention of the AllowAllAzureIps setting.\nSearching through the APIs A resource I often use when creating Bicep templates is the resource reference. There I can browse the APIs and see what properties are configurable on them. I browse through all the sub-APIs for SQL server and the SQL server API itself. Nothing\u0026hellip;\nI then set up a SQL server in my demo environment and start looking at it in Azure Resource Explorer, but still, I find nothing on the setting. It appears that this setting is configurable in the GUI, but not on the API. The more I dive deeper into this, the more curious I get!\nFinding the setting The setting had to be there somewhere on the resource! So how do you find all settings configured on a resource if it\u0026rsquo;s not on the API? It seems that my experience of creating Bicep templates helped me once again! If you export a resource to an ARM-template, you get all configured settings in the Json-file.\nAnd there it was! It was there all along!\nIt was set as a firewall rule on the API! Into the firewall rules I go! Now there was a Powershell command to get Azure SQL Server firewall rules, but there was one problem. You could only get the rules of one SQL server at a time.\nI could script this to get the setting for all my SQL servers, but I wanted to prevent it from being set as well. And the only way to do that is with Azure Policy. But with the information we have so far, it should be easy.\nCreating a Policy The problem was that I had never created a custom Policy before. I had to find something I could copy, and not start from scratch. Back to the built-in policies I went. Luckily, I found exactly what I was looking for.\nA policy that checked for a setting on a resource and then setting an effect. Now I just needed to change it up with the values I had and try it out!\nHere\u0026rsquo;s what the policy rule ended up looking like:\n{ \u0026#34;policyRule\u0026#34;: { \u0026#34;if\u0026#34;: { \u0026#34;allOf\u0026#34;: [ { \u0026#34;field\u0026#34;: \u0026#34;type\u0026#34;, \u0026#34;equals\u0026#34;: \u0026#34;Microsoft.Sql/servers/firewallrules\u0026#34; }, { \u0026#34;field\u0026#34;: \u0026#34;name\u0026#34;, \u0026#34;like\u0026#34;: \u0026#34;AllowAllWindowsAzureIps\u0026#34; } ] }, \u0026#34;then\u0026#34;: { \u0026#34;effect\u0026#34;: \u0026#34;audit\u0026#34; } } } As you can see, I chose to start with an audit effect to see if I was on the right track. After deploying and assigning the policy definition I went on to check my Policy compliance. Now anyone who have worked with compliance in Azure Policy know that it is very slow to check the compliance. And if you don\u0026rsquo;t know, here is the Powershell to force the compliance check:\nStart-AzPolicyComplianceScan After the long wait for the compliance check, it was clear that I had the correct policyrule. I then tested with the rule set with \u0026ldquo;Deny\u0026rdquo; effect. I think that was the first time I had ever been overflowing with joy and dopamine as my deployment failed! Finally, success!\nCreating a template for deployment So, I had created one policy that checked if the setting was there and one that denied the setting from being set. Now I needed to create a simple way to deploy this in other Azure-environments. And as always, I turned to Bicep. This was the easy part!\nI went on to create two different Bicep-templates, one for audit and one for denying. Of course, I could have created one template and used parameters to determine if it should audit or deny, but I knew that I was going to be sharing this with coworker and customers, and that means simplicity is essential.\nIf you want to use the templates for yourself, you can find them both Here. And here is how the Deny template ended up looking like:\ntargetScope = \u0026#39;subscription\u0026#39; param location string = \u0026#39;WestEurope\u0026#39; resource sqldenypolicy \u0026#39;Microsoft.Authorization/policyDefinitions@2021-06-01\u0026#39; = { name: \u0026#39;Deny SQL AllowAllAzureIps\u0026#39; properties: { description: \u0026#39;Deny SQL server from having AllowAllAzureIps configured.\u0026#39; displayName: \u0026#39;Deny SQL server AllowAllAzureIps\u0026#39; mode: \u0026#39;All\u0026#39; metadata: { category: \u0026#39;SQL\u0026#39; } policyType: \u0026#39;Custom\u0026#39; policyRule: { if: { allOf: [ { field: \u0026#39;type\u0026#39; equals: \u0026#39;Microsoft.Sql/servers/firewallRules\u0026#39; } { field: \u0026#39;name\u0026#39; like: \u0026#39;AllowAllWindowsAzureIps\u0026#39; } ] } then: { effect: \u0026#39;deny\u0026#39; } } } } resource policyass \u0026#39;Microsoft.Authorization/policyAssignments@2021-06-01\u0026#39; = { name: \u0026#39;Assign Deny AllowAllAzureIps Policy\u0026#39; location: location properties: { policyDefinitionId: sqldenypolicy.id description: \u0026#39;Denies the use of setting \u0026#34;AllowAllAzureIps\u0026#34;\u0026#39; nonComplianceMessages: [ { message: \u0026#39;AllowAllAzureIps setting is forbidden.\u0026#39; } ] displayName: \u0026#39;Deny SQL server AllowAllAzureIps\u0026#39; } } Closing words This deep dive is the most fun I have had learning in a long time. The roller coaster of not finding anything until suddenly you find the smoking gun, and everything falls into place. I would like to point out that I would not have managed to solve this if it hadn\u0026rsquo;t been for my experience with templates and exploring the APIs in the process. Because of that, I recommend anyone that wants to become an Azure expert to look into the documentation on the Azure APIs and how to use them to query or configure resources.\n","permalink":"https://www.errush.org/blogposts/azure-sql-allowallazureip/","summary":"\u003cp\u003eThis is going to be a longer one. You have been warned!\nThis adventure started last week when I attended the Azure User Group Norway with a session on Azure SQL networking secrets by \u003ca href=\"https://twitter.com/Dennes\"\u003eDennes Torres\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eDennes showed a setting in the firewall rules on Azure SQL server that said, \u0026ldquo;Allow Azure services and resources to access this server\u0026rdquo;. Now you might think \u0026ldquo;Yeah, I need that for my App Service to access the database\u0026rdquo;, but in reality, this setting will allow \u003cstrong\u003eALL\u003c/strong\u003e Azure IPs to access the SQL server! Both me and the other attendees at the session was in shock and thought \u0026ldquo;How do I prevent this from being turned on?\u0026rdquo;. This got me diving down the rabbit hole of firewall rules on Azure SQL server and how this setting worked.\u003c/p\u003e","title":"The SQL Server AllowAllAzureIps setting"},{"content":"What if you could make configuring the supporting services of your VMs so much easier? And without needing to assign and manage several policies. This is where Azure Automanage comes flying in like the savior you always needed!\nWhat is Automanage? Automanage is as simple as a configuration profile that you apply to your VMs that will automatically configure the services that are best practice for VMs in Azure. For example, Azure Log Analytics and Azure Backup.\nMicrosoft even created some predefined automanage profiles, one for Production workloads and one for Dev/Test. So which services are configurable in Automanage?\nService Configuration Profile Supported Scenario Machines Insights Monitoring Production Windows, Linux, Azure Arc Backup Production Windows, Linux Microsoft Defender for Cloud Production, Dev/Test Windows, Linux Microsoft Antimalware Production, Dev/Test Windows Update Management Production, Dev/Test Windows, Linux, Azure Arc Change Tracking and Inventory Production, Dev/Test Windows, Linux, Azure Arc Guest configuration Production, Dev/Test Windows, Linux, Azure Arc Boot Diagnostics Production, Dev/Test Windows, Linux Windows Admin Center Production, Dev/Test Windows Azure Automation Account Production, Dev/Test Windows, Linux, Azure Arc Log Analytics Workspace Production, Dev/Test Windows, Linux, Azure Arc Create a custom configuration profile What if you don\u0026rsquo;t want to use all the features and services in the built-in profiles? You just make your own custom profile. Here\u0026rsquo;s how: Go to the Automanage service and click the \u0026ldquo;Configuration profiles\u0026rdquo; blade. Then click the Create button in the top left of the blade.\nHere you can start checking and unchecking the features you want to include in the configuration profile. You can also configure a backup policy and Antimalware scan policy. As you might notice, some of the services you can\u0026rsquo;t check or uncheck. These are Azure Security Center, Automation Account, and Log Analytics Workspace. Azure Security Center is always checked and will onboard you VMs to the free tier of the service. With Azure Automation Account and Log Analytics Workspace it will be checked or unchecked based on the other services you enable. For example, if you enable Change Tracking, it will also enable the Automation Account because it is dependent of one.\nApply the configuration profile for VMs Now that you have created you own configuration profile or chosen to use one of the built-in ones. The next step is to apply the profile to one or more VM. There is also a built-in policy that you can use to apply configuration profiles for all or several VMs automatically, both new and existing ones. For simplicity I will show you how to apply the profile to a single VM.\nIn the Automanage site, you click into the \u0026ldquo;Automanage machines\u0026rdquo; blade. Here there is a plus button in the top menu of the blade with the text \u0026ldquo;Enable on existing machine\u0026rdquo;. In this page you select the configuration profile to apply. And then you select which VMs to apply it to.\nAfter you apply the configuration profile, you will see all the VMs with a configuration profile applied with info on which profile is applied and the status of deployment. Automanage will use some time to deploy the resources and returning a status.\n","permalink":"https://www.errush.org/blogposts/intro-to-automanage/","summary":"\u003cp\u003eWhat if you could make configuring the supporting services of your VMs so much easier? And without needing to assign and manage several policies. This is where Azure Automanage comes flying in like the savior you always needed!\u003c/p\u003e\n\u003ch2 id=\"what-is-automanage\"\u003eWhat is Automanage?\u003c/h2\u003e\n\u003cp\u003eAutomanage is as simple as a configuration profile that you apply to your VMs that will automatically configure the services that are best practice for VMs in Azure. For example, Azure Log Analytics and Azure Backup.\u003c/p\u003e","title":"Introduction to Automanage"},{"content":"Anyone who have used the portal to add rules to Azure Firewall will know how tedious and annoying it can get. With small fields to write both destination and source, it does get old very quick. And something that I found myself doing for several customers was setting the rules required for Azure AD Connect. I quickly got tired of doing it manually, so I created a Bicep template to deploy it much easier and faster.\nNote That this blogpost is about deploying the firewall rules to Azure Firewall. If you are only looking for required URLs go here\nScenario In today\u0026rsquo;s scenario, we are talking about having a domain controller on a VM in Azure and using an Azure Firewall to manage in- and outbound traffic. We then want to sync out AD identities to Azure AD using Azure AD Connect.\nRequired URLs URL Protocol:Port Description *.aadconnecthealth.azure.com https:443 AAD Connect Health *servicebus.windows.net https:443 AAD Connect Health *.adhybridhealth.azure.com https:443 AAD Connect Health www.management.azure.com https:443 Various Azure services www.policykeyservice.dc.ad.msft.net https:443 AAD Connect Health secure.aadcdn.microsoftonline-p.com https:443 MFA aadcdn.msftauth.net https:443 MFA www.office.com https:443 Authentication *.windows.net https:443 Azure AD Graph *.microsoftonline.com https:443 Configure Azure AD directory and import/export data *.msappproxy.net https:443 Authentication *.verisign.com http:80 Download CRL lists *.entrust.net http:80 Download CRL lists *.crl3.digicert.com http:80 Verify certificates *.crl4digicert.com http:80 Verify certificates *.ocsp.digicert.com http:80 Verify certificates *.www.d-trust.net http:80 Verify certificates *.root-c3-ca2-2009.ocsp.d-trust.net http:80 Verify certificates *.crl.microsoft.com http:80 Verify certificates *.oneocsp.microsoft.com http:80 Verify certificates *.ocsp.msocsp.com http:80 Verify certificates If you can\u0026rsquo;t get Azure AD Connect to work with these ports opened, try this troubleshooting guide from Microsoft on the bare minimum requirements\nBicep template param fwpolicyname string param priority int = 300 param sourceaddresses array resource fwpolicy \u0026#39;Microsoft.Network/firewallPolicies@2021-05-01\u0026#39; existing = { name: fwpolicyname } resource fwPolicyrulecollection \u0026#39;Microsoft.Network/firewallPolicies/ruleCollectionGroups@2021-05-01\u0026#39; = { name: \u0026#39;AllowAadConnect\u0026#39; parent: fwpolicy properties: { priority: priority ruleCollections: [ { ruleCollectionType: \u0026#39;FirewallPolicyFilterRuleCollection\u0026#39; action: { type: \u0026#39;Allow\u0026#39; } rules: [ { name: \u0026#39;AAD Connect health Service Endpoints\u0026#39; ruleType: \u0026#39;ApplicationRule\u0026#39; targetFqdns: [ \u0026#39;*.aadconnecthealth.azure.com\u0026#39; \u0026#39;*servicebus.windows.net\u0026#39; \u0026#39;*.adhybridhealth.azure.com\u0026#39; \u0026#39;www.management.azure.com\u0026#39; \u0026#39;www.policykeyservice.dc.ad.msft.net\u0026#39; \u0026#39;secure.aadcdn.microsoftonline-p.com\u0026#39; \u0026#39;aadcdn.msftauth.net\u0026#39; ] sourceAddresses: sourceaddresses protocols: [ { protocolType: \u0026#39;Https\u0026#39; port: 443 } ] } { name: \u0026#39;Discovery\u0026#39; ruleType: \u0026#39;ApplicationRule\u0026#39; targetFqdns: [ \u0026#39;www.office.com\u0026#39; ] sourceAddresses: sourceaddresses protocols: [ { protocolType: \u0026#39;Https\u0026#39; port: 443 } ] } { name: \u0026#39;Sign in AAD\u0026#39; ruleType: \u0026#39;ApplicationRule\u0026#39; targetFqdns: [ \u0026#39;*.windows.net\u0026#39; ] sourceAddresses: sourceaddresses protocols: [ { protocolType: \u0026#39;Https\u0026#39; port: 443 } ] } { name: \u0026#39;Confidure and import/export AAD\u0026#39; ruleType: \u0026#39;ApplicationRule\u0026#39; targetFqdns: [ \u0026#39;*.microsoftonline.com\u0026#39; ] sourceAddresses: sourceaddresses protocols: [ { protocolType: \u0026#39;Https\u0026#39; port: 443 } ] } { name: \u0026#39;Auth\u0026#39; ruleType: \u0026#39;ApplicationRule\u0026#39; targetFqdns: [ \u0026#39;*.msappproxy.net\u0026#39; ] sourceAddresses: sourceaddresses protocols: [ { protocolType: \u0026#39;Https\u0026#39; port: 443 } ] } { name: \u0026#39;CRL\u0026#39; ruleType: \u0026#39;ApplicationRule\u0026#39; targetFqdns: [ \u0026#39;*.verisign.com\u0026#39; \u0026#39;*.entrust.net\u0026#39; ] sourceAddresses: sourceaddresses protocols: [ { protocolType: \u0026#39;Http\u0026#39; port: 80 } ] } { name: \u0026#39;Verify cert\u0026#39; ruleType: \u0026#39;ApplicationRule\u0026#39; targetFqdns: [ \u0026#39;*.crl3.digicert.com\u0026#39; \u0026#39;*.crl4.digicert.com\u0026#39; \u0026#39;*.ocsp.digicert.com\u0026#39; \u0026#39;*.www.d-trust.net\u0026#39; \u0026#39;*.root-c3-ca2-2009.ocsp.d-trust.net\u0026#39; \u0026#39;*.crl.microsoft.com\u0026#39; \u0026#39;*.oneocsp.microsoft.com\u0026#39; \u0026#39;*.ocsp.msocsp.com\u0026#39; ] sourceAddresses: sourceaddresses protocols: [ { protocolType: \u0026#39;Http\u0026#39; port: 80 } ] } ] } ] } } Deploying the template So how do you deploy this Bicep template? This template requires you to have an already configured Azure Firewall and a firewall policy. Next you need to configure the parameters specified at the top of the template. Only 2 of them are strictly necessary to configure as the priority parameter has a default value of 300, but if you have a rule with that priority, you need to change that too. The parameter \u0026ldquo;fwpolicyname\u0026rdquo; is as simple as the name of your existing firewall policy that you are deploying the ruleset to.\nThe \u0026ldquo;sourceaddresses\u0026rdquo; parameter is a bit different as it expects an array. Therefore, your input should look something like this:\n[ \u0026#34;10.10.7.5\u0026#34; \u0026#34;10.10.7.6\u0026#34; ] It\u0026rsquo;s possible to put several or only one IP-address depending on how many servers you have installed Azure AD Connect on.\nI would recommend to use a smiple parameter file if you want a simpler experience when deploying. A parameter file would look like this:\n{ \u0026#34;$schema\u0026#34;: \u0026#34;https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#\u0026#34;, \u0026#34;contentVersion\u0026#34;: \u0026#34;1.0.0.0\u0026#34;, \u0026#34;parameters\u0026#34;: { \u0026#34;soureceaddresses\u0026#34;: { \u0026#34;value\u0026#34;: [ \u0026#34;10.10.7.5\u0026#34; \u0026#34;10.10.7.6\u0026#34; ] }, \u0026#34;fwpolicyname\u0026#34;: { \u0026#34;value\u0026#34;: \u0026#34;fwpolicyname111\u0026#34; }, \u0026#34;priority\u0026#34;: { \u0026#34;value\u0026#34;: 250 } } } Now to deploy it with Powershell, you use the following command (after authentication ofcourse):\nNew-AzResourceGroupDeployment -TemplateFile fwruleset.bicep -TemplateParameterFile parameters.json ","permalink":"https://www.errush.org/blogposts/azurefw-aadconnectruleset-bicep/","summary":"\u003cp\u003eAnyone who have used the portal to add rules to Azure Firewall will know how tedious and annoying it can get. With small fields to write both destination and source, it does get old very quick. And something that I found myself doing for several customers was setting the rules required for Azure AD Connect. I quickly got tired of doing it manually, so I created a Bicep template to deploy it much easier and faster.\u003c/p\u003e","title":"Deploy Azure Firewall ruleset for Azure AD with Bicep"},{"content":"With information security coming into the spotlight of mainstream media after more and more big companies experience millions of dollars in revenue loss due to security breaches and ransomware. Security is becoming, if not already; the field of IT with the most attention at it. Both companies and individuals are tearing apart operating systems and applications alike trying to find and even exploit the vulnerabilities they find. All this have made it even more critical for IT departments to be fast and thorough with patching systems because they are always catching up to the vulnerabilities.\nIf you ask an IT Pro how you should go about patching your systems, he might tell you that first you need to deploy to the test environment and check that it doesn\u0026rsquo;t break anything, and maybe even wait a few days for the manufacturer to release a list of known problems with the patch. Then you can finally deploy it to production.\nEven though that process lowers the risk of the patch breaking anything, it\u0026rsquo;s not fast. If we look back on the Log4J vulnerability that was disclosed to the public on the 1st of December 2021, already on the 10th of December there were reports of mass exploits of the vulnerability in the wild.\nTo manage patching of servers, IT-departments often have systems or third-party solutions that they can use to find and install new patches. Let\u0026rsquo;s make up a scenario where you use SCCM to manage patching of your servers on-premises. And to support SCCM you also have 2-3 Software Update Point servers in different datacenters to minimize network traffic. Now, you have started a migration project to the cloud and you make an estimation on cost of lift and shift for your SCCM solution. You then see quite clearly that compute is expensive in the cloud. What do you do then?\nLuckily Microsoft values security and offers a free solution in Azure called Update Management with Azure Automation. You now have a SaaS solution that you can use to replace the patch management part of SCCM.\nManaging patching with Update Management There are different ways to enable Update Management on your VMs. Let\u0026rsquo;s look at how to do it from the Virtual Machine overview in Azure. First go to the Azure portal and select Virtual Machines from the menu to the left:\nHere you mark the VMs that you want to enable it for. Then click the three dots in the top menu. In the menu that pops up, click on services and finally Update Management.\nHere you choose to let Azure automatically configure a Log analytics workspace and automation account for you or choose already existing resources. You also get a summary that shows a status whether your VMs support Azure Update Management. If all the chosen VMs are supported, you now need to click enable.\nAfter clicking enable, the deployment will begin. This might take some time as Azure need to install the required extension on your VMs and register the machine as ready.\nWhen your machines are done onboarding to Update Management, you will get a nice dashboard with your machines compliance. This will give you a nice overview of which machines are missing what updates. If you then need to install some of these updates you can click on \u0026ldquo;schedule update deployment\u0026rdquo;. There you specify what updates you want installed and exclude certain types or specified patches. You can also specify other steps in the maintenance windows like if the servers should reboot and if there should be done some extra pre- or post-configuration on the VMs.\nYour options for automated patching in Azure I have talked mostly about Update Management with Azure Automation, but it\u0026rsquo;s not your only options for automating security updates on your VMs in Azure. There is a feature that completely automate it for you. With automatic VM guest patching you just have to enable the feature on your VMs and Azure will automatically install all critical and security patches.\nNow there are both positives and negatives about automating every aspect of patching, but even with the tradeoffs, it might just be what you need. The big upside is obviously that it\u0026rsquo;s fully automated from start till finish. On the downside, you are giving up all control. You don\u0026rsquo;t get to choose what updates get installed or when they are installed.\nBeacause Azure automatically installs all patches that are marked as critical or security. You don\u0026rsquo;t get the chance to opt out of any of these patches. Maybe the patch brings in a bug that breaks printing? Or creates performance issues? So, if you feel fine about the tradeoff that you don\u0026rsquo;t have any control, but then you don\u0026rsquo;t need to think about it at all. Then Automated VM guest patching might be for you.\n","permalink":"https://www.errush.org/blogposts/update-management-with-azureautomation/","summary":"\u003cp\u003eWith information security coming into the spotlight of mainstream media after more and more big companies experience millions of dollars in revenue loss due to security breaches and ransomware. Security is becoming, if not already; the field of IT with the most attention at it. Both companies and individuals are tearing apart operating systems and applications alike trying to find and even exploit the vulnerabilities they find. All this have made it even more critical for IT departments to be fast and thorough with patching systems because they are always catching up to the vulnerabilities.\u003c/p\u003e","title":"Update management with Azure Automation"},{"content":"I started my previous blog by introducing Azure Run Command as a feature to run Powershell and Bash scripts on VMs straight from the Azure Portal. In this blog I\u0026rsquo;m gonna dive deeper into the feature and show a real life example of how to use it.\nThe two versions of Run Command Something I didn\u0026rsquo;t mention in my last blog is that there are actually two different versions of Run Command. They are action Run Command and Managed Run Command. Action Run Command is the most known version. This is also the feature that you have in the menu for VMs in Azure:\nAction Run Command Let\u0026rsquo;s explore what action Run Command actually is so we can compare the two features better! To put it simply, action Run Command is just a API call. When you start a Run Command script the portal sends a POST request to this API:\nhttps://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2021-07-01 And here\u0026rsquo;s an example of what the body of the request looks like:\n{ \u0026#34;commandId\u0026#34;: \u0026#34;RunPowerShellScript\u0026#34; \u0026#34;script\u0026#34;: \u0026#34;Your script here\u0026#34; } But how does that help us? Well, now that we know that it\u0026rsquo; a API call we could automate it. For example, let\u0026rsquo;s say that we have a VM that\u0026rsquo;s a webserver and we have a URL test in Azure Monitor that checks the website that the VM hosts. The URL test checks for timeouts and will trigger an alert if the respond time goes over a configured limit. The alert then triggers a Logic App that will send a POST request to the API with a Powershell script in the request body. The script will restart the IIS service on the VM in hope that it will solve the problem.\nMaybe I\u0026rsquo;ll write a blogpost about that solution one day, but for now look at these refrences on how to integrate an Azure monitor alert with Logic Apps and how to send a Resource Graph API call with Logic Apps\nManaged Run Command How about the Managed Run Command then? First I should mention that Managed Run Command is in public preview. You should always be careful to use preview features in production. Preview features do not have any SLAs, they could be dropped instead of released and if they\u0026rsquo;re released the price for the feature can be higher than it was in preview.\nOn to what it is. Managed Run Command is its own resource type and it removes most of the restrictions that were present for its predesessor. Now that it\u0026rsquo;s a resource type we can use it for more advanced situations than Action Run Command. Let\u0026rsquo;s look at a comparisson between the types from the Microsoft Docs:\nFeature Support Action RunCommand Managed RunCommand ARM template No Yes Long running 90 min limit customer specified timeout Execution account System/root Customer specified user Multiple run commands No Multiple in parallel or sequenced Large output Limited to 4K Uploaded to append blob Progress tracking No Yes Async execution Goal state/provisioning waits for script to complete Customer specified async flag if provisioning waits for the script Virtual machine scale set support No Yes SAS generation No blob support Automated, CRP generates SAS for customer blobs and manages them Gallery (custom commands) Only built-in commandslds Customer can publish scripts and share them As you can see, there are a lot of upgrades from Action Run Command to the new Managed Run Command. Because of these upgrades we can use this feature for other purposes. Some of these purposes might be running script during the creation of a VM, long running reporting script or creating scripts for sharing and reuse.\nCreate a Managed Run Command script with Bicep Since Managed Run Command is a resource type and as of February of 2022 there doesn\u0026rsquo;t seem to be a way to deploy Managed Run Command from the Azure Portal, I\u0026rsquo;m going to show you how to deploy it through a Bicep template. I used code to deploy this code!\nThe script that I\u0026rsquo;m deploying does not matter as im just gonna show you how to deploy it with Bicep. So I\u0026rsquo;m just gonna fill in some filler script. For a full reference on which properties are available with the Run Command API check this link.\nresource runcommand \u0026#39;Microsoft.Compute/virtualMachines/runCommands@2021-07-01\u0026#39; = { name: \u0026#39;HelloWorld\u0026#39; location: resourceGroup().location parent: VM1 properties: { source: { commandId: \u0026#39;HelloWorld\u0026#39; script: \u0026#39;Write-host \u0026#34;Hello World\u0026#34;\u0026#39; } } } What I start with is declaring a resource and using the Run Commands API. The Run Command resource is a child resource under the virtual machine resource. Meaning that I need a parent resource. For the example I\u0026rsquo;ll call that parent for VM1. The part that is more interesting is the source property. Here I need to specify what the script is. I have used a simple Hello World command as an example, but it is also possible to use \u0026ldquo;SciptUri\u0026rdquo; instead. That means that you can have a script made already and stored in a storage account and then reference where the script is stored. Much simpler than writing the script into the Bicep file.\nTip If you want to use the Bicep file as a reusable template use paramters for commandId and scriptUri so you can define what script you wanna run and where it\u0026rsquo;s located.\nYou can use the Bicep code in your VM deployment template for doing post deployment configuration or by by referencing an existing VM in the Bicep file. Like this:\nresource VM1 \u0026#39;Microsoft.Compute/virtualMachines@2021-07-01\u0026#39; existing = { name: \u0026#39;VM1\u0026#39; } Summary In this blogpost I have described the two different versions of the Run Command feature and compared them. The two examples of how to use the features have given an insight into other options to use them other than just runnning a command through the portal. Writing this blog and diving deeper into the technical side of the feature has been exiting and it is just why I started this blog. I\u0026rsquo;m sure that this won\u0026rsquo;t be the last time that I write about this feature as I continue to play with it on my own.\n","permalink":"https://www.errush.org/blogposts/run-command/","summary":"\u003cp\u003eI started my previous blog by introducing Azure Run Command as a feature to run Powershell and Bash scripts on VMs straight from the Azure Portal. In this blog I\u0026rsquo;m gonna dive deeper into the feature and show a real life example of how to use it.\u003c/p\u003e\n\u003ch2 id=\"the-two-versions-of-run-command\"\u003eThe two versions of Run Command\u003c/h2\u003e\n\u003cp\u003eSomething I didn\u0026rsquo;t mention in my last blog is that there are actually two different versions of Run Command. They are action Run Command and Managed Run Command. Action Run Command is the most known version. This is also the feature that you have in the menu for VMs in Azure:\u003c/p\u003e","title":"Use Run Command to run scripts on your VM"},{"content":"The \u0026ldquo;Traditional\u0026rdquo; way to manage servers was to RDP or SSH into them and apply the changes you needed to do. And this was regarded as safe to do (Not by everyone of course) since you usually already were inside the office or datacenter. But when your servers are in another datacenter or even on the other side of the world, what can you do then? You can just open up RDP for your IP-address or a whole range of IP-addresses, but it is not recommended.\nIn the 2020 Unit 42 Incident Response and Data Breach Report published by Palo alto Networks, it is reported that 50% of initial attacks was through RDP. There are services in Azure that makes using RDP safer (like Bastion or JIT-access), but in this series I will focus on services you can use to manage VMs without RDP. This article series will contain this post as an introduction before going into the different Azure services.\nHere are some services that can help you do common operations on your VM from the Azure Portal:\nRun scripts on your VM with Run command Let\u0026rsquo;s say you want to change a registry key or want to return a setting to the portal, the Run Command feature helps you! With Run Command you can choose from a set of pre-configured scripts from Microsoft, or you can run a custom script. Run command work for both Windows and Linux VMs, but there is more premade script for Windows.\nThere are some limitations to what you can do with Run Command custom scripts, here are a few of those restrictions:\nOutput is limited to the last 4,096 bytes. You can\u0026rsquo;t cancel a running script. Only one script can run at a time The maximum time a script can run is 90 minutes Script that prompt for input is not supported. You can find the Run Command feature in the portal by navigating to your VM and scroll down the left menu till you find the Run Command blade:\nTroubleshoot a network connection with Network watcher In Azure there is a lot of networking. And in the cloud with software defined networking, it might not always be as easy as \u0026ldquo;check if the cable is connected\u0026rdquo;. A feature that will help you with troubleshooting network connections in Azure is the Network Watcher, also known as \u0026ldquo;Connection Troubleshoot\u0026rdquo;.\nWith Network Watcher you specify which direction you want to test, inbound or outbound. Next you choose what\u0026rsquo;s your desired destination or source. Here you can choose your current IP-address, a specified IP-address, or an Azure service tag.\nFinally, you select what port you want to test. There are several commonly used services and ports that are pre-configured. So don\u0026rsquo;t worry if you don\u0026rsquo;t remember what port PostgreSQL uses! If you don\u0026rsquo;t find the service or port in the pre-configured list, you can also specify a custom port and what protocol it uses.\nWhen you click check connection Network Watcher will check if the port and protocol specified is allowed in or out of the VM. Now, the Connection troubleshoot will only check if the traffic is allowed or blocked in the Network Security Group for the VM and correlating Subnet. That means that even if Connection Troubleshoot says the traffic is allowed, it might still not work. There is thankfully a detailed version of the connection troubleshooter that is linked on the connection troubleshoot page.\nUpdate management using Azure Automation But what about Security patches and other updates? I don\u0026rsquo;t want the VM to install them whenever they are released without me knowing. Well, there is a solution for that too, and its way less complicated than creating a SCCM server and configuring WSUS on all servers.\nIn Azure Automation there is a feature that is called Update Management. Update Management is a free feature of Azure Automation that helps you patch both your Windows and Linux servers. With Update Management you get a centralized page where you can see and configure:\nVMs to enable the feature on Check compliance of VMs Define deployment schedule Deployment status Deploy application to VMs with Azure compute galleries In the initial config after deploying a VM, you might want to install an application on the VM for it to function. Microsoft changed the formerly known Shared Image Gallery to Azure compute gallery. The reason for the name change is that in addition to storing and sharing images, you can now do the same for application packages.\nWith Azure compute gallery you get the benefits of:\nGrouping and versioning of packages. Control access with Azure Role Based Access Control (RBAC). Install from storage account without a direct internet connection. Automatic deployment with a DeployIfNotExists policy. For example, let\u0026rsquo;s say that you want to update antivirus on all your servers. So instead of RDPing in to all your servers and update or install the new version, you can create an application package in Azure Compute Gallery and create an Azure Policy to automatically deploy the software to servers.\nCollect logs from your VM in the portal with Azure VM Inspector A first step in troubleshooting an application or service is often checking the logs on the server. In Azure there is a feature for VMs to collect event logs, configurations, settings, and registry keys. Then read through the report directly from the portal. This feature is called VM Inspector and is per January of 2022 still in preview. That means that you will have to enable the feature for your subscription.\nNote: Microsoft does not recommend using preview features in production and the price of a service may change when it goes globally available.\nThere are some prerequisites for VM Inspector. You need to have managed disks on your VM, the disks can\u0026rsquo;t be encrypted, and since it is in preview there are a limited amount of regions where it is available. After you have enabled VM Inspector on your subscription you need to connect it to an existing storage account or creating a new one. Once you have connected it to a storage account, you can create your first report! After the report is finished, it will be stored as a zip-file in the connected storage account.\nThis tool combined with the Run Command feature makes it possible to troubleshoot and fix most configuration and other simple errors remotely!\nManage certificates and secrets with Azure Key Vault Management of certificates can be an unappreciated job. It can include waking up at 07:00 on a Sunday to change a certificate and getting yelled at Monday morning cause an undocumented application that used the certificate is now partly unavailable for users. All this headache could be avoided by using Azure Key Vault and some of its features for managing and distributing certificates and secrets!\nAzure Key Vault lets you generate, import, or even buy a managed certificate. With generated and managed certificates you can configure automatic renewal of the certificates. You can then install the Azure Key Vault extension on your VMs and have them automatically deploy the new versions of the certificate to the VM.\nConclusion In this blog I gave a quick introduction to some tools and features in Azure that can help you manage your servers on an OS level without needing to RDP into them. Going forward I will create follow up blogs going further into these features.\n","permalink":"https://www.errush.org/blogposts/vm-operations-wo-rdp/","summary":"\u003cp\u003eThe \u0026ldquo;Traditional\u0026rdquo; way to manage servers was to RDP or SSH into them and apply the changes you needed to do. And this was regarded as safe to do (Not by everyone of course) since you usually already were inside the office or datacenter. But when your servers are in another datacenter or even on the other side of the world, what can you do then?\nYou can just open up RDP for your IP-address or a whole range of IP-addresses, but it is not recommended.\u003c/p\u003e","title":"VM operations in Azure without RDP"},{"content":"I work at Atea in Norway, helping organizations get more from Microsoft Azure. My work focuses on cloud transformation, Azure architecture, security, and cost optimization. I have also helped build cost optimization services that have saved customers hundreds of thousands of euros.\nCertifications and badges:\nAI-103 — Azure AI Apps and Agents Developer Associate AB-100 — Agentic AI Business Solutions Architect Expert AZ-104 — Azure Administrator Associate AZ-140 — Azure Virtual Desktop Specialty AZ-305 — Azure Solutions Architect Expert AZ-500 — Azure Security Engineer Associate AZ-700 — Azure Network Engineer Associate SC-300 — Identity and Access Administrator Associate FOCP — FinOps Certified Practitioner CLF-C01 — AWS Certified Cloud Practitioner GitHub Copilot — Microsoft (expires October 2028) GitHub Administration — Microsoft (expires April 2028) Frontier Transformation Engineer — Microsoft badge I share practical lessons from my work through this blog and at community events. You can find my past and upcoming talks on the Public Speaking page.\n","permalink":"https://www.errush.org/about/","summary":"\u003cp\u003eI work at Atea in Norway, helping organizations get more from Microsoft Azure. My work focuses on cloud transformation, Azure architecture, security, and cost optimization. I have also helped build cost optimization services that have saved customers hundreds of thousands of euros.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eCertifications and badges:\u003c/strong\u003e\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://learn.microsoft.com/en-us/credentials/certifications/azure-ai-apps-and-agents-developer-associate/\"\u003eAI-103 — Azure AI Apps and Agents Developer Associate\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://learn.microsoft.com/en-us/credentials/certifications/exams/ab-100/\"\u003eAB-100 — Agentic AI Business Solutions Architect Expert\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003eAZ-104 — Azure Administrator Associate\u003c/li\u003e\n\u003cli\u003eAZ-140 — Azure Virtual Desktop Specialty\u003c/li\u003e\n\u003cli\u003eAZ-305 — Azure Solutions Architect Expert\u003c/li\u003e\n\u003cli\u003eAZ-500 — Azure Security Engineer Associate\u003c/li\u003e\n\u003cli\u003eAZ-700 — Azure Network Engineer Associate\u003c/li\u003e\n\u003cli\u003eSC-300 — Identity and Access Administrator Associate\u003c/li\u003e\n\u003cli\u003eFOCP — FinOps Certified Practitioner\u003c/li\u003e\n\u003cli\u003eCLF-C01 — AWS Certified Cloud Practitioner\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://learn.microsoft.com/api/credentials/share/en-us/ErlendRushfeldt-0482/A8D6142E341CEEA1\"\u003eGitHub Copilot\u003c/a\u003e — Microsoft (expires October 2028)\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://learn.microsoft.com/api/credentials/share/en-us/ErlendRushfeldt-0482/A9FB122CBE5CB07C\"\u003eGitHub Administration\u003c/a\u003e — Microsoft (expires April 2028)\u003c/li\u003e\n\u003cli\u003eFrontier Transformation Engineer — Microsoft badge\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003eI share practical lessons from my work through this blog and at community events. You can find my past and upcoming talks on the \u003ca href=\"/speaking/\"\u003ePublic Speaking\u003c/a\u003e page.\u003c/p\u003e","title":"About me"},{"content":"Previous talks and appearances 2021 Atea Community Trondheim 2021 2023 Azure User group Norway Summer meetup 2024 EUCTech Spring Microsoft Learn Zero to Hero Community 2025 Microsoft Community Insights Podcast European AI \u0026amp; CloudSummit Azure User Group Norway - Virtual Lunch Atea Community Trondheim — DevSecOps \u0026amp; Microsoft Defender for Cloud (30 September) Atea Community Ålesund — DevSecOps \u0026amp; Microsoft Defender for Cloud (23 October) Atea Community Bergen — DevSecOps \u0026amp; Microsoft Defender for Cloud (30 October) 2026 Cloud Tech Tallinn (January) GitHub Dev Days Oslo (October) Speaker listings Experts Live Denmark 2026 (listed speaker, February 2026) Upcoming talks Experts Live Denmark 2027 — “APIOps CLI – The new way of working with API Management” (10 February 2027, Copenhagen) European AI \u0026amp; Cloud Summit at ECS 2027 (31 May–2 June 2027, Düsseldorf) ","permalink":"https://www.errush.org/speaking/","summary":"\u003ch2 id=\"previous-talks-and-appearances\"\u003ePrevious talks and appearances\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e2021\n\u003cul\u003e\n\u003cli\u003eAtea Community Trondheim 2021\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e2023\n\u003cul\u003e\n\u003cli\u003eAzure User group Norway Summer meetup\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e2024\n\u003cul\u003e\n\u003cli\u003eEUCTech Spring\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://www.youtube.com/watch?v=en2DQwZAHC4\"\u003eMicrosoft Learn Zero to Hero Community\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e2025\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://www.youtube.com/watch?v=bTZsm8HWEc8\"\u003eMicrosoft Community Insights Podcast\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://cloudsummit.eu/en/session?guid=267d577f-ca0e-400a-b92f-966551a29545\"\u003eEuropean AI \u0026amp; CloudSummit\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://www.meetup.com/azure-user-group-norway/events/306951060/?eventOrigin=group_upcoming_events\"\u003eAzure User Group Norway - Virtual Lunch\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://events.atea.no/public/events/aea2be3cf3/seminars/bfba96d07e\"\u003eAtea Community Trondheim — DevSecOps \u0026amp; Microsoft Defender for Cloud\u003c/a\u003e (30 September)\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://events.atea.no/public/events/db56bb8f97/seminars/ccf2d8a79e\"\u003eAtea Community Ålesund — DevSecOps \u0026amp; Microsoft Defender for Cloud\u003c/a\u003e (23 October)\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://events.atea.no/public/events/dbb0587752/seminars/ae8fdcc515\"\u003eAtea Community Bergen — DevSecOps \u0026amp; Microsoft Defender for Cloud\u003c/a\u003e (30 October)\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e2026\n\u003cul\u003e\n\u003cli\u003eCloud Tech Tallinn (January)\u003c/li\u003e\n\u003cli\u003eGitHub Dev Days Oslo (October)\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"speaker-listings\"\u003eSpeaker listings\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://expertslive.dk/announcement-eldk26-speakers-for-technical-sessions-master-classes/\"\u003eExperts Live Denmark 2026\u003c/a\u003e (listed speaker, February 2026)\u003c/li\u003e\n\u003c/ul\u003e\n\u003ch2 id=\"upcoming-talks\"\u003eUpcoming talks\u003c/h2\u003e\n\u003cul\u003e\n\u003cli\u003e\u003ca href=\"https://eldk27.expertslive.dk/#/agenda?day=2\u0026amp;lang=en\u0026amp;sessionId=14880000004686026\"\u003eExperts Live Denmark 2027 — “APIOps CLI – The new way of working with API Management”\u003c/a\u003e (10 February 2027, Copenhagen)\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://ecs.events/en/sessions\"\u003eEuropean AI \u0026amp; Cloud Summit at ECS 2027\u003c/a\u003e (31 May–2 June 2027, Düsseldorf)\u003c/li\u003e\n\u003c/ul\u003e","title":"Public Speaking"}]