Skip to content

test(obs): the PII boundary on spans, enforced rather than documented (telemetry P14) - #454

Merged
athvin merged 1 commit into
mainfrom
bm/telemetry-p14-pii-span-gates
Nov 3, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/telemetry-p14-pii-span-gates

Conversation

@athvin

@athvin athvin commented Nov 3, 2026

Copy link
Copy Markdown
Owner

This is a deduplication engine, so names, emails, phones and addresses are the payload, and §10.4's rule is that telemetry carries identifiers and counts and never attribute values. #429 made that boundary matter more: spans now leave the process over OTLP, so it is an exportable store rather than in-account Postgres.

The real guarantee is structural and already shipped — er_span::sql_span takes no parameter argument, so there is nowhere to put a bind value. These are the shape gates around it, because that property only holds while the call stays where it is.

Gate What it asserts
only_generated_code_calls_sql_span all 244 call sites are in @generated files; product code must use generator_span, which has no sql parameter at all
every_emitted_sql_span_argument_is_a_literal every argument is a string literal, SQL, or a Store discriminant — never a runtime value
forbidden_attribute_names_are_never_recorded the names er-span declares Pii::Never appear nowhere in code

er-span and er-sql-check/src/emit.rs are allowlisted with reasons — the latter writes those calls as string literals rather than making them.

Each test also asserts a floor on what it examined (>60 files, >20 generated callers, >200 statements), so a moved crate tree fails here rather than passing having looked at nothing — the false-green shape this repo keeps being bitten by.

The forbidden list is read out of er-span/src/attr.rs rather than restated. A hardcoded copy is how a registry and its enforcement drift apart, which er-entity-lint's own header records as how three documented codes ended up never implemented.

Two things the gate taught me while being written

Its first version failed on er-server/src/telemetry.rs — whose comment says url.query is deliberately not recorded. A file explaining the rule was being reported as breaking it. Writing down why an attribute is forbidden is exactly the behaviour to encourage, so prose is now exempt and only code counts.

The comment stripper's limitation runs the unsafe way, so it says so. It does not understand string literals, so a // inside one strips the rest of that line and a forbidden name after it on the same line would be missed — a false negative, not a false positive. Accepted because the structural guarantee does not depend on this scan at all; if that ever stops being true, this wants to become a real lint rather than a slightly better regex.

What this deliberately does not do

The plan's "declared statements are literal-free" check is not here, and the reason is worth recording rather than leaving as a silent omission:

  • It cannot be built on a regex. I proved mine wrong — it pairs quotes across comments and '' escapes, reporting the text between two literals as a literal.
  • E010 already validates literals against accepted-values (enum) columns, so the genuinely uncovered risk is a literal against a payload column like email.
  • Distinguishing that needs a PII classification on entity columns, which does not exist yet. That is an entity-spec field plus a lint rule, not a test, and the plan under-estimated it.

Verification

Both gates observed failing on injected violations before being trusted — a sql_span call added to product code, and a url.query const — then restored green. make check passes.

🤖 Generated with Claude Code

… (P14)

This is a deduplication engine, so names, emails, phones and addresses ARE the
payload, and §10.4's rule is that telemetry carries identifiers and counts and
never attribute values. #429 made that boundary matter more: spans now leave
the process over OTLP, so it is an exportable store rather than in-account
Postgres.

The real guarantee is structural and already shipped — `er_span::sql_span`
takes no parameter argument, so there is nowhere to put a bind value. These are
the shape gates around it, because that property only holds while the call
stays where it is:

1. only GENERATED code may call `sql_span` (244 sites, all in er-entities);
   product code calls `generator_span`, which has no `sql` parameter at all.
   `er-span` and `er-sql-check/src/emit.rs` are allowlisted with reasons — the
   latter WRITES those calls as string literals rather than making them.
2. every emitted `sql_span` argument is a string literal, `SQL`, or a `Store`
   discriminant, so none can carry a runtime value.
3. the names `er-span` declares `Pii::Never` appear nowhere in code.

Each test also asserts a floor on what it examined (>60 files, >20 generated
callers, >200 statements), so a moved crate tree fails here rather than passing
having looked at nothing — the false-green shape this repo keeps being bitten
by.

The forbidden list is READ OUT of er-span/src/attr.rs rather than restated. A
hardcoded copy is how a registry and its enforcement drift apart, which
er-entity-lint's own header records as how three documented codes ended up
never implemented.

## Two things the gate taught me while being written

Its first version failed on `er-server/src/telemetry.rs` — whose comment says
`url.query` is deliberately NOT recorded. A file explaining the rule was being
reported as breaking it. Writing down why an attribute is forbidden is exactly
the behaviour to encourage, so prose is now exempt and only code counts.

And the comment stripper's limitation runs the UNSAFE way, so it says so: it
does not understand string literals, so a `//` inside one strips the rest of
that line and a forbidden name after it would be MISSED. A false negative, not
a false positive. Accepted because the structural guarantee does not depend on
this scan; if it ever does, this wants to be a real lint.

Both gates observed failing on injected violations before being trusted.
`make check` passes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit 1f2a6ba into main Nov 3, 2026
34 checks passed
@athvin
athvin deleted the bm/telemetry-p14-pii-span-gates branch November 3, 2026 06:58
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