—— 模型不會忘記,你才會。
昨天我們把「誰可以做什麼」鎖好(RBAC/ABAC/PBAC)。
今天處理另一個靈魂拷問:資料分級 + DLP。
沒分級 = 一律可見;
沒 DLP = 一律可說。
AI 系統若沒有這兩層,就等於把公司知識放在開放式冰箱,大家路過順手拿。
在 LLM/RAG 的世界,資料從「文件」變成「片段(chunk)」與「向量(embedding)」。
分級必須一路跟著資料走:從檔案 → chunk → 向量 → 檢索回傳 → 生成輸出。
等級 | 說明 | 典型範例 | 可見對象 | 可外傳 | DLP 策略 |
---|---|---|---|---|---|
Public | 對外公開 | 官網新聞稿 | 任何人 | ✅ | 最低 |
Internal | 內部使用 | 一般 SOP、FAQ | 全員 | ⛔ | 中 |
Confidential | 機敏 | 客戶名單、報價 | 需授權 | ⛔ | 高 |
Secret | 關鍵/法遵 | 來源碼、併購文件 | 少數人 | ⛔ | 極高 |
原則:分類在前、授權在中、審計在後。
[Ingestion(入庫)] → [Retrieval(檢索)] → [Generation(生成)]
↑遮罩/分級 ↑ACL/過濾 ↑輸出審查/重寫
tenant/department/classification/clearance
tenant_id
條件(不要交給 prompt)block
/ redact
/ rewrite
/ ask-for-justification
{
"query": "請給我客戶ABC最近合約細節",
"filter": {
"must": [
{"key":"tenant_id", "match":{"value":"${user.tenant}"}},
{"key":"department", "match":{"value":"${user.department}"}},
{"key":"classification", "in":["public","internal"]},
{"key":"clearance", "lte":"${user.clearance}"}
]
},
"limit": 5
}
Don’t trust the model. Trust your filter.
SENSITIVE_PATTERNS = {
"email": r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}",
"phone": r"\b(?:\+?\d{1,3}[ -]?)?(?:\d[ -]?){7,12}\b",
"cc": r"\b(?:\d[ -]?){13,19}\b"
}
def redact(text):
for k, pat in SENSITIVE_PATTERNS.items():
text = re.sub(pat, f"<REDACTED:{k}>", text)
return text
def prepare_chunks(doc, meta):
cleaned = redact(doc.text)
chunks = split(cleaned, max_tokens=512)
return [{
"text": c,
"metadata": {**meta, "classification": classify(c)}
} for c in chunks]
先遮罩再嵌入,避免把 Secrets 直接送進向量空間。
type Verdict = "allow" | "rewrite" | "block" | "ask";
export function dlpGuard(user, prompt, answer) {
const hits = detectSensitive(answer); // regex + ner + vector match
if (!hits.length) return { action: "allow", answer };
// 高敏類型(身份證、卡號、API key…)
if (hits.some(h => h.severity === "high")) {
return { action: "block", reason: "contains_secrets" };
}
// 中敏→重寫
const rewritten = rewriteAnonymize(answer);
return { action: "rewrite", answer: rewritten, hits };
}
DLP 不只擋下內容,更要可解釋 + 可審計。
version: 1
labels:
- Public
- Internal
- Confidential
- Secret
rules:
retrieval:
deny_if:
- expr: resource.tenant != user.tenant
- expr: resource.classification in ["Confidential","Secret"] and user.clearance < 3
generation:
block_if:
- detector: "pii.id_number|pii.credit_card|secret.api_key"
rewrite_if:
- detector: "pii.email|pii.phone"
ask_justification_if:
- detector: "financial.quote|customer.personally_identifiable"
retention:
- label: Internal
days: 180
- label: Confidential
days: 90
audit:
store: "siem://dlp-events"
PM:「我們 RAG 很安全,因為文件都內網。」
你:「嗯,那為什麼昨天 AI 回答了A 客戶報價 420 萬
?」
PM:「因為有同事把報價單貼到聊天室,然後我們有做 chat-to-RAG…」
你:「好,先把聊天資料也分級,感謝。」
tenant/department/classification/clearance
多租戶向量庫隔離、檢索白名單、查詢重寫、防資料拼湊(Reconstruction Attack)。