forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupply-chain.yml
More file actions
209 lines (181 loc) · 6.85 KB
/
Copy pathsupply-chain.yml
File metadata and controls
209 lines (181 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Supply Chain Security
on:
push:
branches: [main]
pull_request:
schedule:
- cron: '0 6 * * 1' # Weekly on Monday
workflow_dispatch:
permissions:
contents: read
id-token: write # OIDC for keyless signing / SLSA provenance
packages: write # Push attestations to GHCR
security-events: write # Upload SARIF results
actions: read # Required by SLSA provenance action
env:
REGISTRY: ghcr.io
IMAGE_BACKEND: ghcr.io/pinspace-org/gistpin-backend
IMAGE_FRONTEND: ghcr.io/pinspace-org/gistpin-frontend
jobs:
# ── 1. SBOM Generation ────────────────────────────────────────────────────
sbom:
name: Generate SBOM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Generate SBOM (Syft)
uses: anchore/sbom-action@v0
with:
path: .
format: spdx-json
artifact-name: sbom.spdx.json
output-file: sbom.spdx.json
- name: Generate CycloneDX SBOM
uses: anchore/sbom-action@v0
with:
path: .
format: cyclonedx-json
artifact-name: sbom.cyclonedx.json
output-file: sbom.cyclonedx.json
- name: Upload SBOMs
uses: actions/upload-artifact@v4
with:
name: sboms-${{ github.sha }}
path: |
sbom.spdx.json
sbom.cyclonedx.json
retention-days: 90
# ── 2. Dependency Provenance & Vulnerability Scan ─────────────────────────
dependency-provenance:
name: Dependency Provenance
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Audit Backend dependencies
working-directory: Backend
run: npm audit --audit-level=high
- name: Audit Frontend dependencies
working-directory: Frontend
run: npm audit --audit-level=high
- name: Scan with OSV-Scanner
uses: google/osv-scanner-action@v1
with:
scan-args: |-
--recursive
--format=sarif
--output=osv-results.sarif
./
- name: Upload OSV SARIF
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: osv-results.sarif
category: osv-scanner
# ── 3. Build Attestations ─────────────────────────────────────────────────
build-attestation:
name: Build Attestations
runs-on: ubuntu-latest
needs: [sbom]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
outputs:
backend-digest: ${{ steps.build-backend.outputs.digest }}
frontend-digest: ${{ steps.build-frontend.outputs.digest }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push backend
id: build-backend
uses: docker/build-push-action@v5
with:
context: ./Backend
file: infrastructure/docker/backend.Dockerfile
push: true
tags: ${{ env.IMAGE_BACKEND }}:sha-${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push frontend
id: build-frontend
uses: docker/build-push-action@v5
with:
context: ./Frontend
file: infrastructure/docker/frontend.Dockerfile
push: true
tags: ${{ env.IMAGE_FRONTEND }}:sha-${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Download SBOMs
uses: actions/download-artifact@v4
with:
name: sboms-${{ github.sha }}
- name: Attest SBOM — backend
run: |
cosign attest --yes \
--predicate sbom.spdx.json \
--type spdxjson \
"${{ env.IMAGE_BACKEND }}@${{ steps.build-backend.outputs.digest }}"
- name: Attest SBOM — frontend
run: |
cosign attest --yes \
--predicate sbom.spdx.json \
--type spdxjson \
"${{ env.IMAGE_FRONTEND }}@${{ steps.build-frontend.outputs.digest }}"
# ── 4. SLSA Provenance ────────────────────────────────────────────────────
slsa-provenance:
name: SLSA Provenance
needs: [build-attestation]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.0.0
with:
image: ghcr.io/pinspace-org/gistpin-backend
digest: ${{ needs.build-attestation.outputs.backend-digest }}
registry-username: ${{ github.actor }}
secrets:
registry-password: ${{ secrets.GITHUB_TOKEN }}
# ── 5. Signature Verification ─────────────────────────────────────────────
verify-signatures:
name: Verify Signatures
runs-on: ubuntu-latest
needs: [slsa-provenance]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Verify backend image signature
run: |
cosign verify \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
--certificate-identity-regexp "https://github.com/PinSpace-Org/GistPin/.*" \
"${{ env.IMAGE_BACKEND }}@${{ needs.build-attestation.outputs.backend-digest }}"
env:
COSIGN_EXPERIMENTAL: "1"
# ── 6. Generate full SBOM script ──────────────────────────────────────────
sbom-script:
name: SBOM via Script
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run generate-sbom.sh
run: |
chmod +x infrastructure/scripts/generate-sbom.sh
infrastructure/scripts/generate-sbom.sh
env:
OUTPUT_DIR: ${{ runner.temp }}/sbom-output
- name: Upload script-generated SBOM
uses: actions/upload-artifact@v4
with:
name: sbom-script-output-${{ github.sha }}
path: ${{ runner.temp }}/sbom-output/
retention-days: 90