Rework for SaaS Fusion: calls /tokenize + /restore HTTPS endpoints

This commit is contained in:
2026-07-01 05:09:30 +00:00
parent 3fd9cb2634
commit 20bb8c2417

View File

@@ -1,46 +1,40 @@
# Fusion policy setup (steps 2, 3-route, 8) # Fusion (shared SaaS) policy setup (steps 2, 3-route, 8)
This is the one part that isn't Terraform/CLI — it's configured in the Amplify Fusion is a **shared SaaS instance** configured in the Amplify AI Gateway
AI Gateway (Fusion) itself. Below is the flow the gateway must implement. It is console, not deployed by this repo. Because it's SaaS it **cannot reach private
the orchestration + transformation layer only; detection and the vault are the VPC resources or use local AWS creds**, so it does not call Presidio or DynamoDB
separate components it calls. directly. Instead it calls two **public HTTPS endpoints** this repo exposes
(built in `gateway_api/`, tasks T1/T2), which do the detection, minting, vault
writes, and restore on the AWS side. Fusion owns the orchestration and routing.
## Endpoints to fill in ## Endpoints Fusion calls
- `PRESIDIO_URL` = `http://<presidio-task-ip>:5001/analyze` - `TOKENIZE_URL` = `https://<...>/tokenize` (ingress: detect + mint + vault-write + splice)
- `VAULT_TABLE` = `hncb-deid-demo-vault` (DynamoDB) - `RESTORE_URL` = `https://<...>/restore` (egress: vault lookup + re-attach identity)
- `AGENT_RUNTIME_ARN` = printed by `scripts/agentcore_setup.sh` (step 3) - `AGENT_RUNTIME_ARN` (or its HTTPS invoke endpoint) = printed by `scripts/agentcore_setup.sh`
- Secure all three with an API key / OAuth from the Fusion outbound config.
## Ingress policy (advisor request → cloud) ## Ingress policy (advisor request → cloud)
1. **Authenticate** the advisor and apply the RBAC / business-purpose check. 1. **Authenticate** the advisor; apply the RBAC / business-purpose check.
2. **Detect**: POST the raw query to `PRESIDIO_URL`. You get back typed findings: 2. **Tokenize**: POST `{ query }` to `TOKENIZE_URL`. Receive
`[{entity_type, start, end, score, text}]`. (Findings, not redaction.) `{ deidentified_prompt, session_id }`. (The endpoint runs detect → mint →
3. **Mint + splice** (Fusion owns this): vault-write → splice; detection returns typed findings, never a redacted blob.)
- for each finding, generate a fresh **random** token — different every request. 3. **Route**: invoke the agent with `{ "prompt": deidentified_prompt }`.
Convention: `CUST_<random>` for a PERSON that resolves to a customer, 4. **Trace**: log the **tokenized** payload only — never the raw query.
`TW_<random>` for a `TW_ROC_ID`, etc.
- write the reversible entry to the vault:
`{ token, type, value, session_id, expires_at }`
- replace each finding's span in the text with its token.
4. **Route**: invoke `AGENT_RUNTIME_ARN` with `{ "prompt": "<de-identified text>" }`.
5. **Trace**: log the **tokenized** payload only — never the pre-substitution text.
## Egress policy (cloud response → advisor) ## Egress policy (cloud response → advisor)
1. Receive the agent's de-identified result. 1. Receive the agent's de-identified result.
2. **Restore**: for this `session_id`, look up the vault and re-attach the real 2. **Restore**: POST `{ session_id, text }` to `RESTORE_URL`; receive `{ final }`.
identity (envelope-level here — the talking points are generic, so you prepend 3. Return `{ "final": ..., "deidentified_prompt": ... }` so the UI shows the split view.
"王小明 —"; if any token appears inline, swap it back too).
3. Return `{ "final": "<restored answer>", "deidentified_prompt": "<what the cloud saw>" }`
so the UI can show the split view.
## Vault item shape (DynamoDB) ## Vault item shape (DynamoDB, written by /tokenize)
``` ```
{ "token": "CUST_000123", "type": "CUSTOMER", "value": "cust-0001", { "token": "CUST_000123", "type": "CUSTOMER", "value": "cust-0001",
"session_id": "<conv id>", "expires_at": <epoch+ttl> } "session_id": "<conv id>", "expires_at": <epoch+ttl> }
``` ```
## Demo-simplest alternative ## Why this split
If wiring all of this into Fusion policy is too much for the first recording, Keeping detection, minting, and the vault behind `/tokenize` and `/restore` means
implement steps 2-5 as a thin Fusion flow that calls a small "tokenizer" Lambda the only things exposed to the SaaS gateway are two authenticated HTTPS endpoints —
(detect → mint → vault write → splice) and a "restore" Lambda on egress. Same no AWS creds or private resources leave the account, and Fusion stays a pure
architecture on screen, less console clicking. The point of the demo is that the orchestration/routing layer. That is also the cleanest story on camera: the
gateway owns the flow and the cloud only ever sees tokens. gateway owns the flow; the cloud only ever sees tokens.