Skip to content

feat(scripts): classify agent sessions by personal email and licence context - #167

Merged
blitzcrieg1 merged 1 commit into
masterfrom
feat/identity-enrich-script
Sep 9, 2026
Merged

blitzcrieg1 merged 1 commit into
masterfrom
feat/identity-enrich-script

Conversation

@blitzcrieg1

Copy link
Copy Markdown
Owner

What it does

Reads Agentmetry JSONL and answers whether a session ran under a personal
identity or a work one. Two independent signals, kept separate because they
disagree in the cases worth seeing.

Field Values
email_category PERSONAL_EMAIL / DISPOSABLE_EMAIL / OTHER_EMAIL / NO_EMAIL_FOUND
license_context CORPORATE_APPROVED / OTHER_ORG_SHADOW / LIKELY_PERSONAL_NO_ORG

A work address in an unapproved tenant is shadow IT. A personal address in the
approved tenant is usually a local install nobody configured. One combined
verdict loses that.

Stdlib only, no new dependency. Tails a directory, survives rotation, keeps a
cursor so a restart does not replay the file into the SIEM.

Three decisions worth reviewing

Enrichment never touches event or trail. The trail is chained,
record_sha256 = sha256(prev + canonical_event_json(event))
(trail_chain.py:176),
so a field added inside event invalidates that record and every record after
it. A pipeline that labels sessions while silently voiding agentmetry verify
is worse than no pipeline. Verdicts go in a sibling enrichment object and are
mirrored at top level so a SIEM maps two flat fields.
test_enrichment_leaves_the_chained_event_untouched asserts byte-equality
before and after.

No corporate domain list. Only consumer providers are named; everything
else is OTHER_EMAIL. An allowlist has to be complete to be safe, and a missed
acquisition or contractor domain reads as untrusted, so the list decays into
noise and then into being ignored. This way an unclassified domain reads as an
honest "not sure", and no employer's domain is hardcoded in a public repo.
Fixtures use work.example, reserved by RFC 6761.

Domain matching parses the domain. "gmail.com" in identifier classifies
[email protected] as personal, handing the classification
to whoever picks the domain. Exact or subdomain only:

Identifier Verdict
[email protected] PERSONAL_EMAIL
[email protected] OTHER_EMAIL
[email protected] OTHER_EMAIL

PII

The address is never printed and never added as a field. Stored: the domain,
plus a salted SHA-256 of the address folded for dots and +tags so one Gmail
account correlates as one person. Unsalted, that hash is a dictionary lookup
away from the address, so the script warns when no salt is set.
test_no_raw_address_reaches_the_output asserts no @ survives into the
enrichment object.

A note for whoever configures this

The canonical event has no user.id and no organization.id. Those are
built by the ECS adapter, which sets user.id from actor.id and
organization.id from fleet_id (ecs.py:130 and
ecs.py:172
).
fleet_id is operator-set, not an upstream tenant id, so an org allowlist only
means something if the fleet id is provisioned to match. Field paths are
ordered to work on both the canonical and the ECS shape, and all of them are
configurable.

Checks

42 tests in the new module, 1,240 in the suite, ruff clean. Nothing frozen is
touched and the fingerprint is unchanged at 15846a0915769d4a, so the dogfood
clock is unaffected.

…context

Answers whether an agent session ran under a personal identity or a work one.
Two independent signals, kept separate because they disagree in the cases worth
seeing: a work address in an unapproved tenant is shadow IT, a personal address
in the approved tenant is usually a local install nobody configured.

  email_category   PERSONAL_EMAIL / DISPOSABLE_EMAIL / OTHER_EMAIL / NO_EMAIL_FOUND
  license_context  CORPORATE_APPROVED / OTHER_ORG_SHADOW / LIKELY_PERSONAL_NO_ORG

Three decisions worth stating, because each is a place the obvious version is
wrong.

Enrichment never touches `event` or `trail`. The trail is chained,
`record_sha256 = sha256(prev + canonical_event_json(event))`, so a field added
inside `event` invalidates that record and every record after it. A pipeline
that labels sessions while silently voiding `agentmetry verify` is worse than
no pipeline. The verdicts go in a sibling `enrichment` object and are mirrored
at top level so a SIEM maps two flat fields.

There is no corporate domain list. Only consumer providers are named and
everything else falls to `OTHER_EMAIL`. An allowlist has to be complete to be
safe: miss an acquisition, a contractor or a regional office and their traffic
reads as untrusted, so the list decays into noise and then into being ignored.
Naming only the consumer providers means an unclassified domain reads as an
honest "not sure" rather than an accusation, and no employer's domain is
hardcoded in a public repository.

Domain matching parses the domain rather than testing a substring.
`"gmail.com" in identifier` classifies `[email protected]`
as personal, which hands the classification to whoever picks the domain. Exact
or subdomain only, with the near misses pinned in tests.

PII: the address is never printed and never added as a field. Stored instead is
the domain, which is what you query on, plus a salted SHA-256 of the address
folded for dots and +tags so one Gmail account correlates as one person.
Unsalted, that hash is a dictionary lookup away from the address, so the script
warns when no salt is set.

42 tests. Stdlib only, no new dependency.

Co-Authored-By: Claude Opus 5 <[email protected]>
@blitzcrieg1
blitzcrieg1 merged commit 519afe5 into master Sep 9, 2026
9 checks passed
@blitzcrieg1
blitzcrieg1 deleted the feat/identity-enrich-script branch September 9, 2026 12:39
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant