name: 数据分类
description: 包括敏感性级别、处理要求、标签和数据生命周期管理的数据分类框架
allowed-tools: 读取, 全局搜索, 查找, 写入, 编辑, 任务
数据分类
数据分类、处理要求和数据生命周期管理的全面指南。
何时使用此技能
- 建立数据分类政策
- 定义不同数据类型的处理要求
- 按分类设计数据保护控制
- 实施数据标签和标记
- 创建数据保留和处理程序
分类框架
标准敏感性级别
| 级别 |
描述 |
示例 |
泄露影响 |
| 公开 |
故意公开 |
营销材料、已发布文档 |
无 |
| 内部 |
一般业务使用 |
政策、组织架构图 |
最小 |
| 机密 |
业务敏感 |
财务报告、合同 |
中等 |
| 受限 |
高度敏感 |
个人身份信息(PII)、个人健康信息(PHI)、商业机密 |
严重 |
| 绝密 |
关键/受监管 |
加密密钥、并购数据 |
灾难性 |
视觉标签
┌─────────────────────────────────────────┐
│ █ 公开 │ 绿色
├─────────────────────────────────────────┤
│ █ 内部 - 仅限内部使用 │ 蓝色
├─────────────────────────────────────────┤
│ █ 机密 - 仅限授权人员 │ 黄色
├─────────────────────────────────────────┤
│ █ 受限 - 仅限需要知晓 │ 橙色
├─────────────────────────────────────────┤
│ █ 绝密 - 严格控制 │ 红色
└─────────────────────────────────────────┘
处理要求矩阵
按分类级别
| 要求 |
公开 |
内部 |
机密 |
受限 |
| 访问控制 |
无 |
认证 |
基于角色的访问控制(RBAC) |
需要知晓 + 多因素认证(MFA) |
| 静态加密 |
可选 |
推荐 |
必需 |
必需 + 硬件安全模块(HSM) |
| 传输加密 |
HTTPS |
TLS 1.2+ |
TLS 1.2+ |
TLS 1.3 + 相互TLS(mTLS) |
| 备份 |
标准 |
标准 |
加密 |
加密 + 地理分离 |
| 外部共享 |
允许 |
批准 |
需要保密协议(NDA) |
禁止 |
| 云存储 |
任何 |
批准的云 |
批准 + 加密 |
本地或批准 |
| 打印 |
允许 |
允许 |
水印 |
禁止/跟踪 |
| 保留 |
根据需要 |
3年 |
7年 |
7年 + 法律保留 |
| 处理 |
标准删除 |
安全删除 |
加密擦除 |
物理销毁 |
数据流控制
受限数据流:
┌──────────────┐ 加密 ┌──────────────┐
│ 源系统 │ ───────────────▶ │ 目标系统 │
└──────────────┘ └──────────────┘
│ │
▼ ▼
审计日志 审计日志
│ │
▼ ▼
┌────────────────────────────────────────────┐
│ SIEM / 监控 │
└────────────────────────────────────────────┘
分类实施
.NET数据注释方法
// 分类属性
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class)]
public class DataClassificationAttribute : Attribute
{
public DataClassification Level { get; }
public string? DataCategory { get; set; }
public string? RetentionPolicy { get; set; }
public string[] RequiredRoles { get; set; } = Array.Empty<string>();
public DataClassificationAttribute(DataClassification level)
{
Level = level;
}
}
public enum DataClassification
{
Public = 0,
Internal = 1,
Confidential = 2,
Restricted = 3,
TopSecret = 4
}
// 在领域模型上的使用
public class Customer
{
public Guid Id { get; set; }
[DataClassification(DataClassification.Internal)]
public string Name { get; set; } = string.Empty;
[DataClassification(DataClassification.Restricted,
DataCategory = "PII",
RequiredRoles = new[] { "CustomerAdmin", "Support" })]
public string Email { get; set; } = string.Empty;
[DataClassification(DataClassification.Restricted,
DataCategory = "PII",
RetentionPolicy = "7years")]
public string SocialSecurityNumber { get; set; } = string.Empty;
[DataClassification(DataClassification.Confidential,
DataCategory = "Financial")]
public decimal CreditLimit { get; set; }
}
基于分类的访问控制
public class ClassificationAuthorizationHandler
: AuthorizationHandler<DataAccessRequirement, object>
{
protected override Task HandleRequirementAsync(
AuthorizationHandlerContext context,
DataAccessRequirement requirement,
object resource)
{
var classificationAttr = resource.GetType()
.GetCustomAttribute<DataClassificationAttribute>();
if (classificationAttr == null)
{
context.Succeed(requirement);
return Task.CompletedTask;
}
var userClearance = GetUserClearanceLevel(context.User);
// 用户权限必须满足或超过数据分类
if ((int)userClearance >= (int)classificationAttr.Level)
{
// 如果指定了角色要求,则检查
if (classificationAttr.RequiredRoles.Length > 0)
{
var hasRequiredRole = classificationAttr.RequiredRoles
.Any(r => context.User.IsInRole(r));
if (hasRequiredRole)
{
context.Succeed(requirement);
}
}
else
{
context.Succeed(requirement);
}
}
return Task.CompletedTask;
}
}
字段级加密
public class ClassificationBasedEncryption
{
private readonly IEncryptionService _encryptionService;
public async Task<T> ProtectData<T>(T data, CancellationToken ct) where T : class
{
var properties = typeof(T).GetProperties()
.Where(p => p.GetCustomAttribute<DataClassificationAttribute>() != null);
foreach (var prop in properties)
{
var attr = prop.GetCustomAttribute<DataClassificationAttribute>()!;
if (attr.Level >= DataClassification.Confidential)
{
var value = prop.GetValue(data) as string;
if (!string.IsNullOrEmpty(value))
{
var encrypted = await _encryptionService.Encrypt(value, ct);
prop.SetValue(data, encrypted);
}
}
}
return data;
}
}
数据发现和库存
自动分类
public class DataDiscoveryService
{
private readonly IRegexPatternMatcher _patternMatcher;
public ClassificationSuggestion AnalyzeContent(string content)
{
var detections = new List<DataTypeDetection>();
// 检查个人身份信息(PII)模式
if (_patternMatcher.ContainsPattern(content, PiiPatterns.SocialSecurityNumber))
detections.Add(new DataTypeDetection("社会保障号码", DataClassification.Restricted));
if (_patternMatcher.ContainsPattern(content, PiiPatterns.CreditCard))
detections.Add(new DataTypeDetection("信用卡", DataClassification.Restricted));
if (_patternMatcher.ContainsPattern(content, PiiPatterns.Email))
detections.Add(new DataTypeDetection("电子邮件", DataClassification.Confidential));
if (_patternMatcher.ContainsPattern(content, PiiPatterns.PhoneNumber))
detections.Add(new DataTypeDetection("电话号码", DataClassification.Confidential));
// 检查财务模式
if (_patternMatcher.ContainsPattern(content, FinancialPatterns.BankAccount))
detections.Add(new DataTypeDetection("银行账户", DataClassification.Restricted));
// 确定最高分类
var suggestedLevel = detections.Any()
? detections.Max(d => d.Classification)
: DataClassification.Internal;
return new ClassificationSuggestion
{
SuggestedLevel = suggestedLevel,
Detections = detections,
Confidence = CalculateConfidence(detections)
};
}
}
public static class PiiPatterns
{
public static readonly string SocialSecurityNumber = @"\b\d{3}-\d{2}-\d{4}\b";
public static readonly string CreditCard = @"\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b";
public static readonly string Email = @"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b";
public static readonly string PhoneNumber = @"\b\d{3}[-.]?\d{3}[-.]?\d{4}\b";
}
数据库存模板
数据库存条目:
asset_id: DATA-001
name: 客户数据库
description: 主客户记录
owner: 客户服务部门
custodian: IT运营
location:
- Azure SQL数据库 (prod-sql-001)
- 每日备份到Azure Blob存储
data_categories:
- 个人身份信息(PII) (姓名、电子邮件、地址)
- 财务 (支付历史、信用额度)
- 行为 (购买历史)
classification: 受限
volume: ~2M记录
sensitivity_reason: 包含个人身份信息(PII)和财务数据
regulatory_requirements:
- GDPR (欧盟客户)
- CCPA (加利福尼亚客户)
retention:
active: 客户关系期间
archived: 关系结束后7年
access:
roles:
- CustomerAdmin (完全访问)
- Support (只读)
- Analytics (仅匿名化)
mfa_required: true
vpn_required: true
encryption:
at_rest: AES-256 (透明数据加密)
in_transit: TLS 1.3
backup:
frequency: 每日
retention: 30天
tested: 每月
last_review: 2025-01-15
next_review: 2025-07-15
数据生命周期管理
生命周期阶段
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ 创建 │───▶│ 存储 │───▶│ 使用 │───▶│ 归档 │───▶│ 销毁 │
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
分类 加密 监控 限制 认证
标签 访问控制 审计日志 只读 处理
保留政策实施
public class DataRetentionService
{
private readonly IRetentionPolicyProvider _policies;
private readonly IAuditLogger _auditLogger;
public async Task ApplyRetentionPolicies(CancellationToken ct)
{
var policies = await _policies.GetActivePolicies(ct);
foreach (var policy in policies)
{
var expiredData = await FindExpiredData(policy, ct);
foreach (var item in expiredData)
{
switch (policy.Action)
{
case RetentionAction.Archive:
await ArchiveData(item, policy, ct);
break;
case RetentionAction.Anonymize:
await AnonymizeData(item, policy, ct);
break;
case RetentionAction.Delete:
await SecureDelete(item, policy, ct);
break;
}
await _auditLogger.LogRetentionAction(item, policy, ct);
}
}
}
private async Task SecureDelete(DataItem item, RetentionPolicy policy, CancellationToken ct)
{
var classification = item.Classification;
switch (classification)
{
case DataClassification.Public:
case DataClassification.Internal:
// 标准删除
await _repository.Delete(item.Id, ct);
break;
case DataClassification.Confidential:
// 安全删除,带验证
await _repository.SecureDelete(item.Id, ct);
await VerifyDeletion(item.Id, ct);
break;
case DataClassification.Restricted:
case DataClassification.TopSecret:
// 加密擦除 + 验证
await _encryptionService.DestroyKey(item.EncryptionKeyId, ct);
await _repository.SecureDelete(item.Id, ct);
await VerifyDeletion(item.Id, ct);
await GenerateDeletionCertificate(item, ct);
break;
}
}
}
处理认证
public class DisposalCertificate
{
public required Guid CertificateId { get; init; }
public required DateTimeOffset DisposalDate { get; init; }
public required string DataDescription { get; init; }
public required DataClassification Classification { get; init; }
public required string DisposalMethod { get; init; }
public required string PerformedBy { get; init; }
public required string WitnessedBy { get; init; }
public required string VerificationMethod { get; init; }
public required bool VerificationPassed { get; init; }
public string? Notes { get; init; }
}
标签和标记
文档标签
public class DocumentLabeler
{
public async Task<LabeledDocument> ApplyLabel(
Document document,
DataClassification classification,
CancellationToken ct)
{
var label = new ClassificationLabel
{
Level = classification,
AppliedAt = DateTimeOffset.UtcNow,
AppliedBy = _currentUser.Id,
ExpiresAt = classification >= DataClassification.Confidential
? DateTimeOffset.UtcNow.AddYears(1) // 要求重新分类
: null
};
// 添加视觉页眉/页脚
if (document.Type == DocumentType.Word || document.Type == DocumentType.PDF)
{
await AddVisualLabel(document, label, ct);
}
// 添加元数据
document.Metadata["classification"] = classification.ToString();
document.Metadata["classification_date"] = label.AppliedAt.ToString("O");
document.Metadata["classification_by"] = label.AppliedBy;
// 应用保护
if (classification >= DataClassification.Confidential)
{
await ApplyProtection(document, classification, ct);
}
return new LabeledDocument
{
Document = document,
Label = label
};
}
}
分类政策模板
# 数据分类政策
## 1. 目的
建立基于敏感性的统一数据处理标准。
## 2. 范围
所有由[组织]创建、收集、存储或处理的数据。
## 3. 分类级别
### 3.1 公开
意图公开披露的数据。
- **示例**: 营销材料、新闻稿
- **处理**: 无特殊要求
### 3.2 内部
一般业务信息。
- **示例**: 政策、程序、组织架构图
- **处理**: 访问限于员工
### 3.3 机密
业务敏感信息。
- **示例**: 财务报告、合同、战略
- **处理**: 需要知晓访问、加密必需
### 3.4 受限
高度敏感、受监管数据。
- **示例**: 个人身份信息(PII)、个人健康信息(PHI)、支付卡数据
- **处理**: 严格访问控制、多因素认证(MFA)、加密、审计日志
## 4. 角色和责任
### 数据所有者
- 分配分类级别
- 批准访问请求
- 每年审查分类
### 数据保管者
- 实施技术控制
- 管理访问权限
- 监控违规
### 所有员工
- 按分类处理数据
- 报告错误分类
- 保护敏感数据
## 5. 处理要求
[参见上方矩阵]
## 6. 不合规
违规者将受到纪律处分。
## 7. 审查
政策每年审查一次。
分类清单
实施
- [ ] 定义分类级别
- [ ] 创建处理要求矩阵
- [ ] 确定数据所有者
- [ ] 进行数据库存
- [ ] 对现有数据应用分类
- [ ] 实施技术控制
- [ ] 培训员工
持续
- [ ] 年度分类审查
- [ ] 新数据评估
- [ ] 访问审查
- [ ] 控制有效性测试
- [ ] 政策更新
交叉引用
- GDPR:
gdpr-compliance 用于个人数据
- HIPAA:
hipaa-compliance 用于健康数据
- 安全:
security-frameworks 用于控制
资源