Debian Codegraph @

crt/s2n/.github/workflows/ci_rust.yml

raw symbols SCIP
1 ---
2 name: Rust Bindings
3
4 on:
5 push:
6 branches: [main]
7 pull_request:
8 branches: [main]
9 merge_group:
10 types: [checks_requested]
11 branches: [main]
12
13 env:
14 RUST_NIGHTLY_TOOLCHAIN: nightly
15 # Extended support MSRV
16 ROOT_PATH: bindings/rust/extended
17 # Standard support MSRV
18 STANDARD_PATH: bindings/rust/standard
19 EXAMPLE_WORKSPACE: bindings/rust-examples
20 PCAP_TEST_PATH: tests/pcap
21 # The name of a s2n-tls test gated behind the external build cfg flag.
22 EXTERNAL_BUILD_TEST_NAME: test_unstable_as_ptr
23
24 permissions:
25 contents: read
26
27 jobs:
28 generate:
29 runs-on: ${{ matrix.os }}
30 strategy:
31 fail-fast: false
32 matrix:
33 os: [ubuntu-latest, macOS-latest]
34 steps:
35 - uses: actions/checkout@v7
36
37 - name: Install Rust toolchain
38 id: toolchain
39 run: |
40 rustup toolchain install stable
41 rustup override set stable
42
43 # https://github.com/aws/aws-lc-rs/blob/main/aws-lc-fips-sys/README.md#build-prerequisites
44 # go required for generate.sh to build aws-lc-rs in FIPS mode
45 - name: Install go
46 uses: actions/setup-go@v6
47 with:
48 go-version: '>=1.18'
49
50 - uses: camshaft/rust-cache@v1
51
52 - name: Generate
53 run: ${{env.ROOT_PATH}}/generate.sh
54
55 # Ensure that all tests pass with the default feature set
56 - name: Default Tests
57 working-directory: ${{env.ROOT_PATH}}
58 run: cargo test
59
60 # Test the standard workspace
61 - name: Standard Workspace Tests
62 working-directory: ${{env.STANDARD_PATH}}
63 run: cargo test
64
65 - name: "Feature Tests: Fingerprint, kTLS, QUIC, PQ, and unstable-custom_x509_extensions"
66 working-directory: ${{env.ROOT_PATH}}
67 # Test all features except for FIPS, which is tested separately.
68 run: cargo test --features unstable-fingerprint,unstable-ktls,quic,pq,unstable-custom_x509_extensions
69
70 - name: "Feature Test: Renegotiate"
71 working-directory: ${{env.ROOT_PATH}}
72 run: cargo test --features unstable-renegotiate
73
74 - name: Test external build cfg
75 working-directory: ${{env.ROOT_PATH}}/s2n-tls
76 run: |
77 echo "Using the external build feature should set a cfg flag in s2n-tls. Ensure that"
78 echo "this flag is NOT set when the external build feature isn't used. The"
79 echo "${{env.EXTERNAL_BUILD_TEST_NAME}} test is gated behind this flag, so ensure this test"
80 echo "is NOT run."
81 output=$(cargo test ${{env.EXTERNAL_BUILD_TEST_NAME}})
82 echo "${output}"
83 echo "${output}" | grep -q "test result: ok. 0 passed; 0 failed; 0 ignored;"
84
85 sensitive-tests:
86 runs-on: ubuntu-latest
87 steps:
88 - uses: actions/checkout@v7
89 - name: install rust toolchain
90 id: toolchain
91 run: |
92 rustup toolchain install stable
93 rustup override set stable
94
95 - name: generate bindings
96 run: ${{env.ROOT_PATH}}/generate.sh --skip-tests
97
98 # network tests are sensitive because there is inherent flakiness on the public internet
99 # memory tests are sensitive because memory usage is platform/feature specific
100 - name: sensitive integration tests
101 working-directory: ${{env.STANDARD_PATH}}/integration
102 # no-default-features is used because sensitive tests are hidden behind a
103 # default "negative" feature. This is because we don't want sensitive tests
104 # invoked on the `cargo test --all-features` pattern.
105 run: RUST_LOG=TRACE cargo test --no-default-features --features pq
106
107 - name: metrics-subscriber memory test
108 working-directory: ${{env.STANDARD_PATH}}/s2n-tls-metrics-subscriber
109 run: cargo test --release --features memory-test --test subscriber_memory
110
111 external-build-test:
112 runs-on: ubuntu-latest
113 steps:
114 - uses: actions/checkout@v7
115
116 - name: Install Rust toolchain
117 id: toolchain
118 run: |
119 rustup toolchain install stable
120 rustup override set stable
121
122 - uses: camshaft/rust-cache@v1
123
124 - name: Checkout aws-lc
125 uses: actions/checkout@v7
126 with:
127 repository: aws/aws-lc
128 path: aws-lc
129
130 - name: Build aws-lc
131 working-directory: aws-lc
132 run: |
133 cmake -Bbuild \
134 -DBUILD_SHARED_LIBS=off \
135 -DBUILD_LIBSSL=off \
136 -DCMAKE_INSTALL_PREFIX=./install
137 cmake --build build -j $(nproc)
138 cmake --install build
139
140 - name: Test external build
141 # if this test is failing, make sure that api headers are appropriately
142 # included. For a symbol to be visible in a shared lib, the
143 # __attribute__((visibility("default"))) label must be on a declaration
144 # in the same unit of compilation as the definition. Generally this just
145 # means that if the linker can't resolve foo_method in tls/foo.c, you
146 # forgot to include api/unstable/foo.h in tls/foo.c
147
148 # Note that we don't test the whole "standard" workspace, only the
149 # integration crate. This is because `s2n-tls-sys-internal` (one of our
150 # test dependencies) can not be built with libs2n.so, and requires static
151 # linking to access internal details.
152 run: |
153 cmake . -Bbuild \
154 -DBUILD_SHARED_LIBS=on \
155 -DBUILD_TESTING=off \
156 -DCMAKE_PREFIX_PATH=./aws-lc/install \
157 -DS2N_INTERN_LIBCRYPTO=on
158 cmake --build build -- -j $(nproc)
159
160 export S2N_TLS_LIB_DIR=`pwd`/build/lib
161 export S2N_TLS_INCLUDE_DIR=`pwd`/api
162 export LD_LIBRARY_PATH=$S2N_TLS_LIB_DIR:$LD_LIBRARY_PATH
163
164 cd ${{env.ROOT_PATH}}
165 ./generate.sh
166 # Relative paths
167 cd ../../..
168 ldd ${{env.STANDARD_PATH}}/target/debug/integration | grep libs2n.so
169
170 # Run tests with the external build
171 cargo test --manifest-path ${{env.ROOT_PATH}}/Cargo.toml
172 cargo test --manifest-path ${{env.STANDARD_PATH}}/integration/Cargo.toml
173
174 echo ""
175 echo "Test that the external build will enable the proper cfg flag in s2n-tls. The"
176 echo "${{env.EXTERNAL_BUILD_TEST_NAME}} test is gated behind this flag, so ensure this"
177 echo "test is run."
178 manifest_path="${{env.ROOT_PATH}}/s2n-tls/Cargo.toml"
179 output=$(cargo test --manifest-path ${manifest_path} ${{env.EXTERNAL_BUILD_TEST_NAME}})
180 echo "${output}"
181 echo "${output}" | grep -q "test result: ok. 1 passed; 0 failed; 0 ignored;"
182
183 s2n-tls-binding-examples:
184 runs-on: ubuntu-latest
185 steps:
186 - uses: actions/checkout@v7
187
188 - name: Install Rust toolchain
189 id: toolchain
190 run: |
191 rustup toolchain install stable
192 rustup override set stable
193
194 - name: generate bindings
195 run: ${{env.ROOT_PATH}}/generate.sh --skip-tests
196
197 - name: build examples
198 working-directory: ${{env.EXAMPLE_WORKSPACE}}
199 run: cargo build
200
201 - name: test examples
202 working-directory: ${{env.EXAMPLE_WORKSPACE}}
203 run: cargo test
204
205 generate-openssl-102:
206 runs-on: ubuntu-latest
207 steps:
208 - uses: actions/checkout@v7
209
210 - name: Install Rust toolchain
211 id: toolchain
212 run: |
213 rustup toolchain install stable
214 rustup override set stable
215
216 - uses: camshaft/rust-cache@v1
217
218 - name: Cache OpenSSL 1.0.2
219 id: cache-openssl
220 uses: actions/cache@v5
221 with:
222 path: ~/openssl-102/install
223 # The sha256 suffix pins the cache to a specific source tarball.
224 # Bumping the tarball (or version) busts the cache automatically,
225 # which also prevents a stale cache entry from masking a broken
226 # download step.
227 key: ${{ runner.os }}-openssl-1.0.2u-ecd0c6ff
228
229 - if: ${{ steps.cache-openssl.outputs.cache-hit != 'true' }}
230 name: Install OpenSSL 1.0.2
231 run: |
232 mkdir ~/openssl-102
233 pushd ~/openssl-102
234
235 mkdir install
236 install_dir="$(pwd)"/install
237
238 # OpenSSL moved release hosting to GitHub in 2024. The openssl.org
239 # redirect for the 1.0.2 series points at a non-existent asset
240 # (openssl/openssl under the tag `openssl-1.0.2u`), so fetch directly
241 # from the tag that actually exists (`OpenSSL_1_0_2u`).
242 tarball_url="https://github.com/openssl/openssl/releases/download/OpenSSL_1_0_2u/openssl-1.0.2u.tar.gz"
243 expected_sha256="ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16"
244
245 curl --fail --location --silent --show-error \
246 --output openssl-1.0.2u.tar.gz "${tarball_url}"
247 echo "${expected_sha256} openssl-1.0.2u.tar.gz" | sha256sum --check --strict
248 tar -xzvf openssl-1.0.2u.tar.gz
249
250 pushd openssl-1.0.2u
251 ./config --prefix="${install_dir}" --openssldir="${install_dir}"/openssl
252 make
253 make install
254 popd
255
256 popd
257
258 - name: Generate
259 run: OPENSSL_DIR=~/openssl-102/install ${{env.ROOT_PATH}}/generate.sh
260
261 - name: Tests
262 working-directory: ${{env.ROOT_PATH}}
263 run: cargo test --all-features
264
265 fips:
266 runs-on: ${{ matrix.os }}
267 strategy:
268 fail-fast: false
269 matrix:
270 os: [ubuntu-latest, macOS-latest]
271 steps:
272 - uses: actions/checkout@v7
273 with:
274 submodules: true
275
276 - name: Install Rust toolchain
277 id: toolchain
278 run: |
279 rustup toolchain install stable
280 rustup override set stable
281
282 # https://github.com/aws/aws-lc-rs/blob/main/aws-lc-fips-sys/README.md#build-prerequisites
283 # go required to build aws-lc-rs in FIPS mode
284 - name: Install go
285 uses: actions/setup-go@v6
286 with:
287 go-version: '>=1.18'
288
289 - uses: camshaft/rust-cache@v1
290
291 - name: Generate
292 run: ./${{env.ROOT_PATH}}/generate.sh
293
294 - name: Test fips
295 working-directory: ${{env.ROOT_PATH}}
296 run: |
297 # The doc tests fail to link to AWS-LC in FIPS mode due to
298 # https://github.com/rust-lang/cargo/issues/8531. The --tests flag is provided to disable
299 # the doc tests. The doc tests are tested in the generate test, where FIPS is disabled.
300 cargo test --tests --features fips
301
302 # Test all features, including FIPS
303 - name: Test all
304 working-directory: ${{env.ROOT_PATH}}
305 run: |
306 cargo test --tests --all-features
307
308 # Run the rust unit tests under address sanitizer.
309 #
310 # Rust is generally memory safe, but our bindings contain a large amount of unsafe
311 # code. Additionally, "safe" code doesn't guarentee that the code is free of
312 # memory leaks.
313 asan-unit-tests:
314 runs-on: ubuntu-latest
315 steps:
316 - uses: actions/checkout@v7
317
318 - name: Install Rust toolchain
319 id: toolchain
320 run: |
321 rustup toolchain install ${{env.RUST_NIGHTLY_TOOLCHAIN }} \
322 --profile minimal \
323 --component rust-src \
324 --target x86_64-unknown-linux-gnu
325 rustup override set ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
326
327 - name: Generate
328 run: ./${{env.ROOT_PATH}}/generate.sh --skip-tests
329
330 # asan expects a binary at /usr/bin/llvm-symbolizer but GHA runners include
331 # multiple versioned binaries, like /usr/bin/llvm-symbolizer-13. This step
332 # finds the latest symbolizer and use it as the "base" llvm-symbolizer binary.
333 #
334 # llvm-symbolizer is necessary to get nice stack traces from asan errors.
335 # Otherwise the stack trace just contains a hex address like "0x55bc6a28a9b6"
336 - name: set llvm symbolizer
337 run: |
338 sudo ln -s $(find /usr/bin/ -maxdepth 1 -name "llvm-symbolizer-*" | sort -V | tail -n 1) /usr/bin/llvm-symbolizer
339
340 - name: Run Unit Tests under ASAN
341 env:
342 RUSTDOCFLAGS: -Zsanitizer=address
343 RUSTFLAGS: -Zsanitizer=address
344 run: |
345 cargo test \
346 -Zbuild-std \
347 --manifest-path ${{ env.ROOT_PATH}}/Cargo.toml \
348 --target x86_64-unknown-linux-gnu
349
350 rustfmt:
351 runs-on: ubuntu-latest
352 steps:
353 - uses: actions/checkout@v7
354 with:
355 submodules: true
356
357 - name: Install Rust toolchain
358 id: toolchain
359 run: |
360 rustup toolchain install ${{ env.RUST_NIGHTLY_TOOLCHAIN }} --profile minimal --component rustfmt
361 rustup override set ${{ env.RUST_NIGHTLY_TOOLCHAIN }}
362
363 - uses: camshaft/rust-cache@v1
364
365 # We don't need to format the generated files,
366 # but if they don't exist other code breaks.
367 - name: Generate
368 run: ./${{env.ROOT_PATH}}/generate.sh --skip-tests
369
370 - name: Run cargo fmt - extended packages
371 run: |
372 cargo fmt --manifest-path ${{env.ROOT_PATH}}/Cargo.toml --all -- --check
373
374 - name: Run cargo fmt - standard packages
375 run: |
376 cargo fmt --manifest-path ${{env.STANDARD_PATH}}/Cargo.toml --all -- --check
377
378 clippy:
379 runs-on: ubuntu-latest
380 steps:
381 - uses: actions/checkout@v7
382 with:
383 submodules: true
384
385 - name: Install Rust toolchain
386 id: toolchain
387 run: |
388 rustup toolchain install stable --profile minimal --component clippy
389 rustup override set stable
390
391 - uses: camshaft/rust-cache@v1
392
393 - uses: SebRollen/[email protected]
394 id: read_toml
395 with:
396 file: '${{env.ROOT_PATH}}/rust-toolchain.toml'
397 field: 'toolchain.channel'
398
399 # Enforce that clippy's msrv matches rust-toolchain
400 - name: Check MSRV
401 run: grep "${{steps.read_toml.outputs.value}}" ${{env.ROOT_PATH}}/.clippy.toml
402
403 # We don't need to format the generated files,
404 # but if they don't exist other code breaks.
405 - name: Generate
406 run: ${{env.ROOT_PATH}}/generate.sh
407
408 # TODO translate json reports to in-action warnings
409 - name: Run cargo clippy - extended packages
410 run: |
411 cargo clippy --manifest-path ${{env.ROOT_PATH}}/Cargo.toml --all-targets -- -D warnings
412 cargo clippy --manifest-path ${{env.ROOT_PATH}}/Cargo.toml --all-targets --all-features -- -D warnings
413
414 - name: Run cargo clippy - standard packages
415 run: |
416 cargo clippy --manifest-path ${{env.STANDARD_PATH}}/Cargo.toml --all-targets -- -D warnings
417 cargo clippy --manifest-path ${{env.STANDARD_PATH}}/Cargo.toml --all-targets --all-features -- -D warnings
418
419 msrv:
420 runs-on: ubuntu-latest
421 steps:
422 - uses: actions/checkout@v7
423 with:
424 submodules: true
425
426 - uses: SebRollen/[email protected]
427 id: read_toml
428 with:
429 file: '${{env.ROOT_PATH}}/rust-toolchain.toml'
430 field: 'toolchain.channel'
431
432 # Enforce crate msrv matches rust-toolchain
433 - name: Check MSRV of s2n-tls
434 run: grep "rust-version = \"${{steps.read_toml.outputs.value}}\"" ${{env.ROOT_PATH}}/s2n-tls/Cargo.toml
435
436 - name: Check MSRV of s2n-tls-sys
437 run: grep "rust-version = \"${{steps.read_toml.outputs.value}}\"" ${{env.ROOT_PATH}}/s2n-tls-sys/templates/Cargo.template
438
439 - name: Check MSRV of s2n-tokio
440 run: grep "rust-version = \"${{steps.read_toml.outputs.value}}\"" ${{env.ROOT_PATH}}/s2n-tls-tokio/Cargo.toml
441
442 pcaps:
443 runs-on: ubuntu-24.04
444 steps:
445 - uses: actions/checkout@v7
446 with:
447 submodules: true
448
449 - name: Install Rust toolchain
450 id: toolchain
451 run: |
452 rustup toolchain install stable --component clippy,rustfmt
453 rustup override set stable
454
455 - name: Install tshark
456 run: |
457 sudo apt-get update
458 sudo apt-get install -y tshark
459 tshark --version
460
461 - name: Generate bindings
462 working-directory: ${{env.ROOT_PATH}}
463 run: ./generate.sh --skip-tests
464
465 - name: Run lints
466 working-directory: ${{env.PCAP_TEST_PATH}}
467 run: |
468 cargo fmt --all -- --check
469 cargo clippy --all-targets -- -D warnings
470
471 - name: Run tests
472 working-directory: ${{env.PCAP_TEST_PATH}}
473 run: cargo test --all-features
474
475 minimal-versions:
476 runs-on: ubuntu-24.04
477 strategy:
478 matrix:
479 workspace-path:
480 - bindings/rust/extended
481 - bindings/rust/standard
482 steps:
483 - uses: actions/checkout@v7
484
485 - name: Install Rust toolchain
486 id: toolchain
487 # minimal-versions is an unstable feature, and requires the nightly toolchain:
488 # https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#minimal-versions
489 run: |
490 rustup toolchain install ${{env.RUST_NIGHTLY_TOOLCHAIN}}
491 rustup override set ${{env.RUST_NIGHTLY_TOOLCHAIN}}
492
493 - uses: camshaft/rust-cache@v1
494
495 # cargo-minimal-versions requires cargo-hack:
496 # https://crates.io/crates/cargo-minimal-versions#user-content-prerequisites
497 - name: Install cargo-hack
498 uses: baptiste0928/[email protected]
499 with:
500 crate: cargo-hack
501
502 - name: Install cargo-minimal-versions
503 uses: baptiste0928/[email protected]
504 with:
505 crate: cargo-minimal-versions
506
507 - name: Generate
508 run: ./${{env.ROOT_PATH}}/generate.sh --skip-tests
509
510 - name: Test minimal versions
511 id: test-minimal-versions
512 working-directory: ${{matrix.workspace-path}}
513 run: |
514 cargo +${{env.RUST_NIGHTLY_TOOLCHAIN}} minimal-versions check --direct --ignore-private
515 cargo +${{env.RUST_NIGHTLY_TOOLCHAIN}} minimal-versions check --direct --ignore-private --all-features
516
517 # compare generated s2n-tls-sys/Cargo.toml with the existing one to check if it's up-to-date
518 # unstable features might be updated in the future, new Cargo.toml should be committed in this case
519 check-generated-cargo-toml:
520 runs-on: ubuntu-latest
521 steps:
522 - uses: actions/checkout@v7
523
524 - name: Install Rust toolchain
525 id: toolchain
526 run: |
527 rustup toolchain install stable
528 rustup override set stable
529
530 - uses: camshaft/rust-cache@v1
531
532 - name: Generate
533 run: ${{env.ROOT_PATH}}/generate.sh --skip-tests
534
535 - name: Compare Cargo
536 working-directory: ${{env.ROOT_PATH}}/s2n-tls-sys
537 id: diff
538 run: git diff --exit-code Cargo.toml
539 continue-on-error: true
540
541 - name: Failure
542 if: steps.diff.outcome != 'success'
543 run: |
544 echo "A mismatch between the existing s2n-tls-sys/Cargo.toml and the Cargo.toml generated \
545 from s2n-tls-sys/templates/Cargo.template has been found. Please ensure that the committed \
546 Cargo.toml is up-to-date by regenerating it with ${{env.ROOT_PATH}}/generate.sh"
547 exit 1
548
549 metrics-subscriber-fuzz:
550 name: metrics-subscriber fuzz tests
551 runs-on: ubuntu-latest
552 steps:
553 - uses: actions/checkout@v7
554
555 - name: Install Rust nightly
556 run: |
557 rustup toolchain install nightly
558 rustup override set nightly
559
560 - name: Install go
561 uses: actions/setup-go@v6
562 with:
563 go-version: '>=1.18'
564
565 - uses: camshaft/rust-cache@v1
566
567 - name: Generate
568 run: ${{env.ROOT_PATH}}/generate.sh
569
570 - run: cargo install cargo-fuzz
571
572 - name: fuzz cert parser
573 working-directory: ${{env.STANDARD_PATH}}/s2n-tls-metrics-subscriber
574 run: cargo +nightly fuzz run fuzz_cert_parse --jobs $(nproc) -- -max_total_time=60