Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add harden-runner in audit mode to run_tests Linux jobs (#59446)

John D. Swansona225d510243a
diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml
index 34fb9c123c9..9c0812f4a51 100644
--- a/.github/workflows/run_tests.yml
+++ b/.github/workflows/run_tests.yml
@@ -19,6 +19,10 @@ jobs:
if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
runs-on: namespace-profile-2x4-ubuntu-2404
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -132,6 +136,10 @@ jobs:
if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
runs-on: namespace-profile-4x8-ubuntu-2204
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -212,6 +220,10 @@ jobs:
CC: clang
CXX: clang++
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -356,6 +368,10 @@ jobs:
CC: clang
CXX: clang++
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -454,6 +470,10 @@ jobs:
if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != 'merge_group'
runs-on: namespace-profile-16x32-ubuntu-2204
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -485,6 +505,10 @@ jobs:
CC: clang
CXX: clang++
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -529,6 +553,10 @@ jobs:
CC: clang
CXX: clang++
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -595,6 +623,10 @@ jobs:
if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != 'merge_group'
runs-on: namespace-profile-8x16-ubuntu-2204
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -638,6 +670,10 @@ jobs:
CC: clang
CXX: clang++
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -672,6 +708,10 @@ jobs:
CC: clang
CXX: clang++
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -721,6 +761,10 @@ jobs:
if: needs.orchestrate.outputs.run_licenses == 'true' && github.event_name != 'merge_group'
runs-on: namespace-profile-2x4-ubuntu-2404
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -740,6 +784,10 @@ jobs:
if: needs.orchestrate.outputs.run_action_checks == 'true'
runs-on: namespace-profile-8x16-ubuntu-2204
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
@@ -778,6 +826,10 @@ jobs:
GIT_COMMITTER_NAME: Protobuf Action
GIT_COMMITTER_EMAIL: [email protected]
steps:
+ - name: steps::harden_runner
+ uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411
+ with:
+ egress-policy: audit
- name: steps::checkout_repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
with:
diff --git a/tooling/xtask/src/tasks/workflows/deploy_docs.rs b/tooling/xtask/src/tasks/workflows/deploy_docs.rs
index c859c6a2d9c..f60d1097d6e 100644
--- a/tooling/xtask/src/tasks/workflows/deploy_docs.rs
+++ b/tooling/xtask/src/tasks/workflows/deploy_docs.rs
@@ -162,7 +162,7 @@ pub(crate) fn check_docs() -> NamedJob {
NamedJob {
name: "check_docs".to_owned(),
job: docs_build_steps(
- release_job(&[]),
+ release_job(&[]).add_step(steps::harden_runner()),
None,
DocsChannel::Stable.channel_name(),
DocsChannel::Stable.site_url(),
diff --git a/tooling/xtask/src/tasks/workflows/release.rs b/tooling/xtask/src/tasks/workflows/release.rs
index 77b6494cc14..f04a9f7ca8a 100644
--- a/tooling/xtask/src/tasks/workflows/release.rs
+++ b/tooling/xtask/src/tasks/workflows/release.rs
@@ -19,10 +19,10 @@ pub(crate) fn release() -> Workflow {
let macos_tests = run_tests::run_platform_tests_no_filter(Platform::Mac);
let linux_tests = run_tests::run_platform_tests_no_filter(Platform::Linux);
let windows_tests = run_tests::run_platform_tests_no_filter(Platform::Windows);
- let macos_clippy = run_tests::clippy(Platform::Mac, None);
- let linux_clippy = run_tests::clippy(Platform::Linux, None);
- let windows_clippy = run_tests::clippy(Platform::Windows, None);
- let check_scripts = run_tests::check_scripts();
+ let macos_clippy = run_tests::clippy(Platform::Mac, None, false);
+ let linux_clippy = run_tests::clippy(Platform::Linux, None, false);
+ let windows_clippy = run_tests::clippy(Platform::Windows, None, false);
+ let check_scripts = run_tests::check_scripts(false);
let create_draft_release = create_draft_release();
let (non_blocking_compliance_run, job_output) = compliance_check();
diff --git a/tooling/xtask/src/tasks/workflows/run_tests.rs b/tooling/xtask/src/tasks/workflows/run_tests.rs
index 0758b2b4a75..dd422fa32e9 100644
--- a/tooling/xtask/src/tasks/workflows/run_tests.rs
+++ b/tooling/xtask/src/tasks/workflows/run_tests.rs
@@ -51,16 +51,18 @@ pub(crate) fn run_tests() -> Workflow {
check_style(),
should_run_tests
.and_not_in_merge_queue()
- .then(clippy(Platform::Windows, None)),
+ .then(clippy(Platform::Windows, None, true)),
should_run_tests
.and_always()
- .then(clippy(Platform::Linux, None)),
+ .then(clippy(Platform::Linux, None, true)),
should_run_tests
.and_not_in_merge_queue()
- .then(clippy(Platform::Mac, None)),
- should_run_tests
- .and_not_in_merge_queue()
- .then(clippy(Platform::Mac, Some(Arch::X86_64))),
+ .then(clippy(Platform::Mac, None, true)),
+ should_run_tests.and_not_in_merge_queue().then(clippy(
+ Platform::Mac,
+ Some(Arch::X86_64),
+ true,
+ )),
should_run_tests
.and_not_in_merge_queue()
.then(run_platform_tests(Platform::Windows)),
@@ -90,7 +92,7 @@ pub(crate) fn run_tests() -> Workflow {
should_check_licences
.and_not_in_merge_queue()
.then(check_licenses()),
- should_check_scripts.and_always().then(check_scripts()),
+ should_check_scripts.and_always().then(check_scripts(true)),
];
let ext_tests = extension_tests();
let tests_pass = tests_pass(&jobs, &[&ext_tests.name]);
@@ -295,6 +297,9 @@ fn orchestrate_impl(rules: &[&PathCondition], target: OrchestrateTarget) -> Name
.runs_on(runners::LINUX_SMALL)
.with_repository_owner_guard()
.outputs(outputs)
+ .when(target == OrchestrateTarget::ZedRepo, |this| {
+ this.add_step(steps::harden_runner())
+ })
.add_step(steps::checkout_repo().with_deep_history_on_non_main())
.add_step(Step::new(step_name.clone()).run(script).id(step_name));
@@ -428,6 +433,7 @@ fn check_style() -> NamedJob {
named::job(
release_job(&[])
.runs_on(runners::LINUX_MEDIUM)
+ .add_step(steps::harden_runner())
.add_step(steps::checkout_repo())
.add_step(steps::cache_rust_dependencies_namespace())
.add_step(steps::setup_pnpm())
@@ -467,6 +473,7 @@ fn check_dependencies() -> NamedJob {
named::job(use_clang(
release_job(&[])
.runs_on(runners::LINUX_SMALL)
+ .add_step(steps::harden_runner())
.add_step(steps::checkout_repo())
.add_step(steps::cache_rust_dependencies_namespace())
.add_step(install_cargo_machete())
@@ -498,6 +505,7 @@ fn check_wasm() -> NamedJob {
named::job(
release_job(&[])
.runs_on(runners::LINUX_LARGE)
+ .add_step(steps::harden_runner())
.add_step(steps::checkout_repo())
.add_step(steps::setup_cargo_config(Platform::Linux))
.add_step(steps::cache_rust_dependencies_namespace())
@@ -513,6 +521,7 @@ fn check_workspace_binaries() -> NamedJob {
named::job(use_clang(
release_job(&[])
.runs_on(runners::LINUX_LARGE)
+ .add_step(steps::harden_runner())
.add_step(steps::checkout_repo())
.add_step(steps::setup_cargo_config(Platform::Linux))
.add_step(steps::cache_rust_dependencies_namespace())
@@ -525,7 +534,7 @@ fn check_workspace_binaries() -> NamedJob {
))
}
-pub(crate) fn clippy(platform: Platform, arch: Option<Arch>) -> NamedJob {
+pub(crate) fn clippy(platform: Platform, arch: Option<Arch>, harden: bool) -> NamedJob {
let target = arch.map(|arch| match (platform, arch) {
(Platform::Mac, Arch::X86_64) => "x86_64-apple-darwin",
(Platform::Mac, Arch::AARCH64) => "aarch64-apple-darwin",
@@ -538,6 +547,9 @@ pub(crate) fn clippy(platform: Platform, arch: Option<Arch>) -> NamedJob {
};
let mut job = release_job(&[])
.runs_on(runner)
+ .when(harden && platform == Platform::Linux, |this| {
+ this.add_step(steps::harden_runner())
+ })
.add_step(steps::checkout_repo())
.add_step(steps::setup_cargo_config(platform))
.when(
@@ -565,14 +577,14 @@ pub(crate) fn clippy(platform: Platform, arch: Option<Arch>) -> NamedJob {
}
pub(crate) fn run_platform_tests(platform: Platform) -> NamedJob {
- run_platform_tests_impl(platform, true)
+ run_platform_tests_impl(platform, true, true)
}
pub(crate) fn run_platform_tests_no_filter(platform: Platform) -> NamedJob {
- run_platform_tests_impl(platform, false)
+ run_platform_tests_impl(platform, false, false)
}
-fn run_platform_tests_impl(platform: Platform, filter_packages: bool) -> NamedJob {
+fn run_platform_tests_impl(platform: Platform, filter_packages: bool, harden: bool) -> NamedJob {
let runner = match platform {
Platform::Windows => runners::WINDOWS_DEFAULT,
Platform::Linux => runners::LINUX_DEFAULT,
@@ -596,6 +608,9 @@ fn run_platform_tests_impl(platform: Platform, filter_packages: bool) -> NamedJo
),
)
})
+ .when(harden && platform == Platform::Linux, |this| {
+ this.add_step(steps::harden_runner())
+ })
.add_step(steps::checkout_repo())
.add_step(steps::setup_cargo_config(platform))
.when(platform == Platform::Mac, |this| {
@@ -693,6 +708,7 @@ pub(crate) fn check_postgres_and_protobuf_migrations() -> NamedJob {
.add_env(("GIT_AUTHOR_EMAIL", "[email protected]"))
.add_env(("GIT_COMMITTER_NAME", "Protobuf Action"))
.add_env(("GIT_COMMITTER_EMAIL", "[email protected]"))
+ .add_step(steps::harden_runner())
.add_step(steps::checkout_repo().with_full_history())
.add_step(ensure_fresh_merge())
.add_step(bufbuild_setup_action())
@@ -716,6 +732,7 @@ fn miri_scheduler() -> NamedJob {
named::job(
release_job(&[])
.runs_on(runners::LINUX_DEFAULT)
+ .add_step(steps::harden_runner())
.add_step(steps::checkout_repo())
.add_step(steps::setup_cargo_config(Platform::Linux))
.add_step(steps::cache_rust_dependencies_namespace())
@@ -736,6 +753,7 @@ fn doctests() -> NamedJob {
named::job(use_clang(
release_job(&[])
.runs_on(runners::LINUX_DEFAULT)
+ .add_step(steps::harden_runner())
.add_step(steps::checkout_repo())
.add_step(steps::cache_rust_dependencies_namespace())
.map(steps::install_linux_dependencies)
@@ -751,6 +769,7 @@ fn check_licenses() -> NamedJob {
named::job(
Job::default()
.runs_on(runners::LINUX_SMALL)
+ .add_step(steps::harden_runner())
.add_step(steps::checkout_repo())
.add_step(steps::cache_rust_dependencies_namespace())
.add_step(steps::script("./script/check-licenses"))
@@ -758,7 +777,7 @@ fn check_licenses() -> NamedJob {
)
}
-pub(crate) fn check_scripts() -> NamedJob {
+pub(crate) fn check_scripts(harden: bool) -> NamedJob {
fn download_actionlint() -> Step<Run> {
named::bash(
"bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)",
@@ -790,6 +809,7 @@ pub(crate) fn check_scripts() -> NamedJob {
named::job(
release_job(&[])
.runs_on(runners::LINUX_LARGE)
+ .when(harden, |this| this.add_step(steps::harden_runner()))
.add_step(steps::checkout_repo())
.add_step(run_shellcheck())
.add_step(download_actionlint().id("get_actionlint"))
diff --git a/tooling/xtask/src/tasks/workflows/steps.rs b/tooling/xtask/src/tasks/workflows/steps.rs
index fde9150b1a7..1ee14fc9475 100644
--- a/tooling/xtask/src/tasks/workflows/steps.rs
+++ b/tooling/xtask/src/tasks/workflows/steps.rs
@@ -150,6 +150,16 @@ pub fn checkout_repo() -> CheckoutStep {
CheckoutStep::default()
}
+// Audit mode: logs egress, blocks nothing. Namespace requires v2.19.0+.
+pub fn harden_runner() -> Step<Use> {
+ named::uses(
+ "step-security",
+ "harden-runner",
+ "9af89fc71515a100421586dfdb3dc9c984fbf411", // v2.19.4
+ )
+ .add_with(("egress-policy", "audit"))
+}
+
pub fn setup_pnpm() -> Step<Use> {
named::uses(
"pnpm",