Repository navigation
feat(scripts): classify agent sessions by personal email and licence context - #167
Merged
Merged
Conversation
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
email_categoryPERSONAL_EMAIL/DISPOSABLE_EMAIL/OTHER_EMAIL/NO_EMAIL_FOUNDlicense_contextCORPORATE_APPROVED/OTHER_ORG_SHADOW/LIKELY_PERSONAL_NO_ORGA 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
eventortrail. The trail is chained,record_sha256 = sha256(prev + canonical_event_json(event))(
trail_chain.py:176),so a field added inside
eventinvalidates that record and every record afterit. A pipeline that labels sessions while silently voiding
agentmetry verifyis worse than no pipeline. Verdicts go in a sibling
enrichmentobject and aremirrored at top level so a SIEM maps two flat fields.
test_enrichment_leaves_the_chained_event_untouchedasserts byte-equalitybefore 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 missedacquisition 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 identifierclassifies[email protected]as personal, handing the classificationto whoever picks the domain. Exact or subdomain only:
[email protected]PERSONAL_EMAIL[email protected]OTHER_EMAIL[email protected]OTHER_EMAILPII
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
+tagsso one Gmailaccount 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_outputasserts no@survives into theenrichment object.
A note for whoever configures this
The canonical event has no
user.idand noorganization.id. Those arebuilt by the ECS adapter, which sets
user.idfromactor.idandorganization.idfromfleet_id(ecs.py:130andecs.py:172).fleet_idis operator-set, not an upstream tenant id, so an org allowlist onlymeans 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 dogfoodclock is unaffected.