pii-policy-enforcement
Policy และ mechanisms สำหรับ detect, classify และ protect PII data ใน data platform
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
PII Policy Enforcement
Overview
Policy และ mechanisms สำหรับ detect, classify และ protect PII (Personally Identifiable Information) ใน data platform
Why This Matters
- Compliance: GDPR, CCPA requirements
- Privacy: Protect user data
- Security: Prevent data leaks
- Trust: Build customer confidence
PII Classification
Levels
Level 1 - Public: Name, job title
Level 2 - Internal: Employee ID, department
Level 3 - Confidential: Email, phone, address
Level 4 - Restricted: SSN, credit card, health data
Auto-Detection
from presidio_analyzer import AnalyzerEngine
analyzer = AnalyzerEngine()
# Detect PII
text = "John's email is john@example.com and SSN is 123-45-6789"
results = analyzer.analyze(text, language='en')
for result in results:
print(f"{result.entity_type}: {result.score}")
# Output:
# EMAIL_ADDRESS: 0.95
# US_SSN: 0.85
Enforcement Mechanisms
1. Column-Level Encryption
-- Encrypt PII columns
CREATE TABLE users (
id UUID PRIMARY KEY,
email VARCHAR ENCRYPTED, -- Auto-encrypt
ssn VARCHAR ENCRYPTED,
name VARCHAR -- Not encrypted
);
2. Row-Level Security
-- Only show PII to authorized users
CREATE POLICY pii_access ON users
USING (
current_user IN (SELECT user_id FROM pii_authorized_users)
OR is_admin(current_user)
);
3. Data Masking
def mask_pii(data: dict) -> dict:
"""Mask PII fields"""
masked = data.copy()
if 'email' in masked:
masked['email'] = mask_email(masked['email'])
# john@example.com → j***@example.com
if 'ssn' in masked:
masked['ssn'] = mask_ssn(masked['ssn'])
# 123-45-6789 → ***-**-6789
return masked
Access Control
# pii-policy.yaml
policies:
- name: email_access
resource: users.email
allowed_roles:
- admin
- customer_support
audit: true
- name: ssn_access
resource: users.ssn
allowed_roles:
- admin
require_mfa: true
audit: true
alert: true
Audit Logging
# Log all PII access
def log_pii_access(user_id: str, resource: str, action: str):
audit_log.write({
'timestamp': datetime.now(),
'user_id': user_id,
'resource': resource,
'action': action,
'ip_address': request.ip,
'success': True
})
# Example
@require_pii_access('users.email')
def get_user_email(user_id: str):
log_pii_access(current_user.id, f'users.{user_id}.email', 'read')
return db.query('SELECT email FROM users WHERE id = ?', user_id)
Summary
PII Policy: Protect sensitive personal data
Classification:
- Level 1-4 (Public → Restricted)
- Auto-detection (Presidio)
Enforcement:
- Column encryption
- Row-level security
- Data masking
- Access control
Compliance:
- Audit logging
- Access reviews
- Data retention
- Right to deletion
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!