Skip to content

Commit c541a2c

Browse files
ci: [StepSecurity] Apply security best practices (#420)
Signed-off-by: StepSecurity Bot <bot@stepsecurity.io> Co-authored-by: Filip Christiansen <22807962+filipchristiansen@users.noreply.github.com>
1 parent b85cb18 commit c541a2c

File tree

10 files changed

+168
-21
lines changed

10 files changed

+168
-21
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ updates:
1515
directory: "/"
1616
schedule: { interval: "weekly" }
1717
labels: [ "dependencies", "gh-actions" ]
18+
19+
- package-ecosystem: docker
20+
directory: /
21+
schedule:
22+
interval: daily

.github/workflows/ci.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ jobs:
2424
coverage: true
2525

2626
steps:
27-
- uses: actions/checkout@v4
27+
- name: Harden the runner (Audit all outbound calls)
28+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
29+
with:
30+
egress-policy: audit
31+
32+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2833

2934
- name: Set up Python
30-
uses: actions/setup-python@v5
35+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
3136
with:
3237
python-version: ${{ matrix.python-version }}
3338

@@ -37,7 +42,7 @@ jobs:
3742
run: echo "dir=$(python -m pip cache dir)" >> "$GITHUB_OUTPUT"
3843

3944
- name: Cache pip
40-
uses: actions/cache@v4
45+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
4146
with:
4247
path: ${{ steps.pip-cache.outputs.dir }}
4348
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
@@ -64,7 +69,7 @@ jobs:
6469
6570
- name: Upload coverage to Codecov
6671
if: ${{ matrix.coverage == true }}
67-
uses: codecov/codecov-action@v5
72+
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
6873
with:
6974
token: ${{ secrets.CODECOV_TOKEN }}
7075
files: coverage.xml
@@ -74,5 +79,5 @@ jobs:
7479
verbose: true
7580

7681
- name: Run pre-commit hooks
77-
uses: pre-commit/action@v3.0.1
82+
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
7883
if: ${{ matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest' }}

.github/workflows/codeql.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: ["main"]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: ["main"]
20+
schedule:
21+
- cron: "0 0 * * 1"
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
analyze:
28+
name: Analyze
29+
runs-on: ubuntu-latest
30+
permissions:
31+
actions: read
32+
contents: read
33+
security-events: write
34+
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
language: ["javascript", "python"]
39+
# CodeQL supports [ $supported-codeql-languages ]
40+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
41+
42+
steps:
43+
- name: Harden the runner (Audit all outbound calls)
44+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
45+
with:
46+
egress-policy: audit
47+
48+
- name: Checkout repository
49+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
50+
51+
# Initializes the CodeQL tools for scanning.
52+
- name: Initialize CodeQL
53+
uses: github/codeql-action/init@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
54+
with:
55+
languages: ${{ matrix.language }}
56+
# If you wish to specify custom queries, you can do so here or in a config file.
57+
# By default, queries listed here will override any specified in a config file.
58+
# Prefix the list here with "+" to use these queries and those in the config file.
59+
60+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
61+
# If this step fails, then you should remove it and run the build manually (see below)
62+
- name: Autobuild
63+
uses: github/codeql-action/autobuild@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
64+
65+
# ℹ️ Command-line programs to run using the OS shell.
66+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
67+
68+
# If the Autobuild fails above, remove it and uncomment the following three lines.
69+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
70+
71+
# - run: |
72+
# echo "Run, Build Application using script"
73+
# ./location_of_script_within_repo/buildscript.sh
74+
75+
- name: Perform CodeQL Analysis
76+
uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
77+
with:
78+
category: "/language:${{matrix.language}}"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request,
4+
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
5+
# Once installed, if the workflow run is marked as required,
6+
# PRs introducing known-vulnerable packages will be blocked from merging.
7+
#
8+
# Source repository: https://github.com/actions/dependency-review-action
9+
name: 'Dependency Review'
10+
on: [pull_request]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
dependency-review:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Harden the runner (Audit all outbound calls)
20+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
21+
with:
22+
egress-policy: audit
23+
24+
- name: 'Checkout Repository'
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
- name: 'Dependency Review'
27+
uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1

.github/workflows/docker_image.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ env:
2626
)
2727
}}
2828
29+
permissions:
30+
contents: read
31+
2932
jobs:
3033
docker-build:
3134
runs-on: ubuntu-latest
@@ -35,7 +38,12 @@ jobs:
3538
attestations: write
3639
id-token: write
3740
steps:
38-
- uses: actions/checkout@v4
41+
- name: Harden the runner (Audit all outbound calls)
42+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
43+
with:
44+
egress-policy: audit
45+
46+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3947

4048
- name: Set current timestamp
4149
id: vars
@@ -44,15 +52,15 @@ jobs:
4452
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
4553
4654
- name: Log in to the Container registry
47-
uses: docker/login-action@v3
55+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
4856
with:
4957
registry: ${{ env.REGISTRY }}
5058
username: ${{ github.actor }}
5159
password: ${{ secrets.GITHUB_TOKEN }}
5260

5361
- name: Docker Meta
5462
id: meta
55-
uses: docker/metadata-action@v5
63+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
5664
with:
5765
images: |
5866
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
@@ -65,13 +73,13 @@ jobs:
6573
type=ref,event=pr,suffix=-${{ steps.vars.outputs.sha_short }}-${{ steps.vars.outputs.timestamp }}
6674
6775
- name: Set up QEMU
68-
uses: docker/setup-qemu-action@v3
76+
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
6977

7078
- name: Set up Docker Buildx
71-
uses: docker/setup-buildx-action@v3
79+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
7280

7381
- name: Build and push
74-
uses: docker/build-push-action@v6
82+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
7583
id: push
7684
with:
7785
context: .
@@ -84,7 +92,7 @@ jobs:
8492

8593
- name: Generate artifact attestation
8694
if: github.event_name != 'pull_request' || env.PUSH_FROM_PR == 'true'
87-
uses: actions/attest-build-provenance@v2
95+
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
8896
with:
8997
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
9098
subject-digest: ${{ steps.push.outputs.digest }}

.github/workflows/pr-title-check.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ jobs:
88
validate-pr-title:
99
runs-on: ubuntu-latest
1010
steps:
11+
- name: Harden the runner (Audit all outbound calls)
12+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
13+
with:
14+
egress-policy: audit
15+
1116
- name: PR Conventional Commit Validation
12-
uses: ytanikin/pr-conventional-commits@1.4.1
17+
uses: ytanikin/pr-conventional-commits@8267db1bacc237419f9ed0228bb9d94e94271a1d # 1.4.1
1318
with:
1419
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'
1520
add_label: 'false'

.github/workflows/publish_to_pypi.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v4
16+
- name: Harden the runner (Audit all outbound calls)
17+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
18+
with:
19+
egress-policy: audit
20+
21+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1722

1823
- name: Set up Python 3.13
19-
uses: actions/setup-python@v5
24+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
2025
with:
2126
python-version: "3.13"
2227
cache: pip
@@ -28,7 +33,7 @@ jobs:
2833
python -m pip install build twine
2934
twine check dist/*
3035
- name: Upload dist artefact
31-
uses: actions/upload-artifact@v4
36+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
3237
with:
3338
name: dist
3439
path: dist/
@@ -43,11 +48,16 @@ jobs:
4348
id-token: write # OIDC token for trusted publishing
4449

4550
steps:
46-
- uses: actions/download-artifact@v4
51+
- name: Harden the runner (Audit all outbound calls)
52+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
53+
with:
54+
egress-policy: audit
55+
56+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
4757
with:
4858
name: dist
4959
path: dist/
5060

51-
- uses: pypa/gh-action-pypi-publish@release/v1
61+
- uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # release/v1
5262
with:
5363
verbose: true

.github/workflows/scorecard.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ jobs:
2121
id-token: write # publish results for the badge
2222

2323
steps:
24+
- name: Harden the runner (Audit all outbound calls)
25+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
26+
with:
27+
egress-policy: audit
28+
2429
- name: Checkout
2530
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
2631
with:
@@ -34,6 +39,6 @@ jobs:
3439
publish_results: true # enables the public badge
3540

3641
- name: Upload to code-scanning
37-
uses: github/codeql-action/upload-sarif@v3
42+
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
3843
with:
3944
sarif_file: results.sarif

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,7 @@ repos:
154154
hooks:
155155
- id: check-hooks-apply
156156
- id: check-useless-excludes
157+
- repo: https://github.com/gitleaks/gitleaks
158+
rev: v8.16.3
159+
hooks:
160+
- id: gitleaks

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Stage 1: Install Python dependencies
2-
FROM python:3.13-slim AS python-builder
2+
FROM python:3.13-slim@sha256:6544e0e002b40ae0f59bc3618b07c1e48064c4faed3a15ae2fbd2e8f663e8283 AS python-builder
33

44
WORKDIR /build
55

@@ -16,7 +16,7 @@ RUN set -eux; \
1616
pip install --no-cache-dir --timeout 1000 .
1717

1818
# Stage 2: Runtime image
19-
FROM python:3.13-slim
19+
FROM python:3.13-slim@sha256:6544e0e002b40ae0f59bc3618b07c1e48064c4faed3a15ae2fbd2e8f663e8283
2020

2121
ARG UID=1000
2222
ARG GID=1000

0 commit comments

Comments
 (0)