Monitor git secrets on Azure DevOps with Gitleaks
Introduction
In this article we will see how to scan all repos of an Azure DevOps project.
The secret scanning solution will respect the following guidelines:
- 1 single DevOps pipeline per DevOps project that launches Gitleaks and sends its scan results to an Azure Application Insights.
- This pipeline can be triggered manually for a spot check or through any supported scheduled triggers provided by Microsoft.
- Developers are able to declare a secret as a false positive following Gitleaks procedure.
- 1 Azure monitoring Workbook where you can find:
- An overview tab that displays the total number of secrets found.
- A “Secrets” tab which gives more metrics such as
- the secret trends -> number of secrets observed during each scan,
- count of secrets per repository,
- a complete inventory of results exportable to Excel.
Prerequisite
- Disable the option “Protect access to repositories in YAML pipelines” to allow the Azure DevOps Build Service to pull remote repositories. You can find this option by navigating to the project settings page under “Pipeline” > “Settings”.
- Grant version control permissions to the build service as described in the following procedure.
- You have an Azure Application Insights and are able to read its connection string.
Pipeline
Create an Azure DevOps repo following this procedure and add on this repo the 3 following files (all the source code is available here: azure-devops-secret-scanning).
- azure-pipelines.yml → This yaml file describes the Azure DevOps pipeline workflow that will perform the secret scan.
- send_az_appinsights_event_telemetry.sh → This bash script is in charge of sending data into Azure Application Insights. I have posted a dedicated article here focused on this script and its usages.
- scan_azure_devops_secret.sh → This bash script performs the secret scanning with Gitleaks.
You can now create the Azure DevOps pipeline based on the yaml file you just pushed, for more details on this procedure you can consult the following article.
You can now run the pipeline manually from Azure DevOps by providing the following information:
- Your Azure Application Insights connection string.
- A valid email and name of a git user in your organisation that will be in charge of the secret scanning.
Monitoring Workbook
We can now publish the Azure Monitoring Workbook to find:
- An overview tab that displays the total number of secrets found.
- A “Secrets” tab which gives more metrics such as
- the secret trends -> number of secrets observed during each scan,
- count of secrets per repository,
- a complete inventory of results exportable to Excel.
You can publish the Azure Monitoring workbook following this procedure “Creating a new workbook” and by copy pasting the json code available here: azure-devops-secret-scanning/workbook.json.
Conclusion
Exposed credentials in engineering systems provide easily exploitable opportunities for attackers. To defend against this threat, we demonstrate here how to use a free monitoring workflow that prevents any credentials from being leaked.
Feel free to use it, share it and improve it.
See You in the Cloud
Jamesdld
Published on:
Learn moreRelated posts
This Month in Azure Static Web Apps | 09/2024
We are back with another edition of the Azure Static Web Apps Community! :party_popper: September was yet another month ...
GitHub Copilot for Azure: 6 Must-Try Features
As developers, we are constantly seeking tools that streamline our workflows and boost productivity. … Enter GitHub Copilot for Azure, now in ...
Responsible AI Mitigation Layers
Generative AI is increasingly being used in various kinds of systems to augment humans and infuse intelligent behavior into existing and new a...
Streamline Your Azure Workflow: Introducing GitHub Copilot for Azure in VS Code
I'm excited to announce the public preview of GitHub Copilot for Azure - a new addition to your toolkit that seamlessly integrates with G...
Build Intelligent Apps Code-First with Prompty and Azure AI
Building Generative AI applications can feel daunting for traditional app developers. What does the end-to-end applicati...
Certificación AI-900 (Fundamentos de IA) con Chicas en IA
La inteligencia artificial ha llegado para quedarse, ¡y más aún con la revolucionaria IA generativa! Para ayudar a los profesionales a especia...
Get certified with Learn Live GitHub series!
GitHub Universe is coming, and Microsoft and GitHub are partnering to offer a new special Learn Live series in Brazilian Portuguese, English a...
Certifícate con Learn Live GitHub en Español
Microsoft y GitHub se han unido para ofrecer una nueva serie especial de Learn Live en inglés y español: GitHub 2024. Del 10 al 24 de Octubre,...
Evaluating generative AI: Best practices for developers
As a developer working with generative AI, you've likely marveled at the impressive outputs your models can produce. But how do you ensure the...
Introducing Azure Product Retirement Livestreams
The Azure Retirements team, in collaboration with key partner groups, is excited t...