Skip to content

update: replace unmaintained chrono with jiff - #364

Merged
inureyes merged 3 commits into
mainfrom
update/issue-363-replace-chrono
Nov 19, 2026
Merged

inureyes merged 3 commits into
mainfrom
update/issue-363-replace-chrono

Conversation

@inureyes

@inureyes inureyes commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Replaces the direct chrono dependency with jiff 1.0.1 (MSRV 1.85, pure Rust) at all five call sites. jiff was chosen over time because time's now_local() fails in multi-threaded processes without the unsound opt-out, which would break three local-time call sites. jiff reads the system zone itself (TZ, then /etc/localtime) and falls back to a UTC-equivalent zone without panicking, matching chrono's Local fallback.

  • Audit AuditEvent.timestamp is now jiff::Timestamp. A small serde helper (src/server/audit/timestamp.rs) writes exactly what chrono wrote: RFC 3339 UTC, Z suffix, 0/3/6/9 fractional digits (shortest exact width, chrono's SecondsFormat::AutoSi). Before and after are byte-identical, for example 2026-11-20T01:02:03Z, 2026-11-20T01:02:03.123Z, 2026-11-20T01:02:03.123456789Z. jiff's default printer would have trimmed to 1-9 digits, hence the helper. Deserialization accepts any RFC 3339 input with up to 9 fractional digits.
  • The OTel exporter converts via SystemTime::try_from (jiff's conversion is fallible), falling back to now.
  • TUI log and interactive timestamps keep %H:%M:%S local time; output.rs file names keep local %Y%m%d_%H%M%S and parallel.rs keeps UTC.
  • docs/audit-logging.md documents the timestamp format (no Korean counterpart exists).

Advisory status

RUSTSEC-2026-0543 remains open: cargo tree -i chrono -e normal now shows only russh-sftp 3.0.1 as a dependent, and cargo deny check advisories still reports the advisory through it. Clearing it needs an upstream russh-sftp change, which this PR does not attempt.

Test plan

  • New tests: audit JSON timestamp is RFC 3339 UTC with Z; chrono-written records (.123456789Z, .123456Z, .123Z, no fraction) deserialize and re-serialize to the identical string
  • LogEntry::format_with_time test pins a fixed instant and passes under both UTC and TZ=Asia/Seoul
  • Full suite cargo test --all-features --no-fail-fast: 2743 passed; the 4 tests/integration_test.rs failures need a localhost SSH agent identity and fail identically on main
  • cargo check --all-targets --all-features, cargo clippy --all-targets --all-features -- -D warnings, cargo fmt --check
  • Static musl and vendored PPA builds not run locally; on Linux jiff pulls in only jiff-core and serde_core (pure Rust; the bundled tzdb crates are Windows/wasm only)

Closes #363

chrono is unmaintained (RUSTSEC-2026-0543). jiff reads the system time zone itself, so local timestamps keep working in the multi-threaded tokio process, unlike time's now_local(). If the zone cannot be determined it behaves like UTC, as chrono's Local did.

Audit event timestamps are now jiff::Timestamp with a serde helper that writes the same RFC 3339 UTC form chrono wrote (Z suffix, 0/3/6/9 fractional digits), so audit files and Logstash output are byte-compatible. The otel exporter converts with SystemTime::try_from. TUI log, interactive, and output file name timestamps keep their strftime formats and local-vs-UTC choice.

Tests cover the serialized format and deserializing chrono-written records. chrono remains in Cargo.lock through russh-sftp, so the advisory stays open until that crate changes.

Refs #363
@inureyes inureyes added type:dependency Dependency updates status:review Under review priority:low Low priority issue labels Nov 19, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Replace the direct chrono dependency with jiff while keeping every timestamp format, timezone, and the audit JSON wire format unchanged.

Findings Addressed

  • Module doc in src/server/audit/timestamp.rs claimed any number of fractional digits is accepted; jiff accepts at most 9 (LOW, 5e7df5b)

Remaining Items

  • An invalid TZ value (for example TZ=Nope/Zone) makes jiff use UTC, while chrono fell back to /etc/localtime. This matches glibc and date, and nothing panics (LOW, no change)
  • Deserialization edge cases chrono never wrote: jiff rejects more than 9 fractional digits and a UTC suffix, and reads 23:59:60 as 23:59:59. Old audit JSON is unaffected (LOW, informational)

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass

I checked serialization against chrono 0.4.45 serde output side by side for 0, 1, 3, 6, and 9 digit fractions across several epochs: the bytes are identical. Inputs with +00:00, +09:00, -00:00, +0000, a space separator, or lowercase t/z parse the same as under chrono. cargo fmt --check and cargo clippy --all-targets --all-features -- -D warnings pass, and the server::audit and ui::tui::log_buffer lib tests pass (65 passed, 2 ignored).

@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review of the chrono to jiff migration: no CRITICAL, HIGH, or MEDIUM findings, no fixes pushed.

  • Audit timestamps: AuditEvent.timestamp is only ever set from Timestamp::now(), and AuditEvent is never deserialized outside tests, so no untrusted input reaches the new serde helper. Parsing RFC 3339 with an offset normalizes to the same instant, so ordering is preserved.
  • Panics: Timestamp::now() only panics if the system clock is outside +/-9999 years, which is narrower exposure than chrono's pre-epoch case. Every strftime pattern is a constant using fields that Timestamp and ZonedDateTime always carry, so the Display impl cannot fail.
  • Output file names: the timestamp part is digits and _ only. The PR adds no path-injection surface. Node names are joined into paths the same way as before.
  • TZ handling: jiff caches the system zone with a 5-minute TTL and falls back to UTC on a bad TZ without panicking. Per-line ZonedDateTime::now() in the TUI log buffer costs a cache read plus an Arc clone, comparable to chrono::Local::now().
  • Supply chain: on Linux the tree is jiff, jiff-core, serde_core. Neither jiff crate has a build script (build = false). jiff-static, jiff-tzdb*, portable-atomic*, and windows-link are target-gated and not built for Linux.

LOW: in src/server/audit/otel.rs:144 the SystemTime::try_from fallback to now() is silent. On supported platforms it cannot fail for any jiff Timestamp, so this is acceptable for audit semantics. A tracing::warn! on that branch would make a substitution visible if one ever happened.

Verified: clippy with -D warnings, cargo fmt --check, and cargo test --all-features --lib server::audit (58 passed).

LogEntry::format_with_time now formats through jiff strftime and had no test. Pin the timestamp to a fixed UTC instant and assert the HH:MM:SS prefix so the output stays stable independent of the local time zone.

Validation:
- cargo test --all-features --lib log_buffer: 8 passed
- cargo fmt --check and cargo clippy --all-targets --all-features -- -D warnings clean

Refs #363
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 19, 2026
@inureyes
inureyes merged commit 36896eb into main Nov 19, 2026
5 checks passed
@inureyes
inureyes deleted the update/issue-363-replace-chrono branch November 19, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:low Low priority issue status:done Completed type:dependency Dependency updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

update: Replace unmaintained chrono crate (RUSTSEC-2026-0543)

1 participant