Galosys.Foundation.Compliance
26.9.16.1
dotnet add package Galosys.Foundation.Compliance --version 26.9.16.1
NuGet\Install-Package Galosys.Foundation.Compliance -Version 26.9.16.1
<PackageReference Include="Galosys.Foundation.Compliance" Version="26.9.16.1" />
<PackageVersion Include="Galosys.Foundation.Compliance" Version="26.9.16.1" />
<PackageReference Include="Galosys.Foundation.Compliance" />
paket add Galosys.Foundation.Compliance --version 26.9.16.1
#r "nuget: Galosys.Foundation.Compliance, 26.9.16.1"
#:package Galosys.Foundation.Compliance@26.9.16.1
#addin nuget:?package=Galosys.Foundation.Compliance&version=26.9.16.1
#tool nuget:?package=Galosys.Foundation.Compliance&version=26.9.16.1
Galosys.Foundation.Compliance
合规能力核心包:数据分类 + EntityChanges 字段级 diff + 脱敏辅助 + 合规等级。零破坏性变更,薄层引用现有 Microsoft.Extensions.Compliance.Redaction 与 Galosys.Foundation.Core 资产。
设计文档:能力缺口与行动清单 §行动 1 Phase 1 路线图:合规能力路线图 §Phase 1 决策指南:业务方按本文档「## 快速开始」+「## 特性」段落地
特性
- 数据分类:5 个内置分类(
PrivateData/PublicData/SensitiveData/FinancialData(SOX) /HealthData(HIPAA)),沿用 .NET 10 官方DataClassification抽象 - EntityChanges:
EntityChangerecord +IEntityChangeInterceptor抽象 + 基于反射的默认实现(捕获字段级 diff) - 脱敏辅助:
MaskingHelper静态门面封装Redactor子类调用,供DataMaskConverter和SensitiveDataFilter共同使用 - 合规等级:
ComplianceLevel三档(Lenient/Standard/Strict)+ComplianceOptions配置 +LogTier四档审计分层 - DI 集成:
AddCompliance()一行注册所有合规服务
快速开始
// Program.cs
using Galosys.Foundation.Compliance;
using Microsoft.Extensions.Compliance.Classification;
var builder = WebApplication.CreateBuilder(args);
// 注册合规服务
builder.Services.AddCompliance(opts =>
{
opts.Level = ComplianceLevel.Standard; // Lenient / Standard(默认) / Strict
opts.LogTier = LogTier.Business; // Security / Business / System / Debug
opts.IsEnabled = true;
opts.ExcludedActions = new HashSet<string> { "HealthController.Ping" };
});
// 标注实体属性
public class Order
{
[PrivateData] public string Phone { get; set; } = ""; // PII
[SensitiveData] public string OrderNo { get; set; } = ""; // 业务敏感
[FinancialData] public decimal Amount { get; set; } // SOX 财务
[HealthData] public string? Diagnosis { get; set; } // HIPAA 医疗
[PublicData] public string PublicNote { get; set; } = "";
}
脱敏辅助(MaskingHelper)
MaskingHelper 静态门面封装 6 个官方 Redactor 调用,供业务代码直接使用:
using Galosys.Foundation.Compliance;
var masked = MaskingHelper.MaskPhone("13800138000"); // "138****8000"
var idcard = MaskingHelper.MaskIdCard("110101199001011234"); // "110101********1234"
var email = MaskingHelper.MaskEmail("user@example.com"); // "u***@example.com"
字段级 Diff(EntityChange)
EntityChange record 携带字段级 diff 完整信息(对标 ABP EntityChange + Hibernate Envers):
public sealed record EntityChange(
string PropertyName,
string? OldValue,
string? NewValue,
EntityChangeType ChangeType, // Added / Modified / Deleted
DataClassification Classification);
捕获规则:
- 仅记录标注了
DataClassification子类的属性(避免审计日志膨胀) - JSON 序列化值(自动处理
null/ 原始类型 / 复杂对象) - 仅输出原值与新值不相等的字段
典型用法:EF Core SaveChangesInterceptor 在 SavingChangesAsync 阶段调用 CaptureChanges() → 结果写入 AuditLog.Changes JSON 字段。
依赖
| 包 | 用途 |
|---|---|
Galosys.Foundation.Core |
Entity<T> 基类 + 中央依赖图根节点 |
Microsoft.Extensions.Compliance.Redaction |
.NET 10 官方 Redactor 引擎(薄层引用) |
由 Directory.Packages.props 中央包管理,PackageReference 不指定 Version。
不在本包范围(v1 后续落地)
| 能力 | 落地包 | Phase | 状态 |
|---|---|---|---|
| ASP.NET Core 中间件(自动审计) | Galosys.Foundation.Compliance.AspNetCore |
Phase 2 | ✅ 完成 (2026-08-24) |
| EF Core SaveChangesInterceptor 适配 | Galosys.Foundation.Compliance.AspNetCore |
Phase 2 | ✅ 完成 |
| Roslyn Analyzer GYS001(未标注 PII) | Galosys.Foundation.Compliance.Analyzers |
Phase 3 | ✅ 完成 (2026-08-24) |
| Strict 模式运行期阻断 | Galosys.Foundation.Compliance.AspNetCore |
Phase 2/3 | ✅ 完成 |
详见 合规能力路线图。
测试覆盖
Galosys.Foundation.Compliance.Tests(25 测试全通过):
DataClassificationsTest× 6(5 个分类值 + AttributeUsage)EntityChangeTest× 3(record 创建 + JSON 序列化 + enum 值)ComplianceOptionsTest× 5(默认值 + 配置覆盖 + enum 值)AddComplianceTest× 3(DI 注册 + TryAdd 语义)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Galosys.Foundation.Core (>= 26.9.16.1)
- Microsoft.Extensions.Compliance.Redaction (>= 10.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Galosys.Foundation.Compliance:
| Package | Downloads |
|---|---|
|
Galosys.Foundation.AspNetCore
Galosys.Foundation快速开发库 |
|
|
Galosys.Foundation.Compliance.AspNetCore
Galosys.Foundation快速开发库 |
GitHub repositories
This package is not used by any popular GitHub repositories.