Skip to content

fix(guest): sync system clock from RTC at boot to avoid 'certificate not yet valid'#127

Open
arlishansenn wants to merge 2 commits into
earendil-works:mainfrom
arlishansenn:fix/guest-rtc-clock-sync
Open

fix(guest): sync system clock from RTC at boot to avoid 'certificate not yet valid'#127
arlishansenn wants to merge 2 commits into
earendil-works:mainfrom
arlishansenn:fix/guest-rtc-clock-sync

Conversation

@arlishansenn

Copy link
Copy Markdown

Problem

Inside the guest, every HTTPS egress (curl, apk, Node/Python runtimes) can fail with:

SSL certificate problem: certificate is not yet valid
TLS: server certificate not trusted

against the gondolin-mitm-ca proxy certificates.

Root cause

The host signs short-lived MITM TLS certificates with notBefore set to the host wall-clock time. When the guest system clock lags behind the host, those freshly minted certificates are seen as not yet valid, so the TLS handshake through the egress proxy is rejected.

Observed in an aarch64 QEMU guest:

  • boot: rtc-pl031 set the system clock to e.g. 06:57:39
  • guest system clock then ran behind host wall time
  • host-signed cert notBefore was minutes ahead of guest time -> not yet valid
  • the QEMU-exposed hardware RTC (/dev/rtc0) actually tracked host time correctly

Confirmed fix in-guest: hwclock -s immediately restored strict TLS (curl https://api.github.com -> 200, apk update over HTTPS -> OK), with no CA or repo changes.

There is currently no guest-side time sync and no host option to control this (no clock/rtc/time knobs in the SDK/CLI, no -rtc exposure), and guest init does not seed the clock.

Change

Seed the system clock from the hardware RTC early in guest/image/init (after /dev is mounted, before networking/CA setup). Tries hwclock --hctosys --utc, falls back to hwclock -s, and degrades gracefully (logs and continues) when hwclock is unavailable.

Notes

  • busybox (present in the Alpine base image) provides an hwclock applet, so this is available by default.
  • Pure addition; no behavior change when the clock is already correct.
  • Alternative/complementary host-side fix would be ensuring QEMU is launched with -rtc base=utc,clock=host; this guest-side change is the minimal self-contained fix.

The host signs short-lived MITM TLS certificates with notBefore set to the
host wall-clock time. When the guest system clock lags behind the host, those
freshly minted certificates are rejected as "certificate is not yet valid",
breaking every HTTPS egress (curl, apk, Node/Python runtimes, ...).

Seed the system clock from the QEMU-exposed hardware RTC early in guest init
(before networking/CA setup) so the guest stays inside the certificate
validity window. Falls back gracefully when hwclock is unavailable.
Alpine splits resize2fs into the e2fsprogs-extra package; e2fsprogs
alone does not ship it. Without resize2fs in the guest image, setting
rootfs.size makes the VM fail to boot with "requires resize2fs in the
guest image (install e2fsprogs)".

Also gitignore the top-level image-out/ build output directory.
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.

1 participant