Merged
# Audit Framework and Schema Definition #512
zhangxiangAdd on Sep 10
# Audit Framework and Schema Definition #512
Merged
Pull Request has been successfully merged by 曹玉哲.
(Thank you for zhangxiang's contribution.)atomgit-bot
Sep 10 Comments:
Sep 10 Comments:
变更摘要
本 PR 新增安全审计日志框架 foundation/openjiuwen_runtime/foundation/audit/ 包,实现 SRS FR1(schema 驱动的日志格式、合规校验门、NTP 时钟同步)并为其后续 FR2–FR8(脱敏、异步输出、存储、外送、访问控制、配置下发、打点)提供配置骨架与接口占位。核心包括:AuditLogSchema(头部 HeaderSchema + 内容 ContentSchema)、validate_schema 合规校验门、SyncedClock NTP 同步时钟、format_audit_line/parse_audit_line 格式化与解析、AuditLogConfig 配置聚合及 AuditFacade 打点门面,并随附三份单元测试(test_audit_clock.py、test_audit_formatter.py、test_audit_schema.py)。
主要改动
- Schema 定义与默认常量: 新增
schema.py与constants.py,定义 11 字段头部(DEFAULT_HEADER_FIELDS,|分隔、-占位)与内容层(#UA:/#EVT:关键字、|@|要素分隔、=KV 分隔、replace/escape 两种转义模式),并声明不可削弱的红线字段DEFAULT_REDLINE_FIELDS与 RSPCD 码表RSPCD_KNOWN。 - 合规校验门: 新增
validator.py的validate_schema,在自定义 schema 生效前强制校验 semver 版本、红线字段齐全、timestamp保留、占位符/分隔符/转义模式声明、NTP 配置合法性及command_force_redact不被关闭,不通过则抛SchemaValidationError,并拒绝占位符形式的 NTP 地址。 - NTP 同步时钟: 新增
clock.py的SyncedClock/UdpNtpClient/SequenceNtpClient,实现启动同步与周期同步,时间源由配置注入(禁止硬编码),全部源不可达时降级本地时钟不阻断调用方,主源 failover 或偏差超阈值时产生ClockEvent事件。 - 日志行格式化与解析: 新增
formatter.py的format_audit_line/parse_audit_line,自动补全头部pid/tid/caller/时间戳,required 字段缺失时占位、校验 RSPCD 格式与 caller 行号,沙箱要素(ACTION/SANDBOXID/RESULT)转入EXT(x_前缀),format_clock_event将 NTP 事件落成#EVT管道行。 - 配置聚合与未实现接口占位: 新增
config.py的AuditLogConfig/default_config聚合 format/ntp/identity/redaction 等子配置并在加载时过校验门;writer.py/storage.py/shipper.py/access.py/deploy.py/redaction.py/linkpoint.py及facade.py的log_audit仅提供接口骨架,明确以AuditNotImplementedError拒绝假装落盘。


Incorrect?
atomgit-bot
Sep 10 Comments:
Sep 10 Comments:
🤖 AI 代码检视正在进行中,请稍候…


Incorrect?
openJiuwen-bot
Sep 10 Comments:
Sep 10 Comments:
欢迎来到 openJiuwen 社区
Hey @seanzhang_cn , 感谢你对社区的贡献.
机器人使用手册
有关指令的使用,可以点击 此处 查看详情。开发人员可以在每个PR或Issue下方评论特定指令来触发机器人任务。


atomgit-bot
Sep 10 Comments:
Sep 10 Comments:
Sep 10 Added label: openJiuwen-cla/yes
openJiuwen-bot
Sep 10 Comments:
Sep 10 Comments:
Sep 10 Modify description of pull request
Sep 10 Modify description of pull request
openJiuwen-bot
Sep 10 Comments:
Sep 10 Comments:
| 任务名称 | 结果 | 日志操作 |
|---|---|---|
| 静态检查 | ❌FAILED | 点此跳转 |
| 禁用词扫描 | ✅SUCCESS | 点此跳转 |
| 防投毒检查 | ✅SUCCESS | 点此跳转 |
| 开源合规检查 | ✅SUCCESS | 点此跳转 |
| UT测试 | N/A | N/A |
| ST测试 | N/A | N/A |
| build 编译包 | N/A | N/A |
| ruff codecheck | {{ruff_codecheck_result}} | {{ruff_codecheck_link_text}} |
| issue关联检查 | {{issue_linked_result}} | {{issue_linked_link_text}} |
| pr size检查 | {{pr_size_result}} | {{pr_size_link_text}} |


Sep 10 Added label: ci-failed
Sep 10 Removed label: ci-failed
openJiuwen-bot
Sep 10 Comments:
Sep 10 Comments:
| 任务名称 | 结果 | 日志操作 |
|---|---|---|
| 静态检查 | ✅SUCCESS | 点此跳转 |
| 禁用词扫描 | ✅SUCCESS | 点此跳转 |
| 防投毒检查 | ✅SUCCESS | 点此跳转 |
| 开源合规检查 | ✅SUCCESS | 点此跳转 |
| UT测试 | N/A | N/A |
| ST测试 | N/A | N/A |
| build 编译包 | N/A | N/A |
| ruff codecheck | {{ruff_codecheck_result}} | {{ruff_codecheck_link_text}} |
| issue关联检查 | {{issue_linked_result}} | {{issue_linked_link_text}} |
| pr size检查 | {{pr_size_result}} | {{pr_size_link_text}} |


Sep 10 Added label: ci-successful
Sep 10 Removed label: ci-successful
Paired: GitHub #169 ↔ GitCode !512
What type of PR is this?
/kind feature
Self-checklist:(请自检,在[ ]内打上x,我们将检视你的完成情况,否则会导致pr无法合入)
Linked Closing Issues: