We will learn how to build Docker image for a springboot app and upload the Docker image into Azure Container Registry(ACR) using Azure YAML pipelines.
GitHub Advanced Security for Azure DevOps brings the secret scanning, dependency scanning and CodeQL code scanning solutions already available for GitHub users and natively integrates them into Azure DevOps to protect your Azure Repos and Pipelines.
Dependency scanning is a pipeline-based scanning tool. Results are aggregated per repository. It's recommended that you add the dependency scanning task to all the pipelines you'd like to be scanned.
Add the task Advanced Security Dependency Scanning task (AdvancedSecurity-Dependency-Scanning@1) directly to your YAML pipeline file or select the Advanced Security Dependency Scanning task from the task assistant.
How to Set up code scanning
Code scanning is also a pipeline-based scanning tool where results are aggregated per repository.
Let us learn how to configure a self-hosted agent using Docker in Azure DevOps pipelines.
What is an Agent?
An agent is computing infrastructure with installed agent software that runs one job at a time.To build your code or deploy your software using Azure Pipelines, you need at least one agent. As you add more code and people, you'll eventually need more.
When your pipeline runs, the system begins one or more jobs.
In Azure pipelines, there are two types of build agents:
Microsoft-hosted agents - This is a service totally managed by Microsoft and it's cleared on every execution of the pipeline (on each pipeline execution, you have a fresh new environment).
Self-hosted agents - This is a service that you can to set up and manage by yourself. This can be a custom virtual machine on Azure or a custom on-premise machine inside your infrastructure. In a self-hosted agent, you can install all the software you need for your builds, and this is persisted on every pipeline execution. A self-hosted agent can be on Windows, Linux, macOS, or in a Docker container.
You can set up a self-hosted agent in Azure Pipelines to run inside a Windows Server Core (for Windows hosts), or Ubuntu container (for Linux hosts) with Docker.We will learn in this article on how to host Ubuntu Docker container on Linux machines.
Microsoft has temporarily disabled the free grant of parallel jobs for public projects and for certain private projects in new organizations. However, you can request this grant by submitting a request. Submit a ticket using below url to request increased parallelism in Azure DevOps. Please note that it takes us 2-3 business days to respond to your free tier requests.
Securing your Azure DevOps pipelines is crucial to protect your code, data, and infrastructure. Here are several best practices to consider for securing your Azure DevOps pipelines:
1. Pipeline Security:
Use Version Control: Store your pipeline definitions and code in version control repositories. This ensures version history, change tracking, and controlled access.
Secure Branch Policies: Implement branch policies to control who can make changes to specific branches. This prevents unauthorized or unreviewed changes from being deployed.
Use Parameterized Builds: Avoid hardcoding sensitive information like credentials directly into pipeline definitions. Use pipeline variables or parameterized builds instead.
Limit Access: Follow the principle of least privilege. Only grant necessary permissions to users and groups. Use role-based access control (RBAC) to manage access to pipelines and resources.
Monitor and Audit: Regularly review access logs, audit logs, and pipeline run history to identify suspicious activities.
2. Secrets Management:
Use Variable Groups: Azure DevOps provides variable groups that allow you to store sensitive information securely. These can be linked to pipelines without exposing the values directly in pipeline definitions.
Use Secure File Variables: For sensitive files, use secure file variables to securely store and manage encrypted files that your pipelines can use during execution.
Azure Key Vault Integration: Integrate Azure Key Vault to store and manage secrets, keys, and certificates. You can then reference these secrets in your pipelines securely.
3. Secure Pipeline Code:
Use Private Repositories: Store sensitive code in private repositories. Avoid exposing secrets in public repositories.
Encryption: Encrypt sensitive data at rest and during transmission. Use HTTPS for repository connections and secure protocols for data storage.
Secure Code Review: Implement code review processes to catch and address security issues in pipeline definitions.
4. Secure Pipeline Execution:
Agent Security: Secure the build and deployment agents by regularly updating them, applying security patches, and using agents in private networks when possible.
Use Service Principals: If your pipeline needs access to Azure resources, use service principals with the least privilege required. Avoid using personal credentials.
Secure Pipeline Variables: When using pipeline variables, ensure that they are set to "Secret" to hide their values in logs and run history.
5. Compliance:
Regulatory Compliance: If your organization needs to adhere to specific regulatory standards, ensure that your pipelines and processes align with those standards.
Compliance Scanning: Use security and compliance scanning tools to identify vulnerabilities in your pipeline code and configurations.
6. Continuous Improvement:
Stay Updated: Regularly review Azure DevOps documentation, security best practices, and new features to stay informed about security improvements.
Incident Response Plan: Develop an incident response plan to handle security breaches or unauthorized access.
By following these best practices, you can significantly enhance the security of your Azure DevOps pipelines and safeguard your development and deployment processes. Remember that security is an ongoing effort, and it's important to regularly assess and update your security measures as needed.
Click here to know the CICD process flow digram using Azure DevOps.
We are going to learn how to deploy Springboot Microservices Docker container into Azure Kubernetes Cluster(AKS) using Helm and Azure pipelines.
Sample springboot App Code:
I have created a sample Springboot App setup in GitHub. Click here to access code base in GitHub.
Watch steps in YouTube channel:
What is Helm?
Helm is a package manager for Kubernetes. Helm is the K8s equivalent of yum or apt. It accomplishes the same goals as Linux system package managers like APT or YUM: managing the installation of applications and dependencies behind the scenes and hiding the complexity from the user.
Helm Charts
Helm uses a packaging format called Charts.A Helm Chart is a collection of files that describe a set of Kubernetes resources.Helm Charts helps you define, install, and upgrade even the most complex Kubernetes application. Charts are easy to create, version, share, and publish.
Implementation steps:
Create a resource group, AKS cluster and Azure container registry
Provide pull access for AKS to pull image from ACR
Create a namespace for helm deployment
Create a helm chart for spring boot app
Create a build pipeline to automate docker image
Customize pipeline with helm package tasks
Create a release pipeline
Customize pipeline with helm upgrade tasks
Run the pipeline to deploy springboot app into AKS
If you see any errors after deploying the pods, you can check the pod logs.
kubectl describe pod <pod_name> -n helm-deployment
Go to the browser enter http://localhost:8080
You should see below web page.
Clean up Resources
Let us see how to clean up the resources that were created. We can use az group delete command to remove the resource group, AKS cluster, and all related resources.