<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[devopsengage.com]]></title><description><![CDATA[devopsengage.com]]></description><link>https://devopsengage.com</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1630335538874/SdBGT_-TL.jpeg</url><title>devopsengage.com</title><link>https://devopsengage.com</link></image><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Nov 2026 11:16:38 GMT</lastBuildDate><atom:link href="https://devopsengage.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[PowerShell  automation cleanup]]></title><description><![CDATA[Automate Azure identity cleanup with PowerShell for efficient management and cleanliness in your subscription environments]]></description><link>https://devopsengage.com/powershell-automation-cleanup</link><guid isPermaLink="true">https://devopsengage.com/powershell-automation-cleanup</guid><category><![CDATA[Powershell]]></category><category><![CDATA[Azure]]></category><category><![CDATA[azure-devops]]></category><dc:creator><![CDATA[Alen Demirovic]]></dc:creator><pubDate>Fri, 05 Jul 2024 12:12:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1720181491262/261169fe-6cab-4d63-aa13-cb3c8f4d2335.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Recently I had to do tedious work, i needed to cleanup dangling identities in my Azure subscriptions, but who would go one by one and remove them by hand... 😒</p>
<p>I decided that this issue could be great example where I could automate entire process, so when you work in enterprise environments, where everything is changing rapidly, you can have a ton of unmanaged identities which was removed at some point, however Azure UI, will still show them as present when you go to iam blade, whether that is subscription, resource group or resources itself, and it looks like this.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1720178773672/16e8f4d9-675b-4de3-8e34-60448d8dff6e.png" alt class="image--center mx-auto" /></p>
<p>At first glance, you don't understand what is it, where it comes from, and why it's unknown, so this was confusing for me as well at first sight. After reading some documentation, I stumbled upon documentation page for greater context, so I highly recommend that you check <a target="_blank" href="https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/managed-identity-best-practice-recommendations">this</a> out.</p>
<p>So instead of checking every subscription, resource group, or resource manually, you can fire up the script, and script will behave in a manner where you will have to provide subscription ID, and your email account that corresponds to your Azure environment. Important thing to notice is that you would need to have Owner role or some custom elevated permission that will give you rights to manage RBAC, otherwise, this won't work.</p>
<p>Here you can find the script written in PowerShell core 7.4. Feel free to name your script as you wish, I will give it a name "<a target="_blank" href="http://cleanup.ps">cleanup.ps</a>1"</p>
<pre><code class="lang-powershell"><span class="hljs-comment"># Enable debugging</span>
<span class="hljs-comment"># $DebugPreference = "Continue" </span>
<span class="hljs-variable">$subscriptionId</span> = <span class="hljs-built_in">Read-Host</span> <span class="hljs-string">"Please enter subscription id"</span>
<span class="hljs-variable">$accountId</span> = <span class="hljs-built_in">Read-Host</span> <span class="hljs-string">"Please enter your email"</span>
<span class="hljs-comment"># Login to Azure</span>
<span class="hljs-variable">$context</span> = <span class="hljs-built_in">Connect-AzAccount</span> <span class="hljs-literal">-AccountID</span> <span class="hljs-variable">$accountId</span> <span class="hljs-literal">-Subscription</span> <span class="hljs-variable">$subscriptionId</span>

<span class="hljs-variable">$resourcegroups</span> = <span class="hljs-built_in">Get-AzResourceGroup</span> <span class="hljs-literal">-DefaultProfile</span> <span class="hljs-variable">$context</span>

<span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$group</span> <span class="hljs-keyword">in</span> <span class="hljs-variable">$resourcegroups</span>) {
    <span class="hljs-variable">$groupName</span> = <span class="hljs-variable">$group</span>.ResourceGroupName
    <span class="hljs-variable">$scope</span> = <span class="hljs-string">"/subscriptions/<span class="hljs-variable">$subscriptionId</span>/resourcegroups/<span class="hljs-variable">$groupName</span>"</span>

    <span class="hljs-built_in">Write-Host</span> <span class="hljs-string">"Listing all unknown identities within <span class="hljs-variable">$groupName</span>"</span>
    <span class="hljs-variable">$unknownIdentities</span> = <span class="hljs-built_in">Get-AzRoleAssignment</span> <span class="hljs-literal">-DefaultProfile</span> <span class="hljs-variable">$context</span> <span class="hljs-literal">-Scope</span> <span class="hljs-variable">$scope</span> | <span class="hljs-built_in">Where-Object</span> { <span class="hljs-variable">$_</span>.ObjectType <span class="hljs-operator">-eq</span> <span class="hljs-string">"Unknown"</span> }

    <span class="hljs-keyword">if</span> (<span class="hljs-variable">$unknownIdentities</span>) {
        <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$identity</span> <span class="hljs-keyword">in</span> <span class="hljs-variable">$unknownIdentities</span>) {
            <span class="hljs-built_in">Write-Host</span> <span class="hljs-string">"Scope: <span class="hljs-variable">$</span>(<span class="hljs-variable">$identity</span>.Scope)"</span> <span class="hljs-literal">-ForegroundColor</span> DarkRed <span class="hljs-literal">-BackgroundColor</span> Yellow <span class="hljs-literal">-NoNewline</span>
            <span class="hljs-built_in">Write-Host</span> <span class="hljs-string">", Role: <span class="hljs-variable">$</span>(<span class="hljs-variable">$identity</span>.RoleDefinitionName)"</span> <span class="hljs-literal">-BackgroundColor</span> Green <span class="hljs-literal">-NoNewline</span>
            <span class="hljs-built_in">Write-Host</span> <span class="hljs-string">", ObjectType: <span class="hljs-variable">$</span>(<span class="hljs-variable">$identity</span>.ObjectType)"</span> <span class="hljs-literal">-BackgroundColor</span> DarkMagneta <span class="hljs-literal">-ForegroundColor</span> White <span class="hljs-literal">-NoNewline</span>
            <span class="hljs-built_in">Write-Host</span> <span class="hljs-string">", ObjectId: <span class="hljs-variable">$</span>(<span class="hljs-variable">$identity</span>.ObjectId)"</span> <span class="hljs-literal">-BackgroundColor</span> Black <span class="hljs-literal">-ForegroundColor</span> White
        }
    }
    <span class="hljs-keyword">else</span> {
        <span class="hljs-built_in">Write-Host</span> <span class="hljs-string">"No unknown identities found in resource group <span class="hljs-variable">$groupName</span>"</span>
        <span class="hljs-keyword">continue</span>
    }

    <span class="hljs-variable">$confirmation</span> = <span class="hljs-built_in">Read-Host</span> <span class="hljs-literal">-Prompt</span> <span class="hljs-string">"Do you want to remove unknown identities from the <span class="hljs-variable">$groupName</span> ? (y/n)?"</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-variable">$confirmation</span> <span class="hljs-operator">-eq</span> <span class="hljs-string">"y"</span>) {
        <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$identity</span> <span class="hljs-keyword">in</span> <span class="hljs-variable">$unknownIdentities</span>) {
            <span class="hljs-built_in">Get-AzRoleAssignment</span> <span class="hljs-literal">-Scope</span> <span class="hljs-variable">$scope</span> | <span class="hljs-built_in">Where-Object</span> { <span class="hljs-variable">$_</span>.ObjectType <span class="hljs-operator">-eq</span> <span class="hljs-string">"Unknown"</span> } | <span class="hljs-built_in">Remove-AzRoleAssignment</span> <span class="hljs-literal">-Scope</span> <span class="hljs-variable">$scope</span>
        }
        <span class="hljs-built_in">Write-Host</span> <span class="hljs-string">"All unknown identities removed from <span class="hljs-variable">$groupName</span>"</span>
    }
    <span class="hljs-keyword">else</span> {
        <span class="hljs-built_in">Write-Host</span> <span class="hljs-string">"Skipping <span class="hljs-variable">$groupName</span>, unknown identities still remain"</span>
    }
}
</code></pre>
<p>How to use the script?</p>
<p>run <code>./cleanup.ps1</code>, script will ask you to provide your desired subscription id and your email. Providing your credentials on the Microsoft login page is necessary only when you first use your script as it will try to connect your AD account, after that everything should work in automated fashion.</p>
<p>Script will for_each resource groups within your subscription, so you will be prompted with results first, you will get colored output, so it can be easier for your eye, and you will be able to see the scope, role, Object type, and Object ID. Object type will always be "Unknown" so that is what we want to remove. If you are satisfied with results presented, you will be asked do you want to delete unknown identities from resource group &lt;resource_group_name&gt; (y/n)? If you are satisfied press y, and you will be shown confirmation with removed unknown identities, if you are not satisfied and you want to opt-out, press n, and script will reiterate to next resource group.</p>
<p>I just want to clarify one thing, you will be prompted with scope that is only scoped to subscription level or you will be prompted with scope that is set to resource directly? That is because of inheritance. So if you attach the role to the subscription level, it will be propagated to the resource group, or if you attach the role to the resource group it can be propagated to the resource itself. This can be confusing, but the script is designed to be smart enough to catch unknown identities and remove them from right scope so they don't leave dangling.</p>
<p>PS in case you need debug help, uncomment line 2 to have logs in the console 👌</p>
<p>Let me know what do you think about this, does it make your life easier and what can be done better?</p>
<p>Thank you for reading 😊</p>
]]></content:encoded></item><item><title><![CDATA[Configure Renovate on Azure DevOps mono-repo]]></title><description><![CDATA[Configure renovate on Azure DevOps mono-repo]]></description><link>https://devopsengage.com/configure-renovate-on-azure-devops-mono-repo</link><guid isPermaLink="true">https://devopsengage.com/configure-renovate-on-azure-devops-mono-repo</guid><category><![CDATA[Azure]]></category><category><![CDATA[renovate]]></category><category><![CDATA[azure-devops]]></category><dc:creator><![CDATA[Alen Demirovic]]></dc:creator><pubDate>Thu, 09 May 2024 09:52:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1715248178194/c1845622-de54-4328-900e-bd31bc58cd77.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today i will be providing details about setting up Renovate via Azure DevOps CI/CD pipeline which runs on monthly basis. Here you can see how automation of dependency management takes place in Enterprise environments where you have software, infrastructure and other possible code configurations.</p>
<p>Before we dive deep let's just take short brief on what is Renovate and why should we use it. Renovate is an automated dependency update tool commonly used in software development workflows. It helps streamline the process of keeping project dependencies up-to-date by automatically identifying outdated dependencies in code repositories and generating pull requests to update them. Renovate supports a wide range of package managers and platforms, including npm, Maven, Docker, and GitHub repositories. By automating dependency updates, Renovate reduces the burden on developers to manually track and update dependencies, ensuring projects stay secure, compatible, and up-to-date with the latest features and bug fixes.</p>
<p>Now that we have understanding what is Renovate and why we want to implement it, let's see how we can configure it. First clone the repo that you want to automate with Renovate, or if you already did that, create new branch where you will implement Renovate. First and most important thing. Mono-repo is configured in a way that holds multiple code bundles, now in order to make it operational we need to visualize the repo. Here is what we have as a baseline.</p>
<pre><code class="lang-plaintext">monorepo/
├── app/
├── infrastructure/
└── configuration/
</code></pre>
<p>Our first step is going to implement 3 files , <code>renovate.json</code> which is configuration file on how Renovate should behave, next we will have <code>config.js</code> which will store target destination in terms of platform that we use as a repository, it can be Github, bitbucket, Azure DevOps etc. and last we need pipeline which we've call <code>renovate-pipeline.yaml</code>, this pipeline will run all of this logic. Don't worry, i will be providing content of these files so you can see what is going on in there. After implementing these 3 files your project structure should look something like this.</p>
<pre><code class="lang-powershell">monorepo/
├── app/
├── infrastructure/
├── configuration/
|- config.js
|- renovate<span class="hljs-literal">-pipeline</span>.yaml
|- renovate.json
</code></pre>
<p><strong><em>Now very important thing!</em></strong> All these 3 files needs to sit at the <strong><em>root of the project</em></strong> otherwise pipeline will not be able to see <code>config.js</code> file, even though there is an option to specify <code>config.js</code> path, Renovate is not able to see it, so if you store this into <code>app/</code> or <code>infrastructure/</code>, Renovate will fail, stating that authentication is wrong, and if you open logs, it says that it switches to Github target , even we didn't configure it in such a fashion, I spent 3 days roaming around this, that is the reason why I'm writing this article today, to save you pain and grind.</p>
<p>Here is the config.js file</p>
<pre><code class="lang-yaml"><span class="hljs-string">module.exports</span> <span class="hljs-string">=</span> {
  <span class="hljs-attr">platform:</span> <span class="hljs-string">'azure'</span>,
  <span class="hljs-attr">endpoint:</span> <span class="hljs-string">'https://dev.azure.com/&lt;organization_name&gt;/'</span>,
  <span class="hljs-attr">token:</span> <span class="hljs-string">process.env.TOKEN</span>,
  <span class="hljs-attr">hostRules:</span> [
    {
      <span class="hljs-attr">hostType:</span> <span class="hljs-string">'npm'</span>,
      <span class="hljs-attr">matchHost:</span> <span class="hljs-string">'pkgs.dev.azure.com'</span>,
      <span class="hljs-attr">username:</span> <span class="hljs-string">'apikey'</span>,
      <span class="hljs-attr">password:</span> <span class="hljs-string">process.env.TOKEN</span>,
    },
  ],
  <span class="hljs-attr">repositories:</span> [<span class="hljs-string">'&lt;project_name&gt;/&lt;repo_name&gt;'</span>],
}<span class="hljs-string">;</span>
</code></pre>
<p>Here we can clearly see that platform in azure, endpoint directs to organization of your desire and host-rules block of code is stating which artifactory your are targeting. In this case we will update npm packages. At the end, we have defined repository that needs to be updated.</p>
<p>Next we will have <code>renovate-pipeline.yaml</code>.</p>
<pre><code class="lang-yaml"><span class="hljs-attr">schedules:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">cron:</span> <span class="hljs-string">'0 02 8-14 * sat'</span> 
    <span class="hljs-attr">displayName:</span> <span class="hljs-string">'Every second Saturday of the month at 2am'</span>
    <span class="hljs-attr">branches:</span>
      <span class="hljs-attr">include:</span> [<span class="hljs-string">main</span>]
    <span class="hljs-attr">always:</span> <span class="hljs-literal">true</span>

<span class="hljs-attr">trigger:</span> <span class="hljs-string">none</span>

<span class="hljs-attr">pool:</span> <span class="hljs-string">'&lt;agent-pool&gt;'</span>

<span class="hljs-attr">steps:</span>
  <span class="hljs-bullet">-</span> <span class="hljs-attr">task:</span> <span class="hljs-string">npmAuthenticate@0</span>
    <span class="hljs-attr">inputs:</span>
      <span class="hljs-attr">workingFile:</span> <span class="hljs-string">.npmrc</span>

  <span class="hljs-bullet">-</span> <span class="hljs-attr">task:</span> <span class="hljs-string">NodeTool@0</span>
    <span class="hljs-attr">inputs:</span>
      <span class="hljs-attr">versionSpec:</span> <span class="hljs-string">'18.x'</span>
    <span class="hljs-attr">displayName:</span> <span class="hljs-string">'Install Node.js'</span>

  <span class="hljs-bullet">-</span> <span class="hljs-attr">script:</span> <span class="hljs-string">npm</span> <span class="hljs-string">install</span> <span class="hljs-string">npx</span>
    <span class="hljs-attr">displayName:</span> <span class="hljs-string">'npm install npx'</span>

  <span class="hljs-bullet">-</span> <span class="hljs-attr">bash:</span> <span class="hljs-string">|
      git config --global user.email 'bot@renovateapp.com'
      git config --global user.name 'Renovate Bot'
      npx --userconfig .npmrc renovate
      LOG_LEVEL=debug npx --userconfig .npmrc renovate
</span>    <span class="hljs-attr">env:</span>
      <span class="hljs-attr">TOKEN:</span> <span class="hljs-string">$(System.AccessToken)</span>
      <span class="hljs-attr">RENOVATE_TOKEN:</span> <span class="hljs-string">$(System.AccessToken)</span>
</code></pre>
<p>Here we have first authentication to artifactory with npmAuthenticate@0 task, he will look for information about artifactory url in the .npmrc file, next it will install node 18 so latest Renovate can run, and then it will install npx so it can run bash script that fires up Renovate. In the bash section we have configuration of the Renovate bot username and email and then we have command for running renovate. In case things go south for you i have added <code>LOG_LEVEL=debug npx --userconfig .npmrc renovate</code></p>
<p>This line will ensure to provide you with verbose output in at the runtime, so you can see if something is bad for you. This is how i figured out potential missing <code>config.js</code> file.</p>
<p>At last we have tokens that are generated on the fly that has been used by project-collection build service. The "Project Collection Build Service" in Azure DevOps is a system identity that represents the build service in your Azure DevOps organization. It's automatically created and used by Azure DevOps to run builds and access resources within your organization.</p>
<p>When you set up authentication for Azure DevOps pipelines, you might encounter the need to grant permissions, and these permissions in the picture below. Beside these 3, you need to grant Read rights as well, and this can be achieved by opening project that you want to automate with Renovate so <code>Project - &gt; Project Settings -&gt; Repository name -&gt; Repository -&gt; Security</code> and then you will see page where you can configure permissions for the system identity.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715245892100/f39c03f9-3fd5-48fb-885b-ef9083e7716d.png" alt class="image--center mx-auto" /></p>
<p>If this is not configured, Renovate will fail, so before running anything, this should be done before. Last thing that we have is renovate.json. This file tells Renovate how to behave. If you have only application folder, there is general file for that which you can find below.</p>
<pre><code class="lang-yaml">{
  <span class="hljs-string">"$schema"</span><span class="hljs-string">:</span> <span class="hljs-string">"https://docs.renovatebot.com/renovate-schema.json"</span>,
  <span class="hljs-attr">"branchPrefix":</span> <span class="hljs-string">"renovate/update-"</span>,
  <span class="hljs-attr">"groupName":</span> <span class="hljs-string">"all dependencies"</span>,
  <span class="hljs-attr">"groupSlug":</span> <span class="hljs-string">"all"</span>,
  <span class="hljs-attr">"lockFileMaintenance":</span> {
    <span class="hljs-attr">"enabled":</span> <span class="hljs-literal">false</span>
  },
  <span class="hljs-attr">"packageRules":</span> [
    {
      <span class="hljs-attr">"groupName":</span> <span class="hljs-string">"all dependencies"</span>,
      <span class="hljs-attr">"groupSlug":</span> <span class="hljs-string">"all"</span>,
      <span class="hljs-attr">"matchPackagePatterns":</span> [<span class="hljs-string">"*"</span>]
    },
    {
      <span class="hljs-attr">"matchPackageNames":</span> [<span class="hljs-string">"@types/node"</span>],
      <span class="hljs-attr">"allowedVersions":</span> <span class="hljs-string">"&lt; 18.18.0"</span>
    }
  ],
  <span class="hljs-attr">"separateMajorMinor":</span> <span class="hljs-literal">false</span>
}
</code></pre>
<p>Place this at the root of your project and you will be good to go. However if you have mono-repo, you will encounter mess, this file that you can see above it will scan all folders and it will create one big chunky PR with all dependencies, and you will not know what needs to be updated and what not, now in order to avoid this, i have created config file that will help you alleviate this, by creating separate PR per folder that you have.</p>
<pre><code class="lang-yaml">{
  <span class="hljs-string">"$schema"</span><span class="hljs-string">:</span> <span class="hljs-string">"https://docs.renovatebot.com/renovate-schema.json"</span>,
  <span class="hljs-attr">"branchPrefix":</span> <span class="hljs-string">"renovate/update-"</span>,
  <span class="hljs-attr">"groupName":</span> <span class="hljs-string">"all dependencies"</span>,
  <span class="hljs-attr">"groupSlug":</span> <span class="hljs-string">"all"</span>,
  <span class="hljs-attr">"lockFileMaintenance":</span> {
    <span class="hljs-attr">"enabled":</span> <span class="hljs-literal">false</span>
  },
  <span class="hljs-attr">"packageRules":</span> [
    {
      <span class="hljs-attr">"groupName":</span> <span class="hljs-string">"app"</span>,
      <span class="hljs-attr">"groupSlug":</span> <span class="hljs-string">"function-app dependancies"</span>,
      <span class="hljs-attr">"matchFiles":</span> [<span class="hljs-string">"function-app/package.json"</span>],
      <span class="hljs-attr">"matchPackagePatterns":</span> [<span class="hljs-string">"*"</span>],
      <span class="hljs-attr">"labels":</span> [<span class="hljs-string">"root"</span>, <span class="hljs-string">"Renovate"</span>]
    },
    {
      <span class="hljs-attr">"groupName":</span> <span class="hljs-string">"infrastrucutre"</span>,
      <span class="hljs-attr">"groupSlug":</span> <span class="hljs-string">"Terraform module dependancies"</span>,
      <span class="hljs-attr">"matchFiles":</span> [<span class="hljs-string">"infrastructure/"</span>],
      <span class="hljs-attr">"matchPackagePatterns":</span> [<span class="hljs-string">"*"</span>],
      <span class="hljs-attr">"labels":</span> [<span class="hljs-string">"module"</span>, <span class="hljs-string">"Renovate"</span>]
    },
    {
      <span class="hljs-attr">"groupName":</span> <span class="hljs-string">"Configuration"</span>,
      <span class="hljs-attr">"groupSlug":</span> <span class="hljs-string">"config dependancies"</span>,
      <span class="hljs-attr">"matchFileNames":</span> [<span class="hljs-string">"Configuration/"</span>],
      <span class="hljs-attr">"matchPackagePatterns":</span> [<span class="hljs-string">"*"</span>],
      <span class="hljs-attr">"labels":</span> [<span class="hljs-string">"terraform"</span>, <span class="hljs-string">"Renovate"</span>]
    },
    {
      <span class="hljs-attr">"matchPackageNames":</span> [<span class="hljs-string">"@types/node"</span>],
      <span class="hljs-attr">"allowedVersions":</span> <span class="hljs-string">"&lt; 18.18.0"</span>
    }
  ],
  <span class="hljs-attr">"separateMajorMinor":</span> <span class="hljs-literal">false</span>
}
</code></pre>
<p>As described above Renovate will target app, infrastructure and configuration folder where it will create two separate PRs. The PRs will be named using a combination of branchPrefix + groupSlug. For the application, package.json needs to be targeted as he is using that file to look for dependencies, for infrastructure and configuration, no specific dependency file needs to be defined. Renovate is smart enough to go trough the file and scan them standalone.</p>
<p>After all of this is configured, you need to run pipeline. Submit PR and go to Azure DevOps where you will be creating new pipeline. You will have option to specify your branch upon pipeline selection. After successful run of the pipeline you should get PR by Renovate</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1715247100370/050a39f5-8265-460a-b35c-5116bc4daa64.png" alt class="image--center mx-auto" /></p>
<p>Approve the PR if you are satisfied, and after this Renovate will run periodically as it was defined in the Azure DevOps Pipeline. Hope this article helps you configure Renovate on Mono-Repo and provide you with greater security and stability. Let me know in the comments if this helps you with your task!</p>
<blockquote>
<p>Managing dependencies across multiple projects within a mono-repository can be challenging. Renovate simplifies this process by automating dependency updates. With Renovate, you can effortlessly track, monitor, and update dependencies across your entire codebase. This blog post explores how Renovate can help you maintain up-to-date dependencies, improve security, and streamline your development workflow in a mono-repository setup. Discover how Renovate can save you time and effort while keeping your projects in sync with the latest dependencies."</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Fine-Grained Access Control: Building Custom Roles in Azure via Terraform]]></title><description><![CDATA[When it comes to Azure roles, I need to mention early days of Azure, when access was governed by three roles: Account Administrator, Service Administrator…]]></description><link>https://devopsengage.com/fine-grained-access-control-building-custom-roles-in-azure-via-terraform</link><guid isPermaLink="true">https://devopsengage.com/fine-grained-access-control-building-custom-roles-in-azure-via-terraform</guid><category><![CDATA[Azure]]></category><category><![CDATA[Terraform]]></category><category><![CDATA[role-based-access-control]]></category><dc:creator><![CDATA[Alen Demirovic]]></dc:creator><pubDate>Mon, 13 Nov 2023 08:48:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/40s5X5D9Aqo/upload/08d4a8e6200d9baadd273fd63bc13b18.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When it comes to Azure roles, I need to mention early days of Azure, when access was governed by three roles: Account Administrator, Service Administrator, and Co-Administrator. Over time, Azure introduced a more modern approach to role management through Azure Role-Based Access Control (Azure RBAC). With 70 built-in roles, including Owner, Contributor, Reader, and User Access Administrator, Azure RBAC offers a comprehensive system.</p>
<p>While a detailed discussion on Azure RBAC could span an entire article, I'll focus on specific aspects here. Beyond basic access control (managing users and groups), you can customize roles and define scopes. Microsoft Entra ID roles, formerly known as Azure Active Directory roles, such as Global Admin, Application Admin, and Application Developer, are also noteworthy.</p>
<p>For a detailed understanding of scopes, refer to this <a target="_blank" href="https://learn.microsoft.com/en-us/azure/role-based-access-control/scope-overview">link</a>. Additionally, Microsoft provides a helpful topology to visualize these roles."</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699370168958/b03734d4-45d9-4ac4-9d33-7946d8f6f3bd.png" alt class="image--center mx-auto" /></p>
<p>The mentioned roles are built-in and provided by Azure for assignment. However, what if these roles don't offer the needed access? In such cases, custom roles become essential. Whether enforcing specific access restrictions or adhering to Azure RBAC best practices like the principle of least privilege, custom roles allow fine-grained control.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://giphy.com/gifs/door-useless-itsjakeberg-Zb0Xzgma68CT1nr8NI">https://giphy.com/gifs/door-useless-itsjakeberg-Zb0Xzgma68CT1nr8NI</a></div>
<p> </p>
<p>Now, returning to our primary objective, Azure RBAC is built on <a target="_blank" href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/overview">Azure Resource Manager</a>, which provides access to Azure resources like storage, computing etc, via SDK, Powershell, Azure CLI or Portal, we will utilize it to deploy our custom role to our Azure environment via Terraform so that will be our bridge to the cloud.</p>
<p>I'm tackling a scenario that spotlights the implementation of a specific custom role—let's call it <strong>data-factory-reader</strong>. The aim is to grant a select group of engineers in the tester Azure AD group access to certain data factories within our Azure subscriptions. Their mandate? Reading data, and nothing more. Let's zoom in on the code snippet for this functionality</p>
<pre><code class="lang-powershell"><span class="hljs-keyword">data</span><span class="hljs-literal">-factory</span><span class="hljs-literal">-reader</span><span class="hljs-string">" = {
      description = "</span>This role allows to read <span class="hljs-keyword">data</span> factory instances and their child resources<span class="hljs-string">"
      permissions = {
        actions = [
          "</span>Microsoft.DataFactory/datafactories/read<span class="hljs-string">",
          "</span>Microsoft.DataFactory/datafactories/linkedServices/read<span class="hljs-string">",
          "</span>Microsoft.DataFactory/datafactories/datapipelines/read<span class="hljs-string">",
          "</span>Microsoft.DataFactory/datafactories/datasets/read<span class="hljs-string">",
          "</span>Microsoft.DataFactory/datafactories/tables/read<span class="hljs-string">"
        ]
        not_actions = [
          "</span>Microsoft.DataFactory/datafactories/delete<span class="hljs-string">",
          "</span>Microsoft.DataFactory/factories/credentials/delete<span class="hljs-string">"
        ]
        data_actions = []
        not_data_actions = []
      }
    }</span>
</code></pre>
<p>In the snippet above, the first two lines set the name and description, which are mandatory. Moving forward, we specify actions that are allowed and not allowed. This custom role is defined within the locals.tf file, with the primary implementation residing in the role_definition.tf file or any other naming convention that would suggest that you are building a role here.</p>
<p>Considering that the built-in roles offer more permissions than needed for our case (Data Factory has only the contributor role), we've tailored our role. To achieve this, we've explored the Azure Resource Provider Operations page, pinpointing operations used in built-in roles and selecting only the components that align with our requirements</p>
<p>In this context, our focus lies in defining a role with precision and also with a set of permissions specified within properties. The diverse range of properties encompasses actions, not actions, data actions, and not data actions. For a detailed breakdown, refer to the documentation <a target="_blank" href="https://chat.openai.com/c/link-to-more-details">here</a>.</p>
<p>Delving into specifics, our purview includes data factories, linked services, data pipelines, datasets, and tables. However, the primary objective is to safeguard against inadvertent deletions, especially concerning data factories and associated credentials. Imagine assigning this custom role to an Azure AD group for testers, granting them read access while reserving management responsibilities for another team, such as the DevOps AD group.</p>
<p>For a graphical representation of these properties, consult the visual guide below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699609602996/7b25e856-51c2-4060-9c4e-769f0dd55475.png" alt class="image--center mx-auto" /></p>
<p>Now <em>actions</em> and <em>not_actions</em> are quite easy to grasp, you are defining what is allowed or what is not allowed on the resource level, so right after <code>Microsoft.DataFactory/</code> we have <code>datafactories/</code> and the last one is the action itself, it can be <code>read</code>, <code>write</code>, or <code>delete</code>, so depending on the use case we will choose the desired action. Regarding <em>data_actions</em> and <em>not_data</em> action, the idea is the same, however, we are going one level deeper so we are defining what we are allowing or not with the data that resides within the resource. Since we are managing only top-level resources or Control plane to be more precise, we have defined it within the Action property. Our main goal here is to give our engineers access to specific parts of data-factory so that they can read it, however, data should not be altered, hence we are not going into <em>data_action</em> parameters area where these data can be touched.</p>
<p>There is a question that arises, if we have a reader role for example assigned to a user on a subscription level which is inherited all the way down to the resource level, why do we need to do all of this? Well this role has basic reading functionality and that is why we need to extend it with specifics, hence we are doing all of this. If you want to see datasets within datafactory or data-factory resource health, we need to have these specifics in place. Datafactory is one of the resources in Azure that has an entire ecosystem of subservices within.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://giphy.com/gifs/lukecosgrove-luke-cosgrove-3o7aD4XavHnL5UsWEE">https://giphy.com/gifs/lukecosgrove-luke-cosgrove-3o7aD4XavHnL5UsWEE</a></div>
<p> </p>
<p>In our journey of creating custom roles in Azure using Terraform, we've come across a crucial player in this process – the <code>azurerm_role_definition</code>. If you're curious to delve deeper into its intricacies, you can find more details <a target="_blank" href="https://chat.openai.com/c/link-to-more-details">here</a>.</p>
<p>All in all, this article delves into the significance of crafting custom roles, addressing diverse motivations, such as operational needs and compliance requirements, within large organizations. Understanding the timing, purpose, and continual communication with role assignees are pivotal aspects, emphasizing the importance of both technical implementation and responsiveness to organizational needs.</p>
<p><img src="https://giphy.com/embed/dfNYKfFIbI1a0" alt class="image--center mx-auto" /></p>
]]></content:encoded></item></channel></rss>