> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenetlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rehydration and audit

> Who can re-identify and how it's enforced: per-caller IAM through VPC Lattice, per-route auth policies, the approval tag, KMS isolation, and audit before plaintext — plus the reidentify v3 and erasure v1 record schemas.

**Rehydration** is the only path that returns stored plaintext. It runs as its own service (`TENET_ROLE=rehydrate`) behind its own VPC Lattice service, mounts only `POST /reidentify`, admits only the IAM roles you name, and writes one immutable audit record per call **before** it answers. If the record can't be written, the call fails with `503` and restores nothing.

## When to use it

Deploy rehydration when a person or system downstream needs the original values back — a reviewer reading a model's summary with the real names in it. If nothing ever needs the originals, turn it off (`rehydration.enabled=false`, `EnableRehydration=false`, `enable_rehydration = false`): no rehydrate service, role or Lattice service is created, and detection and de-identification work fully. The audit bucket stays, because the detect service audits erasures.

## Layers a caller must clear

Every caller signs each request (SigV4, service `vpc-lattice-svcs`) as its own IAM role. There's no shared secret to leak, rotate or inject. Any one layer stops a request.

1. **Identity, per request.** Lattice verifies the signature. A same-account caller needs `vpc-lattice-svcs:Invoke` in its own IAM policy (the `RehydrateCallerPolicy` / `rehydrate_caller_policy` output) **and** in the service's auth policy — either alone is denied.
2. **Auth policy, per route and method.** The rehydrate service allows `POST /reidentify` only to `RehydrateInvokerRoleArns` (`rehydrate_invoker_role_arns`, `lattice.rehydrateInvokerRoleArns`) plus the [break-glass](https://docs.tenetlabs.com/pii-engine/operate/break-glass.md) role, only from `AllowedSourceVpcIds`, and — with the approval tag required — only from a role session tagged `tenet-approval-id`. The tag is checked on **every** call. The listener forwards only that exact route; anything else is a Lattice `404`.
3. **Network.** Tasks and pods admit port 19991 only from the `com.amazonaws.<region>.vpc-lattice` prefix list (security groups on ECS, a NetworkPolicy `ipBlock` on EKS). A direct call to a task IP doesn't connect.
4. **App-side re-check.** The service checks every request again and refuses with a fixed `403 {"detail": "forbidden"}` if the peer isn't a Lattice address, the Lattice identity headers aren't present exactly once, the request targets another Lattice service, the raw path isn't canonical, or the principal's role isn't on its own allow-list (`TENET_LATTICE_REIDENTIFY_PRINCIPALS`, set from the invoker list). Lattice strips any copy of those headers a client sends. The reason is logged at `WARNING`: `refused POST on route reidentify: <principal> is not allowed to call reidentify`.
5. **Route isolation.** The detect service doesn't mount `/reidentify` at all; the rehydrate service mounts nothing else.
6. **KMS.** Only the rehydrate role can unwrap a vault key pair's private key, so only it can decrypt a stored value. The key policy and the detect role's own policy deny detect that decrypt. [Architecture — KMS design](https://docs.tenetlabs.com/pii-engine/concepts/architecture.md#kms-design).
7. **Audit before plaintext.** The record is written synchronously after authorization and before the response. Write fails → `503 {"detail": "reidentify audit failed; nothing was restored"}`.

Allow-list entries are IAM **role** ARNs (`arn:aws:iam::<account-id>:role/[<path>/]<name>`). Each matches every session of that role. Users, the root user and wildcards are refused at startup.

## Approval workflow

With `RequireRehydrateApprovalTag=true` (`require_rehydrate_approval_tag`, `lattice.requireApprovalTag`):

1. On approval, your workflow assumes the invoker role with `sts:TagSession`, setting the session tag `tenet-approval-id=<ticket>`. Make the invoker role's trust policy require `aws:RequestTag/tenet-approval-id`.
2. It also sets `RoleSessionName=<ticket>`. Lattice access logs record principal tags only on **denied** requests, so the session name — part of the caller ARN in every audit record — is what ties a successful rehydration to its approval.
3. An approval lasts as long as that session: rehydration stops when the tagged session expires.

## Erasure

`DELETE /sessions/{session_id}` on the detect service is its own permission: the detect auth policy allows it only to `ErasureInvokerRoleArns` (`erasure_invoker_role_arns`, `lattice.erasureInvokerRoleArns`), and the service re-checks the same list (`TENET_LATTICE_ERASE_PRINCIPALS`). An empty list means nobody can erase; sessions just expire. Every erasure that passes auth writes a `tenet.erasure-audit.v1` record **before** anything is deleted. If it can't, the call returns `503 {"detail": "erase audit failed; nothing was deleted"}` and the session survives. Otherwise the response is `204`, whether the session existed or not.

## The audit records

Rehydrate writes one `tenet.reidentify-audit.v3` record per `/reidentify` call that passes auth — `200`, `404` and `400` alike. Detect writes one `tenet.erasure-audit.v1` record per erasure. A `403` is never audited: it never reached the handler. Look for refusals in the service log and the Lattice access log.

```json theme={null}
{"schema": "tenet.reidentify-audit.v3", "auth_mode": "lattice-iam", "request_id": "5f0c…(32 hex)",
 "session_ref": "9b1d4c0e…(32 hex)", "caller": "arn:aws:sts::<account-id>:assumed-role/claims-reviewer/CHG-1042",
 "caller_account": "<account-id>", "caller_org_id": null,
 "source_vpc": "arn:aws:ec2:us-east-1:<account-id>:vpc/vpc-0123…", "upstream_request_id": "<uuid>",
 "outcome": "restored", "placeholders_requested": 2, "restored": 2, "unresolved": 0,
 "timestamp_utc": "2026-11-06T12:34:56.789Z", "engine_version": "<engine version>"}
```

| Field | reidentify v3 | erasure v1 | Meaning |
| - | - | - | - |
| `schema` | ✓ | ✓ | `tenet.reidentify-audit.v3` or `tenet.erasure-audit.v1` |
| `request_id` | ✓ | ✓ | Server-generated, 32 hex characters. Returned as the `X-Request-ID` response header — join on it. |
| `session_ref` | ✓ | ✓ | HMAC of the session id under the vault's current lookup key, 32 lowercase hex characters. Equal refs = same session. **Never the raw `session_id`**, which with an admitted role would re-identify until expiry. `"<malformed>"` only with `outcome: "malformed_session"`. |
| `caller` | ✓ | ✓ | The caller's IAM principal ARN — for a role, the role session ARN (`…:assumed-role/<role>/<session name>`). |
| `auth_mode` | ✓ | ✓ | Always `lattice-iam`. |
| `caller_account` | ✓ | ✓ | The caller's 12-digit account id, or `null`. |
| `caller_org_id` | ✓ | ✓ | The caller's AWS Organizations id (`o-…`), or `null`. |
| `source_vpc` | ✓ | ✓ | ARN of the VPC the request came from, or `null`. |
| `upstream_request_id` | ✓ | ✓ | The Lattice request id. Joins the record to the Lattice access log. Correlation only — never trusted for security. `null` if absent. |
| `outcome` | ✓ | ✓ | reidentify: `restored` · `partial` (some restored, some unresolved) · `none_resolved` (a `200` that restored nothing, including text with no placeholders) · `unknown_session` (`404`) · `malformed_session` (`400`). erasure: `erased` · `unknown_session` · `malformed_session` (all `204` to the client). |
| `placeholders_requested` | ✓ | — | Placeholder-shaped strings in the request text, counting repeats. |
| `restored`, `unresolved` | ✓ | — | Integers. On a `200`, `restored + unresolved == placeholders_requested`. |
| `timestamp_utc` | ✓ | ✓ | ISO 8601, UTC, millisecond precision. |
| `engine_version` | ✓ | ✓ | Version of the detection engine that served the call. It isn't the product release number. |

The schema is an allowlist: exactly these fields, each checked against a narrow pattern. A record with any other field — including a raw `session_id` — or a malformed value is rejected, which fails the request closed with `503`. No value, placeholder or document text ever appears in a record.

**Where they go.** Each service writes the S3 object first, then the same JSON as one line on stdout (→ your log pipeline). The first failure fails the request. Rehydrate writes under `AuditPrefix` (default `rehydrate/`), detect under `ErasureAuditPrefix` (default `erasure/`) — Helm `rehydration.auditS3Uri` and `lattice.erasureAuditS3Uri`. S3 key:

```text theme={null}
<prefix>year=YYYY/month=MM/day=DD/hour=HH/<YYYYMMDDTHHMMSS.mmmZ>_<request_id>.json
```

Objects are written with a SHA-256 checksum, as Object Lock requires.

**Who's in it.** Caller ARNs are workforce identifiers: an SSO role session name is often an email address. Tell your people they're in the audit trail, and prefer `sts:SourceIdentity` for human callers.

## Joining with the Lattice access log

The templates send both services' Lattice access logs to `/<NamePrefix>/lattice` (Helm: `lattice.accessLogDestinationArn`). They record every request, including refusals, with the caller principal and source VPC. `requestId` there equals `upstream_request_id` in the audit record.

## Startup checks

Both services refuse to start unless:

* `TENET_AUDIT_S3_URI` is set and looks like `s3://bucket/prefix/` — `the rehydrate role requires an audit sink: set TENET_AUDIT_S3_URI` (or `the detect role …`).
* `GetObjectLockConfiguration` on the bucket succeeds and shows Object Lock `Enabled`. A bucket without a default retention rule is accepted with a `WARNING` — objects aren't retention-locked unless one is set.

The rehydrate service also refuses if its allow-list is empty, and if the vault keyring has no key yet: it never creates keys, so start the detect service first.

## Reading the trail

```bash theme={null}
# Every call for one session, in order (session_ref from any one record)
aws s3api list-objects-v2 --bucket "$AUDIT_BUCKET" --prefix "rehydrate/year=2026/month=11/" \
  --query 'Contents[].Key' --output text | tr '\t' '\n' \
  | while read -r k; do aws s3 cp "s3://$AUDIT_BUCKET/$k" -; done \
  | jq -c 'select(.session_ref == "9b1d4c0e…")'
```

For volume, query the bucket with Athena using the `year=/month=/day=/hour=` partitions, or ingest the stdout lines from CloudWatch Logs into your SIEM.

Verify a deployment's rehydration controls and audit trail end to end — read-only plus a few signed test calls.

Verify the rehydration controls of my Tenet PII Engine (Enterprise) deployment, following [https://docs.tenetlabs.com/pii-engine/concepts/rehydration-and-audit](https://docs.tenetlabs.com/pii-engine/concepts/rehydration-and-audit.md). Do not change any configuration.

Ask me for: platform (ECS stack name, or EKS namespace and release), Region, the detect and rehydrate endpoints, the audit bucket and its rehydrate and erasure prefixes, and two places I can run signed test calls from inside an allowed VPC: one running as a role in the rehydrate invoker list (with its caller identity policy) and one running as a role that is NOT. Ask whether the approval tag is required; if it is, ask how my workflow assumes the invoker role with the tenet-approval-id session tag. Use the `tenet-pii-lattice` CLI (`python -m tenet_pii_lattice <endpoint> <operation>`).

Check and report pass/fail:

1. `aws s3api get-object-lock-configuration --bucket <bucket>` shows ObjectLockEnabled=Enabled with a DefaultRetention rule; report mode and days.
2. The rehydrate auth policy names only the expected roles and conditions: ECS `aws vpc-lattice get-auth-policy --resource-identifier <rehydrate service ARN>`; EKS `kubectl get iamauthpolicy -o yaml`. Report the principals, the method/path and source-VPC conditions, and whether `aws:PrincipalTag/tenet-approval-id` is required.
3. From the allowed role: `echo "hello [FIRST_NAME_1]" | ... reidentify 00000000000000000000aa` (a well-formed id that doesn't exist) returns 404, and within a minute a new object under the rehydrate prefix has outcome "unknown\_session", restored 0 and a `caller` ARN for that role session. (If you call through a client that exposes response headers, its `request_id` equals the X-Request-ID header.)
4. From the NOT-allowed role: the same call returns 403 and writes no audit object.
5. `reidentify` sent to the DETECT endpoint returns 404 (Lattice has no such route there).
6. Inspect the newest five audit objects: each has exactly the fields schema, auth\_mode, request\_id, session\_ref, caller, caller\_account, caller\_org\_id, source\_vpc, upstream\_request\_id, outcome, placeholders\_requested, restored, unresolved, timestamp\_utc, engine\_version; schema is tenet.reidentify-audit.v3; none contains a session\_id or any text.
7. If any erasure records exist under the erasure prefix, check one has schema tenet.erasure-audit.v1 and no counts.
   Never print real data. Report a table of results.

## Gotchas

* **KMS enforces the split.** Detect wraps each key pair's private half but is denied unwrapping it, so a compromised detect task — even with the vault's database credentials — can't read a stored value. What it doesn't cover: detect still sees the plaintext of each request it's sent, and with the lookup key it can test guesses of a low-entropy value against a session's dedupe digests.
* **`session_ref` correlation stops at a key rotation.** It's keyed under the current lookup key, and a new key takes effect at the next rollout. [Key rotation](https://docs.tenetlabs.com/pii-engine/operate/key-rotation.md).
* **A `403` doesn't say which layer refused.** Lattice's and the service's refusals look the same to the caller. The Lattice access log shows auth-policy denials; the service's `WARNING` line shows its own.
* **The approval tag can't be checked by the service.** Lattice doesn't forward session tags to the target, so the auth policy is the only place it's enforced. Don't loosen that policy by hand.

## Links

* [Break-glass access](https://docs.tenetlabs.com/pii-engine/operate/break-glass.md)
* [Architecture — IAM roles](https://docs.tenetlabs.com/pii-engine/concepts/architecture.md#iam-roles)
* [Monitoring — alarm on audit failures](https://docs.tenetlabs.com/pii-engine/operate/monitoring.md)
* [Troubleshooting](https://docs.tenetlabs.com/pii-engine/troubleshooting.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.