Audit effective runtime privileges and bound lease policy arithmetic

Review P1: the v2 attribute-only runtime role check accepted a login that
inherits pg_write_all_data, which can UPDATE lease rows directly and
bypass fencing. apply.sql now audits, on every migrate run, the runtime
group and all transitive members: privileged attributes, any membership
outside the group (inherited or SET-able), table privileges in evolution
(including PUBLIC), CREATE rights and EXECUTE beyond the five fenced
functions. 0002 and its checksum are unchanged. CI reproduces the bypass
and proves each configuration is rejected and rolled back.

Review P2: valid(LeasePolicy) bounds every term by the duration before
arithmetic; LeaseAuthority validates durations before deadline math and
renewal_unknown ignores impossible (>60s) and fences non-positive requests.
Extreme min/max tests reproduce the old UBSan overflow and now pass.

Validated: Windows CTest 55/55; WSL Release, clang-tidy and ASan/UBSan
private-PostgreSQL suites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-09-28 13:50:44 -04:00
co-authored by Claude Opus 5.5
parent 2496649a9b
commit 07116446c6
8 changed files with 197 additions and 17 deletions
+4 -2
View File
@@ -30,7 +30,8 @@ struct LeaseGrant {
std::chrono::milliseconds duration{};
};
// Selected M7.3 timings. Validity: duration 1..60s (database bound); margin at
// Selected M7.3 timings. Validity: duration 1..60s (database bound); every other
// term positive and below the duration (checked before any arithmetic); margin at
// least 10% of duration (clock-rate and check-to-effect allowance); two complete
// renewal attempts fit before local fencing; I/O deadlines within adapter limits.
struct LeasePolicy {
@@ -76,7 +77,8 @@ class LeaseAuthority {
LeaseClock::time_point sent,
LeaseClock::time_point received) noexcept;
// Ambiguous renewal: the database may have applied a shorter expiry, so keep
// the earlier of the old deadline and the one the attempt could have set.
// the earlier of the old deadline and the one the attempt could have set. A
// request above 60s cannot have applied; a non-positive request fences.
void renewal_unknown(std::chrono::milliseconds requested, LeaseClock::time_point sent) noexcept;
void fence() noexcept;
[[nodiscard]] LeaseState state(LeaseClock::time_point now) const noexcept;