Skip to content

Commit 1995d0f

Browse files
chore(ci): source code tampering protection for release (#2301)
* chore: create download-artifact, upload-artifact * chore: seals source code, separate quality check & build Uses new mechanism to seal source code, run quality checks separately, and always reuses sealed source code in every step to prevent source code tampering. It documents every job purpose, and creates a new faster action to upload and download artifacts. * chore: ruben's feedback Co-authored-by: Ruben Fonseca <[email protected]> Signed-off-by: Heitor Lessa <[email protected]> * chore: document remaining sections; update release process doc * chore: include python bytecode in tarball for accurate hash verification * chore: add hash verification * chore: cleanup before review * chore: fix build integrity hash reference * chore: upgrade download-artifact to v3 due to node deprecation warnings --------- Signed-off-by: Heitor Lessa <[email protected]> Co-authored-by: Ruben Fonseca <[email protected]>
1 parent 653db45 commit 1995d0f

File tree

3 files changed

+387
-71
lines changed

3 files changed

+387
-71
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Download artifact
2+
description: Wrapper around GitHub's official action, with additional extraction before download
3+
4+
# PROCESS
5+
#
6+
# 1. Downloads artifact using actions/download-artifact action
7+
# 2. Extracts and overwrites tarball previously uploaded
8+
# 3. Remove archive after extraction
9+
10+
# NOTES
11+
#
12+
# Upload-artifact and download-artifact takes ~2m40s to upload 8MB
13+
# so this is custom action cuts down the entire operation to 1s
14+
# by uploading/extracting a tarball while relying on the official upload-artifact/download-artifact actions
15+
#
16+
17+
# USAGE
18+
#
19+
# NOTE: Meant to be used with ./.github/actions/upload-artifact
20+
#
21+
# - name: Restore sealed source code
22+
# uses: ./.github/actions/download-artifact
23+
# with:
24+
# name: ${{ needs.seal.outputs.INTEGRITY_HASH }}
25+
# path: .
26+
27+
# https://github.com/actions/download-artifact/blob/main/action.yml
28+
inputs:
29+
name:
30+
description: Artifact name
31+
required: true
32+
path:
33+
description: Destination path. By default, it will download to the current working directory.
34+
required: false
35+
default: .
36+
37+
runs:
38+
using: composite
39+
steps:
40+
- name: Download artifacts
41+
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
42+
with:
43+
name: ${{ inputs.name }}
44+
path: ${{ inputs.path }}
45+
46+
- name: Extract artifacts
47+
run: tar -xvf "${ARCHIVE}"
48+
env:
49+
ARCHIVE: ${{ inputs.name }}.tar
50+
shell: bash
51+
working-directory: ${{ inputs.path }}
52+
53+
- name: Remove archive
54+
run: rm -f "${ARCHIVE}"
55+
env:
56+
ARCHIVE: ${{ inputs.name }}.tar
57+
shell: bash
58+
working-directory: ${{ inputs.path }}
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Upload artifact
2+
description: Wrapper around GitHub's official action, with additional archiving before upload
3+
4+
# PROCESS
5+
#
6+
# 1. Creates tarball excluding .git files
7+
# 2. Uploads tarball using actions/upload-artifact action, fail CI job if no file is found
8+
# 3. Remove archive after uploading it.
9+
10+
# NOTES
11+
#
12+
# Upload-artifact and download-artifact takes ~2m40s to upload 8MB
13+
# so this is custom action cuts down the entire operation to 1s
14+
# by uploading/extracting a tarball while relying on the official upload-artifact/download-artifact actions
15+
#
16+
17+
# USAGE
18+
#
19+
# NOTE: Meant to be used with ./.github/actions/download-artifact
20+
#
21+
# - name: Upload sealed source code
22+
# uses: ./.github/actions/upload-artifact
23+
# with:
24+
# name: ${{ steps.integrity.outputs.INTEGRITY_HASH }}
25+
# path: .
26+
27+
# https://github.com/actions/upload-artifact/blob/main/action.yml
28+
inputs:
29+
name:
30+
description: Artifact name
31+
required: true
32+
path:
33+
description: >
34+
A file, directory or wildcard pattern that describes what to upload.
35+
36+
You can pass multiple paths separated by space (e.g., dir1 dir2 file.txt).
37+
38+
Paths and wildcard patterns must be tar command compatible.
39+
required: true
40+
retention-days:
41+
description: >
42+
Artifact retention in days. By default 1 day, max of 90 days, and 0 honours default repo retention.
43+
44+
You can change max days in the repository settings.
45+
required: false
46+
default: "1"
47+
if-no-files-found:
48+
description: >
49+
Action to perform if no files are found: warn, error, ignore. By default, it fails fast with 'error'.
50+
51+
Options:
52+
warn: Output a warning but do not fail the action
53+
error: Fail the action with an error message
54+
ignore: Do not output any warnings or errors, the action does not fail
55+
required: false
56+
default: error
57+
58+
runs:
59+
using: composite
60+
steps:
61+
- name: Archive artifacts
62+
run: |
63+
tar --exclude-vcs \
64+
-cvf "${ARCHIVE}" "${PATH_TO_ARCHIVE}"
65+
env:
66+
ARCHIVE: ${{ inputs.name }}.tar
67+
PATH_TO_ARCHIVE: ${{ inputs.path }}
68+
shell: bash
69+
70+
- name: Upload artifacts
71+
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
72+
with:
73+
if-no-files-found: ${{ inputs.if-no-files-found }}
74+
name: ${{ inputs.name }}
75+
path: ${{ inputs.name }}.tar
76+
retention-days: ${{ inputs.retention-days }}
77+
78+
- name: Remove archive
79+
run: rm -f "${ARCHIVE}"
80+
env:
81+
ARCHIVE: ${{ inputs.name }}.tar
82+
shell: bash

0 commit comments

Comments
 (0)