Skip to content

Commit 5428028

Browse files
Security pipeline and minor fixes (#312) (#315)
* addressing zizmor findings * added scorecards.yml * zizmor on pre-commit * added bandit config * bandit fp * added security scan on pre-merge * fix bandit config * dependabot config * enable CodeQL * version upgrade * CodeQL CPP * style fix * style fix * style fix * prettier-ignore --------- Signed-off-by: Barabanov <[email protected]> Co-authored-by: Alexander Barabanov <[email protected]>
1 parent 4afd3c9 commit 5428028

File tree

15 files changed

+329
-49
lines changed

15 files changed

+329
-49
lines changed

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: /
5+
schedule:
6+
interval: "weekly"
7+
target-branch: "master"
8+
groups:
9+
github-actions-dependency:
10+
applies-to: version-updates
11+
patterns:
12+
- "*"
13+
- package-ecosystem: pip
14+
directory: /src/python
15+
schedule:
16+
interval: weekly
17+
target-branch: "master"

.github/workflows/codeql.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "CodeQL Scan"
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["master"]
8+
schedule:
9+
- cron: "37 3 * * 0"
10+
11+
permissions: {} # No permissions by default on workflow level
12+
13+
jobs:
14+
analyze:
15+
name: Analyze (${{ matrix.language }})
16+
runs-on: ubuntu-latest
17+
permissions:
18+
security-events: write # required to publish sarif
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
include:
24+
- language: actions
25+
build-mode: none
26+
- language: python
27+
build-mode: none
28+
- language: c-cpp
29+
build-mode: none
30+
31+
steps:
32+
- name: Checkout repository
33+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34+
with:
35+
persist-credentials: false
36+
37+
# Initializes the CodeQL tools for scanning.
38+
- name: Initialize CodeQL
39+
uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
40+
with:
41+
languages: ${{ matrix.language }}
42+
build-mode: ${{ matrix.build-mode }}
43+
queries: security-extended
44+
45+
- name: Perform CodeQL Analysis
46+
uses: github/codeql-action/analyze@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
47+
with:
48+
category: "/language:${{matrix.language}}"

.github/workflows/docs.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Build Docs
2-
permissions: read-all
2+
permissions: {} # No permissions by default on workflow level
33

44
on:
55
workflow_dispatch: # run on request (no need for PR)
@@ -14,20 +14,29 @@ jobs:
1414
contents: write
1515
steps:
1616
- name: Checkout repository
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18+
with:
19+
persist-credentials: false
1820
- name: Set up Python
19-
uses: actions/setup-python@v5
21+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
2022
with:
2123
python-version: "3.10"
2224
- name: Install dependencies
2325
run: pip install 'src/python/.[docs]'
2426
- name: Install and Generate Doxygen
25-
uses: mattnotmitt/[email protected]
27+
uses: mattnotmitt/doxygen-action@b84fe17600245bb5db3d6c247cc274ea98c15a3b # v1.12.0
2628
- name: Build Docs
2729
run: |
2830
cd docs
2931
make html
32+
- name: Branch name
33+
id: branch_name
34+
shell: bash
35+
run: |
36+
echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/}
3037
- name: Create gh-pages branch
38+
env:
39+
SOURCE: ${{steps.branch_name.outputs.SOURCE_NAME}}
3140
run: |
3241
if [[ ${{github.event_name}} == 'workflow_dispatch' ]]; then
3342
echo RELEASE_VERSION="test_build" >> $GITHUB_ENV
@@ -52,7 +61,7 @@ jobs:
5261
git add .nojekyll
5362
git commit -m "Initializing gh-pages branch"
5463
git push origin gh-pages
55-
git checkout ${{steps.branch_name.outputs.SOURCE_NAME}}
64+
git checkout "${SOURCE}"
5665
echo "Created gh-pages branch"
5766
else
5867
echo "Branch gh-pages already exists"
@@ -77,7 +86,7 @@ jobs:
7786
git add index.html
7887
git commit -m "Update documentation" -a || true
7988
- name: Push changes
80-
uses: ad-m/github-push-action@master
89+
uses: ad-m/github-push-action@77c5b412c50b723d2a4fbc6d71fb5723bcd439aa
8190
with:
8291
github_token: ${{ secrets.GITHUB_TOKEN }}
8392
branch: gh-pages

.github/workflows/pr-labeler.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
#####
2+
# This workflow is triggered by pull_request_target event.
3+
# Never checkout the PR and run ANY local code on it.
4+
#####
5+
16
name: "Pull Request Labeler"
2-
permissions: read-all
7+
permissions: {} # No permissions by default on workflow level
38
on:
4-
- pull_request_target
9+
- pull_request_target # zizmor: ignore[dangerous-triggers]
510

611
jobs:
712
labeler:
@@ -10,6 +15,6 @@ jobs:
1015
pull-requests: write
1116
runs-on: ubuntu-latest
1217
steps:
13-
- uses: actions/labeler@v5
18+
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0
1419
with:
1520
repo-token: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/pre_commit.yml

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Pre-Commit Checks
2-
permissions: read-all
2+
permissions: {} # No permissions by default on workflow level
33

44
on:
55
push:
@@ -18,13 +18,15 @@ jobs:
1818
runs-on: ubuntu-22.04
1919
steps:
2020
- name: CHECKOUT REPOSITORY
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
with:
23+
persist-credentials: false
2224
- name: Set up Python
23-
uses: actions/setup-python@v5
25+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
2426
with:
2527
python-version: "3.10"
2628
- name: Set up Node.js
27-
uses: actions/setup-node@v4
29+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2830
with:
2931
node-version: 22
3032
- name: Install clang-format
@@ -37,12 +39,47 @@ jobs:
3739
runs-on: ubuntu-22.04
3840
steps:
3941
- name: CHECKOUT REPOSITORY
40-
uses: actions/checkout@v4
42+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
43+
with:
44+
persist-credentials: false
4145
- name: Set up Python
42-
uses: actions/setup-python@v5
46+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
4347
with:
4448
python-version: "3.9"
4549
- name: Install dependencies
4650
run: pip install 'src/python/.[tests,ovms]'
4751
- name: Run python unit tests
4852
run: pytest tests/python/unit
53+
Zizmor-Scan-PR:
54+
runs-on: ubuntu-latest
55+
permissions:
56+
contents: read
57+
steps:
58+
- name: Checkout code
59+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
60+
with:
61+
persist-credentials: false
62+
- name: Run Zizmor scan
63+
uses: open-edge-platform/anomalib/.github/actions/security/zizmor@fadfedd5150eb8cd39dfb659ae9bd0eb1c06720d
64+
with:
65+
scan-scope: "changed"
66+
severity-level: "MEDIUM"
67+
confidence-level: "HIGH"
68+
fail-on-findings: true
69+
Bandit-Scan-PR:
70+
runs-on: ubuntu-latest
71+
permissions:
72+
contents: read
73+
steps:
74+
- name: Checkout code
75+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
76+
with:
77+
persist-credentials: false
78+
- name: Run Bandit scan
79+
uses: open-edge-platform/anomalib/.github/actions/security/bandit@fadfedd5150eb8cd39dfb659ae9bd0eb1c06720d
80+
with:
81+
scan-scope: "changed"
82+
severity-level: "LOW"
83+
confidence-level: "LOW"
84+
config_file: "src/python/pyproject.toml"
85+
fail-on-findings: true

.github/workflows/publish.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ on:
55
release:
66
types: [published]
77

8-
# Declare default permissions as read only.
9-
permissions: read-all
8+
permissions: {} # No permissions by default on workflow level
109

1110
jobs:
1211
build:
1312
name: Build
1413
runs-on: ubuntu-latest
1514
steps:
1615
- name: Checkout
17-
uses: actions/checkout@v4
16+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
17+
with:
18+
persist-credentials: false
1819
- name: Set up Python 3.10
19-
uses: actions/setup-python@v5
20+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
2021
with:
2122
python-version: "3.10"
2223
- name: Install pypa/build
@@ -25,14 +26,14 @@ jobs:
2526
- name: Build sdist
2627
run: |
2728
python -m build --sdist src/python/
28-
- uses: actions/upload-artifact@v4
29+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
2930
with:
3031
name: artifact-sdist
3132
path: src/python/dist/*.tar.gz
3233
- name: Build wheel
3334
run: |
3435
python -m build --wheel src/python/
35-
- uses: actions/upload-artifact@v4
36+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
3637
with:
3738
name: artifact-wheel
3839
path: src/python/dist/*.whl
@@ -43,9 +44,8 @@ jobs:
4344
environment: pypi
4445
runs-on: ubuntu-latest
4546
permissions:
46-
packages: write
47-
contents: write
48-
id-token: write
47+
contents: write # required by svenstaro/upload-release-action
48+
id-token: write # required by trusted publisher
4949
steps:
5050
- name: Download artifacts
5151
uses: actions/download-artifact@v4
@@ -56,13 +56,13 @@ jobs:
5656
# to determine where to publish the package distribution to PyPI or TestPyPI
5757
- name: Check tag
5858
id: check-tag
59-
uses: actions-ecosystem/action-regex-match@v2
59+
uses: actions-ecosystem/action-regex-match@9e6c4fb3d5e898f505be7a1fb6e7b0a278f6665b # v2.0.2
6060
with:
6161
text: ${{ github.ref }}
6262
regex: '^refs/tags/[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)+(\.[0-9]+rc[0-9]+|rc[0-9]+)?$'
6363
- name: Upload package distributions to github
6464
if: ${{ steps.check-tag.outputs.match != '' }}
65-
uses: svenstaro/upload-release-action@04733e069f2d7f7f0b4aebc4fbdbce8613b03ccd # v2
65+
uses: svenstaro/upload-release-action@ebd922b779f285dafcac6410a0710daee9c12b82 # v2.10.0
6666
with:
6767
repo_token: ${{ secrets.GITHUB_TOKEN }}
6868
file: dist/*
@@ -71,10 +71,10 @@ jobs:
7171
file_glob: true
7272
- name: Publish package distributions to PyPI
7373
if: ${{ steps.check-tag.outputs.match != '' }}
74-
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3
74+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
7575
- name: Publish package distributions to TestPyPI
7676
if: ${{ steps.check-tag.outputs.match == '' }}
77-
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3
77+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
7878
with:
7979
repository-url: https://test.pypi.org/legacy/
8080
verbose: true

.github/workflows/scorecards.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Scorecards supply-chain security
2+
on:
3+
# For Branch-Protection check. Only the default branch is supported. See
4+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
5+
branch_protection_rule:
6+
schedule:
7+
# Run security checks every day at 2 AM UTC
8+
- cron: "0 2 * * *"
9+
workflow_dispatch:
10+
11+
permissions: {}
12+
13+
jobs:
14+
analysis:
15+
name: Scorecards analysis
16+
runs-on: ubuntu-latest
17+
permissions:
18+
# Needed to upload the results to code-scanning dashboard
19+
security-events: write
20+
# Needed to publish results and get a badge
21+
id-token: write
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
with:
27+
persist-credentials: false
28+
29+
- name: Run analysis
30+
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
31+
with:
32+
results_file: results.sarif
33+
results_format: sarif
34+
publish_results: true
35+
36+
# Upload the results to GitHub's code scanning dashboard
37+
- name: Upload to code-scanning
38+
uses: github/codeql-action/upload-sarif@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
39+
with:
40+
sarif_file: results.sarif

0 commit comments

Comments
 (0)