Skip to content

Commit dcdb455

Browse files
authored
Merge pull request #1488 from nscuro/backport-gha-hardening
Backport: GitHub Actions hardening
2 parents aaeec35 + 6525277 commit dcdb455

9 files changed

Lines changed: 84 additions & 132 deletions

File tree

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ updates:
55
directory: /
66
schedule:
77
interval: daily
8+
cooldown:
9+
default-days: 7
810
- package-ecosystem: docker
911
directory: /docker
1012
schedule:
1113
interval: daily
14+
cooldown:
15+
default-days: 7
1216
- package-ecosystem: github-actions
1317
directory: /
1418
schedule:
1519
interval: daily
20+
cooldown:
21+
default-days: 7
1622
# Receive minor and patch updates on latest release branch.
1723
# Ignore minor releases for NPM since they may ship breaking
1824
# changes, and we don't have the test coverage in place to
@@ -22,6 +28,8 @@ updates:
2228
directory: /
2329
schedule:
2430
interval: daily
31+
cooldown:
32+
default-days: 7
2533
ignore:
2634
- dependency-name: "*"
2735
update-types:
@@ -32,6 +40,8 @@ updates:
3240
directory: /docker
3341
schedule:
3442
interval: daily
43+
cooldown:
44+
default-days: 7
3545
ignore:
3646
- dependency-name: "*"
3747
update-types:

.github/workflows/_meta-build.yaml

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
permissions: {}
2+
13
on:
24
workflow_call:
35
inputs:
@@ -27,10 +29,12 @@ jobs:
2729

2830
steps:
2931
- name: Checkout Repository
30-
uses: actions/checkout@v6.0.2
32+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
33+
with:
34+
persist-credentials: false
3135

3236
- name: Set up NodeJs
33-
uses: actions/setup-node@v6.3.0
37+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # tag=v6.3.0
3438
with:
3539
node-version: '20'
3640
cache: 'npm'
@@ -43,7 +47,7 @@ jobs:
4347
npm run build --if-present
4448
4549
- name: Upload Artifacts
46-
uses: actions/upload-artifact@v7.0.0
50+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # tag=v7.0.0
4751
with:
4852
name: assembled-frontend
4953
path: |-
@@ -57,24 +61,26 @@ jobs:
5761

5862
steps:
5963
- name: Checkout Repository
60-
uses: actions/checkout@v6.0.2
64+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
65+
with:
66+
persist-credentials: false
6167

6268
- name: Download Artifacts
63-
uses: actions/download-artifact@v8.0.0
69+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # tag=v8.0.0
6470
with:
6571
name: assembled-frontend
6672

6773
- name: Set up QEMU
68-
uses: docker/setup-qemu-action@v4.0.0
74+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # tag=v3.7.0
6975

7076
- name: Set up Docker Buildx
71-
uses: docker/setup-buildx-action@v4.0.0
77+
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # tag=v4.0.0
7278
id: buildx
7379
with:
7480
install: true
7581

7682
- name: Login to Docker.io
77-
uses: docker/login-action@v4.0.0
83+
uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # tag=v4.0.0
7884
if: ${{ inputs.publish-container }}
7985
with:
8086
registry: docker.io
@@ -83,23 +89,25 @@ jobs:
8389

8490
- name: Set Container Tags
8591
id: tags
92+
env:
93+
REF_NAME: ${{ inputs.ref-name }}
94+
APP_VERSION: ${{ inputs.app-version }}
8695
run: |-
8796
IMAGE_NAME="docker.io/dependencytrack/frontend"
88-
REF_NAME="${{ inputs.ref-name }}"
8997
TAGS=""
9098
9199
if [[ $REF_NAME == feature-* ]]; then
92100
TAGS="${IMAGE_NAME}:${REF_NAME,,}"
93101
else
94-
TAGS="${IMAGE_NAME}:${{ inputs.app-version }}"
95-
if [[ "${{ inputs.app-version }}" != "snapshot" ]]; then
102+
TAGS="${IMAGE_NAME}:${APP_VERSION}"
103+
if [[ "${APP_VERSION}" != "snapshot" ]]; then
96104
TAGS="${TAGS},${IMAGE_NAME}:latest"
97105
fi
98106
fi
99107
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
100108
101109
- name: Build multi-arch Container Image
102-
uses: docker/build-push-action@v7.0.0
110+
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # tag=v7.0.0
103111
with:
104112
tags: ${{ steps.tags.outputs.tags }}
105113
build-args: |-
@@ -109,23 +117,3 @@ jobs:
109117
push: ${{ inputs.publish-container }}
110118
context: .
111119
file: docker/Dockerfile.alpine
112-
113-
- name: Run Trivy Vulnerability Scanner
114-
if: ${{ inputs.publish-container }}
115-
uses: aquasecurity/trivy-action@0.34.2
116-
env:
117-
# https://github.com/aquasecurity/trivy-action/issues/389
118-
TRIVY_DB_REPOSITORY: 'public.ecr.aws/aquasecurity/trivy-db:2'
119-
TRIVY_JAVA_DB_REPOSITORY: 'public.ecr.aws/aquasecurity/trivy-java-db:1'
120-
with:
121-
image-ref: docker.io/dependencytrack/frontend:${{ inputs.app-version }}
122-
format: 'sarif'
123-
output: 'trivy-results.sarif'
124-
ignore-unfixed: true
125-
vuln-type: 'os'
126-
127-
- name: Upload Trivy Scan Results to GitHub Security Tab
128-
if: ${{ inputs.publish-container }}
129-
uses: github/codeql-action/upload-sarif@v4
130-
with:
131-
sarif_file: 'trivy-results.sarif'

.github/workflows/ci-build.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
- 'feature-**' # Feature branches
1212
workflow_dispatch:
1313

14+
permissions: {}
15+
1416
jobs:
1517
call-build:
1618
uses: ./.github/workflows/_meta-build.yaml

.github/workflows/ci-publish.yaml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ name: Publish CI
33
on:
44
release:
55
types:
6-
- released
6+
- created
77
workflow_dispatch:
88

9+
permissions: {}
10+
911
jobs:
1012
read-version:
1113
runs-on: ubuntu-latest
@@ -20,7 +22,9 @@ jobs:
2022
fi
2123
2224
- name: Checkout Repository
23-
uses: actions/checkout@v6.0.2
25+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
26+
with:
27+
persist-credentials: false
2428

2529
- name: Parse Version from package.json
2630
id: parse
@@ -42,15 +46,19 @@ jobs:
4246

4347
update-github-release:
4448
runs-on: ubuntu-latest
49+
permissions:
50+
contents: write # Required to edit release.
4551
needs:
4652
- read-version
4753
- call-build
4854
steps:
4955
- name: Checkout Repository
50-
uses: actions/checkout@v6.0.2
56+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
57+
with:
58+
persist-credentials: false
5159

5260
- name: Download Artifacts
53-
uses: actions/download-artifact@v8.0.0
61+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # tag=v8.0.0
5462
with:
5563
name: assembled-frontend
5664

@@ -67,22 +75,31 @@ jobs:
6775
6876
- name: Update Release
6977
env:
70-
GITHUB_TOKEN: ${{ secrets.BOT_RELEASE_TOKEN }}
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
RELEASE_VERSION: ${{ needs.read-version.outputs.version }}
7180
run: |-
7281
cat << EOF >> .github/default-release-notes.md
7382
\`\`\`text
7483
$(cat checksums.txt)
7584
\`\`\`
7685
EOF
7786
78-
gh release view ${{ needs.read-version.outputs.version }} \
87+
gh release view "${RELEASE_VERSION}" \
7988
--json body --jq .body >> .github/default-release-notes.md
8089
81-
gh release edit ${{ needs.read-version.outputs.version }} \
90+
gh release edit "${RELEASE_VERSION}" \
8291
--notes-file ".github/default-release-notes.md"
8392
84-
gh release upload ${{ needs.read-version.outputs.version }} \
93+
gh release upload "${RELEASE_VERSION}" \
8594
--clobber \
8695
frontend-dist.zip \
8796
checksums.txt \
8897
bom.xml bom.json
98+
99+
- name: Publish Release
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
RELEASE_VERSION: ${{ needs.read-version.outputs.version }}
103+
run: |-
104+
gh release edit "${RELEASE_VERSION}" \
105+
--draft=false

.github/workflows/ci-release.yaml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,50 @@ on:
1616
- premajor
1717
- prerelease
1818

19+
permissions: {}
20+
1921
jobs:
2022
prepare-release:
2123
runs-on: ubuntu-latest
24+
permissions:
25+
contents: write # Required to create commits.
2226
steps:
2327
- name: Checkout Repository
24-
uses: actions/checkout@v6.0.2
28+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # tag=v6.0.2
2529

2630
- name: Set up NodeJs
27-
uses: actions/setup-node@v6.3.0
31+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # tag=v6.3.0
2832
with:
2933
node-version: '20'
3034
cache: 'npm'
3135

3236
- name: Bump version and tag via NodeJS
37+
env:
38+
VERSION_TO_BUMP: ${{ github.event.inputs.version-to-bump }}
39+
GIT_REF: ${{ github.ref }}
3340
run: |-
3441
git config user.name "dependencytrack-bot"
3542
git config user.email "106437498+dependencytrack-bot@users.noreply.github.com"
3643
37-
npm version ${{ github.event.inputs.version-to-bump }} -m "prepare-release: set version to %s"
44+
npm version "${VERSION_TO_BUMP}" -m "prepare-release: set version to %s"
3845
39-
git push origin "HEAD:${{ github.ref }}"
46+
git push origin "HEAD:${GIT_REF}"
4047
4148
- name: Create GitHub Release
4249
env:
4350
GITHUB_TOKEN: ${{ secrets.BOT_RELEASE_TOKEN }}
44-
GH_OPTS: ''
51+
VERSION_TO_BUMP: ${{ github.event.inputs.version-to-bump }}
52+
GIT_REF_NAME: ${{ github.ref_name }}
4553
run: |-
4654
VERSION=`jq -r '.version' package.json`
55+
GH_OPTS=""
4756
48-
if [[ "${{ contains(github.event.inputs.version-to-bump, 'pre') }}" == "true" ]]; then
57+
if [[ "${VERSION_TO_BUMP}" == *pre* ]]; then
4958
GH_OPTS="--prerelease"
5059
fi
5160
5261
gh release create "${VERSION}" ${GH_OPTS} \
53-
--target "${{ github.ref_name }}" \
62+
--target "${GIT_REF_NAME}" \
5463
--title "${VERSION}" \
64+
--draft \
5565
--generate-notes

.github/workflows/codeql-analysis.yaml

Lines changed: 0 additions & 61 deletions
This file was deleted.

.github/workflows/dependency-review.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)