Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 84 additions & 10 deletions .github/scripts/check-no-test-trusted-root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,89 @@ if ! grep -q 'refusing an optimized build' "$err"; then
exit 1
fi

# Every release, publish, or tag workflow must run this script. Prove the
# guard rejects such a workflow without it, then check the real ones.

# Every release, publish, or tag workflow must run this script on a run:
# line. Prove the guard rejects each release form without it (including a
# comment-only mention), accepts it with it, then check the real workflows.
probe=$(mktemp -d)
trap 'rm -f "$err"; rm -rf "$probe"' EXIT
printf 'on:\n push:\n tags: ["v*"]\njobs:\n p:\n runs-on: ubuntu-latest\n steps:\n - run: cargo publish --dry-run\n' >"$probe/release.yml"
if "$root/.github/scripts/check-release-workflows.sh" "$probe" 2>/dev/null; then
echo "release-workflow guard accepted a workflow without this check" >&2
exit 1
fi
printf ' - run: .github/scripts/check-no-test-trusted-root.sh\n' >>"$probe/release.yml"
"$root/.github/scripts/check-release-workflows.sh" "$probe"
"$root/.github/scripts/check-release-workflows.sh"
guard="$root/.github/scripts/check-release-workflows.sh"
case_no=0
# expect_guard want(pass|fail) name < workflow
expect_guard() {
case_no=$((case_no + 1))
d="$probe/$case_no"
mkdir -p "$d"
cat >"$d/wf.yml"
if "$guard" "$d" 2>/dev/null; then got=pass; else got=fail; fi
if [ "$got" != "$1" ]; then
echo "release-workflow guard: $2: expected $1, got $got" >&2
exit 1
fi
}
steps='jobs:
p:
runs-on: ubuntu-latest
steps:
- run: echo build'
check=' - run: .github/scripts/check-no-test-trusted-root.sh'

expect_guard fail "push tags" <<X
on:
push:
tags: ["v*"]
$steps
X
expect_guard fail "flow list on: [push, release]" <<X
on: [push, release]
$steps
X
expect_guard fail "scalar on: release" <<X
on: release
$steps
X
expect_guard fail "map release trigger" <<X
on:
release:
types: [published]
$steps
X
expect_guard fail "reusable workflow_call that publishes" <<X
on:
workflow_call:
$steps
- run: cargo publish --dry-run
X
expect_guard fail "guard named only in comments" <<X
on: [release]
# - run: .github/scripts/check-no-test-trusted-root.sh
$steps
- run: echo skip # .github/scripts/check-no-test-trusted-root.sh
X
expect_guard fail "guard outside a run step" <<X
on: [release]
env:
NOTE: check-no-test-trusted-root.sh
$steps
X
expect_guard pass "release with guard on a run line" <<X
on: [release]
$steps
$check
X
expect_guard pass "workflow_call publish with guard in a run block" <<X
on:
workflow_call:
$steps
- run: |
set -e
.github/scripts/check-no-test-trusted-root.sh
cargo publish --dry-run
X
expect_guard pass "non-release workflow" <<X
on:
push:
branches: [main]
$steps
X
"$guard"
52 changes: 47 additions & 5 deletions .github/scripts/check-release-workflows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,60 @@
# Any workflow that can release, publish, or tag must run
# check-no-test-trusted-root.sh, so a release cannot ship the test-only
# trust-root switch. Usage: check-release-workflows.sh [workflows-dir]
#
# Comments are stripped before matching. A workflow counts as releasing
# when it has a `release`, `registry_package`, or `tags` trigger (map, flow
# list, or scalar `on:` form), or when it runs a publish, release, or tag
# command (this also covers reusable `workflow_call` workflows). The guard
# counts only on a `run:` line or inside a `run: |` / `run: >` block.
set -eu
root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
dir=${1:-"$root/.github/workflows"}

# Print the file with YAML/shell comments removed.
uncommented() {
sed -e 's/^[[:space:]]*#.*$//' -e 's/[[:space:]]#.*$//' "$1"
}

releases() {
uncommented "$1" | grep -E -q \
-e '^[[:space:]]*(release|registry_package|tags):' \
-e '^[[:space:]]*["'\'']?on["'\'']?:.*(^|[^A-Za-z0-9_-])(release|registry_package)([^A-Za-z0-9_-]|$)' \
-e 'cargo[[:space:]]+publish' \
-e 'gh[[:space:]]+release' \
-e 'softprops/action-gh-release' \
-e 'git[[:space:]]+push.*--tags' \
-e 'git[[:space:]]+tag[[:space:]]'
}

runs_guard() {
uncommented "$1" | awk '
{
line = $0
ind = match(line, /[^ ]/) - 1
if (inblk && line ~ /[^ \t]/ && ind <= blkind) inblk = 0
if (inblk) {
if (line ~ /check-no-test-trusted-root\.sh/) found = 1
next
}
if (line ~ /^[ \t]*(-[ \t]+)?run:/) {
if (line ~ /run:[ \t]*[|>][-+0-9]*[ \t]*$/) {
inblk = 1
blkind = ind
} else if (line ~ /check-no-test-trusted-root\.sh/) {
found = 1
}
}
}
END { exit found ? 0 : 1 }'
}

fail=0
for wf in "$dir"/*.yml "$dir"/*.yaml; do
[ -f "$wf" ] || continue
if grep -E -q '^[[:space:]]*(release|tags|registry_package):|cargo[[:space:]]+publish|gh[[:space:]]+release|softprops/action-gh-release|git[[:space:]]+push[^#]*--tags|git[[:space:]]+tag[[:space:]]' "$wf"; then
if ! grep -q 'check-no-test-trusted-root\.sh' "$wf"; then
echo "$wf: release/publish/tag workflow does not run check-no-test-trusted-root.sh" >&2
fail=1
fi
if releases "$wf" && ! runs_guard "$wf"; then
echo "$wf: release/publish/tag workflow does not run check-no-test-trusted-root.sh on a run: line" >&2
fail=1
fi
done
exit "$fail"
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versioning: se
- `geode run --home` refuses a path that is itself a symlink. The flag docs now say plainly that these checks are a usability guard, not a security boundary.
- CI fails if any release, publish, or tag workflow does not run `check-no-test-trusted-root.sh`.
- The interim custody argv lint compares path components and requires the pinned command to sit directly in `/usr/local/libexec/hedronite`.
- `geode-grotto` also refuses its `test-trusted-root` feature in any optimized build, matching the CLI guard.
- The release-workflow guard ignores comments, requires `check-no-test-trusted-root.sh` on a `run:` line or inside a run block, and detects release triggers in map, flow-list (`on: [release]`), and scalar (`on: release`) form.
- `cargo test -p geode-cli` with default features passes. The run tests that spawn a child with a secret need the test-only host override and are compiled only with `test-trusted-root`, which CI uses.
- Local `geode run` enforces `allow_hosts` for every secret binding on every platform, including macOS. The check is the custody allowlist (`AllowList`): a host that is not listed is `host_denied` and is not dialed. A secret binding with an empty or unusable `allow_hosts` is refused before spawn (non-zero exit). There is no environment variable, flag, or config key that disables the check. Pass hosts with repeatable `--allow-host`. macOS confines the child with a deny-by-default seatbelt: file and process access is limited to what the child needs to run, mach-lookup is a named allowlist with no network service, Apple events are denied, and network helper programs cannot be exec'd. LaunchServices, the preferences daemon, and the keychain service are not on that list. The seatbelt used when there is no egress proxy is deny-by-default as well and has no outbound network. Outbound network for a confined run is allowed only to the local egress proxy. The proxy listens on both loopback stacks, because the seatbelt loopback name covers both, and refuses to start if either bind fails. Each run puts a token in the proxy URL; a request without it is not dialed. A process that can read the child environment can present that token. A DNS answer in a loopback, private, link-local, multicast, benchmarking, reserved, NAT64, or other non-global range is not dialed unless the request host is an IP literal already on `allow_hosts`. Proxy denials are audit rows with outcome `host_denied`. Linux keeps the network namespace and the same proxy checks.
- The egress dial filter treats the local-use NAT64 prefix `64:ff9b:1::/48` as restricted, next to the well-known prefix `64:ff9b::/96`. A name that resolves into that range is not dialed unless the request host is an IP literal already on `allow_hosts`.

Expand Down
2 changes: 1 addition & 1 deletion crates/geode-cli/tests/p0_custody_home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ fn has_secret_bytes(text: &str) -> bool {
MARKERS.iter().any(|m| text.contains(m))
}

/// Every SPEC rule `text` breaks. Empty means the argv is valid.
/// The pinned command must be a file directly in the libexec dir. Compares
/// path components, not text. `Path::components` drops `//`, a trailing
/// `/`, and inner `.`, so the raw string is checked for those too.
Expand All @@ -87,6 +86,7 @@ fn pinned_cmd_path(path: &str) -> bool {
p.parent() == Some(Path::new(DIR)) && p.file_name().is_some_and(|n| !n.is_empty())
}

/// Every SPEC rule `text` breaks. Empty means the argv is valid.
fn broken_rules(text: &str) -> BTreeSet<&'static str> {
let mut bad = BTreeSet::new();
if text.contains('\0') {
Expand Down
27 changes: 27 additions & 0 deletions crates/geode-cli/tests/run_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
//! `test-trusted-root`). That feature is also what builds the helper, so
//! the helper tests are compiled only when it is on. A root-owned install
//! is `#[ignore]` and is not part of the default run.
//!
//! Tests that spawn a child with a secret need `--test-unconfined-hosts`,
//! which exists only with `test-trusted-root`, because a secret run with no
//! allowed hosts is refused before spawn. They are compiled only with that
//! feature, so a default-feature run stays green and still runs the no-host
//! refusal tests. CI runs this file with the feature.

use std::path::{Path, PathBuf};
use std::process::{Command, Output};
Expand Down Expand Up @@ -161,6 +167,7 @@ fn canonical_on_path(name: &str) -> String {
.to_owned()
}

#[cfg(feature = "test-trusted-root")]
fn on_path(name: &str) -> bool {
std::env::var_os("PATH")
.is_some_and(|p| std::env::split_paths(&p).any(|d| d.join(name).is_file()))
Expand Down Expand Up @@ -191,6 +198,7 @@ fn assert_no_dummy(o: &Output, what: &str) {
);
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn echo_base64_xxd_redact_and_row_is_local() {
let fx = Fx::new();
Expand Down Expand Up @@ -247,6 +255,7 @@ fn echo_base64_xxd_redact_and_row_is_local() {
);
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn child_env_is_built_from_scratch() {
let fx = Fx::new();
Expand All @@ -271,6 +280,7 @@ fn child_env_is_built_from_scratch() {
assert!(!env.contains("XDG_STATE_HOME"));
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn child_exit_3_is_spawned_and_passed_through() {
let fx = Fx::new();
Expand Down Expand Up @@ -300,6 +310,7 @@ fn child_exit_3_is_spawned_and_passed_through() {
assert_no_dummy(&j, "json");
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn timeout_terms_the_child() {
let fx = Fx::new();
Expand Down Expand Up @@ -429,6 +440,7 @@ fn local_allow_hosts_outcome_is_per_os() {
}
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn refusals_do_not_spawn() {
let fx = Fx::new();
Expand Down Expand Up @@ -497,6 +509,7 @@ fn refusals_do_not_spawn() {
assert!(!fx.marker().exists(), "a refused run spawned a child");
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn policy_deny_is_exit_3_and_does_not_spawn() {
let fx = Fx::new();
Expand Down Expand Up @@ -535,6 +548,7 @@ fn policy_deny_is_exit_3_and_does_not_spawn() {
assert_eq!((*custody, argv0.as_str(), *exit_code), (0, "", None));
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn needle_in_argv_is_argv_rejected_without_hashing_argv() {
let fx = Fx::new();
Expand Down Expand Up @@ -651,6 +665,7 @@ fn allow_cmd_must_be_canonical() {
}
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn audit_verify_good_then_tampered() {
let fx = Fx::new();
Expand Down Expand Up @@ -733,6 +748,7 @@ fn fix3_audit_failure_before_spawn_releases_nothing() {
assert_eq!(fx.rows().len(), before, "no row was written");
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn fix3_success_writes_one_intent_row_without_the_value() {
let fx = Fx::new();
Expand All @@ -757,6 +773,7 @@ fn fix3_success_writes_one_intent_row_without_the_value() {
assert_eq!(code(&v), Some(0), "{}", err(&v));
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn fix3_close_row_failure_is_non_zero_but_output_still_redacted() {
let fx = Fx::new();
Expand All @@ -773,6 +790,7 @@ fn fix3_close_row_failure_is_non_zero_but_output_still_redacted() {
assert_eq!(fx.rows().last().unwrap().0, "started", "intent row stays");
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn fix3_deny_path_writes_row_or_fails_closed() {
let fx = Fx::new();
Expand All @@ -795,6 +813,7 @@ fn fix3_deny_path_writes_row_or_fails_closed() {
assert!(!fx.marker().exists());
}

#[cfg(feature = "test-trusted-root")]
fn sha256_hex(path: &Path) -> String {
use sha2::{Digest, Sha256};
Sha256::digest(std::fs::read(path).expect("read pin target"))
Expand All @@ -805,6 +824,7 @@ fn sha256_hex(path: &Path) -> String {

/// Copy `src` to `dir/bin/name` as a 0755 file. The pin path is this absolute
/// path. A `#!` file cannot be pinned on Linux.
#[cfg(feature = "test-trusted-root")]
fn copy_exec(dir: &Path, name: &str, src: &Path) -> PathBuf {
use std::os::unix::fs::PermissionsExt;
let bin = dir.join("bin");
Expand All @@ -821,6 +841,7 @@ fn copy_exec(dir: &Path, name: &str, src: &Path) -> PathBuf {
dest
}

#[cfg(feature = "test-trusted-root")]
fn write_pins(dir: &Path, rules: &serde_json::Value) {
std::fs::write(dir.join("pins.json"), serde_json::to_vec(rules).unwrap()).unwrap();
}
Expand Down Expand Up @@ -1266,6 +1287,7 @@ fn pinned_user_tmp_writable_and_symlink_are_refused() {
let _ = std::fs::remove_dir_all(&base);
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn pinned_wrong_digest_refused() {
let fx = Fx::new();
Expand Down Expand Up @@ -1298,6 +1320,7 @@ fn pinned_wrong_digest_refused() {
assert_eq!(fx.rows().last().unwrap().0, "policy_deny");
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn unpinned_path_refused() {
let fx = Fx::new();
Expand Down Expand Up @@ -1328,6 +1351,7 @@ fn unpinned_path_refused() {
assert_eq!(fx.rows().last().unwrap().0, "policy_deny");
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn args_prefix_mismatch_refused() {
let fx = Fx::new();
Expand Down Expand Up @@ -1359,6 +1383,7 @@ fn args_prefix_mismatch_refused() {
assert!(!fx.marker().exists(), "args_prefix mismatch spawned");
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn relative_pin_refused() {
let fx = Fx::new();
Expand Down Expand Up @@ -1422,6 +1447,7 @@ fn relative_pin_refused() {
assert!(!fx.marker().exists());
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn symlink_swap_refused() {
use std::os::unix::fs::PermissionsExt;
Expand Down Expand Up @@ -1478,6 +1504,7 @@ fn symlink_swap_refused() {
assert!(!marker.exists(), "symlink swap spawned");
}

#[cfg(feature = "test-trusted-root")]
#[test]
fn require_pin_refuses_unpinned_rules_and_off_allows_them() {
let fx = Fx::new();
Expand Down
8 changes: 4 additions & 4 deletions crates/geode-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ path = "src/lib.rs"
default = []
# Test-only and insecure. Off unless a build asks for it. Exposes
# `plan_with_test_root`, which moves the pin trust root. The crate
# refuses to compile this feature only when debug assertions are off
# (`cargo build --release`, `cargo install`). A dev or test build can
# still enable it. That is not a release guarantee. Release builds of
# `geode` do not enable it.
# refuses to compile this feature when debug assertions are off
# (`cargo build --release`, `cargo install`) and, from build.rs, at any
# opt-level other than 0. A plain dev or test build can still enable it.
# Release builds of `geode` do not enable it.
test-trusted-root = []

[dependencies]
Expand Down
Loading
Loading