|
| 1 | +name: msdo-reusable |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + branch: |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: 'main' |
| 11 | + secrets: |
| 12 | + GH_TOKEN: |
| 13 | + required: false |
| 14 | + |
| 15 | +jobs: |
| 16 | + msdo: |
| 17 | + name: Microsoft Security DevOps |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + id-token: write |
| 23 | + actions: read |
| 24 | + security-events: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Manually checkout repository (internal-safe) |
| 28 | + run: | |
| 29 | + git clone https://github.com/${{ github.repository }} . |
| 30 | + git checkout ${{ inputs.branch }} |
| 31 | +
|
| 32 | + - name: Set environment variables for tools |
| 33 | + shell: pwsh |
| 34 | + run: | |
| 35 | + $TOOLS = "" |
| 36 | +
|
| 37 | + if ((Get-ChildItem -Recurse -Include *.js, *.jsx, *.ts, *.tsx | Measure-Object).Count -gt 0) { |
| 38 | + $TOOLS += "eslint," |
| 39 | + echo "ESLint enabled - JS/JSX/TS/TSX files detected." |
| 40 | + } else { |
| 41 | + echo "ESLint skipped - No JS/JSX/TS/TSX files found." |
| 42 | + } |
| 43 | +
|
| 44 | + if ((Get-ChildItem -Recurse -Include *.exe, *.dll | Measure-Object).Count -gt 0) { |
| 45 | + $TOOLS += "binskim," |
| 46 | + echo "BinSkim enabled - EXE/DLL files detected." |
| 47 | + } else { |
| 48 | + echo "BinSkim skipped - No EXE/DLL files found." |
| 49 | + } |
| 50 | +
|
| 51 | + if ((Get-ChildItem -Recurse -Include *.py | Measure-Object).Count -gt 0) { |
| 52 | + $TOOLS += "bandit," |
| 53 | + echo "Bandit enabled - Python files detected." |
| 54 | + } else { |
| 55 | + echo "Bandit skipped - No Python files found." |
| 56 | + } |
| 57 | +
|
| 58 | + if ((Get-ChildItem -Recurse -Include *.tf, *.json, *.yml, *.yaml, *.dockerfile, *.template, *.bicep | Measure-Object).Count -gt 0) { |
| 59 | + $TOOLS += "checkov," |
| 60 | + echo "Checkov enabled - Terraform/JSON/YML/YAML/Dockerfiles/Templates/Bicep files detected." |
| 61 | + } else { |
| 62 | + echo "Checkov skipped - No Terraform/JSON/YML/YAML/Dockerfiles/Templates/Bicep files found." |
| 63 | + } |
| 64 | +
|
| 65 | + if ((Get-ChildItem -Recurse -Include *.json | Select-String 'resources' | Measure-Object).Count -gt 0) { |
| 66 | + $TOOLS += "templateanalyzer," |
| 67 | + echo "Template Analyzer enabled - ARM templates detected." |
| 68 | + } |
| 69 | +
|
| 70 | + if ((Get-ChildItem -Recurse -Include *.bicep | Measure-Object).Count -gt 0) { |
| 71 | + $TOOLS += "templateanalyzer," |
| 72 | + echo "Template Analyzer enabled - Bicep files detected." |
| 73 | + } |
| 74 | +
|
| 75 | + if ((Get-ChildItem -Recurse -Include *.tf, *.json, *.yml, *.yaml | Measure-Object).Count -gt 0) { |
| 76 | + $TOOLS += "terrascan," |
| 77 | + echo "Terrascan enabled - Terraform/JSON/YML/YAML files detected." |
| 78 | + } |
| 79 | +
|
| 80 | + if ((Get-ChildItem -Recurse -Include Dockerfile | Measure-Object).Count -gt 0) { |
| 81 | + $TOOLS += "trivy," |
| 82 | + echo "Trivy enabled - Dockerfiles detected." |
| 83 | + } |
| 84 | +
|
| 85 | + $TOOLS = $TOOLS.TrimEnd(',') |
| 86 | +
|
| 87 | + if ($TOOLS -eq "") { |
| 88 | + echo "No applicable tools found. The MSDO scan will be skipped." |
| 89 | + exit 0 |
| 90 | + } |
| 91 | +
|
| 92 | + echo "TOOLS=$TOOLS" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 |
| 93 | +
|
| 94 | + - name: Run Microsoft Security DevOps |
| 95 | + uses: theangrytech-git/security-devops-action@main |
| 96 | + id: msdo |
| 97 | + with: |
| 98 | + tools: ${{ env.TOOLS }} |
| 99 | + |
| 100 | + - name: Check Repository Visibility |
| 101 | + shell: bash |
| 102 | + run: | |
| 103 | + if [ "${{ github.repository_visibility }}" == "private" ]; then |
| 104 | + echo "This is a private repository. Code Scanning is not available unless GitHub Advanced Security (GHAS) is enabled." |
| 105 | + exit 0 |
| 106 | + fi |
| 107 | +
|
| 108 | + - name: Upload SARIF to GitHub Code Scanning |
| 109 | + if: github.repository_visibility == 'public' |
| 110 | + run: | |
| 111 | + echo "Compressing and uploading SARIF..." |
| 112 | + sarif_file="${{ steps.msdo.outputs.sarifFile }}" |
| 113 | + if [ ! -f "$sarif_file" ]; then |
| 114 | + echo "SARIF file not found at $sarif_file" |
| 115 | + exit 0 |
| 116 | + fi |
| 117 | +
|
| 118 | + gzip -c "$sarif_file" | base64 -w 0 > msdo.sarif.base64 |
| 119 | + encoded_sarif=$(cat msdo.sarif.base64) |
| 120 | +
|
| 121 | + curl -s -X POST \ |
| 122 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 123 | + -H "Accept: application/vnd.github+json" \ |
| 124 | + -H "Content-Type: application/json" \ |
| 125 | + https://api.github.com/repos/${{ github.repository }}/code-scanning/sarifs \ |
| 126 | + -d @- <<EOF |
| 127 | + { |
| 128 | + "commit_sha": "${{ github.sha }}", |
| 129 | + "ref": "${{ github.ref }}", |
| 130 | + "sarif": "$encoded_sarif", |
| 131 | + "checkout_uri": "https://github.com/${{ github.repository }}", |
| 132 | + "tool_name": "MSDO" |
| 133 | + } |
| 134 | + EOF |
0 commit comments