Azure DevOps Pipeline Integration
Relevant source files
The following files were used as context for generating this wiki page:
2ms (Too Many Secrets) provides a lightweight integration for Azure DevOps Pipelines, allowing developers to automate the detection of sensitive data like secrets, authentication keys, and passwords during the CI/CD process. By utilizing Docker, 2ms can be easily incorporated into an azure-pipelines.yml file to scan the source code residing in the pipeline's agent environment.
Sources: README.md:14-18, README.md:120-136
Integration Overview
The integration primarily relies on the 2ms Docker image to execute scans without requiring manual installation of Go or precompiled binaries on the Azure DevOps agent. The pipeline mounts the current working directory (the checked-out repository) into the Docker container, allowing the 2ms git or filesystem commands to analyze the codebase.
Pipeline Workflow
The following diagram illustrates how the Azure DevOps agent interacts with the 2ms Docker container to perform a scan.
The diagram shows the standard flow where the pipeline checks out the source code and then invokes 2ms via Docker. Sources: README.md:129-136, cmd/main.go:88-91
Configuration and Implementation
To implement the integration, a script step is added to the Azure DevOps YAML configuration. This step pulls the specific version of the checkmarx/2ms image and runs the tool against the repository.
Azure DevOps YAML Template
The standard configuration for an Azure DevOps pipeline using 2ms is as follows:
trigger:
- master
pool:
vmImage: ubuntu-latest
steps:
- script: docker run -v $(pwd):/repo checkmarx/2ms:2.8.1 git /repo
displayName: Run 2ms
Sources: README.md:129-136
Key Components
| Component | Description | Source |
|---|---|---|
| Docker Image | checkmarx/2ms:2.8.1 is used to provide the execution environment. | README.md:131 |
| Volume Mounting | -v $(pwd):/repo maps the agent's current directory to the container. | README.md:134 |
| Scan Command | git /repo tells 2ms to treat the mounted directory as a Git repository for scanning. | README.md:134 |
| Agent Pool | Typically uses ubuntu-latest for Docker compatibility. | README.md:131 |
Execution Logic and Exit Codes
The integration's success or failure depends on the exit codes generated by the 2ms engine. By default, finding secrets results in a non-zero exit code, which Azure DevOps interprets as a task failure, thereby breaking the build to prevent secret leakage.
Global Flags for Pipeline Customization
Developers can customize the behavior of 2ms within the pipeline using global flags:
--ignore-on-exit: Defines which non-zero exit codes to ignore (e.g.,all,results,errors).--report-path: Specifies a path to generate report files in JSON, YAML, or SARIF format.--validate: Triggers additional validation to check if discovered secrets are active.
Sources: README.md:154-177, cmd/main.go:44-53
Exit Code Handling Logic
This sequence shows the interaction between the engine and the pipeline agent during a scan execution. Sources: engine/engine.go:102-136, cmd/main.go:88-115
Advanced Usage in CI/CD
Beyond simple scans, the integration can be extended to use local configuration files or custom regex rules to tailor the detection to specific organizational needs.
Using Configuration Files
A .2ms.yml file can be placed in the repository and passed to the Docker command. This allows for persistent configuration of ignored results or specific rules without cluttering the pipeline YAML.
docker run -v $(pwd):/repo checkmarx/2ms:2.8.1 git /repo --config /repo/.2ms.yml
Sources: README.md:183-187, cmd/main.go:37
Handling Large Repositories
In high-performance environments or large monorepos, the --max-target-megabytes flag can be used to skip massive files that might slow down the pipeline execution.
Sources: README.md:257, engine/engine.go:61
Conclusion
The Azure DevOps Pipeline integration for 2ms is a critical security gate that ensures sensitive information is not committed to the repository. By leveraging Docker and standard Git/Filesystem plugins, it provides a portable and configurable solution for secret detection within Microsoft's CI/CD ecosystem.
Sources: README.md:16-24, CONTRIBUTING.md:10-15