hub (unreleased): the end dates of the hub's own public names are read once a day; 14 days before, the operator is told (D85, R-1379)
The names are the setting HUB_OWN_NAMES; with no setting the hub makes no call. The setting is NOT in the manifest yet. Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
c616727d84
commit
c72ecf52b4
8 files changed
+616
-5
No files matched your search
@@ -822,7 +822,7 @@ another date or new names each hour. **Not proven:** on a box or a deployed hub;
|
||||
|
||||
| End date (block) | Who knows the date today | Could the product read it? | Proposed |
|
||||
|---|---|---|---|
|
||||
| The hub address's certificate, and the download, ISO, Gitea and website names (DH20) | anybody: readable from outside with no login | yes — the hub can open a TLS connection to its own five names once a day | **build next:** the same checker, a third source. Small. Not built tonight: it is a call from the hub to outside names, and the name list needs the operator's yes |
|
||||
| The hub address's certificate, and the download, ISO, Gitea and website names (DH20) | anybody: readable from outside with no login | yes — the hub can open a TLS connection to its own five names once a day | **BUILT, not released (2026-11-15; D85, `09` §3 decision 310): §12.3** |
|
||||
| A node's Tailscale key (DH30) | the Tailscale admin page; one date is in `operations/tailscale.md` | not from a box (the service does not run on two of three) | the operator's list |
|
||||
| The package signing keys (DB16) | measured: the soonest key in use ends 2029-01-15 | yes, by the root wrapper's facts read | no warning now; read again in the yearly end-dates pass |
|
||||
| The 30-day restore copy (DB24) | the box (the copy's own date) | yes | not an alarm: a page fact. The household's restore page shows the date already; nothing for the operator |
|
||||
@@ -835,3 +835,38 @@ another date or new names each hour. **Not proven:** on a box or a deployed hub;
|
||||
**A third source that is small and was left out on purpose:** the hub's own five public names (first row). It needs
|
||||
no secret, and its cost is one outbound connection a day; it waits for a yes because tonight's brief forbids outside
|
||||
calls and the list of names is a promise about what the hub watches.
|
||||
|
||||
### 12.3 The hub's own public names `[FACT — built, not released: hub `main` after v0.182.0, 2026-11-15]` (D85, `09` §3 decision 310, R-1379)
|
||||
|
||||
Once a day (06:40 Budapest, the daily job `own-names-check`) the hub opens one TLS connection to each of its own
|
||||
public names and reads the end date of the certificate that is served (`monitor.OwnNameChecker`). The third source
|
||||
beside an operator token and a box's web certificate; the same 14 days.
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| The names | **the setting `HUB_OWN_NAMES`** (the hub's manifest), never code and never a box's word: `host` or `host:port`, at most 16; an entry that is not a plain host name is refused and named in the start log. **No setting → no call.** The operator's list (D85): the hub address, the download address, the ISO address, the Gitea address, the website |
|
||||
| 14 days before the end | `hub_name_cert_ends_soon`, warning, operator-only, once per name; the text names the name, the days and the day |
|
||||
| The date passed and the certificate is still served | the same event once more, as an error |
|
||||
| A renewal | nothing to clear: the renewed certificate has a later date and is told only when that one comes near |
|
||||
| **A name that does not answer** | its OWN line, `hub_name_unreachable` (warning, operator-only, once while it lasts; `hub_name_reachable` clears it). **Never an end-date alarm:** „did not answer” says nothing about the certificate |
|
||||
| The run was skipped (the hub was down at 06:40) | the daily ledger tells it at the next start (`hub_daily_job_skipped`, `05` §16.6) |
|
||||
| Two names the same day | two mails: the cooldown is per name |
|
||||
| The read | no chain check, on purpose: a certificate that has ENDED must still give its date. Nothing is trusted from the connection and nothing is sent over it |
|
||||
|
||||
**For the release (not done tonight — no manifest change, no outside call):** add to `manifests/hub.yaml`, with the
|
||||
image tag, the lines
|
||||
|
||||
```
|
||||
- name: HUB_OWN_NAMES
|
||||
value: "hub.felhom.eu,files.felhom.eu,iso.felhom.eu,gitea.dooplex.hu,felhom.eu"
|
||||
```
|
||||
|
||||
and read the start line „own-names check: 5 name(s) are read daily…”. The five names are CC's reading of the list in
|
||||
the end-dates evidence (`audits/end-dates-list-2026-11-11/`, DH20: the hub, the download, the ISO, Gitea, the
|
||||
website); **the operator confirms the five at the deploy.** From inside the cluster the hub's own address may answer
|
||||
from the LAN side — the certificate is the same one.
|
||||
|
||||
**Not proven:** on a deployed hub; no outside name was read. Tests with a real TLS server on the test machine and with
|
||||
a certificate that has ended (`TestOwnNames_*`, `TestD85_*`); 18 mutations seen red
|
||||
(`audits/build-release-4-2026-11-15/C/redproof-hub-own-names.txt`).
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
== MUTATION: the warning comes at 7 days, not 14
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_WarnsOncePerNameFourteenDaysBefore (0.00s)
|
||||
own_names_test.go:78: want one warning for each of the two near names, got 1: [hub_name_cert_ends_soon|warning||hub|The certificate of the hub's own name iso.example.test ends in 3 day(s), on 2026-11-18. It renews by itself about
|
||||
--- FAIL: TestOwnNames_TheLineIsFourteenDays (0.00s)
|
||||
own_names_test.go:109: not told at 14 days: []
|
||||
== MUTATION: the same certificate is told at every run
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_WarnsOncePerNameFourteenDaysBefore (0.00s)
|
||||
own_names_test.go:94: the same certificate was told again the next day: [hub_name_cert_ends_soon|warning||hub|The certificate of the hub's own name hub.example.test ends in 13 day(s), on 2026-11-28. It renews by itself about 30 da
|
||||
== MUTATION: an ended certificate stays a warning
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_EndedIsAnErrorAndARenewalIsNewNews (0.00s)
|
||||
own_names_test.go:123: want one warning then one error for the ended certificate: [hub_name_cert_ends_soon|warning||hub|The certificate of the hub's own name a.example.test ends in 5 day(s), on 2026-11-20. It renews by itself abou
|
||||
== MUTATION: a renewed certificate near its own end is never told again
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_EndedIsAnErrorAndARenewalIsNewNews (0.00s)
|
||||
own_names_test.go:133: the renewed certificate's own end was not told: [hub_name_cert_ends_soon|warning||hub|The certificate of the hub's own name a.example.test ends in 5 day(s), on 2026-11-20. It renews by itself about 30 days b
|
||||
== MUTATION: a name that does not answer raises the end-date alarm
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_ANameThatDoesNotAnswerIsNotAnEndDateAlarm (0.00s)
|
||||
own_names_test.go:146: want ONE unreachable line for two runs, got 0: [hub_name_cert_ends_soon|warning||hub|The hub could not read the certificate of its own name down.example.test today: the name did not answer a TLS connection f
|
||||
== MUTATION: the unreachable line is told at every run
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_ANameThatDoesNotAnswerIsNotAnEndDateAlarm (0.00s)
|
||||
own_names_test.go:146: want ONE unreachable line for two runs, got 2: [hub_name_unreachable|warning||hub|The hub could not read the certificate of its own name down.example.test today: the name did not answer a TLS connection from
|
||||
== MUTATION: a dead name stops the names after it
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_ANameThatDoesNotAnswerIsNotAnEndDateAlarm (0.00s)
|
||||
own_names_test.go:154: the name after the dead one was not read: [hub_name_unreachable|warning||hub|The hub could not read the certificate of its own name down.example.test today: the name did not answer a TLS connection from the
|
||||
== MUTATION: the recovery keeps the unreachable mark
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_ANameThatDoesNotAnswerIsNotAnEndDateAlarm (0.00s)
|
||||
own_names_test.go:162: the recovery was not told once, or its mark stayed: events [hub_name_unreachable|warning||hub|The hub could not read the certificate of its own name down.example.test today: the name did not answer a TLS con
|
||||
== MUTATION: any text in the setting is dialled
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_OnlyPlainHostNamesFromTheSettingAreDialled (0.00s)
|
||||
own_names_test.go:176: names = ["hub.example.test" "iso.example.test:8443" "https://evil.example/x" "a..b" "user@host" "10.0.0.1"]
|
||||
== MUTATION: the list has no cap
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_OnlyPlainHostNamesFromTheSettingAreDialled (0.00s)
|
||||
own_names_test.go:191: the list is not capped at 16: 17 names, 0 refused
|
||||
== MUTATION: a name with a port is dialled on 443
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_OnlyPlainHostNamesFromTheSettingAreDialled (0.00s)
|
||||
own_names_test.go:187: dialled ["hub.example.test:443|hub.example.test" "iso.example.test:443|iso.example.test" "10.0.0.1:443|10.0.0.1"]
|
||||
== MUTATION: the read verifies the chain (an ended certificate gives no date)
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_DialCertEndReadsTheServedDate_AlsoOfAnEndedCertificate (0.02s)
|
||||
own_names_test.go:226: served end 2026-11-24 13:34:53 +0000 UTC, read 0001-01-01 00:00:00 +0000 UTC (err tls: failed to verify certificate: x509: certificate signed by unknown authority)
|
||||
== MUTATION: the read gives the time of the read, not the certificate's end
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestOwnNames_DialCertEndReadsTheServedDate_AlsoOfAnEndedCertificate (0.00s)
|
||||
own_names_test.go:226: served end 2026-11-24 13:34:56 +0000 UTC, read 2026-08-26 13:34:56 +0000 UTC (err <nil>)
|
||||
|
||||
13 mutations, 0 not a red-proof
|
||||
|
||||
## the wiring
|
||||
== MUTATION: the ledger does not watch the own-names job
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestD85_MainWiresTheOwnNamesCheck (0.00s)
|
||||
d85_wiring_test.go:28: main.go: want exactly one "\"deadline-check\", \"offsite-key-audit\", ownNamesJob)", found 0
|
||||
== MUTATION: the names are a list in code
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestD85_MainWiresTheOwnNamesCheck (0.00s)
|
||||
d85_wiring_test.go:28: main.go: want exactly one "monitor.ParseOwnNames(os.Getenv(\"HUB_OWN_NAMES\"))", found 0
|
||||
d85_wiring_test.go:34: main.go names hub.felhom.eu in code — the list of own names must come from the setting
|
||||
== MUTATION: the job is never started
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestD85_MainWiresTheOwnNamesCheck (0.00s)
|
||||
d85_wiring_test.go:28: main.go: want exactly one "go scheduleDaily(ctx, ownNamesJob, \"06:40\", ownNames.CheckOnce, logger)", found 0
|
||||
d85_wiring_test.go:40: the own-names job is not started inside the branch that has names — an empty setting would start it
|
||||
|
||||
3 mutations, 0 not a red-proof
|
||||
== MUTATION: the end-date event of a hub name can reach a household
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestD85_TheEventsAreOperatorOnlyAndPerName (0.00s)
|
||||
d85_wiring_test.go:48: hub_name_cert_ends_soon is not operator-only: a household could get a mail about the hub's own names
|
||||
== MUTATION: two names of one day share one cooldown
|
||||
RED on the mutant, GREEN on the real file
|
||||
--- FAIL: TestD85_TheEventsAreOperatorOnlyAndPerName (0.00s)
|
||||
d85_wiring_test.go:51: hub_name_cert_ends_soon has no per-name cooldown: the second name of the same day would be suppressed and never told again
|
||||
d85_wiring_test.go:51: hub_name_unreachable has no per-name cooldown: the second name of the same day would be suppressed and never told again
|
||||
d85_wiring_test.go:51: hub_name_reachable has no per-name cooldown: the second name of the same day would be suppressed and never told again
|
||||
|
||||
2 mutations, 0 not a red-proof
|
||||
@@ -1,5 +1,13 @@
|
||||
## Unreleased (after v0.182.0)
|
||||
|
||||
- **D85 (2026-11-15, R-1379; `08` §12.3): the hub reads the end dates of its own public names once a day.**
|
||||
`monitor.OwnNameChecker` + `monitor.DialCertEnd`; daily job `own-names-check` at 06:40 Budapest, watched by the daily
|
||||
ledger. 14 days before a name's certificate ends: `hub_name_cert_ends_soon` (warning; error once the date passed and
|
||||
the certificate is still served), once per name. A name that does not answer is its own line
|
||||
(`hub_name_unreachable` / `hub_name_reachable`), never an end-date alarm. All three are operator-only with a
|
||||
per-name cooldown. **The names are the setting `HUB_OWN_NAMES`; with no setting the hub makes no call. THE RELEASE
|
||||
MUST ADD THE SETTING TO `manifests/hub.yaml` (the lines are in `08` §12.3) — it is not in the manifest yet.**
|
||||
`notify.HasPerSubjectCooldown` (new, for the wiring test). Tests `TestOwnNames_*`, `TestD85_*`; 18 mutations seen red.
|
||||
- **Review fix 5 (2026-11-15), the hub's half — version skew.** (1) `POST /offsite/window-open` answers **400** on a
|
||||
body it cannot read (not JSON, or cut at the read limit); it used to decide the window on „count 0”, i.e. with the
|
||||
smallest cap, which then refused the honest plan. The empty body of the oldest boxes is still „no count”.
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/monitor"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/notify"
|
||||
)
|
||||
|
||||
// D85 (R-1379): the own-names check is a component with a seam; unit-green and never called is the inert-seam defect.
|
||||
// Read from main.go: the names come from the HUB_OWN_NAMES setting (never a literal list in code), the real dial is
|
||||
// handed in, the job runs on the daily scheduler under the name the ledger watches, and no setting means no job.
|
||||
func TestD85_MainWiresTheOwnNamesCheck(t *testing.T) {
|
||||
b, err := os.ReadFile("main.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
src := string(b)
|
||||
for _, want := range []string{
|
||||
`monitor.ParseOwnNames(os.Getenv("HUB_OWN_NAMES"))`,
|
||||
`monitor.NewOwnNameChecker(names, monitor.DialCertEnd, dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger)`,
|
||||
`go scheduleDaily(ctx, ownNamesJob, "06:40", ownNames.CheckOnce, logger)`,
|
||||
`"deadline-check", "offsite-key-audit", ownNamesJob)`,
|
||||
} {
|
||||
if strings.Count(src, want) != 1 {
|
||||
t.Errorf("main.go: want exactly one %q, found %d", want, strings.Count(src, want))
|
||||
}
|
||||
}
|
||||
// the list is configuration, not code: no public name of the hub is written in main.go
|
||||
for _, name := range []string{"hub.felhom.eu", "iso.felhom.eu", "files.felhom.eu"} {
|
||||
if strings.Contains(src, name) {
|
||||
t.Errorf("main.go names %s in code — the list of own names must come from the setting", name)
|
||||
}
|
||||
}
|
||||
// the job is started only inside the „names were given” branch
|
||||
at, job := strings.Index(src, `if len(names) > 0 {`+"\n\t\t\townNames :="), strings.Index(src, `go scheduleDaily(ctx, ownNamesJob`)
|
||||
if at < 0 || job < at {
|
||||
t.Error("the own-names job is not started inside the branch that has names — an empty setting would start it")
|
||||
}
|
||||
}
|
||||
|
||||
// The three events are the operator's only, and each NAME has its own mail (not one per type per hour).
|
||||
func TestD85_TheEventsAreOperatorOnlyAndPerName(t *testing.T) {
|
||||
for _, typ := range []string{monitor.EventHubNameEndsSoon, monitor.EventHubNameUnreachable, monitor.EventHubNameReachable} {
|
||||
if !notify.IsOperatorOnly(typ) {
|
||||
t.Errorf("%s is not operator-only: a household could get a mail about the hub's own names", typ)
|
||||
}
|
||||
if !notify.HasPerSubjectCooldown(typ) {
|
||||
t.Errorf("%s has no per-name cooldown: the second name of the same day would be suppressed and never told again", typ)
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-1
@@ -372,7 +372,7 @@ func main() {
|
||||
}
|
||||
// (1) a daily check whose slot passed while the hub was down — told at this start.
|
||||
dailyLedger = monitor.NewDailyLedger(dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger,
|
||||
"deadline-check", "offsite-key-audit")
|
||||
"deadline-check", "offsite-key-audit", ownNamesJob)
|
||||
|
||||
// MAIL-HOLD (internal/mailhold): while <data_dir>/MAIL-HOLD exists the hub sends NO e-mail on any path —
|
||||
// dispatcher, /notify, app-mail relay. A hub started on a restored database mailed households within a minute
|
||||
@@ -1049,6 +1049,22 @@ func main() {
|
||||
go scheduleDaily(ctx, "db-snapshot "+at, at, runSnapshot, logger)
|
||||
}
|
||||
|
||||
// R-1379 (D85, `09` §3 decision 310): the end dates of the hub's OWN public names, once a day. The names are the
|
||||
// operator's setting (HUB_OWN_NAMES in the manifest), never code: this is a call from the hub to outside names.
|
||||
// No setting → no call. A skipped run is told by the daily ledger.
|
||||
if names, bad := monitor.ParseOwnNames(os.Getenv("HUB_OWN_NAMES")); len(names) > 0 || len(bad) > 0 {
|
||||
if len(bad) > 0 {
|
||||
logger.Printf("[WARN] own-names check: %d entr(y/ies) of HUB_OWN_NAMES are not host names and are not read: %q", len(bad), bad)
|
||||
}
|
||||
if len(names) > 0 {
|
||||
ownNames := monitor.NewOwnNameChecker(names, monitor.DialCertEnd, dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger)
|
||||
logger.Printf("[INFO] own-names check: %d name(s) are read daily at 06:40 Budapest: %s", len(names), strings.Join(ownNames.Names(), ", "))
|
||||
go scheduleDaily(ctx, ownNamesJob, "06:40", ownNames.CheckOnce, logger)
|
||||
}
|
||||
} else {
|
||||
logger.Printf("[INFO] own-names check: HUB_OWN_NAMES is not set — the hub reads no certificate of its own names")
|
||||
}
|
||||
|
||||
// Backup deadline checker — runs daily at 05:00 Budapest
|
||||
go scheduleDaily(ctx, "deadline-check", "05:00", func() {
|
||||
monitor.CheckBackupDeadlines(dataStore, stalenessChecker, dispatcher.ProcessEvent, logger)
|
||||
@@ -1141,6 +1157,9 @@ var processStart = time.Now()
|
||||
// ledger is safe to call.
|
||||
var dailyLedger *monitor.DailyLedger
|
||||
|
||||
// ownNamesJob is the daily job that reads the hub's own names' end dates (D85); the ledger watches it by this name.
|
||||
const ownNamesJob = "own-names-check"
|
||||
|
||||
// scheduleDaily runs fn once daily at the given "HH:MM" time in Europe/Budapest.
|
||||
// It blocks until ctx is cancelled.
|
||||
func scheduleDaily(ctx context.Context, name, timeStr string, fn func(), logger *log.Logger) {
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// OwnNameChecker (R-1379, D85, `09` §3 decision 310; `08-alarm-ladder.md` §12.3) reads, once a day, the end date of
|
||||
// the certificate that each of the hub's OWN public names serves, and warns the operator 14 days before. The third
|
||||
// source beside an operator token and a box's web certificate (EndDateChecker): if the hub's own name ends, every box
|
||||
// fails to report and the hub then sees all of them as silent — and nothing in the product warned before that day.
|
||||
//
|
||||
// The names are CONFIGURATION (the hub's HUB_OWN_NAMES setting), never code and never a box's word: this checker
|
||||
// opens connections from the hub to outside names, so the list is the operator's.
|
||||
//
|
||||
// Two things, kept apart:
|
||||
// - an END DATE within 14 days (or passed): the operator-only alarm `hub_name_cert_ends_soon`, told once per
|
||||
// (name, stage); a renewed certificate has a later date and is told again only when that one comes near.
|
||||
// - a name that CANNOT BE REACHED: its own operator-only line `hub_name_unreachable`, told once per name while it
|
||||
// lasts and cleared by the first good read (`hub_name_reachable`). It is never an end-date alarm: „the name did
|
||||
// not answer” says nothing about its certificate.
|
||||
//
|
||||
// The certificate is read whatever its state (no chain check): a certificate that has ENDED must still give its date.
|
||||
// State: the hub's time-by-key settings. Pinned by TestOwnNames_*.
|
||||
type OwnNameChecker struct {
|
||||
names []string
|
||||
dial func(ctx context.Context, addr, serverName string) (notAfter time.Time, err error)
|
||||
told func(key string) time.Time
|
||||
setTold func(key string, t time.Time) error
|
||||
onEvent EventNotifyFunc
|
||||
logger *log.Logger
|
||||
now func() time.Time
|
||||
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
const (
|
||||
EventHubNameEndsSoon = "hub_name_cert_ends_soon"
|
||||
EventHubNameUnreachable = "hub_name_unreachable"
|
||||
EventHubNameReachable = "hub_name_reachable"
|
||||
ownNamesMax = 16
|
||||
ownNameDialTimeout = 15 * time.Second
|
||||
)
|
||||
|
||||
// a host name, with an optional port. Nothing else from the setting is ever dialled.
|
||||
var ownNameRe = regexp.MustCompile(`^[a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?(:[0-9]{1,5})?$`)
|
||||
|
||||
// ParseOwnNames reads the setting: names separated by commas or spaces, each `host` or `host:port`. A name that is
|
||||
// not a plain host name is dropped and returned in `bad`, so the start line can say so. At most ownNamesMax names.
|
||||
func ParseOwnNames(setting string) (names, bad []string) {
|
||||
seen := map[string]bool{}
|
||||
for _, f := range strings.FieldsFunc(setting, func(r rune) bool { return r == ',' || r == ' ' || r == '\n' || r == '\t' }) {
|
||||
n := strings.ToLower(strings.TrimSpace(f))
|
||||
if n == "" || seen[n] {
|
||||
continue
|
||||
}
|
||||
seen[n] = true
|
||||
if !ownNameRe.MatchString(n) || strings.Contains(n, "..") || len(names) >= ownNamesMax {
|
||||
bad = append(bad, f)
|
||||
continue
|
||||
}
|
||||
names = append(names, n)
|
||||
}
|
||||
return names, bad
|
||||
}
|
||||
|
||||
// DialCertEnd is the real read: one TLS handshake, the leaf's end date, nothing sent after it.
|
||||
func DialCertEnd(ctx context.Context, addr, serverName string) (time.Time, error) {
|
||||
d := &tls.Dialer{NetDialer: &net.Dialer{Timeout: ownNameDialTimeout},
|
||||
// No chain check ON PURPOSE: the date of a certificate that has already ended is exactly what must be read.
|
||||
// Nothing is trusted from this connection and nothing is sent over it.
|
||||
Config: &tls.Config{ServerName: serverName, InsecureSkipVerify: true, MinVersion: tls.VersionTLS12}}
|
||||
conn, err := d.DialContext(ctx, "tcp", addr)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
defer conn.Close()
|
||||
certs := conn.(*tls.Conn).ConnectionState().PeerCertificates
|
||||
if len(certs) == 0 {
|
||||
return time.Time{}, fmt.Errorf("the name served no certificate")
|
||||
}
|
||||
return certs[0].NotAfter, nil
|
||||
}
|
||||
|
||||
func NewOwnNameChecker(names []string, dial func(context.Context, string, string) (time.Time, error),
|
||||
told func(string) time.Time, setTold func(string, time.Time) error, onEvent EventNotifyFunc, logger *log.Logger) *OwnNameChecker {
|
||||
return &OwnNameChecker{names: names, dial: dial, told: told, setTold: setTold, onEvent: onEvent, logger: logger, now: time.Now}
|
||||
}
|
||||
|
||||
// Names is the list the checker reads (for the start line).
|
||||
func (c *OwnNameChecker) Names() []string { return append([]string(nil), c.names...) }
|
||||
|
||||
// CheckOnce reads every name once. It is the body of the hub's daily job „own-names-check” (the daily ledger tells
|
||||
// the operator when that job was skipped).
|
||||
func (c *OwnNameChecker) CheckOnce() {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
now := c.now()
|
||||
warn := time.Duration(endDateWarnDays) * 24 * time.Hour
|
||||
for _, name := range c.names {
|
||||
host, addr := name, name
|
||||
if h, _, err := net.SplitHostPort(name); err == nil {
|
||||
host = h
|
||||
} else {
|
||||
addr = net.JoinHostPort(name, "443")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), ownNameDialTimeout)
|
||||
end, err := c.dial(ctx, addr, host)
|
||||
cancel()
|
||||
downKey := "own_name:unreachable:" + name
|
||||
if err != nil {
|
||||
c.logger.Printf("[WARN] own-names check: %s did not answer: %v", name, err)
|
||||
if c.told(downKey).IsZero() {
|
||||
_ = c.setTold(downKey, now)
|
||||
details, _ := json.Marshal(map[string]any{"name": name, "subject": name})
|
||||
c.onEvent("", EventHubNameUnreachable, "warning",
|
||||
fmt.Sprintf("The hub could not read the certificate of its own name %s today: the name did not answer a TLS connection from the hub. This is NOT an end-date warning — the end date of that certificate is not known today. Do: open the address in a browser; if it answers, the fault is on the hub's way out.", name),
|
||||
string(details), "hub")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !c.told(downKey).IsZero() {
|
||||
_ = c.setTold(downKey, time.Time{}) // a zero time deletes the mark
|
||||
details, _ := json.Marshal(map[string]any{"name": name, "subject": name})
|
||||
c.onEvent("", EventHubNameReachable, "info", fmt.Sprintf("The hub's own name %s answers again; its certificate ends on %s.", name, end.UTC().Format("2006-01-02")), string(details), "hub")
|
||||
}
|
||||
left := end.Sub(now)
|
||||
stage := ""
|
||||
switch {
|
||||
case left > warn:
|
||||
case left > 0:
|
||||
stage = "soon"
|
||||
default:
|
||||
stage = "ended"
|
||||
}
|
||||
c.logger.Printf("[INFO] own-names check: %s ends %s (%d day(s) left)", name, end.UTC().Format("2006-01-02"), int(left/(24*time.Hour)))
|
||||
if stage == "" {
|
||||
continue
|
||||
}
|
||||
// The mark holds the END DATE that was told: the same certificate is told once per stage; a certificate with a
|
||||
// later date (a renewal that is itself near its end, which does not happen with a 90-day certificate) again.
|
||||
k := "end_date:hub_name:" + name + ":" + stage
|
||||
if toldEnd := c.told(k); !toldEnd.IsZero() && !end.After(toldEnd.Add(24*time.Hour)) {
|
||||
continue
|
||||
}
|
||||
_ = c.setTold(k, end)
|
||||
sev, msg := "warning", fmt.Sprintf("The certificate of the hub's own name %s ends in %d day(s), on %s. It renews by itself about 30 days before the end, so the renewal has FAILED for about two weeks. On the end date every box that uses this name stops (for the hub's address: no report, no alarm, no update). Do: read the certificate's state on the machine that serves the name.",
|
||||
name, int(left/(24*time.Hour)), end.UTC().Format("2006-01-02"))
|
||||
if stage == "ended" {
|
||||
sev, msg = "error", fmt.Sprintf("The certificate of the hub's own name %s ENDED on %s and is still served: every box that uses this name fails now. Do: renew the certificate on the machine that serves the name.",
|
||||
name, end.UTC().Format("2006-01-02"))
|
||||
}
|
||||
details, _ := json.Marshal(map[string]any{"name": name, "not_after": end.UTC().Format(time.RFC3339), "stage": stage, "subject": name + ":" + stage})
|
||||
c.onEvent("", EventHubNameEndsSoon, sev, msg, string(details), "hub")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
"crypto/rand"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"math/big"
|
||||
"net"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ownBox is the checker with the hub's settings in a map and its events in a list.
|
||||
type ownBox struct {
|
||||
marks map[string]time.Time
|
||||
events []string // "type|severity|message|details"
|
||||
ends map[string]time.Time
|
||||
down map[string]bool
|
||||
dials []string
|
||||
now time.Time
|
||||
c *OwnNameChecker
|
||||
}
|
||||
|
||||
func newOwnBox(names ...string) *ownBox {
|
||||
b := &ownBox{marks: map[string]time.Time{}, ends: map[string]time.Time{}, down: map[string]bool{},
|
||||
now: time.Date(2026, 11, 15, 6, 0, 0, 0, time.UTC)}
|
||||
b.c = NewOwnNameChecker(names,
|
||||
func(_ context.Context, addr, server string) (time.Time, error) {
|
||||
b.dials = append(b.dials, addr+"|"+server)
|
||||
if b.down[server] {
|
||||
return time.Time{}, errors.New("dial tcp: connection refused")
|
||||
}
|
||||
return b.ends[server], nil
|
||||
},
|
||||
func(k string) time.Time { return b.marks[k] },
|
||||
func(k string, t time.Time) error {
|
||||
if t.IsZero() {
|
||||
delete(b.marks, k)
|
||||
} else {
|
||||
b.marks[k] = t
|
||||
}
|
||||
return nil
|
||||
},
|
||||
func(customer, typ, sev, msg, details, source string) {
|
||||
b.events = append(b.events, typ+"|"+sev+"|"+customer+"|"+source+"|"+msg+"|"+details)
|
||||
}, log.New(io.Discard, "", 0))
|
||||
b.c.now = func() time.Time { return b.now }
|
||||
return b
|
||||
}
|
||||
|
||||
func (b *ownBox) count(typ string) int {
|
||||
n := 0
|
||||
for _, e := range b.events {
|
||||
if strings.HasPrefix(e, typ+"|") {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// The consequence: 14 days before a name's certificate ends the operator gets ONE warning that names the name and
|
||||
// the day; a name that is far from its end gets none; the next day's run does not tell it again.
|
||||
func TestOwnNames_WarnsOncePerNameFourteenDaysBefore(t *testing.T) {
|
||||
b := newOwnBox("hub.example.test", "iso.example.test", "far.example.test")
|
||||
b.ends["hub.example.test"] = b.now.Add(13*24*time.Hour + time.Hour)
|
||||
b.ends["iso.example.test"] = b.now.Add(3 * 24 * time.Hour)
|
||||
b.ends["far.example.test"] = b.now.Add(60 * 24 * time.Hour)
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameEndsSoon) != 2 {
|
||||
t.Fatalf("want one warning for each of the two near names, got %d: %v", b.count(EventHubNameEndsSoon), b.events)
|
||||
}
|
||||
for _, e := range b.events {
|
||||
if strings.Contains(e, "far.example.test") {
|
||||
t.Fatalf("a name 60 days from its end was told: %s", e)
|
||||
}
|
||||
if !strings.HasPrefix(e, EventHubNameEndsSoon+"|warning||hub|") {
|
||||
t.Fatalf("not an operator-level warning from the hub with no household: %s", e)
|
||||
}
|
||||
}
|
||||
if !strings.Contains(b.events[0], "hub.example.test ends in 13 day(s), on 2026-11-28") || !strings.Contains(b.events[0], `"subject":"hub.example.test:soon"`) {
|
||||
t.Fatalf("the warning does not name the name, the days and the day, or has no subject: %s", b.events[0])
|
||||
}
|
||||
b.now = b.now.Add(24 * time.Hour)
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameEndsSoon) != 2 {
|
||||
t.Fatalf("the same certificate was told again the next day: %v", b.events)
|
||||
}
|
||||
}
|
||||
|
||||
// Exactly on the line: 14 days and one second is not told; 14 days is.
|
||||
func TestOwnNames_TheLineIsFourteenDays(t *testing.T) {
|
||||
b := newOwnBox("a.example.test")
|
||||
b.ends["a.example.test"] = b.now.Add(14*24*time.Hour + time.Second)
|
||||
b.c.CheckOnce()
|
||||
if len(b.events) != 0 {
|
||||
t.Fatalf("told at 14 days and one second: %v", b.events)
|
||||
}
|
||||
b.ends["a.example.test"] = b.now.Add(14 * 24 * time.Hour)
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameEndsSoon) != 1 {
|
||||
t.Fatalf("not told at 14 days: %v", b.events)
|
||||
}
|
||||
}
|
||||
|
||||
// A certificate that has ended and is still served is told once more, as an ERROR — and a renewal ends the matter:
|
||||
// the renewed certificate is told only when IT comes near its end.
|
||||
func TestOwnNames_EndedIsAnErrorAndARenewalIsNewNews(t *testing.T) {
|
||||
b := newOwnBox("a.example.test")
|
||||
b.ends["a.example.test"] = b.now.Add(5 * 24 * time.Hour)
|
||||
b.c.CheckOnce()
|
||||
b.now = b.now.Add(6 * 24 * time.Hour) // the date passed, the same certificate is served
|
||||
b.c.CheckOnce()
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameEndsSoon) != 2 || !strings.HasPrefix(b.events[1], EventHubNameEndsSoon+"|error|") || !strings.Contains(b.events[1], "ENDED on 2026-11-20") {
|
||||
t.Fatalf("want one warning then one error for the ended certificate: %v", b.events)
|
||||
}
|
||||
b.ends["a.example.test"] = b.now.Add(90 * 24 * time.Hour) // renewed
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameEndsSoon) != 2 {
|
||||
t.Fatalf("a renewed certificate was told: %v", b.events)
|
||||
}
|
||||
b.now = b.now.Add(80 * 24 * time.Hour) // the RENEWED one is 10 days from its end
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameEndsSoon) != 3 || !strings.Contains(b.events[2], "|warning|") {
|
||||
t.Fatalf("the renewed certificate's own end was not told: %v", b.events)
|
||||
}
|
||||
}
|
||||
|
||||
// A name that does not answer is its OWN line — never an end-date alarm — told once while it lasts, and cleared by
|
||||
// the first good read. And a name that is down does not stop the names after it.
|
||||
func TestOwnNames_ANameThatDoesNotAnswerIsNotAnEndDateAlarm(t *testing.T) {
|
||||
b := newOwnBox("down.example.test", "near.example.test")
|
||||
b.down["down.example.test"] = true
|
||||
b.ends["near.example.test"] = b.now.Add(2 * 24 * time.Hour)
|
||||
b.c.CheckOnce()
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameUnreachable) != 1 {
|
||||
t.Fatalf("want ONE unreachable line for two runs, got %d: %v", b.count(EventHubNameUnreachable), b.events)
|
||||
}
|
||||
for _, e := range b.events {
|
||||
if strings.HasPrefix(e, EventHubNameEndsSoon) && strings.Contains(e, "down.example.test") {
|
||||
t.Fatalf("a name that did not answer raised an END-DATE alarm: %s", e)
|
||||
}
|
||||
}
|
||||
if b.count(EventHubNameEndsSoon) != 1 {
|
||||
t.Fatalf("the name after the dead one was not read: %v", b.events)
|
||||
}
|
||||
// it answers again, with a certificate far from its end: one „answers again”, no end-date alarm, and a later
|
||||
// outage is told again
|
||||
b.down["down.example.test"] = false
|
||||
b.ends["down.example.test"] = b.now.Add(60 * 24 * time.Hour)
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameReachable) != 1 || len(b.marks) != 1 {
|
||||
t.Fatalf("the recovery was not told once, or its mark stayed: events %v marks %v", b.events, b.marks)
|
||||
}
|
||||
b.down["down.example.test"] = true
|
||||
b.c.CheckOnce()
|
||||
if b.count(EventHubNameUnreachable) != 2 {
|
||||
t.Fatalf("a second outage was not told: %v", b.events)
|
||||
}
|
||||
}
|
||||
|
||||
// The setting is the only source of names, and only plain host names are ever dialled: `host` goes to port 443 with
|
||||
// the host as the TLS name; `host:port` keeps its port.
|
||||
func TestOwnNames_OnlyPlainHostNamesFromTheSettingAreDialled(t *testing.T) {
|
||||
names, bad := ParseOwnNames("hub.example.test, ISO.example.test:8443 ,https://evil.example/x, a..b, user@host, ,hub.example.test, 10.0.0.1")
|
||||
if strings.Join(names, " ") != "hub.example.test iso.example.test:8443 10.0.0.1" {
|
||||
t.Fatalf("names = %q", names)
|
||||
}
|
||||
if len(bad) != 3 {
|
||||
t.Fatalf("want three refused entries (a URL, a double dot, a user@), got %q", bad)
|
||||
}
|
||||
b := newOwnBox(names...)
|
||||
for _, n := range []string{"hub.example.test", "iso.example.test", "10.0.0.1"} {
|
||||
b.ends[n] = b.now.Add(60 * 24 * time.Hour)
|
||||
}
|
||||
b.c.CheckOnce()
|
||||
if strings.Join(b.dials, " ") != "hub.example.test:443|hub.example.test iso.example.test:8443|iso.example.test 10.0.0.1:443|10.0.0.1" {
|
||||
t.Fatalf("dialled %q", b.dials)
|
||||
}
|
||||
many, bad2 := ParseOwnNames(strings.Repeat("a.example.test b.example.test c.example.test ", 1) + "d1.t d2.t d3.t d4.t d5.t d6.t d7.t d8.t d9.t d10.t d11.t d12.t d13.t d14.t")
|
||||
if len(many) != 16 || len(bad2) != 1 {
|
||||
t.Fatalf("the list is not capped at 16: %d names, %d refused", len(many), len(bad2))
|
||||
}
|
||||
if n, _ := ParseOwnNames(""); len(n) != 0 {
|
||||
t.Fatalf("an empty setting gave names: %q", n)
|
||||
}
|
||||
}
|
||||
|
||||
// The real read against a real TLS server on this machine: the end date that comes back is the served certificate's
|
||||
// — also for a certificate that has ALREADY ended (a verified handshake would refuse it and give no date).
|
||||
func TestOwnNames_DialCertEndReadsTheServedDate_AlsoOfAnEndedCertificate(t *testing.T) {
|
||||
for _, end := range []time.Time{time.Now().Add(9 * 24 * time.Hour), time.Now().Add(-3 * 24 * time.Hour)} {
|
||||
end = end.UTC().Truncate(time.Second)
|
||||
key, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
tmpl := &x509.Certificate{SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "own.example.test"},
|
||||
NotBefore: end.Add(-90 * 24 * time.Hour), NotAfter: end, DNSNames: []string{"own.example.test"}}
|
||||
der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ln, err := tls.Listen("tcp", "127.0.0.1:0", &tls.Config{Certificates: []tls.Certificate{{Certificate: [][]byte{der}, PrivateKey: key}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go func() { _ = c.(*tls.Conn).Handshake(); c.Close() }()
|
||||
}
|
||||
}()
|
||||
got, err := DialCertEnd(context.Background(), ln.Addr().String(), "own.example.test")
|
||||
ln.Close()
|
||||
if err != nil || !got.Equal(end) {
|
||||
t.Fatalf("served end %s, read %s (err %v)", end, got, err)
|
||||
}
|
||||
}
|
||||
// nothing listens: an error, not a date
|
||||
ln, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
addr := ln.Addr().String()
|
||||
ln.Close()
|
||||
if got, err := DialCertEnd(context.Background(), addr, "own.example.test"); err == nil {
|
||||
t.Fatalf("a dead address gave a date: %s", got)
|
||||
}
|
||||
}
|
||||
@@ -644,6 +644,8 @@ var perSubjectCooldownEvents = map[string]bool{
|
||||
"proxmox_trust_problem": true,
|
||||
// D72/D84: one refusal per app (details `subject` = the app) — two apps refused in one window are two mails.
|
||||
"offsite_ended_app_refused": true,
|
||||
// R-1379 (D85): one line per NAME of the hub's own (details `subject`) — two names that end the same week are two mails.
|
||||
"hub_name_cert_ends_soon": true, "hub_name_unreachable": true, "hub_name_reachable": true,
|
||||
// one never-seen app is one mail (subject = the app); one window's large request is one mail (subject = the window)
|
||||
"offsite_end_claim_unseen": true,
|
||||
"offsite_ended_large_agreement": true,
|
||||
@@ -1073,9 +1075,13 @@ var operatorOnlyEvents = map[string]bool{
|
||||
// R-1379 (D77): an end date 14 days away — the operator's to act on.
|
||||
"operator_token_ends_soon": true,
|
||||
"web_cert_ends_soon": true,
|
||||
"box_clock_wrong": true, // R-1384: a box's clock against the hub's — the operator's to read
|
||||
"box_clock_ok": true,
|
||||
"proxmox_trust_ok": true,
|
||||
// R-1379 (D85): the hub's own public names — never a household's matter.
|
||||
"hub_name_cert_ends_soon": true,
|
||||
"hub_name_unreachable": true,
|
||||
"hub_name_reachable": true,
|
||||
"box_clock_wrong": true, // R-1384: a box's clock against the hub's — the operator's to read
|
||||
"box_clock_ok": true,
|
||||
"proxmox_trust_ok": true,
|
||||
// R-836 (hub v0.143.0): the kernel lane's step results and the day-before notice's own record — operator facts. The
|
||||
// household's word is the day-before mail itself (SendKernelNotice), never these events.
|
||||
"os_kernel_step": true,
|
||||
@@ -1208,6 +1214,9 @@ var operatorOnlyEvents = map[string]bool{
|
||||
// Read-only: the register itself stays unexported so nothing can widen it at runtime.
|
||||
func IsOperatorOnly(eventType string) bool { return operatorOnlyEvents[eventType] }
|
||||
|
||||
// HasPerSubjectCooldown reports whether an event type's operator cooldown is keyed per thing (details `subject`).
|
||||
func HasPerSubjectCooldown(eventType string) bool { return perSubjectCooldownEvents[eventType] }
|
||||
|
||||
// householdFreeableStorage is the storage KINDS (the agent's reported vocabulary, `storage_type` in the event's
|
||||
// details) on which a household can free space by itself: a drive it plugged in or was given (`usb`, `local-dir`) and
|
||||
// its own network storage (`nfs`, `cifs`). D68 (`09` §3 decision 287, 2026-11-10).
|
||||
|
||||
Reference in new issue
Block a user