Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 47fd496

Browse files
authored
Re-Enable Vulnerability 3p Scanning Workflow (#42049)
After migrating to standalone yaml (rather than included as a part of the scorecards yaml), the vuln scanning workflow needs to be re-enabled with sarif results uploading to the dashboard under the security tab. A successful test run of this workflow can be seen at https://github.com/flutter/engine/actions/runs/4982210161 (in linked run, fails to upload SARIF file given lack of permissions on any branch besides default) This change also adds use of cwd in python subprocess commands rather than using directory prefix in command string. Addresses b/280294707 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent bf01bf5 commit 47fd496

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

.github/workflows/third_party_scan.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,19 @@ jobs:
2222
uses: actions/setup-python@57ded4d7d5e986d7296eab16560982c6dd7c923b
2323
with:
2424
python-version: '3.7.7' # install the python version needed
25-
- name: "execute py script"
25+
- name: "extract and flatten deps"
2626
run: python ci/deps_parser.py
27+
- name: "scan deps for vulnerabilities"
28+
run: python ci/scan_flattened_deps.py
29+
# Upload the results as artifacts.
30+
- name: "Upload artifact"
31+
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce
32+
with:
33+
name: SARIF file
34+
path: osvReport.sarif
35+
retention-days: 5
36+
# Upload the results to GitHub's code scanning dashboard.
37+
- name: "Upload to security tab"
38+
uses: github/codeql-action/upload-sarif@29b1f65c5e92e24fe6b6647da1eaabe529cec70f
39+
with:
40+
sarif_file: osvReport.sarif

ci/scan_flattened_deps.py

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@
3333
sarif_log = {
3434
'$schema':
3535
'https://json.schemastore.org/sarif-2.1.0.json', 'version':
36-
'2.1.0', 'runs': [{
37-
'tool': {'driver': {'name': 'OSV Scan', 'rules': []}},
38-
'results': []
39-
}]
36+
'2.1.0',
37+
'runs': [{
38+
'tool': {
39+
'driver': {
40+
'name': 'OSV Scan', 'informationUri': 'https://osv.dev/',
41+
'semanticVersion': '1.0.0', 'rules': []
42+
}
43+
}, 'results': []
44+
}]
4045
}
4146

4247

@@ -49,9 +54,7 @@ def sarif_result():
4954
'ruleId':
5055
'N/A', 'message': {'text': 'OSV Scan Finding'}, 'locations': [{
5156
'physicalLocation': {
52-
'artifactLocation': {
53-
'uri': 'No location associated with this finding'
54-
},
57+
'artifactLocation': {'uri': 'DEPS'},
5558
'region': {'startLine': 1, 'startColumn': 1, 'endColumn': 1}
5659
}
5760
}]
@@ -184,56 +187,48 @@ def get_common_ancestor_commit(dep, deps_list):
184187
upstream = deps_list.get(UPSTREAM_PREFIX + dep_name)
185188
temp_dep_dir = DEP_CLONE_DIR + '/' + dep_name
186189
# clone dependency from mirror
187-
subprocess.check_output([
188-
'git', 'clone', '--quiet', '--', dep[0], temp_dep_dir
189-
])
190+
subprocess.check_output(['git', 'clone', '--quiet', '--', dep[0], dep_name],
191+
cwd=DEP_CLONE_DIR)
190192

191193
# create branch that will track the upstream dep
192194
print(
193195
'attempting to add upstream remote from: {upstream}'.format(
194196
upstream=upstream
195197
)
196198
)
197-
subprocess.check_output([
198-
'git', '--git-dir', temp_dep_dir + '/.git', 'remote', 'add', 'upstream',
199-
upstream
200-
])
201-
subprocess.check_output([
202-
'git', '--git-dir', temp_dep_dir + '/.git', 'fetch', '--quiet',
203-
'upstream'
204-
])
199+
subprocess.check_output(['git', 'remote', 'add', 'upstream', upstream],
200+
cwd=temp_dep_dir)
201+
subprocess.check_output(['git', 'fetch', '--quiet', 'upstream'],
202+
cwd=temp_dep_dir)
205203
# get name of the default branch for upstream (e.g. main/master/etc.)
206204
default_branch = subprocess.check_output(
207-
'git --git-dir ' + temp_dep_dir + '/.git remote show upstream ' +
208-
"| sed -n \'/HEAD branch/s/.*: //p\'",
205+
'git remote show upstream ' + "| sed -n \'/HEAD branch/s/.*: //p\'",
206+
cwd=temp_dep_dir,
209207
shell=True
210208
)
211209
default_branch = byte_str_decode(default_branch)
212210
default_branch = default_branch.strip()
213-
print(
214-
'default_branch found: {default_branch}'.format(
215-
default_branch=default_branch
216-
)
217-
)
211+
218212
# make upstream branch track the upstream dep
219213
subprocess.check_output([
220-
'git', '--git-dir', temp_dep_dir + '/.git', 'checkout', '-b',
221-
'upstream', '--track', 'upstream/' + default_branch
222-
])
214+
'git', 'checkout', '--force', '-b', 'upstream', '--track',
215+
'upstream/' + default_branch
216+
],
217+
cwd=temp_dep_dir)
223218
# get the most recent commit from default branch of upstream
224219
commit = subprocess.check_output(
225-
'git --git-dir ' + temp_dep_dir + '/.git for-each-ref ' +
220+
'git for-each-ref ' +
226221
"--format=\'%(objectname:short)\' refs/heads/upstream",
222+
cwd=temp_dep_dir,
227223
shell=True
228224
)
229225
commit = byte_str_decode(commit)
230226
commit = commit.strip()
231227

232228
# perform merge-base on most recent default branch commit and pinned mirror commit
233229
ancestor_commit = subprocess.check_output(
234-
'git --git-dir {temp_dep_dir}/.git merge-base {commit} {depUrl}'.format(
235-
temp_dep_dir=temp_dep_dir, commit=commit, depUrl=dep[1]
236-
),
230+
'git merge-base {commit} {depUrl}'.format(commit=commit, depUrl=dep[1]),
231+
cwd=temp_dep_dir,
237232
shell=True
238233
)
239234
ancestor_commit = byte_str_decode(ancestor_commit)

0 commit comments

Comments
 (0)