queryable-encryption-workshop
Skill8 starsChanged 9 months agoMITView on GitHub
Generate MongoDB Queryable Encryption demos customized for industry verticals (healthcare, finance, government) with compliance mapping and production patterns
- Reads credentials
In this repository9 other files it gives its agents.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Use this skill when demonstrating Queryable Encryption, mapping compliance requirements, or building industry-specific security demos.
- Distinctive: line 269
Warning: Not for production (key stored in code)
- Distinctive: line 310
Create data encryption keys
- Distinctive: line 499
Use deterministic sparingly (lower security)
- Distinctive: line 505
Create new data encryption key
- Distinctive: line 507
Update schema to reference new key
- Distinctive: line 509
Automation: Use scripts, schedule quarterly
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
queryable-encryption-workshop
Trigger
Use this skill when demonstrating Queryable Encryption, mapping compliance requirements, or building industry-specific security demos.
Trigger phrases:
- "Build QE demo for [healthcare/finance/government]"
- "Map QE to HIPAA/PCI-DSS/GDPR"
- "Generate encryption demo"
- "Show QE compliance patterns"
Overview
Queryable Encryption (QE) is MongoDB's client-side field-level encryption that allows encrypted search. Different industries have different compliance needs, data sensitivity levels, and use cases.
This skill generates industry-customized demos that map QE features to specific compliance requirements.
Not for: General encryption education. This is about vertical-specific demos with compliance context.
How to Use
Quick Start
- Analyze vertical requirements:
python scripts/vertical_analyzer.py --vertical healthcare --output analysis.json - Generate demo code:
python scripts/demo_generator.py analysis.json --output demo/ - Map compliance requirements:
python scripts/compliance_mapper.py --vertical healthcare --framework HIPAA --output compliance.md
Python Tools
scripts/vertical_analyzer.py— Analyze industry data sensitivity patternsscripts/demo_generator.py— Generate vertical-specific QE demo codescripts/compliance_mapper.py— Map QE to compliance frameworks
Reference Docs
references/qe-compliance-guide.md— QE mapped to HIPAA, PCI-DSS, GDPRreferences/industry-patterns.md— Common patterns by vertical
Templates & Assets
assets/healthcare-schema.json— Patient data with PHI fieldsassets/finance-schema.json— Financial data with PII/PCI fieldsassets/government-schema.json— Citizen data with SSN/TIN fields
Industry Verticals
Healthcare (HIPAA)
Sensitive data:
- PHI (Protected Health Information)
- SSN, date of birth, medical record numbers
- Diagnoses, prescriptions, lab results
QE approach:
- Equality queries: SSN, medical record number (exact lookups)
- Range queries: Date of birth (age-based queries)
- Unencrypted: Non-PHI (names for display, city for analytics)
Example schema:
{
patientId: "P12345", // Deterministic (equality search)
ssn: "***-**-6789", // Deterministic (encrypted, searchable)
dob: "1980-05-15", // Range (encrypted, age queries)
diagnosis: "...", // Random (encrypted, not searchable)
fullName: "John Doe", // Plaintext (not PHI for display)
city: "Boston" // Plaintext (analytics)
}Compliance mapping:
- HIPAA §164.312(a)(2)(iv): Encryption at rest ✅
- HIPAA §164.312(e)(2)(ii): Encryption in transit ✅
- HIPAA §164.308(a)(4): Access controls ✅ (key management)
Finance (PCI-DSS)
Sensitive data:
- Credit card numbers (PAN)
- CVV, expiration dates
- Account numbers, routing numbers
- SSN, transaction details
QE approach:
- Deterministic: Last 4 digits of card (customer lookup)
- Random: Full card number (store but never query)
- Unencrypted: Transaction amounts (reporting), merchant names
Example schema:
{
customerId: "C12345", // Deterministic
cardLast4: "4242", // Deterministic (searchable)
cardNumberFull: "****", // Random (encrypted, not searchable)
expirationDate: "12/25", // Random
transactionAmount: 99.99, // Plaintext (analytics)
merchantName: "Store Inc" // Plaintext
}Compliance mapping:
- PCI-DSS Req 3.4: Encryption of PAN ✅
- PCI-DSS Req 3.5.1: Key management ✅
- PCI-DSS Req 3.6.4: Cryptographic key changes ✅
Government (FedRAMP, FISMA)
Sensitive data:
- SSN, TIN (Tax ID)
- Clearance levels
- Citizen records
- Classified information
QE approach:
- Deterministic: SSN (citizen lookup)
- Range: Security clearance level (range queries)
- Random: Classified notes
- Unencrypted: Public records, statistics
Example schema:
{
citizenId: "CIT12345", // Deterministic
ssn: "***-**-6789", // Deterministic (searchable)
clearanceLevel: 3, // Range (encrypted, level queries)
classifiedNotes: "...", // Random (encrypted, not searchable)
state: "MA", // Plaintext (analytics)
registrationDate: "2020" // Plaintext
}Compliance mapping:
- FISMA: Encryption requirements ✅
- FedRAMP: Key management ✅
- NIST 800-53: Access controls ✅
QE Encryption Types
1. Deterministic (Equality Queries)
Use for: Exact match searches (SSN, email, account number)
Properties:
- Same plaintext → same ciphertext (searchable)
- Supports:
$eq,$in,$ne - Not secure for low-cardinality fields (gender, state)
Example:
{
ssn: {
encrypt: {
keyId: "key1",
algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
bsonType: "string"
}
}
}2. Range (Range Queries)
Use for: Numeric ranges, date ranges (age, salary, dates)
Properties:
- Supports:
$gt,$gte,$lt,$lte,$range - More secure than deterministic
- Requires min/max bounds
Example:
{
dateOfBirth: {
encrypt: {
keyId: "key2",
algorithm: "Range",
bsonType: "date",
min: ISODate("1900-01-01"),
max: ISODate("2024-12-31"),
sparsity: 2
}
}
}3. Random (No Queries)
Use for: Sensitive data never queried (full card numbers, notes)
Properties:
- Same plaintext → different ciphertext (most secure)
- Not searchable
- Best for high-sensitivity fields
Example:
{
creditCardNumber: {
encrypt: {
keyId: "key3",
algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Random",
bsonType: "string"
}
}
}Key Management Patterns
Pattern 1: AWS KMS (Production)
Best for: Production deployments, compliance audits
Setup:
const clientEncryption = new ClientEncryption(client, {
keyVaultNamespace: "encryption.__keyVault",
kmsProviders: {
aws: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
}
}
});Compliance: FIPS 140-2 validated, audit trails, key rotation
Pattern 2: Local Key (Demos)
Best for: Workshops, POCs, local development
Setup:
const localKey = crypto.randomBytes(96);
const clientEncryption = new ClientEncryption(client, {
keyVaultNamespace: "encryption.__keyVault",
kmsProviders: {
local: {
key: localKey
}
}
});Warning: Not for production (key stored in code)
Pattern 3: Azure Key Vault
Best for: Azure deployments, Microsoft shops
Setup:
const clientEncryption = new ClientEncryption(client, {
keyVaultNamespace: "encryption.__keyVault",
kmsProviders: {
azure: {
tenantId: process.env.AZURE_TENANT_ID,
clientId: process.env.AZURE_CLIENT_ID,
clientSecret: process.env.AZURE_CLIENT_SECRET
}
}
});Demo Structure
Phase 1: Unencrypted Baseline (5 min)
Show data in plaintext, query patterns:
// Insert plaintext
db.patients.insertOne({
ssn: "123-45-6789",
dob: new Date("1980-05-15"),
diagnosis: "Hypertension"
});
// Query plaintext
db.patients.findOne({ ssn: "123-45-6789" });Demonstrate: Data visible in MongoDB Compass, logs, backups
Phase 2: Enable QE (10 min)
- Create data encryption keys
- Define encrypted fields schema
- Create encrypted client
- Insert encrypted data
// Create DEK
const keyId = await clientEncryption.createDataKey("local");
// Define schema
const schema = {
"patients": {
encryptedFields: {
fields: [
{ path: "ssn", keyId, bsonType: "string", queries: { queryType: "equality" } },
{ path: "dob", keyId, bsonType: "date", queries: { queryType: "range", min: ..., max: ... } },
{ path: "diagnosis", keyId, bsonType: "string" } // Random
]
}
}
};
// Insert encrypted
const encryptedClient = new MongoClient(uri, { autoEncryption: { keyVaultNamespace, kmsProviders, encryptedFieldsMap: schema } });
await encryptedClient.db("hospital").collection("patients").insertOne({
ssn: "123-45-6789", // Encrypted deterministic
dob: new Date("1980-05-15"), // Encrypted range
diagnosis: "Hypertension" // Encrypted random
});Phase 3: Query Encrypted Data (10 min)
Show what queries work:
// ✅ Works: Equality on deterministic field
await patients.findOne({ ssn: "123-45-6789" });
// ✅ Works: Range on range field
await patients.find({ dob: { $gte: new Date("1980-01-01") } });
// ❌ Fails: Query on random field
await patients.findOne({ diagnosis: "Hypertension" }); // No results (encrypted)Show in Compass: Ciphertext blobs, metadata collection
Phase 4: Compliance Mapping (5 min)
Connect to compliance requirements:
- "This meets HIPAA §164.312(a)(2)(iv) encryption requirement"
- "Key vault in AWS KMS provides FIPS 140-2 compliance"
- "Access controls via MongoDB RBAC satisfy HIPAA §164.308(a)(4)"
Python Tool Details
1. Vertical Analyzer
Input: Vertical name
Output: Sensitivity analysis
{
"vertical": "healthcare",
"sensitive_fields": [
{ "name": "ssn", "type": "deterministic", "regulation": "HIPAA", "reason": "PHI identifier" },
{ "name": "dob", "type": "range", "regulation": "HIPAA", "reason": "PHI demographic" },
{ "name": "diagnosis", "type": "random", "regulation": "HIPAA", "reason": "PHI medical" }
],
"plaintext_fields": ["fullName", "city"],
"compliance_frameworks": ["HIPAA", "HITECH"]
}2. Demo Generator
Input: Vertical analysis
Output: Complete demo code (Node.js + Python)
setup.js— Create keys, schemainsert.js— Insert encrypted dataquery.js— Query examplesREADME.md— Workshop guide
3. Compliance Mapper
Input: Vertical + framework
Output: Compliance mapping document
# HIPAA Compliance Mapping
## §164.312(a)(2)(iv): Encryption and Decryption
✅ MongoDB Queryable Encryption provides encryption at rest
✅ TLS 1.2+ provides encryption in transit
## §164.308(a)(4): Access Controls
✅ MongoDB RBAC restricts key vault access
✅ AWS KMS provides key access audit trails
...Common Patterns
Pattern 1: Healthcare Patient Lookup
Scenario: Find patient by SSN, show non-PHI
// Encrypted: ssn, dob, diagnosis
// Plaintext: fullName, city (for UX)
const patient = await patients.findOne({ ssn: "123-45-6789" });
// Returns: { fullName: "John Doe", city: "Boston", ssn: <encrypted>, ... }Pattern 2: Finance Transaction Search
Scenario: Lookup by last 4 digits, hide full card
// Encrypted: cardLast4 (deterministic), cardNumberFull (random)
// Plaintext: merchantName, amount
const transactions = await txns.find({ cardLast4: "4242" });
// Returns masked card, plaintext merchant/amountPattern 3: Government Clearance Query
Scenario: Find citizens with clearance level >= 3
// Encrypted: ssn (deterministic), clearanceLevel (range)
// Plaintext: state, registrationDate
const citizens = await citizens.find({ clearanceLevel: { $gte: 3 } });Workshop Agenda (60 min)
0-10 min: Introduction
- Why encryption? (breaches, compliance)
- Encryption at rest vs in use vs QE
- Demo preview
10-25 min: QE Deep Dive
- Three encryption types (deterministic, range, random)
- Key management (AWS KMS, local)
- Schema definition
25-45 min: Live Demo
- Phase 1: Plaintext baseline
- Phase 2: Enable QE
- Phase 3: Query encrypted data
- Show in Compass (ciphertext)
45-55 min: Compliance Mapping
- Map to HIPAA/PCI-DSS/FISMA
- Production considerations
- Key rotation, access controls
55-60 min: Q&A + Resources
Compliance Cheat Sheet
| Framework | Requirements | QE Mapping |
| HIPAA | Encryption at rest (§164.312) | ✅ QE encrypts fields |
| Access controls (§164.308) | ✅ RBAC + KMS | |
| Audit trails (§164.312) | ✅ KMS logs | |
| PCI-DSS | Encrypt PAN (Req 3.4) | ✅ QE on card fields |
| Key management (Req 3.5) | ✅ AWS KMS | |
| Key rotation (Req 3.6.4) | ✅ Manual rotation | |
| GDPR | Data protection (Art 32) | ✅ QE encryption |
| Right to erasure (Art 17) | ⚠️ Manual delete | |
| FISMA | FIPS 140-2 (NIST 800-53) | ✅ AWS KMS FIPS |
Production Considerations
1. Performance
Impact:
- Encrypted writes: ~10-20% slower (encryption overhead)
- Encrypted reads: ~5-10% slower (decryption)
- Range queries: Higher overhead than equality
Mitigation:
- Index plaintext fields for filtering
- Use deterministic sparingly (lower security)
- Cache decrypted results when safe
2. Key Rotation
Manual process:
- Create new data encryption key
- Re-encrypt data with new key
- Update schema to reference new key
Automation: Use scripts, schedule quarterly
3. Backup & Disaster Recovery
Key vault backup:
- AWS KMS: Automatic replication
- Local keys: Backup to secure storage
Encrypted data backup:
- Backup encrypted documents (safe)
- Restore requires key vault access
Quality Checklist
Before workshop:
- Vertical analysis complete
- Demo code tested locally
- Compliance mapping reviewed
- AWS KMS credentials configured (or local key ready)
- MongoDB Compass installed (show ciphertext)
- Timing rehearsed (60 min)
During demo:
- Show plaintext first (contrast)
- Explain each encryption type clearly
- Demo all three query patterns
- Show Compass (visual proof)
- Map to compliance requirements
- Leave time for Q&A
When to Use vs. Other Tools
Use queryable-encryption-workshop | Use other tools |
| Industry-specific QE demos | General encryption education |
| Compliance mapping | Security architecture design |
| Workshop prep | Production implementation |
| Vertical analysis | Performance tuning |
References
- QE Compliance Guide:
references/qe-compliance-guide.md - Industry Patterns:
references/industry-patterns.md - Official docs: https://www.mongodb.com/docs/manual/core/queryable-encryption/
- Compliance: https://www.mongodb.com/compliance
Credits
Michael Lynn — mlynn.org · @mlynn · LinkedIn · GitHub
Next steps after workshop:
- Customer-specific schema design
- Production KMS setup
- Performance testing
- Compliance audit preparation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

