Skip to content

Commit 606ae0f

Browse files
authored
dev: include security auditing in the local lint suite (#25359)
## Which issue does this PR close? - Part of #21048. The issue stays open for the other checklist items. ## Rationale for this change The "Security audit" workflow runs `cargo audit` with two advisory exceptions, but `dev/rust_lint.sh` has no audit step. A contributor can pass the local lint suite and find a vulnerable dependency only in CI. This PR moves the audit command and its exceptions into one script that CI and the local suite share. ## What changes are included in this PR? - `ci/scripts/security_audit.sh` is a new executable script. It audits the root `Cargo.lock` from the repository root, even when invoked from a subdirectory, with the same `--ignore` flags that CI uses today. It keeps the audit output and exit status. It requires `cargo-audit` and does not install it. The rationale for the two quick-xml exceptions moves from the workflow into the script. - `.github/workflows/audit.yml` calls the script. The workflow name, job, triggers, permissions, runner, and pinned actions do not change. Only the run line changes. - `dev/rust_lint.sh` installs `cargo-audit` when it is missing, through the existing helper, and runs the script as a read-only step after the Markdown link check and before the Rust documentation build. The `--write` and `--allow-dirty` flags never reach it. - `docs/source/contributor-guide/testing.md` documents the standalone command and why the result can change without a repository change. ## What is the testing strategy for this PR? - The workflow's inline command and the new script ran on the same `Cargo.lock` with `cargo-audit` 0.22.2 and the same advisory database. Both passed with identical findings, and no manifest or lockfile changed. - A disposable fixture with a logging `cargo` stub exercised the script. Invoked from a subdirectory, it runs the exact CI command at the repository root. It keeps the audit exit status. It reports a clear error when `cargo-audit` is missing. - A disposable fixture with stubbed steps and tools exercised the runner. The audit runs once with no arguments in check mode and in both write modes. A missing `cargo-audit` triggers the existing install path, and a present one triggers no install. An install failure stops the suite before any step, and an audit failure stops the later steps. - The parsed workflow YAML is identical to `main` except the run line. The workflow install check, the ASF status check validator, `git diff --check`, and the full `./dev/rust_lint.sh` pass on this branch. The audit workflow filters pull requests by Cargo manifest and lockfile paths, so this PR does not trigger it. The merge queue runs it without that filter. ## Are there any user-facing changes? No. The local lint suite gains the audit and installs `cargo-audit` when it is missing. CI behavior is unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 86ba5e0 commit 606ae0f

4 files changed

Lines changed: 69 additions & 5 deletions

File tree

‎.github/workflows/audit.yml‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,4 @@ jobs:
4949
with:
5050
tool: cargo-audit
5151
- name: Run audit check
52-
# Note: you can ignore specific RUSTSEC issues using the `--ignore` flag ,for example:
53-
# run: cargo audit --ignore RUSTSEC-2026-0001
54-
# TODO: remove once object_store upgrades to quick-xml >= 0.41.0
55-
# https://github.com/apache/datafusion/issues/23297
56-
run: cargo audit --ignore RUSTSEC-2026-0194 --ignore RUSTSEC-2026-0195
52+
run: bash ci/scripts/security_audit.sh

‎ci/scripts/security_audit.sh‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
# Audits the root `Cargo.lock` with `cargo audit`, the same way the
21+
# "Security audit" GitHub workflow does.
22+
23+
set -euo pipefail
24+
25+
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
26+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
27+
ROOT_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)"
28+
29+
if ! command -v cargo-audit &> /dev/null; then
30+
echo "[${SCRIPT_NAME}] cargo-audit is required. Install it with: cargo install cargo-audit --locked" >&2
31+
exit 1
32+
fi
33+
34+
# RUSTSEC-2026-0194 and RUSTSEC-2026-0195 are in quick-xml, reached through
35+
# object_store. Remove them once object_store upgrades to quick-xml >= 0.41.0.
36+
# https://github.com/apache/datafusion/issues/23297
37+
IGNORED_ADVISORIES=(
38+
RUSTSEC-2026-0194
39+
RUSTSEC-2026-0195
40+
)
41+
42+
IGNORE_ARGS=()
43+
for advisory in "${IGNORED_ADVISORIES[@]}"; do
44+
IGNORE_ARGS+=(--ignore "${advisory}")
45+
done
46+
47+
cd "${ROOT_DIR}"
48+
49+
echo "[${SCRIPT_NAME}] \`cargo audit ${IGNORE_ARGS[*]}\`"
50+
# The guarded expansion keeps `set -u` happy on bash 3.2 (macOS) if the list is empty.
51+
cargo audit ${IGNORE_ARGS[@]+"${IGNORE_ARGS[@]}"}

‎dev/rust_lint.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ ensure_tool "taplo" "cargo install taplo-cli --locked"
112112
ensure_tool "hawkeye" "cargo install hawkeye --locked"
113113
ensure_tool "typos" "cargo install typos-cli --locked"
114114
ensure_tool "lychee" "cargo install lychee --locked --version ${LYCHEE_VERSION}"
115+
ensure_tool "cargo-audit" "cargo install cargo-audit --locked"
115116

116117
run_step() {
117118
local name="$1"
@@ -133,6 +134,7 @@ declare -a READONLY_STEPS=(
133134
"ci/scripts/check_no_cargo_install_in_workflows.sh|false"
134135
"ci/scripts/check_asf_yaml_status_checks.py|false"
135136
"ci/scripts/markdown_link_check.sh|false"
137+
"ci/scripts/security_audit.sh|false"
136138
"ci/scripts/rust_docs.sh|false"
137139
)
138140

‎docs/source/contributor-guide/testing.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ uv run python3 ci/scripts/check_asf_yaml_status_checks.py
239239
[pyyaml]: https://pypi.org/project/PyYAML/
240240
[uv]: https://docs.astral.sh/uv/
241241

242+
## Security Audit
243+
244+
`ci/scripts/security_audit.sh` runs `cargo audit` on the root `Cargo.lock` with
245+
the advisory exceptions that CI uses. `./dev/rust_lint.sh` runs it and installs
246+
[cargo-audit] if it is missing. To run the audit on its own:
247+
248+
```shell
249+
./ci/scripts/security_audit.sh
250+
```
251+
252+
The audit fetches the RustSec advisory database. A new advisory or a different
253+
`cargo-audit` version can change the result without any change to the repository.
254+
255+
[cargo-audit]: https://github.com/rustsec/rustsec/blob/main/cargo-audit/README.md
256+
242257
## Benchmarks
243258

244259
### Criterion Benchmarks

0 commit comments

Comments
 (0)