@@ -47,103 +47,106 @@ on:
4747 default : false
4848
4949jobs :
50- security -scan :
50+ dependency -scan :
5151 runs-on : ubuntu-latest
52- name : Security Scanning
52+ name : Dependency Vulnerability Scanning
53+ if : inputs.project-type == 'python' && inputs.dependency-scan
5354 defaults :
5455 run :
5556 working-directory : ${{ inputs.working-directory }}
56- env :
57- SEMGREP_EXCLUDES : " --exclude='.git' --exclude='node_modules' --exclude='dist' --exclude='build' --exclude='coverage' --exclude='__pycache__' --exclude='.venv' --exclude='.cache' --exclude='.pytest_cache' --exclude='.tox' --exclude='.mypy_cache' --exclude='uv.lock' --exclude='*.pyc' --exclude='*.min.js' --exclude='*.bundle.js' --exclude='.gradle' --exclude='gradle/wrapper' --exclude='*.class' --exclude='*.jar'"
58-
5957 steps :
6058 - name : Checkout repository
6159 uses : actions/checkout@v5
6260
63- # Run dependency vulnerability scans
6461 - name : Install and run Python dependency scanner
65- if : inputs.project-type == 'python' && inputs.dependency-scan
6662 run : |
6763 pip install uv-secure
6864 uv-secure ${{ inputs.working-directory }}/uv.lock --format json > ${{ inputs.working-directory }}/uv-secure.json || true
6965
70- # Run Semgrep code scanning
71- - name : Run Semgrep
66+ security-scan :
67+ runs-on : ubuntu-latest
68+ name : Security Scanning
69+ defaults :
70+ run :
71+ working-directory : ${{ inputs.working-directory }}
72+ strategy :
73+ fail-fast : false
74+ matrix :
75+ scan-config :
76+ - name : semgrep
77+ tool : semgrep
78+ output-file : semgrep.sarif
79+ category : semgrep
80+ condition : true
81+ - name : trivy-filesystem
82+ tool : trivy
83+ scan-type : fs
84+ scan-ref : ${{ inputs.working-directory }}
85+ scanners : vuln,secret,config
86+ output-file : trivy-filesystem.sarif
87+ category : trivy-filesystem
88+ condition : true
89+ - name : trivy-dockerfile
90+ tool : trivy
91+ scan-type : config
92+ scan-ref : ${{ inputs.working-directory }}/Dockerfile
93+ scanners : vuln,config
94+ output-file : trivy-dockerfile.sarif
95+ category : trivy-dockerfile
96+ condition : ${{ inputs.scan-dockerfile }}
97+
98+ env :
99+ SEMGREP_EXCLUDES : " --exclude='.git' --exclude='node_modules' --exclude='dist' --exclude='build' --exclude='coverage' --exclude='__pycache__' --exclude='.venv' --exclude='.cache' --exclude='.pytest_cache' --exclude='.tox' --exclude='.mypy_cache' --exclude='uv.lock' --exclude='*.pyc' --exclude='*.min.js' --exclude='*.bundle.js' --exclude='.gradle' --exclude='gradle/wrapper' --exclude='*.class' --exclude='*.jar'"
100+
101+ steps :
102+ - name : Checkout repository
103+ uses : actions/checkout@v5
104+
105+ - name : Run Semgrep scan
106+ if : matrix.scan-config.tool == 'semgrep' && matrix.scan-config.condition
72107 run : |
73108 pip install semgrep
74- semgrep --config auto --sarif --output semgrep.sarif \
109+ semgrep --config auto --sarif --output ${{ matrix.scan-config.output-file }} \
75110 $SEMGREP_EXCLUDES \
76111 ${{ inputs.semgrep-excludes }}
77112
78- # Fix and upload Semgrep results
79- - name : Fix Semgrep SARIF file paths for GitHub Security tab
80- if : always() && hashFiles(format('{0}/semgrep.sarif', inputs.working-directory)) != ''
81- uses : ./.github/actions/fix-trivy-sarif
82- with :
83- sarif-file : ' ${{ inputs.working-directory }}/semgrep.sarif'
84- scan-path : ' ${{ inputs.working-directory }}'
85-
86- - name : Upload Semgrep results to GitHub Security tab
87- uses : github/codeql-action/upload-sarif@v3
88- with :
89- sarif_file : ${{ inputs.working-directory }}/semgrep.sarif
90- category : semgrep-${{ inputs.component-name }}
91-
92- # Run Trivy filesystem scan
93- - name : Run Trivy filesystem scan
113+ - name : Run Trivy scan
114+ if : matrix.scan-config.tool == 'trivy' && matrix.scan-config.condition
94115 uses : aquasecurity/trivy-action@0.33.1
95116 with :
96- scan-type : fs
97- scan-ref : ${{ inputs.working-directory }}
98- scanners : vuln,secret, config
117+ scan-type : ${{ matrix.scan-config.scan-type }}
118+ scan-ref : ${{ matrix.scan-config.scan-ref }}
119+ scanners : ${{ matrix.scan- config.scanners }}
99120 format : sarif
100- output : ${{ inputs.working-directory }}/trivy-filesystem.sarif
121+ output : ${{ inputs.working-directory }}/${{ matrix.scan-config.output-file }}
101122 ignore-unfixed : true
102123 exit-code : ' 0'
103124
104- - name : Fix Trivy filesystem SARIF file paths for GitHub Security tab
105- if : always() && hashFiles(format('{0}/trivy-filesystem.sarif ', inputs.working-directory)) != ''
125+ - name : Fix SARIF file paths for GitHub Security tab
126+ if : matrix.scan-config.condition && always() && hashFiles(format('{0}/{1} ', inputs.working-directory, matrix.scan-config.output-file )) != ''
106127 uses : ./.github/actions/fix-trivy-sarif
107128 with :
108- sarif-file : ' ${{ inputs.working-directory }}/trivy-filesystem.sarif '
129+ sarif-file : ' ${{ inputs.working-directory }}/${{ matrix.scan-config.output-file }} '
109130 scan-path : ' ${{ inputs.working-directory }}'
110131
111- - name : Upload Trivy filesystem results to GitHub Security tab
132+ - name : Upload ${{ matrix.scan-config.name }} results to GitHub Security tab
133+ if : matrix.scan-config.condition
112134 uses : github/codeql-action/upload-sarif@v3
113135 with :
114- sarif_file : ${{ inputs.working-directory }}/trivy-filesystem.sarif
115- category : trivy-${{ inputs.component-name }}-filesystem
116-
117- # Run Trivy Dockerfile scan (optional)
118- - name : Run Trivy Dockerfile scan
119- if : inputs.scan-dockerfile
120- uses : aquasecurity/trivy-action@0.33.1
121- with :
122- scan-type : config
123- scan-ref : ${{ inputs.working-directory }}/Dockerfile
124- scanners : vuln,config
125- format : sarif
126- output : ${{ inputs.working-directory }}/trivy-dockerfile.sarif
127- ignore-unfixed : true
128- exit-code : ' 0'
136+ sarif_file : ${{ inputs.working-directory }}/${{ matrix.scan-config.output-file }}
137+ category : ${{ matrix.scan-config.category }}-${{ inputs.component-name }}
129138
130- - name : Fix Trivy Dockerfile SARIF file paths for GitHub Security tab
131- if : inputs.scan-dockerfile && always() && hashFiles(format('{0}/trivy-dockerfile.sarif', inputs.working-directory)) != ''
132- uses : ./.github/actions/fix-trivy-sarif
133- with :
134- sarif-file : ' ${{ inputs.working-directory }}/trivy-dockerfile.sarif'
135- scan-path : ' ${{ inputs.working-directory }}'
136-
137- - name : Upload Trivy Dockerfile results to GitHub Security tab
138- if : inputs.scan-dockerfile
139- uses : github/codeql-action/upload-sarif@v3
140- with :
141- sarif_file : ${{ inputs.working-directory }}/trivy-dockerfile.sarif
142- category : trivy-${{ inputs.component-name }}-dockerfile
139+ upload-artifacts :
140+ runs-on : ubuntu-latest
141+ name : Upload Security Artifacts
142+ needs : [dependency-scan, security-scan]
143+ if : always()
144+ steps :
145+ - name : Checkout repository
146+ uses : actions/checkout@v5
143147
144148 # Upload all security reports as artifacts
145149 - name : Upload Security scan reports as artifact
146- if : always()
147150 uses : actions/upload-artifact@v4
148151 with :
149152 name : security-reports-${{ inputs.component-name }}
0 commit comments