> ## 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.

# Architecture

> The in-VPC reference architecture: component diagram, every network edge and what crosses it, VPC Lattice caller auth, the KMS key-pair design that keeps detect out of the vault, and the IAM role-by-permission matrix.

**The reference architecture**: detect and rehydrate services on EC2 Graviton in your private subnets, each behind an Amazon VPC Lattice service with a per-route IAM auth policy, an Aurora PostgreSQL vault, a customer-managed KMS key, an Object Lock audit bucket, and VPC endpoints for every AWS API — no NAT, no internet route, no Tenet principal anywhere.

## When to use it

For your security review, your network team, and anyone changing IAM, auth or endpoint policies after deploy. The CloudFormation template, Terraform module and Helm chart all implement this design; the ECS variant is drawn below, with EKS differences after it.

## Component diagram

```mermaid theme={null}
flowchart LR
  subgraph acct["Your AWS account"]
    subgraph vpc["Your VPC: private subnets only, no IGW/NAT route"]
      app["Your apps<br/>(detect and erasure callers)"]
      rcall["Rehydrate callers<br/>(RehydrateInvokerRoleArns)"]
      lat["VPC Lattice service network<br/>detect + rehydrate services<br/>IAM auth policy per route"]
      subgraph ecs["ECS on EC2: c9g.xlarge, arm64"]
        det["detect tasks ×≥2<br/>/detect /redact /deidentify /sessions"]
        reh["rehydrate tasks ×2<br/>/reidentify"]
      end
      aur[("Aurora PostgreSQL vault<br/>sealed values only")]
      vpce["VPC endpoints<br/>kms · sts · metering-marketplace · logs<br/>secretsmanager · ecr · ecs · S3 gateway"]
    end
    kms["KMS: your CMK"]
    s3a[("S3 audit bucket<br/>Object Lock")]
    cwl["CloudWatch Logs"]
    sm["Secrets Manager<br/>DB secret"]
  end
  meter["AWS Marketplace<br/>Metering Service"]

  app -- "E22 HTTPS 443, SigV4: raw text in, placeholders out" --> lat
  rcall -- "E22 HTTPS 443, SigV4: placeholders in, restored text out" --> lat
  lat -- "E23 HTTPS 19991 + identity headers" --> det
  lat -- "E23" --> reh
  det -- "E5 HPKE-sealed values + keyed digests" --> aur
  reh -- "E6 reads sealed values" --> aur
  det -- "E7 Encrypt new key pair; Decrypt lookup key only" --> vpce
  reh -- "E8 Decrypt lookup + private key" --> vpce
  det -- "E11 erasure record" --> vpce
  reh -- "E11 reidentify record" --> vpce
  vpce --> kms
  vpce --> s3a
  vpce --> cwl
  vpce --> sm
  vpce -- "E9 MeterUsage: quantities only" --> meter
```

**EKS differences:** the AWS Gateway API Controller creates the Lattice services from the chart's HTTPRoutes and IAMAuthPolicies, and the `ClusterIP` Services are only Lattice backends; DNS is CoreDNS; credentials come from IRSA through the `sts` endpoint; a NetworkPolicy `ipBlock` admits only the Lattice ranges in place of the task security groups; logs ship through your cluster's log agent; vault credentials come from a Kubernetes Secret (typically synced from Secrets Manager); the cluster also needs the `ec2`, `eks`, `eks-auth` and `elasticloadbalancing` endpoints, plus `vpc-lattice` and `tagging` for the controller. [Deploy on EKS](https://docs.tenetlabs.com/pii-engine/deploy/eks-helm.md).

## Every network edge

| # | Source → destination | Port | What crosses | Why it stays in your account |
| - | - | - | - | - |
| E4 | Tasks and callers → VPC resolver (EKS: CoreDNS) | 53 | Hostnames: AWS endpoints, Aurora, the Lattice services | VPC resolver. |
| E5 | Detect → Aurora | 5432, TLS (`sslmode=require`) | Each value sealed with HPKE to the current key pair's public key; per-session HMAC-SHA256 dedupe digest; session id, placeholder, TTL; vault metadata. **No plaintext.** | DB SG admits only the two task SGs; private subnets; not publicly accessible; CMK-encrypted storage, backups and master secret. |
| E6 | Rehydrate → Aurora | same | Reads sealed values by session and placeholder | Same. |
| E7 | Detect → `kms` endpoint → your CMK | 443 | `Encrypt` of a new key pair's lookup key and private key (detect then drops the private key); `Decrypt` of the lookup key. Canonical encryption contexts. **No payload.** KMS denies detect the private key. | PrivateLink to your key. Endpoint policy denies keys in other accounts. |
| E8 | Rehydrate → `kms` endpoint | 443 | `Decrypt` of the lookup key and private key (it can't create keys) | Same. |
| E9 | Detect → `metering-marketplace` endpoint → AWS Marketplace Metering Service | 443 | `MeterUsage`: product code, usage dimension, quantity, timestamp, the caller's AWS identity. Rehydrate never calls it. **No payload.** | PrivateLink. The one call that reaches an AWS service on Tenet's behalf — quantities only; AWS bills from it. |
| E10 | Pod → `sts` endpoint (EKS/IRSA) | 443 | Projected service-account token → temporary credentials | PrivateLink; `AWS_STS_REGIONAL_ENDPOINTS=regional`. ECS uses the agent's credential endpoint. |
| E11 | Rehydrate and detect → S3 gateway → audit bucket | 443 | Rehydrate: one `tenet.reidentify-audit.v3` record per call. Detect: one `tenet.erasure-audit.v1` record per erasure. Identifiers, the caller's role session ARN, account, source VPC, Lattice request id, outcome, counts. **Never values, never a raw `session_id`.** | Gateway route. Bucket in your account: public access blocked, TLS required, writes only from the two roles, each under its own prefix; Object Lock and SSE-KMS (CMK). |
| E12 | ECS agent → `logs` endpoint → CloudWatch Logs | 443 | Container stdout/stderr: counts and identifiers only, audit lines, usage records if `TENET_TELEMETRY_PATH` is unset | PrivateLink; CMK-encrypted log groups with finite retention. Depends on nothing logging values. |
| E13 | ECS agent → `secretsmanager` endpoint | 443 | DB username and password (and the opt-in telemetry key), injected at task start | PrivateLink; CMK-encrypted secrets. |
| E14 | ECS agent / kubelet → `us-east-1` `ecr.api`, `ecr.dkr` endpoints; image layers through the S3 gateway (in `us-east-1`) or a `us-east-1` `s3` interface endpoint (elsewhere) | 443 | Image manifests and layers, **inbound**, from the AWS Marketplace registry, which serves images only from `us-east-1` | PrivateLink; outside `us-east-1` the three endpoints are cross-Region (service Region `us-east-1`), still with no NAT. The layer endpoint's policy allows only the Marketplace layer bucket. |
| E15 | ECS agent → `ecs`, `ecs-agent`, `ecs-telemetry` | 443 | Task state, container CPU/memory metrics | PrivateLink. No payload. |
| E16 | Operator → SSM endpoints → host (optional, off) | 443 | Interactive shell | Off by default — a host shell can read process memory. |
| E19 | AWS services → KMS on your behalf (S3, Aurora, Logs, Secrets Manager) | AWS-internal | Data-key operations on the CMK | Scoped with `kms:ViaService` or the Logs encryption context; visible in your CloudTrail. |
| E20 | Aurora → automated backups and snapshots | AWS-internal | Encrypted DB pages | CMK-encrypted, this account and Region. |
| E21 | (EKS) kubelet → pod | 19991, HTTPS | `/healthz`, `/readyz` probes | Node-local. |
| E22 | Caller → VPC Lattice service | 443, HTTPS, AWS-managed certificate | **Raw text with PII** in and placeholders out (detect); placeholders in and **restored PII** out (rehydrate). SigV4-signed by the caller's role. | Lattice's data plane in your VPC (or an associated one). The auth policy checks role, route, method, source VPC and approval tag before anything reaches a task. |
| E23 | VPC Lattice → detect and rehydrate tasks | 19991, HTTPS, the task's ephemeral self-signed certificate | Same as E22, plus identity headers (principal ARN, source VPC, target service), and `/readyz` health checks | Task SGs admit 19991 only from the `com.amazonaws.<region>.vpc-lattice` prefix list; the runtime refuses peers outside the Lattice ranges. |

**Absent by design:** NAT gateways, internet gateway routes, security-group egress to `0.0.0.0/0`, public IPs, internet-facing load balancers, IMDS access from tasks, cross-Region calls, any Tenet endpoint, crash reporting. The one opt-in exception is usage telemetry egress (CloudFormation and Terraform only): a NAT gateway and a tcp/443 path from the detect task carrying the counts-only usage records. The opt-in opens tcp/443 from the detect task to any destination through the NAT. [Monitoring](https://docs.tenetlabs.com/pii-engine/operate/monitoring.md).

## Caller authorization

Rehydration returns plaintext, so a caller clears every layer below, and any one of them stops a request:

1. **Identity, per request.** Lattice verifies the SigV4 signature. A same-account caller needs `vpc-lattice-svcs:Invoke` in its own IAM policy **and** in the service's auth policy. Credentials are the role's short-lived session credentials — there's no shared secret to leak, rotate or inject.
2. **Auth policy, per route and method.** The rehydrate service allows `POST /reidentify` only to `RehydrateInvokerRoleArns`, only from `AllowedSourceVpcIds`, and with the approval tag required, only from a role session tagged `tenet-approval-id` — checked on every call. Break-glass is allowed the same route without the tag. Detect allows `POST /detect`, `/redact`, `/deidentify` to `DetectInvokerRoleArns` and `DELETE /sessions/*` to `ErasureInvokerRoleArns`. The listeners forward only those exact routes; anything else is a Lattice `404`.
3. **Network.** Tasks admit 19991 only from the Lattice prefix list (EKS: a NetworkPolicy admitting only `lattice.peerCidrs`). A direct call to a task IP doesn't connect.
4. **App-side re-check.** The runtime refuses, with a fixed `403 {"detail":"forbidden"}`, any request whose peer isn't a Lattice address, that lacks exactly one of each Lattice identity header, that targets another service, whose raw path isn't canonical, or — for `/reidentify` and erasure — whose principal isn't on the role's own allow-list. Lattice strips client copies of the identity headers.
5. **Route isolation.** Detect doesn't mount `/reidentify`; rehydrate mounts nothing else.
6. **Audit before plaintext or deletion.** Every rehydration writes its record before the response, and every erasure before the delete; if the record can't be written, the call fails with `503` and nothing is restored or deleted.

Details and the record schemas: [Rehydration and audit](https://docs.tenetlabs.com/pii-engine/concepts/rehydration-and-audit.md).

## KMS design

Each vault key is a **key pair**, in two parts:

1. A **lookup key** (32 bytes) keys the per-session HMAC-SHA256 dedupe digest — so a recurring value reuses its placeholder — and the audit `session_ref`. Both services hold it.
2. An **X25519 key pair**. Detect seals each value to the public key with HPKE (RFC 9180; AES-256-GCM), bound to its (session, placeholder) slot. Only the private key opens it, and only rehydrate holds the private key.

Detect generates the pair on first start (or in `rotate-key`), wraps the lookup key and the private key with `kms:Encrypt`, stores both blobs and the public key in the vault's metadata table, and keeps only the write-only half in memory. Each wrapped blob carries its own encryption context:

```json theme={null}
{"tenet:purpose": "pii-vault-lookup-key",  "tenet:key_id": "<key_id>", "tenet:deployment": "<deployment id>", "tenet:public_key": "<base64 X25519 public key>"}
{"tenet:purpose": "pii-vault-private-key", "tenet:key_id": "<key_id>", "tenet:deployment": "<deployment id>", "tenet:public_key": "<base64 X25519 public key>"}
```

Every key-policy and IAM statement pins `kms:EncryptionContext:tenet:purpose` and `kms:EncryptionContext:tenet:deployment`. `tenet:key_id` and `tenet:public_key` change with every key, so don't pin them. Because the public key is in both contexts, someone who can write the vault but can't call KMS can't swap in a public key of their own — the lookup key would fail to unwrap and the service refuses to start.

| Role | Allow | Deny |
| - | - | - |
| detect | `kms:Encrypt` for `pii-vault-lookup-key`, `pii-vault-private-key`; `kms:Decrypt` for `pii-vault-lookup-key` | `kms:Decrypt` for `pii-vault-private-key`; `kms:ReEncrypt*` and `kms:CreateGrant`, unconditionally — in the key policy **and** the detect role's own policy |
| rehydrate | `kms:Decrypt` for `pii-vault-lookup-key`, `pii-vault-private-key` | — |
| `rotate-key` job | runs with the detect grants | — |

An explicit Deny beats every Allow, so no IAM policy attached to the detect role later can lift it, and the role-policy copy holds even on an existing CMK whose policy the templates don't write.

**What KMS enforces.** A compromised detect task, even with the vault's database credentials, can't decrypt any value stored under a key pair. Only the rehydrate role can.

**What it doesn't cover:**

* Detect sees the plaintext of every request it's sent. Key isolation protects what's stored.
* With the lookup key and vault read access, detect can test guesses of a low-entropy value against a session's dedupe digests.

The key policy the templates write names a key admin (no data-plane encrypt or decrypt), the roles above, the Logs service principal scoped to this deployment's log groups, and the deployer through RDS and Secrets Manager. The account-root statement is opt-in (`KeyPolicyIncludeAccountRoot`). No Tenet principal appears. With your own key: [Bringing your own KMS key](https://docs.tenetlabs.com/pii-engine/deploy/ecs-cloudformation.md#bringing-your-own-kms-key).

## IAM roles

✔ = granted. `ctx` = the `tenet:deployment` pin plus the purposes above. `via X` = `kms:ViaService` for service X.

| Role | Marketplace metering | KMS vault keys | KMS other | S3 audit | Secrets Manager | Other |
| - | - | - | - | - | - | - |
| **detect** task / IRSA | ✔ | `Encrypt` (lookup, private), `Decrypt` (lookup), ctx; **denied** `Decrypt` of private keys, `ReEncrypt*`, `CreateGrant` | `GenerateDataKey` via s3 | `PutObject` on `<bucket>/<erasure prefix>*`; `GetBucketObjectLockConfiguration` | — | EKS: `vpc-lattice:ListServices` |
| **rehydrate** task / IRSA | — | `Decrypt` (lookup, private; ctx) | `GenerateDataKey` via s3 | `PutObject` on `<bucket>/<prefix>*`; `GetBucketObjectLockConfiguration`. No Get, Delete or retention bypass | — | EKS: `vpc-lattice:ListServices` |
| **ECS Lattice infrastructure** (`ecs`) | — | — | — | — | — | `AmazonECSInfrastructureRolePolicyForVpcLattice`: registers task IPs in the target groups |
| **detect execution** (ECS) | — | — | `Decrypt` via secretsmanager | — | DB secret; the telemetry key with egress on | `AmazonECSTaskExecutionRolePolicy` |
| **rehydrate execution** (ECS) | — | — | `Decrypt` via secretsmanager | — | DB secret | same |
| **ECS instance** | — | — | — | — | — | `AmazonEC2ContainerServiceforEC2Role`; SSM only if enabled |
| **detect invokers** (yours) | — | — | — | — | — | `vpc-lattice-svcs:Invoke` on detect: `POST /detect`, `/redact`, `/deidentify` |
| **erasure invokers** (yours) | — | — | — | — | — | `vpc-lattice-svcs:Invoke` on detect: `DELETE /sessions/*` only |
| **rehydrate invokers** (yours) | — | — | — | — | — | `vpc-lattice-svcs:Invoke` on rehydrate: `POST /reidentify`, plus the approval tag when required |
| **break-glass** (MFA, ≤ 1 h) | — | — | — | — | — | `vpc-lattice-svcs:Invoke` on rehydrate, no approval tag |
| **key admin** (runs the stack) | — | **no** Encrypt/Decrypt | Key administration; grants and data keys via rds and secretsmanager only | — | — | — |
| **audit reader** (optional) | — | — | `Decrypt` via s3 | `GetObject`, `GetObjectVersion`, `GetObjectRetention`, `ListBucket` | — | — |
| **Tenet** | — | — | — | — | — | **nothing** |

Only detect has `aws-marketplace:MeterUsage`: rehydrate doesn't check the subscription or meter. It's on `Resource: "*"` — it has no resource-level scoping — and AWS accepts it only from the ECS task role or IRSA, not node roles, EKS Pod Identity or long-term keys. Task-role trust policies carry `aws:SourceAccount` and `aws:SourceArn`. Separate execution roles keep each service's secrets to its own tasks.

## Vault backend

Aurora PostgreSQL (Serverless v2 in the templates). The vault holds sealed values, keyed digests, TTLs and the wrapped key ring in three tables (`tenet_pii_sessions`, `tenet_pii_mappings`, `tenet_pii_vault_meta`), so it can share a database with other tenants. Both services connect as the same database user unless you provision a separate role per service.

## Gotchas

* **Logging hygiene is part of the boundary.** E12 is safe because the services log counts and identifiers, never values. If you add a sidecar, proxy or APM agent in front of the services, it must not log request or response bodies.
* **Caller ARNs are workforce identifiers.** Audit records and Lattice access logs name the caller's role session, and an SSO session name is often an email address. Prefer `sts:SourceIdentity` for human callers.
* **Opening SSM, telemetry egress, or another VPC or account to the service network changes the boundary.** All are off by default; turn them on deliberately and record it in your risk assessment.
* **Adding a NAT later breaks the zero-egress claim** even though the services never use it.

Check a running deployment still matches this architecture — read-only drift audit.

Audit my running Tenet PII Engine (Enterprise) deployment for drift from the reference architecture at [https://docs.tenetlabs.com/pii-engine/concepts/architecture](https://docs.tenetlabs.com/pii-engine/concepts/architecture.md). Read-only: do not change anything.

Ask me for: Region, VPC id, platform (ECS stack name, or EKS cluster and namespace), the CMK ARN, the deployment id, the detect and rehydrate task/IRSA role ARNs, and the role ARNs I expect in each invoker list (detect, erasure, rehydrate, break-glass).

Check and report pass/fail with evidence:

1. No route table in the VPC's private subnets routes to a NAT gateway or internet gateway (if usage telemetry egress is on, report the NAT and its route as the expected exception).
2. No security group attached to the detect/rehydrate tasks or nodes has egress to 0.0.0.0/0 or ::/0 (except the detect task's opt-in telemetry rule), and the task security groups admit tcp/19991 only from the `com.amazonaws.<region>.vpc-lattice` prefix list (EKS: the NetworkPolicy ingress admits only lattice.peerCidrs).
3. The CMK key policy contains no principal outside my account; every statement granting the detect or rehydrate role kms:Encrypt or kms:Decrypt pins kms:EncryptionContext:tenet:purpose and kms:EncryptionContext:tenet:deployment = the deployment id; the key policy AND the detect role's own policy deny the detect role kms:Decrypt for tenet:purpose = pii-vault-private-key and deny kms:ReEncrypt\* and kms:CreateGrant.
4. The rehydrate role has kms:Decrypt but no kms:Encrypt or kms:GenerateDataKey for vault keys (GenerateDataKey via s3 for audit writes is expected).
5. The detect and rehydrate VPC Lattice services have auth type AWS\_IAM, and their auth policies (`aws vpc-lattice get-auth-policy`) name only the roles I listed, per route and method, with vpc-lattice-svcs:SourceVpc conditions; report any extra principal, wildcard or missing condition.
6. The audit bucket has Object Lock enabled with a default retention rule, and public access blocked.
7. Optional surfaces — SSM endpoints, the telemetry NAT, extra VPC associations or RAM shares of the service network: report whether they exist and flag them for my review rather than failing.
   Output a table and, for each failure, the specific resource and the fix.

## Links

* [Data flow for your HIPAA risk assessment](https://docs.tenetlabs.com/pii-engine/security/data-flow.md)
* [Shared responsibility](https://docs.tenetlabs.com/pii-engine/security/shared-responsibility.md)
* [Prerequisites](https://docs.tenetlabs.com/pii-engine/deploy/prerequisites.md)
* [Rehydration and audit](https://docs.tenetlabs.com/pii-engine/concepts/rehydration-and-audit.md)


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