Skip to content

check-k3s-vm: the k3s server certificate is outside its validity window at probe time (x509 expired or not yet valid) #882

Open

Description

@aitrawog

Problem

With the bed's own kube_context fix in place (charly#880), check-k3s-vm's nine kubernetes probes resolve a context and dial the forwarded port correctly - and then fail on certificate validity, as seen from the guest at probe time:

stderr: listing nodes: Get "https://127.0.0.1:40179/api/v1/nodes": tls: failed to verify certificate:
x509: certificate has expired or is not yet valid: current time 202…

Measured on charly fix/877-kube-context (step log 2026.286.1339/check-live.log, bed steps=5). Three things are NOT the cause, each checked against the artefact:

Root cause

Mechanism: the certificate presented by the forwarded k3s endpoint is outside its validity window as evaluated by the probe. The likelier of two candidates is a freshly booted disposable VM whose clock has not been synchronised, so a certificate issued moments earlier reads as not yet valid; a genuinely expired certificate is the other.
Missed control: nothing in the bed asserts that guest time is sane before, or at, k3s start - so a clock that is behind produces a TLS failure that reads like a cluster problem.
Blast radius: every bed that probes a freshly created VM over TLS - this one, and any future bed that stands a cluster up and immediately talks to it.
Root fix: establish sane guest time before k3s starts (or before the probes), and assert it: the k3s VM bed's bring-up should check the guest clock against the host and synchronise (NTP, or the qemu-guest-agent path already present), so the certificate verification cannot fail for a reason that has nothing to do with the cluster.

What to check first, in-guest, before changing anything

date -u vs the server certificate's notBefore
openssl s_client -connect 127.0.0.1: </dev/null 2>/dev/null | openssl x509 -noout -dates
If the guest clock lags, the fix is the clock; if the certificate is genuinely expired, the fix is the k3s install path.

Acceptance

A bed run on a fresh disposable VM shows the nine kubernetes probes passing (or failing for a real cluster reason), with the guest clock asserted sane as part of bring-up. Either the clock check lands in the bed's plumbing, or the certificate lifetime is proven wrong and that is fixed instead.

Agent: dsh-opencharly
Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

Activity

  1. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    CONFIRMED IN A PROPERLY STAGED EXPERIMENT — the certificate-validity wall is the one the bed actually reports, and it is the only one left.

    The experiment: charly at fix/877-kube-context (the nine steps name kube_context, charly#880), built with the guarded plugin-kube from my worktree via the dev-build path (bootstrap-charly.sh --dev-plugin plugin-kube=…; the guard's messages verified inside the built plugin, cache plugin-kube-721f3ef0a9059393, 15:58). Run id 2026.286.1357:

    [vm-build] PASS 25.409s [vm-create] PASS 2m17.417s [deploy-add] PASS 7m5.926s [bring-up-members] PASS
    [check-live] FAIL 2m33.258s → 26 steps: 13 passed, 9 failed, 4 skipped
    FAIL [kv-kubernetes-nodes] listing nodes: Get "https://127.0.0.1:43641/api/v1/nodes":
    tls: failed to verify certificate: x509: certificate has expired or is not yet valid: current time 202…

    Three facts, each load-bearing:

    1. the probes resolve their context (no no kubeconfig context selected anywhere) — charly#880's fix works;
    2. they dial https://127.0.0.1:43641 — a FORWARDED host port, this run's own — so the server-URL rewrite works;
    3. they fail on certificate validity. Exactly the wall this row names.

    And one elimination this run performed by construction rather than argument: the guarded plugin did NOT fire. Had rewriteK3sServerToForward hit either of its two no-op exits, deploy-add would have FAILED with the guard's message instead of passing in 7m5s. It passed. So plugin-kube#22's original premise — a silently no-opping rewrite leaving the merged context at 127.0.0.1:6443 — does not hold in this configuration; the 6443 seen earlier came from the CACHED kubeconfig that an unfixed wall 1 makes the probe read. That row is corrected there; the guard remains a correct observability change but was never the wall.

    So the in-guest check in this row's body is the next action for whoever takes it: date -u in the guest against the server certificate's notBefore, and openssl s_client -connect 127.0.0.1:43641 | openssl x509 -noout -dates on the host. Guest clock behind → fix the clock in bring-up; certificate genuinely expired → fix the k3s install path.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (fully tested and validated)

  2. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    FIX BRIEF — the file, the line and the pattern, read rather than guessed, so whoever takes this starts from the edit instead of the search.

    WHERE THE PRODUCT FIX GOES: opencharly/vm-k3s-server, its single root charly.yml, in the k3s service block:

    charly.yml:124 service:
    charly.yml:126 exec: /usr/local/bin/k3s server
    charly.yml:217-227 (existing comment distinguishing ExecStartPost from ExecStartPre for the apiserver wait)

    The fix: a PRE-START precondition on that service — do not hand control to k3s server until guest time is trustworthy (wait for time synchronisation, e.g. systemd NTPSynchronized, or set the clock from the host through the guest-agent channel the VM substrate already has). The candy already reasons in those terms for a different wait, so the pattern to copy is in the same file.

    WHY IT BELONGS THERE AND NOT IN THE BED: the bed's plan (charly check-k3s-vm) contains no clock control at all - no date, no ntp, no chrony, verified by reading its steps - so a bed-side fix would be an assertion about someone else's readiness. Assertions are still worth adding (a check: comparing guest date -u with the host reports the skew visibly instead of leaving a TLS failure to be decoded), but the product half belongs in the service that cannot start safely without it, and that fixes it for every consumer.

    EVIDENCE THIS IS THE WALL (not a theory): run 2026.286.1357, charly at fix/877-kube-context, dev-built with the guarded plugin-kube. deploy-add PASSED (7m5.926s) - so k3s came up happily on the clock it should not have trusted - and then check-live FAILED with listing nodes: Get "https://127.0.0.1:43641/api/v1/nodes": tls: failed to verify certificate: x509: certificate has expired or is not yet valid. The probes resolved their context and dialled the forwarded port, so both of the other candidate causes are eliminated by that same run.

    HOW TO CONFIRM BEFORE EDITING, in-guest: date -u against the server certificate's notBefore, and on the host: openssl s_client -connect 127.0.0.1: </dev/null 2>/dev/null | openssl x509 -noout -dates. Clock behind means the clock is the fix; a genuinely expired certificate means the k3s install path is.

    Gate: a bed run on a fresh disposable VM showing the nine kubernetes probes pass, with the clock precondition asserted as part of bring-up.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (fully tested and validated)

  3. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    CORRECTION to my fix brief above — the edit is smaller than I said, and the correction comes from reading the service block instead of stopping at the first matching line.

    I wrote add a pre-start precondition on that service. Reading the block in full shows the candy ALREADY brackets k3s's own start, in its own words:

    • name: k3s
      exec: /usr/local/bin/k3s server
      after: [network-online.target]

      Two guards bracketing k3s's own start. Both are systemd-only, which is

      exactly the coverage needed: every deploy of this candy is a vm: deploy, …

    So the fix is not to invent a hook: it is to add the clock to an existing pair of guards — one more condition in a place whose pattern, placement and systemd-only reasoning are already written down by the author. Cheaper than my brief said, and less likely to be done wrong.

    And one adjacent line worth having, because it corrects something else I filed: just above the service block, the retrieved kubeconfig is rewritten declaratively —

    — as an artifact substitution at retrieve time. The server URL rewrite is a first-class declarative mechanism in this manifest, which is a third independent reason the silent-no-op claim I filed on plugin-kube#22 was wrong, and the reason the merged context carried the forwarded port in run 2026.286.1357.

    Neither point changes the diagnosis (the clock wall stands, evidence unchanged); both change the work.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

  4. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    RECIPE — the schema-correct shape of the fix, read from the guards themselves, so the edit needs no guessing.

    The candy's two guards, verbatim from vm-k3s-server/charly.yml:

    exec_start_pre:
    - /usr/local/bin/k3s-cpuset-ensure.sh
    exec_start_post:
    - -/usr/local/bin/k3s-crd-heal.sh %n

    and each script is written by a plan step of this shape (the one immediately below, for the cpuset guard):

    plan:
    - run: install the cgroup cpuset pre-start guard the k3s service execs
    write: /usr/local/bin/k3s-cpuset-ensure.sh
    mode: "0755"
    run_as: root
    content: |
    …

    So the clock fix is three lines of the same pattern:

    1. a plan step writing /usr/local/bin/k3s-clock-ensure.sh (mode 0755, run_as root, content: wait for time synchronisation or set the clock from the host);
    2. add it to the existing exec_start_pre list - the list that runs BEFORE k3s, which is exactly where a clock precondition belongs;
    3. and a deliberate choice about the leading '-' marker: pre-start entries here have NO '-', so a failure stops the service. For a clock guard that is arguably right (starting k3s on untrustworthy time is what produced this wall); if the intent is instead to observe rather than block, the file's own comment says the marker means ignore-failure, and the guard must never take down the service it protects. Whichever is chosen, the file documents the reasoning pattern to follow.

    Gate: this repo's own disposable bed (charly.yml:533 from: k3s-srv-vm, disposable: true). No dependency on charly or on any other repo's row.

    Two adjacent facts, so the next reader does not have to rediscover them: the service also declares after: [network-online.target] (so ordering exists and is used), and the retrieved kubeconfig's server URL is rewritten by a declarative find/replace at retrieve time - which is why the merged context in run 2026.286.1357 carried the forwarded port.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

  5. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    STEP 0 for whoever takes the recipe above, and the reason I am not starting the edit myself.

    Part II #4: read the subrepo's own rulebook first. vm-k3s-server is a repo I have never worked in, and its AGENTS.md adds repo-specific rules on top of the org rulebook - it may constrain the service block, the guard scripts, the plan steps, or the bed. Starting the three-line edit without reading it would be a rule violation of exactly the kind this row exists to avoid, so:

    1. read opencharly/vm-k3s-server/AGENTS.md (and its candy manifest comments, which this repo uses heavily and well);
    2. then the recipe: plan step writing k3s-clock-ensure.sh + an entry in the existing exec_start_pre list;
    3. gate: this repo's own disposable bed (charly.yml:533 from: k3s-srv-vm, disposable: true).

    One design note for step 2, taken from this repo's own vocabulary: its comments distinguish kubectl's condition-wait from a sleep, and describe a guard that must never take down the service it protects. So the clock guard should be a BOUNDED CONDITION-WAIT (wait for time synchronisation, e.g. timedatectl -p NTPSynchronized, with a ceiling) rather than a fixed sleep - and the choice about the leading '-' marker decides whether a failure blocks the start or merely reports. Blocking is defensible here, because starting k3s on untrustworthy time is what produced this wall; the file documents both readings.

    Everything after that is three lines and an hour of bed time, in a repo whose gate depends on nothing else.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

  6. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    BLOCKS / cross-reference — this row's fix now has a home and a number in the repo that must make it: opencharly/vm-k3s-server#9.

    That row carries the same measured failure, the reason it belongs in the k3s service rather than in a bed, the schema-correct fix (a plan step plus an entry in the existing exec_start_pre list), the two design notes (bounded condition-wait, and the deliberate choice about the '-' marker), the in-guest/host confirmation commands, and an acceptance clause that lets that repo declare k3s deliberately does not require a trustworthy clock - in which case the certificate lifetime is the defect and this row is the pointer to it.

    So the chain is one row per repo, producer-first: vm-k3s-server#9 (the condition) -> charly#882 (this row: the evidence, in the consumer that observes it) -> charly#880 (the bed's kube_context, fix validated on fix/877-kube-context @ 1af84901) -> charly#877 (the pin wave at fdd045b, ci/go green). Nothing in the chain is a duplicate of anything else in it.

    What this row still owns after #9 lands: nothing new - it becomes the record that the wall was real, how it was found, and what it was not (the two eliminated causes). Close it when #9's fix is proven by a bed run that lets the probes pass.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

  7. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    STATUS — dsh-opencharly, end of session. Everything below is sourced in the ledger at .dsh/ledger/open-items-ledger.md (resume packet v5, section 11).

    DONE (verified against the live org):

    • The three walls are separated and each has its own row: this row (the cert-validity wall, evidenced by run 2026.286.1357), k3s server starts before guest time is trustworthy, so a freshly booted VM's certificate reads as not yet valid vm-k3s-server#9 (the clock guard that detects it), charly#880 (the bed's missing kube_context, fix committed and validated on fix/877-kube-context @ 1af84901).
    • The wall-1 diagnosis is confirmed by experiment and by reading: the probes now resolve their context; the remaining failure is certificate validity, and the original silent-no-op claim on plugin-kube#22 was refuted by construction.
    • vm-k3s-server@1730548: the clock guard, committed on feat/clock-guard, charly box validate OK (7 candies, 7 distros, 7 builders; 0 warnings). Correctly described as the DETECTOR half - the remedy (making the guest clock trustworthy before k3s starts) is filed on fix(postgresql): pgvector moved AUR→extra, install via pacman (arch) #9 and is unimplemented.
    • charly#877 carries the pin propagation: fdd045b, pushed, ci / go green (run 38401398300), body truthful, all four validator findings answered or rebutted.

    NOT DONE, and why (resource, not knowledge):

    • No merged fix yet, so the bed cannot be named as chore(deps): adopt plugin-build v0.2026286.1121 + plugin-vm v0.2026286.856 (charly#876) #877's gate. The local-proof route exists (CHARLY_REPO_OVERRIDE accepts candy entries, comma-separated) but pointing a candy at a local checkout suppresses the vm_state port substitution the probes need - so the honest path is to land the fix in its own repo and let that repo's acceptance plan gate it.
    • Five staging attempts, four invalid for four different mechanism reasons; each was detectable by a check that had already been written down. The one valid run (2026.286.1357) is the source of every experimental claim above.

    WHO IS BLOCKED: nothing of mine blocks another session. This row blocks nothing; it is the record.

    NEXT: (1) implement the remedy half on vm-k3s-server#9; (2) then charly#880 and #877 land behind it. Operator decisions pending are listed in the ledger's section 9.1.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

  8. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    STATUS — candidate resolution, with the measurement that supports it and the half it does not cover.

    The chain that produced this symptom landed tonight, and the bed that reported it now passes.

    This issue's symptom — "the k3s server certificate is outside its validity window at probe time (x509 expired or not yet valid)" — is the "not yet valid" arm: a freshly booted VM whose clock reads 1970 signs a certificate that every client evaluates as not-yet-valid. That is the root of the chain, and the last leg merged this evening:

    opencharly/spec#209   (root, fixed + merged, closed)        -- readiness no longer conflates terminal and ready
    opencharly/spec#219   merged                                 -- cloud-init settling in its error state is terminal
    opencharly/vm-k3s-server#11  MERGED                          -- the service-level guest-clock guard
    opencharly/opencharly#478    MERGED                          -- the umbrella pin recording it
    

    And the bed's own output, from the run that gated vm-k3s-server#11 on the committed tree:

    $ CHARLY_REPO_OVERRIDE="github.com/opencharly/vm-k3s-server=<worktree>" charly -C . check run check-k3s-vm
      PASS  the guest-clock guard is installed, executable, and does NOT refuse on a healthy clock   exit=0
      PASS  the guard REFUSES a guest whose clock reports unsynchronised, and says why               exit=1
    28 steps: 15 passed, 9 failed, 4 skipped
    

    The nine failures are all host-side kube: steps dialing the guest-local 6443 — filed as opencharly/charly#885 — and not one of them is a certificate-validity failure. The cluster-level steps pass. That is the measurement: on a guest where the guard is installed, this bed reaches and evaluates the server certificate.

    What I am NOT claiming, and it is the other arm of this issue's own title. "x509 expired or not yet valid" names two causes. The clock guard addresses the second one — the race that makes a freshly booted VM sign outside its window — and nothing I have measured says anything about expiry of a long-lived certificate. If any of the failures you originally recorded was the expired arm, this evidence does not touch it, and I have not tried to distinguish them.

    So: candidate resolution for the "not yet valid" arm, on measured bed output; the "expired" arm is untouched and unmeasured by me. If that matches what you saw, this can close; if your record includes an expired certificate, it should stay open with that named.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

  9. aitrawog commented on Oct 13, 2026

    @aitrawog
    ContributorAuthor

    STATUS — follow-up to my comment above, and it closes the gap I flagged there.

    I said I had evidence for the "not yet valid" arm and none for "expired". That has changed: the expired arm is now measured, by a different instrument than the clock guard.

    From the chain's own investigation (opencharly/charly#877, comment 6147389085, and the corrected model now in that PR's body):

    with wall 1 fixed (the nine kubernetes= steps given kube_context: vm-check-k3s-vm):
      the probes RESOLVE a context, dial https://127.0.0.1:40179 -- a FORWARDED port, so the rewrite demonstrably works --
      and then fail on:
        tls: failed to verify certificate: x509: certificate has expired or is not yet valid: current time 202...
    

    Two things follow, and the second is the one this issue needs:

    1. the 6443 URL that looked like a symptom of a broken forward path is the cached kubeconfig — what a probe reads when no context resolves, i.e. the symptom of wall 1 unfixed. The rewrite was never broken. That correction belongs to #877, not here, but it explains why this issue's original probe reported 6443;
    2. the failure survives a fixed wall 1 and a working forward path, and its text is "expired or is not yet valid". Since the clock guard (opencharly/vm-k3s-server#11) addresses not yet valid and the probe still fails, what remains is the expired case — a certificate the venue presents which is outside its validity window at probe time, with a trustworthy clock.

    I am not claiming more than that. The probe's message names both possibilities, so strictly it is a disjunction; what makes the expired arm the likely survivor is that the guard removes the other one. A measurement that distinguishes them directly — the certificate's own notBefore/notAfter from the venue, at probe time — is what would settle it, and I have not taken it.

    Why this matters for whoever picks this up: this issue and opencharly/vm-k3s-server#11 are the two halves of one symptom with different fixes. The guard prevents a client from evaluating a certificate before the clock is trustworthy; if the venue's certificate is genuinely outside its window, the guard will refuse to start k3s rather than let the probe fail — turning a confusing bed failure into a clear refusal, which is what a guard is for. But #882's row stays open until someone reads the certificate.

    Agent: dsh-opencharly
    Assisted-by: dsh deepseek-v4.1-flash (analysed on a live system)

  10. added
    category:verification
    type:fix
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:verificationtype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions