Skip to content

Commit c43c945

Browse files
authored
feat: modernize GitHub Actions with security hardening and centralized Rust toolchain (microsoft#470)
Security Improvements: - Pin all GitHub Actions to specific commit hashes instead of version tags - Update actions/checkout from v4 to commit 08eba0b27e820071cde6df949e0beb9ba4906955 - Update actions/setup-python from v5 to commit a26af69be951a213d495a4c3e4e4022e16d87065 (v5.6.0) - Update actions/setup-java from v4 to commit dded0888837ed1f317902acf8a20df0ad188d165 (v5.0.0) - Update actions/setup-node from v4 to commit 1e60f620b9541d16bece96c5465dc8ee9832be0b (v4.4.0) - Update actions/setup-go from v5 to commit 41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed (v5.1.0) - Update actions/setup-dotnet from v4 to commit 3e891b0cb619bf60e2c25674b222b8940e2c1c25 (v4.1.0) - Update actions/upload-artifact from v4 to commit ea165f8d65b6e75b540449e92b4886f43607fa02 (v4.6.2) - Update actions/download-artifact from v4 to commit 634f93cb2916e3fdff6788551b99b062d0335ce0 (v5.0.0) - Update github/codeql-action from v3 to commit 01fe2e8c43536ad5e1085bad5e7cd6fbc8a30988 (v3.29.11) Rust Toolchain Consolidation: - Create custom composite action .github/actions/toolchains/rust/action.yml - Standardize on Rust 1.89.0 (latest stable) with clippy and rustfmt components - Add optional targets parameter for cross-compilation support - Replace dtolnay/rust-toolchain@stable across 16 workflows This creates a more secure, maintainable, and consistent CI/CD pipeline with centralized Rust toolchain management across all workflows. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
1 parent 2a0b4ae commit c43c945

19 files changed

Lines changed: 116 additions & 70 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: rust-toolchain
2+
description: Setup Rust toolchain with specified version and components
3+
inputs:
4+
toolchain:
5+
description: 'Rust toolchain version'
6+
required: false
7+
default: '1.89.0'
8+
components:
9+
description: 'Additional components to install'
10+
required: false
11+
default: 'clippy rustfmt'
12+
targets:
13+
description: 'Target architectures to install'
14+
required: false
15+
default: ''
16+
runs:
17+
using: composite
18+
steps:
19+
- shell: bash
20+
run: |
21+
rustup override set ${{ inputs.toolchain }}
22+
if [ -n "${{ inputs.components }}" ]; then
23+
rustup component add ${{ inputs.components }}
24+
fi
25+
if [ -n "${{ inputs.targets }}" ]; then
26+
rustup target add ${{ inputs.targets }}
27+
fi
28+
cargo --version
29+
rustc --version

.github/workflows/pr-extensions.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jobs:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
22+
- name: Setup Rust toolchain
23+
uses: ./.github/actions/toolchains/rust
2224
- name: Build only std
2325
run: cargo build -r --example regorus --no-default-features --features "std,rego-extensions"
2426
- name: Doc Tests

.github/workflows/pr.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ jobs:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
22+
- name: Setup Rust toolchain
23+
uses: ./.github/actions/toolchains/rust
2224
- name: Format Check
2325
run: cargo fmt --check
2426
- name: Fetch

.github/workflows/publish-java.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ jobs:
3232
os: windows-latest
3333
extension: dll
3434
steps:
35-
- uses: actions/checkout@v4
35+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
3636
with:
3737
fetch-depth: 0
38-
- uses: actions/setup-java@v4
38+
- uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
3939
with:
4040
java-version: 8
4141
distribution: "corretto"
42-
- uses: dtolnay/rust-toolchain@stable
42+
- uses: ./.github/actions/toolchains/rust
4343
with:
4444
targets: ${{ matrix.target }}
4545
- if: ${{ matrix.build_cmd == 'zigbuild' }}
46-
uses: actions/setup-python@v5
46+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
4747
with:
4848
python-version: "3.11"
4949
- if: ${{ matrix.build_cmd == 'zigbuild' }}
@@ -52,7 +52,7 @@ jobs:
5252
- run: cargo ${{ matrix.build_cmd || 'build' }} --release --frozen --target ${{ matrix.target }}${{ matrix.glibc && format('.{0}', matrix.glibc) || '' }} --manifest-path ./bindings/java/Cargo.toml
5353
- run: mkdir -p native/${{ matrix.target }}
5454
- run: mv target/${{ matrix.target }}/release/*.${{ matrix.extension }} ./native/${{ matrix.target }}/
55-
- uses: actions/upload-artifact@v4
55+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
5656
with:
5757
name: native-libraries-${{ matrix.target }}
5858
path: native/
@@ -62,24 +62,24 @@ jobs:
6262
runs-on: ubuntu-latest
6363
needs: build
6464
steps:
65-
- uses: actions/checkout@v4
65+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
6666
with:
6767
fetch-depth: 0
68-
- uses: actions/setup-java@v4
68+
- uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
6969
with:
7070
java-version: 8
7171
distribution: "corretto"
7272
server-id: ossrh
7373
server-username: MAVEN_USERNAME
7474
server-password: MAVEN_PASSWORD
75-
- uses: actions/download-artifact@v4
75+
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
7676
with:
7777
pattern: native-libraries-*
7878
merge-multiple: true
7979
path: ./bindings/java/native/
8080
- run: mvn package
8181
working-directory: ./bindings/java
82-
- uses: actions/upload-artifact@v4
82+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
8383
with:
8484
name: built-jars
8585
path: ./bindings/java/target/regorus-java-*.jar

.github/workflows/publish-python.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ jobs:
1818
matrix:
1919
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
2020
steps:
21-
- uses: actions/checkout@v3
22-
- uses: actions/setup-python@v4
21+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
22+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
2323
with:
2424
python-version: '3.10'
25+
- uses: ./.github/actions/toolchains/rust
2526

2627
- name: Build Python extension
2728
run: |
@@ -38,9 +39,9 @@ jobs:
3839
sccache: 'true'
3940
manylinux: auto
4041
- name: Upload wheels
41-
uses: actions/upload-artifact@v3
42+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
4243
with:
43-
name: wheels
44+
name: wheels-linux-${{ matrix.target }}
4445
path: dist
4546

4647
windows:
@@ -49,11 +50,12 @@ jobs:
4950
matrix:
5051
target: [x64, x86]
5152
steps:
52-
- uses: actions/checkout@v3
53-
- uses: actions/setup-python@v4
53+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
54+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
5455
with:
5556
python-version: '3.10'
5657
architecture: ${{ matrix.target }}
58+
- uses: ./.github/actions/toolchains/rust
5759

5860
- name: Build Python extension
5961
run: |
@@ -69,9 +71,9 @@ jobs:
6971
args: --release --out dist --manifest-path bindings/python/Cargo.toml --frozen --strip
7072
sccache: 'true'
7173
- name: Upload wheels
72-
uses: actions/upload-artifact@v3
74+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
7375
with:
74-
name: wheels
76+
name: wheels-windows-${{ matrix.target }}
7577
path: dist
7678

7779
macos:
@@ -80,10 +82,11 @@ jobs:
8082
matrix:
8183
target: [x86_64, aarch64, universal2-apple-darwin]
8284
steps:
83-
- uses: actions/checkout@v3
84-
- uses: actions/setup-python@v4
85+
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
86+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
8587
with:
8688
python-version: '3.10'
89+
- uses: ./.github/actions/toolchains/rust
8790

8891
- name: Build Python extension
8992
run: |
@@ -99,9 +102,9 @@ jobs:
99102
args: --release --out dist --manifest-path bindings/python/Cargo.toml --offline --strip
100103
sccache: 'true'
101104
- name: Upload wheels
102-
uses: actions/upload-artifact@v3
105+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
103106
with:
104-
name: wheels
107+
name: wheels-macos-${{ matrix.host.target }}
105108
path: dist
106109

107110
release:
@@ -111,9 +114,11 @@ jobs:
111114
# if: "startsWith(github.ref, 'refs/tags/')"
112115
needs: [linux, windows, macos]
113116
steps:
114-
- uses: actions/download-artifact@v3
117+
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
115118
with:
116-
name: wheels
119+
pattern: wheels-*
120+
merge-multiple: true
121+
path: wheels
117122
- name: Publish to PyPI
118123
uses: PyO3/maturin-action@63b75c597b83e247fbf4fb7719801cc4220ae9f3 # v1.43.0
119124
env:

.github/workflows/publish-wasm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout repository
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
1616
with:
1717
fetch-depth: 0
1818
# Setup .npmrc file to publish to npm
19-
- uses: actions/setup-node@v4
19+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
2020
with:
2121
node-version: '20.x'
2222
registry-url: 'https://registry.npmjs.org'

.github/workflows/release-plz.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
contents: write
1515
steps:
1616
- name: Checkout repository
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
1818
with:
1919
fetch-depth: 0
2020
- name: Install Rust toolchain
21-
uses: dtolnay/rust-toolchain@stable
21+
uses: ./.github/actions/toolchains/rust
2222
- name: Run release-plz
2323
uses: MarcoIeni/release-plz-action@8724d33cd97b8295051102e2e19ca592962238f5 #v0.5.108
2424
env:

.github/workflows/rust-clippy.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,10 @@ jobs:
3030
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
3131
steps:
3232
- name: Checkout code
33-
uses: actions/checkout@v2
33+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
3434

35-
- name: Install Rust toolchain
36-
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1
37-
with:
38-
profile: minimal
39-
toolchain: stable
40-
components: clippy
41-
override: true
35+
- name: Setup Rust toolchain
36+
uses: ./.github/actions/toolchains/rust
4237

4338
- name: Install required cargo
4439
run: cargo install clippy-sarif sarif-fmt
@@ -55,7 +50,7 @@ jobs:
5550
continue-on-error: true
5651

5752
- name: Upload analysis results to GitHub
58-
uses: github/codeql-action/upload-sarif@v1
53+
uses: github/codeql-action/upload-sarif@c298edae2d512d807fe4bdc57c0ac5a036f61501 # v3.29.11
5954
with:
6055
sarif_file: rust-clippy-results.sarif
6156
wait-for-processing: true

.github/workflows/test-c-cpp.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout repository
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
1818
with:
1919
fetch-depth: 0
2020

21+
- uses: ./.github/actions/toolchains/rust
22+
2123
- name: Setup gcc, g++, cmake, ninja
2224
run: sudo apt update && sudo apt install -y gcc g++ cmake ninja-build
2325

.github/workflows/test-csharp.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ jobs:
3838
# **/release/libregorus_ffi.dylib
3939
steps:
4040
- name: Checkout repository
41-
uses: actions/checkout@v4
41+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
4242
with:
4343
fetch-depth: 0
44+
- uses: ./.github/actions/toolchains/rust
4445

4546
- name: Fetch crates
4647
run: cargo fetch
@@ -59,7 +60,7 @@ jobs:
5960
working-directory: ./bindings/ffi
6061

6162
- name: Upload regorus ffi shared library
62-
uses: actions/upload-artifact@v4
63+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
6364
with:
6465
name: regorus-ffi-artifacts-${{ matrix.runtime.target }}
6566
# Note: The full path of each artifact relative to . is preserved.
@@ -73,17 +74,17 @@ jobs:
7374
needs: build-ffi
7475
steps:
7576
- name: Checkout repository
76-
uses: actions/checkout@v4
77+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
7778
with:
7879
fetch-depth: 0
79-
- uses: actions/setup-dotnet@v4
80+
- uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 # v4.1.0
8081
with:
8182
global-json-file: ./bindings/csharp/global.json
8283

8384
- run: echo '${{ steps.stepid.outputs.dotnet-version }}'
8485

8586
- name: Download regorus ffi shared libraries
86-
uses: actions/download-artifact@v4
87+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
8788
with:
8889
pattern: regorus-ffi-artifacts-*
8990
merge-multiple: true
@@ -102,7 +103,7 @@ jobs:
102103
working-directory: ./bindings/csharp/Regorus
103104

104105
- name: Upload Regorus nuget
105-
uses: actions/upload-artifact@v4
106+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
106107
with:
107108
name: regorus-nuget
108109
path: bindings/csharp/Regorus/bin/Release/Regorus*.nupkg
@@ -126,18 +127,18 @@ jobs:
126127
# target: aarch64-apple-darwin
127128
steps:
128129
- name: Checkout repository
129-
uses: actions/checkout@v4
130+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4
130131
with:
131132
fetch-depth: 0
132133

133-
- uses: actions/setup-dotnet@v4
134+
- uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 # v4.1.0
134135
with:
135136
global-json-file: ./bindings/csharp/global.json
136137

137138
- run: echo '${{ steps.stepid.outputs.dotnet-version }}'
138139

139140
- name: Download regorus nuget
140-
uses: actions/download-artifact@v4
141+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
141142
with:
142143
name: regorus-nuget
143144
path: ./bindings/csharp/regorus-nuget/

0 commit comments

Comments
 (0)