Skip to content

Commit 5dfc701

Browse files
step-security-botBigMichi1Copilotkodiakhq[bot]
authored
[StepSecurity] Apply security best practices (#8)
* [StepSecurity] Apply security best practices Signed-off-by: StepSecurity Bot <bot@stepsecurity.io> * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: StepSecurity Bot <bot@stepsecurity.io> Co-authored-by: Michael Cramer <michael@bigmichi1.de> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 9223bb9 commit 5dfc701

6 files changed

Lines changed: 225 additions & 12 deletions

File tree

.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-typescript"]
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@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
45+
with:
46+
egress-policy: audit
47+
48+
- name: Checkout repository
49+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
50+
51+
# Initializes the CodeQL tools for scanning.
52+
- name: Initialize CodeQL
53+
uses: github/codeql-action/init@7fd177fa680c9881b53cdab4d346d32574c9f7f4 # v3.35.4
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@7fd177fa680c9881b53cdab4d346d32574c9f7f4 # v3.35.4
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@7fd177fa680c9881b53cdab4d346d32574c9f7f4 # v3.35.4
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@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
21+
with:
22+
egress-policy: audit
23+
24+
- name: 'Checkout Repository'
25+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
26+
- name: 'Dependency Review'
27+
uses: actions/dependency-review-action@2031cfc080254a8a887f58cffee85186f0e49e48 # v4.9.0

.github/workflows/docker.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ env:
1616
REGISTRY: ghcr.io
1717
IMAGE_NAME: ${{ github.repository }}
1818

19+
permissions:
20+
contents: read
21+
1922
jobs:
2023
build:
2124
name: Build Docker Image
@@ -25,23 +28,28 @@ jobs:
2528
packages: write
2629

2730
steps:
31+
- name: Harden the runner (Audit all outbound calls)
32+
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
33+
with:
34+
egress-policy: audit
35+
2836
- name: Checkout code
29-
uses: actions/checkout@v6.0.2
37+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3038

3139
- name: Set up Docker Buildx
32-
uses: docker/setup-buildx-action@v4.0.0
40+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
3341

3442
- name: Log in to Container Registry
3543
if: github.event_name != 'pull_request'
36-
uses: docker/login-action@v4.1.0
44+
uses: step-security/docker-login-action@870af644803bf9f204aed474adbad2958fec048b # v4.1.0
3745
with:
3846
registry: ${{ env.REGISTRY }}
3947
username: ${{ github.actor }}
4048
password: ${{ secrets.GITHUB_TOKEN }}
4149

4250
- name: Extract metadata
4351
id: meta
44-
uses: docker/metadata-action@v6.0.0
52+
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6.0.0
4553
with:
4654
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4755
tags: |
@@ -52,7 +60,7 @@ jobs:
5260
type=raw,value=latest,enable={{is_default_branch}}
5361
5462
- name: Build and push Docker image
55-
uses: docker/build-push-action@v7.1.0
63+
uses: step-security/docker-build-push-action@846549baaf047e867d038826129a64d81df0f704 # v7.1.0
5664
with:
5765
context: .
5866
push: ${{ github.event_name != 'pull_request' }}
@@ -68,8 +76,13 @@ jobs:
6876
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
6977

7078
steps:
79+
- name: Harden the runner (Audit all outbound calls)
80+
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
81+
with:
82+
egress-policy: audit
83+
7184
- name: Checkout code
72-
uses: actions/checkout@v6.0.2
85+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7386

7487
- name: Deploy notification
7588
run: |

.github/workflows/scorecards.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# This workflow uses actions that are not certified by GitHub. They are provided
2+
# by a third-party and are governed by separate terms of service, privacy
3+
# policy, and support documentation.
4+
5+
name: Scorecard supply-chain security
6+
on:
7+
# For Branch-Protection check. Only the default branch is supported. See
8+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
9+
branch_protection_rule:
10+
# To guarantee Maintained check is occasionally updated. See
11+
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
12+
schedule:
13+
- cron: '20 7 * * 2'
14+
push:
15+
branches: ["main"]
16+
17+
# Declare default permissions as read only.
18+
permissions: read-all
19+
20+
jobs:
21+
analysis:
22+
name: Scorecard analysis
23+
runs-on: ubuntu-latest
24+
permissions:
25+
# Needed to upload the results to code-scanning dashboard.
26+
security-events: write
27+
# Needed to publish results and get a badge (see publish_results below).
28+
id-token: write
29+
contents: read
30+
actions: read
31+
# To allow GraphQL ListCommits to work
32+
issues: read
33+
pull-requests: read
34+
# To detect SAST tools
35+
checks: read
36+
37+
steps:
38+
- name: Harden the runner (Audit all outbound calls)
39+
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
40+
with:
41+
egress-policy: audit
42+
43+
- name: "Checkout code"
44+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
45+
with:
46+
persist-credentials: false
47+
48+
- name: "Run analysis"
49+
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
50+
with:
51+
results_file: results.sarif
52+
results_format: sarif
53+
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
54+
# - you want to enable the Branch-Protection check on a *public* repository, or
55+
# - you are installing Scorecards on a *private* repository
56+
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
57+
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
58+
59+
# Public repositories:
60+
# - Publish results to OpenSSF REST API for easy access by consumers
61+
# - Allows the repository to include the Scorecard badge.
62+
# - See https://github.com/ossf/scorecard-action#publishing-results.
63+
# For private repositories:
64+
# - `publish_results` will always be set to `false`, regardless
65+
# of the value entered here.
66+
publish_results: true
67+
68+
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
69+
# format to the repository Actions tab.
70+
- name: "Upload artifact"
71+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
72+
with:
73+
name: SARIF file
74+
path: results.sarif
75+
retention-days: 5
76+
77+
# Upload the results to GitHub's code scanning dashboard.
78+
- name: "Upload to code-scanning"
79+
uses: github/codeql-action/upload-sarif@7fd177fa680c9881b53cdab4d346d32574c9f7f4 # v3.35.4
80+
with:
81+
sarif_file: results.sarif

.github/workflows/secrets.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,37 @@ on:
88
branches:
99
- main
1010

11+
permissions:
12+
contents: read
13+
1114
jobs:
1215
secrets:
1316
name: Scan for Secrets
1417
runs-on: ubuntu-latest
1518
permissions:
1619
contents: read
1720
security-events: write
21+
issues: write
1822

1923
steps:
24+
- name: Harden the runner (Audit all outbound calls)
25+
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
26+
with:
27+
egress-policy: audit
28+
2029
- name: Checkout code
21-
uses: actions/checkout@v6.0.2
30+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2231
with:
2332
fetch-depth: 0
2433

2534
- name: Run Gitleaks
26-
uses: gitleaks/gitleaks-action@v2.3.9
35+
uses: gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v2.3.9
2736
env:
2837
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2938
GITLEAKS_ENABLE_COMMENTS: true
3039

3140
- name: Run TruffleHog
32-
uses: trufflesecurity/trufflehog@v3.95.2
41+
uses: trufflesecurity/trufflehog@17456f8c7d042d8c82c9a8ca9e937231f9f42e26 # v3.95.2
3342
with:
3443
path: ./
3544
base: ${{ github.event.before || github.event.repository.default_branch }}
@@ -41,8 +50,13 @@ jobs:
4150
runs-on: ubuntu-latest
4251

4352
steps:
53+
- name: Harden the runner (Audit all outbound calls)
54+
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
55+
with:
56+
egress-policy: audit
57+
4458
- name: Checkout code
45-
uses: actions/checkout@v6.0.2
59+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4660

4761
- name: Detect untracked .env files
4862
run: |

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Builder stage
2-
FROM debian:13.4-slim AS builder
2+
FROM debian:13.4-slim@sha256:109e2c65005bf160609e4ba6acf7783752f8502ad218e298253428690b9eaa4b AS builder
33

44
WORKDIR /app
55

@@ -44,7 +44,7 @@ COPY src/lib ./src/lib
4444
RUN bin/mise run prod:build
4545

4646
# Production stage
47-
FROM debian:13.4-slim AS production
47+
FROM debian:13.4-slim@sha256:109e2c65005bf160609e4ba6acf7783752f8502ad218e298253428690b9eaa4b AS production
4848

4949
WORKDIR /app
5050

0 commit comments

Comments
 (0)