Skip to content

security(server): authenticate audit records with HMAC (#304) - #328

Draft
JeongWon4034 wants to merge 1 commit into
mainfrom
codex/304-audit-hmac
Draft

JeongWon4034 wants to merge 1 commit into
mainfrom
codex/304-audit-hmac

Conversation

@JeongWon4034

Copy link
Copy Markdown
Member

Summary

Closes #304.

A log-file writer could edit audit records and recompute the entire unkeyed SHA-256 chain. Add opt-in HMAC-SHA256 authentication from server-owned configuration: recomputed forgeries, stripped authentication fields and wrong/unknown keys fail verification and prevent append.

  • Preserve existing SHA digests and browser replay; authenticate every semantic field and key ID in a versioned, unambiguous MAC payload.
  • Load the key ring, active key ID and trusted legacy migration boundary at startup. Rotate keys without rewriting old records; explicitly warn for unsigned legacy operation.
  • Remove audit credentials from execution children. Validate existing history through the same locked Windows-compatible handle before signing.
  • Return authentication status from one snapshot at GET /security/audit/chain; return HTTP 500 when POST /security/audit cannot persist a record.
  • Document permissions, migration, rotation and the remaining security(audit): 외부 앵커링/체크포인트 + 변조·누락 탐지 테스트 + 위협모델 #305 checkpoint boundary.

Type of change

  • New feature (feat:)
  • Bug fix (fix:)
  • Documentation (docs:)

Checklist

  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets --locked -- -D warnings passes
  • cargo test --workspace --locked passes — 759 passed, 0 failed, 0 ignored
  • Full-workspace dependency policy passes — existing baseline failures, detailed below
  • Architecture constraints respected
  • New behavior covered by tests, including production server processes
  • CHANGELOG.md updated
  • No unimplemented capability presented as implemented

Validation

Windows GNU, Rust/Cargo 1.98.0; RTX 4070 Laptop GPU detected (driver 591.44). CARGO_PROFILE_DEV_DEBUG=0 and CARGO_PROFILE_TEST_DEBUG=0 avoid the documented GNU executable-size limit. Default Cargo features; GPU acceptance was not enabled for this server-only change.

Server coverage: 132 unit tests and 3 real-process HTTP tests. New checks include RFC 4231 and a Python HMAC golden, full-chain hash recomputation attacks, optional-field ambiguity, auth stripping, malformed tags, wrong/missing keys, rotation, legacy migration, failed-append preservation, startup/API rejection, and two server processes writing the same authenticated log. All logs/DBs are temporary; tests do not modify operator environment variables or runtime audit data.

Reproduction and evidence.

Notes for reviewers

Draft because the broader dependency gate is not green. With cargo-deny 0.20.2:

  • The existing root-manifest cargo deny --all-features check passes, but only covers the CLI graph.
  • cargo deny --workspace --all-features check reports 37 errors: 16 license rejections, 14 vulnerability diagnostics, 3 unsoundness, 2 unmaintained packages and 2 yanked versions.
  • The full-workspace check on a separate snapshot of base b347688 produces identical error diagnostic counts and the same 19 RustSec IDs. No locked package version changed; the only lockfile change is the server's edge to already-locked hmac 0.13.0.
  • The current CI license job lacks --workspace; its success must not be interpreted as full-workspace coverage. No advisory suppression or license-policy changes are included.

HMAC assumes the file writer cannot read/change the server's keys or trusted configuration; environment injection alone does not enforce OS permissions. Valid-prefix rollback/tail truncation and external checkpoints remain #305. Legacy prefixes remain explicitly unauthenticated.

#[test]
fn rfc4231_sha256_vector() {
// https://www.rfc-editor.org/rfc/rfc4231.html#section-4.2
let mut mac = Hmac::<Sha256>::new_from_slice(&[0x0b; 20]).unwrap();
let expected =
hex::decode("e8fec96ef84c8203953e92a8795813659ee30a201f3784322da5a1153380cd10")
.unwrap();
record_mac(&record, &[0xab; 32])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(audit): 감사로그 HMAC 기록 인증 + 로그/키 권한 분리

2 participants