Skip to content
Closed
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
2 changes: 1 addition & 1 deletion docs/incidents.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pipeline still calls it there.
| bn. `bn_infra_list_follows_aws` | Security, Infrastructure kept ten rows while AWS had moved on: an RDS instance deleted two days before still showed two pending actions, a Lambda function on a retired runtime came from a Terraform module nothing called, five rows already fixed kept their Runbook and Fix PR buttons, an older CVE row and the engine patch to the same version stood as two rows, and a serverless platform update and an operating system update on each instance AWS listed never appeared. The read kept every resource for three days and the match took them all as running. | Each read says which kinds it saw in full; what a full read no longer lists is dropped and its findings close as removed, with the time; a failed or partial read drops and closes nothing. The same move on one database is one item. Every pending action is an item, applied by CoderHelm after one approval when it has no code change, and a version change on a resource in code is a pull request whichever source raised it. Closed items offer nothing to do. Opening the page refreshes a read older than five minutes, at most once per team in that time. |
| bp. `bp_repo_traced_not_asked` | A secrets finding on a production API's log group posted "Which repo should this fix go to?" with the right repo as its best guess, two others as "also possible", no fix started, and "there is no direct AWS pointer" as its reason. The task definition's image came from an ECR repository named for the app plus its environment word, tagged with the app's name and the commit it was built from, and pushed by the app repo's workflow; none of it counted, and the hedged answer was cached for a week. | The repo is traced (`common::log_repo`): the running image's commit is looked up in every repo's history, a workflow or build file that ships the image counts as shipping it while Terraform that only defines it is context, image repository and tag names count without their environment word, and the classes and text of the error's own lines are looked for in the code. Evidence for one repo starts the fix there, saves the repo and says why in one line; split evidence still starts on the best guess with one card offering "Wrong repo? Move it"; only a log group nothing ties to any repo asks. An older resolver's or an unsure answer is not served from the cache for long. |
| bq. `bq_upstream_read_not_guessed` | A card said "1 new log finding: Seen again: Request failed with 503 in AUTH GUARD" for two lines of an error the API logs most days, with "the evidence does not show which upstream service returned the 503", an AWS account id line and a generic link; nothing had read the guard's code, which names the service it calls, and each analysis sent every line of a burst to the model. | A sighting is judged against its own week first (`common::log_triage`, the analyzer's same cases): at its usual rate it is counted with no card and no fix, rising is act, new or back after a quiet week is said once. A failed call's code is read: the card names the upstream (host and setting), its timeout and retries, the lines, tasks and the week's rate, with the decision on the first line and no account id. A burst is one entry before any model call, known errors are counted without the model, and an hourly budget caps analyses. |
| br. `br_description_writer_upgrade` | After the description writer was upgraded (a final review in the one save, the repository's template as the structure), a pull request opened the day before kept its old text: six checks "Not run: still running when this was written", the file to read first and the way back said twice, filler and a raw page id. Its head had not moved and its checked text was unchanged, so its stamp said current and nothing rebuilt it. | The stamp names the writer version (`description::WRITER`, raised with every change to what a description says or how it is laid out); a description built by another writer, or before the version, is not current. The pull request watch's sweep catches up open pull requests CoderHelm opened, whatever the age of their run: a few per team each sweep (`pr_watch::CATCH_UP_PER_TEAM`), inside its GitHub budget, each rebuilt once and marked on its run. A description still wholly CoderHelm's is built again from the facts of the head alone: nothing of the old text is kept, not even in a fold, except a line that closes an issue. A description with no CoderHelm stamp, or whose checked text a person changed, is left as it is. |
| br. `br_description_writer_upgrade` | After the description writer was upgraded (a final review in the one save, the repository's template as the structure), a pull request opened the day before kept its old text: six checks "Not run: still running when this was written", the file to read first and the way back said twice, filler and a raw page id. Its head had not moved and its checked text was unchanged, so its stamp said current and nothing rebuilt it. | The stamp names the writer version (`description::WRITER`, raised with every change to what a description says or how it is laid out); a description built by another writer, or before the version, is not current. The pull request watch's sweep catches up open pull requests CoderHelm opened, whatever the age of their run: a few per team each sweep (`pr_watch::CATCH_UP_PER_TEAM`), inside its GitHub budget, each rebuilt once and marked on its run. A description still wholly CoderHelm's is built again from the facts of the head alone: nothing of the old text is kept, not even in a fold, except a line that closes an issue. A security fix's pull request gets the same: its sections are computed from the lockfile on the head and nothing else of its old body is kept (`security_fixes::fresh_body`). A description with no CoderHelm stamp, or whose checked text a person changed, is left as it is. |

## Adding a case

Expand Down
1 change: 1 addition & 0 deletions services/worker/src/passes/description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ async fn build(
number,
ticket_id,
&pr,
fresh,
)
.await
} else {
Expand Down
153 changes: 153 additions & 0 deletions services/worker/src/passes/incidents/br_description_writer_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,156 @@ fn the_watch_sweep_catches_up_a_few_per_team() {
// No age window: an old run's open pull request is reached too.
assert!(!all.contains(":cut"));
}

/// A security fix's pull request from before the upgrade: its old body has
/// no lead or reviewer-block markers and its check rows froze as running.
/// Its sections are computed from the lockfile on the head
/// (`security_fixes::at_head`), which in an ordinary rebuild keeps the rest
/// of the body. In the catch-up, wholly CoderHelm's, it is built from the
/// sections computed now and the facts alone: no old line survives, and
/// the line that closes its issue is kept.
#[test]
fn an_old_security_description_keeps_no_old_line() {
use crate::passes::security_fixes;
use common::dep_head::{self, LockAt};
use common::security_fixes::{self as sec, Advisory, Bump, Finding, FindingState, FixUnit};

let unit = FixUnit {
repo: format!("{OWNER}/{REPO}"),
ecosystem: "npm".into(),
bundle: true,
bumps: vec![Bump {
package: "xml-kit".into(),
from: "1.4.4".into(),
to: "1.4.9".into(),
major: false,
manifest: "pnpm-lock.yaml".into(),
}],
..Default::default()
};
let finding = Finding {
id: "f-1".into(),
package: "xml-kit".into(),
version: "1.4.4".into(),
fixed_version: Some("1.4.9".into()),
manifest: "pnpm-lock.yaml".into(),
advisory: Advisory {
primary: "GHSA-xxxx-0011".into(),
ids: vec!["GHSA-xxxx-0011".into()],
..Default::default()
},
..Default::default()
};
let state = FindingState::default();
let copies = |v: &str| Some(vec![("xml-kit".to_string(), v.to_string())]);
let head = dep_head::resolve(
&unit,
HEAD,
&[LockAt {
path: "pnpm-lock.yaml".into(),
base: copies("1.4.4"),
head: copies("1.4.9"),
why: String::new(),
}],
);
let check = common::upgrade_notes::WhatToCheck::default();
let pairs = [(&finding, &state)];

let old_body = format!(
"{marker}
Bumps xml-kit to fix GHSA-xxxx-0011.

**For the reviewer**
* **Look first:** `pnpm-lock.yaml`, the only change.
* **Roll back:** revert this pull request; nothing outside the code changes with it.

**Rollback:** Revert this pull request; nothing outside the code changes with it.

### Verification

| Check | Result |
|---|---|
| Lint (CI) | Not run: still running when this was written |
| Unit tests (CI) | Not run: still running when this was written |
| Audit (CI) | Not run: still running when this was written |

Fixes #34
",
marker = sec::MARKER
);
assert!(!old_body.contains("<!-- coderhelm:lead -->"));
let old = stamped_before(&old_body);
assert_eq!(description::catch_up(&old, HEAD), CatchUp::Rebuild);

// What `at_head` gives the build in the catch-up: the sections computed
// now, and only the closing line of the old body.
let computed = sec::pr_body_at_head(
&unit,
&pairs,
"Bumped.",
&check,
&sec::BodyLinks::default(),
&head,
);
// Before: the ordinary rebuild keeps the rest of the old body.
let kept = security_fixes::rebuilt_body(&description::flat(&old), &computed);
assert!(kept.contains("Look first") && kept.contains("still running when this was written"));
let base = security_fixes::fresh_body(&computed, &description::flat(&old));
let dependency = common::pr_dependency::facts(&unit, &pairs, &head, &check);
let files = vec![(
"pnpm-lock.yaml".to_string(),
"modified".to_string(),
"@@ -1 +1 @@\n-a\n+b\n".to_string(),
)];
let floor = pr_risk::floor(&files, &std::collections::HashMap::new());
let checks: Vec<Check> = ["Lint", "Unit tests"]
.iter()
.map(|n| Check {
name: n.to_string(),
url: format!("https://ci.example.com/{}", n.replace(' ', "-")),
state: State::Passed,
})
.collect();
let facts = description_facts::facts(&Inputs {
head: HEAD,
body: &base,
files: &files,
floor: &floor,
checks: Some(&checks),
why: None,
dependency: Some(dependency),
outside: None,
run_url: "",
notes: vec![],
evidence: vec![],
repo_url: "https://github.com/acme/site",
});
let shaped = description_facts::shape_for(&base, "Fix GHSA-xxxx-0011", facts, None, None);
let next = description::with_stamp(&shaped.body, HEAD);
let reviewed = common::pr_review::review(&description::clean(&next));
let new = common::pr_layout::layout(&common::person_gate::sink(&reviewed.body).text);

for line in [
"still running when this was written",
"Look first",
"Roll back",
"For the reviewer",
"| Audit (CI)",
] {
assert!(!new.contains(line), "{line:?} is still in: {new}");
}
assert!(new.contains("xml-kit"), "the computed sections: {new}");
assert!(new.contains("Fixes #34"), "the issue still closes: {new}");
assert!(description::is_current(&new, HEAD), "{new}");
assert_eq!(description::catch_up(&new, HEAD), CatchUp::Current);

// The build passes the catch-up on to the security sections.
let src = include_str!("../description.rs");
let build = fn_src(src, "\nasync fn build(");
let at = &build[build.find("security_fixes::at_head(").unwrap()..];
assert!(at[..at.find(".await").unwrap()].contains("fresh,"), "{at}");
let sec_src = include_str!("../security_fixes.rs");
let at_head = fn_src(sec_src, "\npub(crate) async fn at_head(");
assert!(at_head.contains("if fresh_only {"));
assert!(at_head.contains("fresh_body(&fresh, body)"));
}
26 changes: 25 additions & 1 deletion services/worker/src/passes/security_fixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4649,7 +4649,10 @@ async fn refresh_ci_sections(cx: &Ctx<'_>, repo: &str, number: u64, ticket: &str
/// the base branch), "What to check" and Proof (where CI stands on this
/// head). The rest (the draft status at its top, the run's words) stays.
/// `None` for a pull request that is not a dependency fix's. Saved by
/// `description::reconcile`, the only caller.
/// `description::reconcile`, the only caller. `fresh`: the catch-up after
/// an upgrade, on a description wholly CoderHelm's: nothing of the old
/// body is kept but the lines that close an issue ([`fresh_body`]).
#[allow(clippy::too_many_arguments)]
pub(crate) async fn at_head(
state: &WorkerState,
gh: &GitHubClient,
Expand All @@ -4658,6 +4661,7 @@ pub(crate) async fn at_head(
number: u64,
ticket: &str,
pr: &Value,
fresh_only: bool,
) -> Option<(String, common::pr_facts::DependencyFacts)> {
let unit = load_unit(state, team_id, ticket).await?;
if unit.ecosystem == common::infra_vuln::records::UNIT_ECOSYSTEM {
Expand Down Expand Up @@ -4701,9 +4705,29 @@ pub(crate) async fn at_head(
// The same lockfile read, as facts: what the lead and the fact check of
// the description are written from.
let facts = common::pr_dependency::facts(&unit, &pairs, &head, &check);
if fresh_only {
return Some((fresh_body(&fresh, body), facts));
}
Some((rebuilt_body(body, &fresh), facts))
}

/// A security pull request's description built again from its head alone
/// (the catch-up after an upgrade, `description::catch_up_run`): the
/// sections computed now, and of the old body only the lines that close an
/// issue (`description::fresh_base`). No earlier writer's line (a frozen
/// check row, a reviewer block, a lead without markers) is carried over.
pub(crate) fn fresh_body(fresh: &str, old: &str) -> String {
let closing = crate::passes::description::fresh_base(old);
let closing: Vec<&str> = closing
.lines()
.filter(|l| !fresh.contains(l.trim()))
.collect();
if closing.is_empty() {
return fresh.to_string();
}
format!("{}\n\n{}", fresh.trim_end(), closing.join("\n"))
}

/// `body` with the sections computed from the head taken from `fresh`.
/// Every section CoderHelm owns elsewhere (the draft status, review fixes,
/// the settled items, CI notes, the reviewer guide, open items and the
Expand Down
Loading