hub v0.181.0 (not deployed): root files are 'behind' only when the files differ (R-1392, decision 304); Go 1.27.4 (R-1391)
gates / gates (push) Successful in 1m55s
gates / gates (push) Successful in 1m55s
This commit is contained in:
1 parent
561a4d98e9
commit
83316fc986
15 files changed
+442
-11
No files matched your search
@@ -112,6 +112,7 @@
|
||||
| `(*Store).GetOperatorPasswordHash` / `SetOperatorPasswordHash` | hub/internal/store/store.go (~L1350) | `() string` / `(hash) error` | The DB-backed (hub_settings) operator login password override | Read via `Server.effectivePasswordHash()`, not directly. "" = no override (config seed authoritative). Store the bcrypt hash, never the plaintext. |
|
||||
| `(*Server).handleSetArtifacts` + `resolveArtifactSHA` | hub/internal/web/configs.go (~L644 / ~L680) | `POST /configuration/artifacts` | Operator UI to vouch artifact versions | With a Gitea client the sha is fetched AUTHORITATIVELY (submitted sha ignored); fetch failure refuses the save. Manual sha only in the no-creds fallback. |
|
||||
| `(*gitea.Client).ListVersions` / `FileSHA256` | hub/internal/gitea/gitea.go (~L47 / ~L72) | `(ctx, pkg) ([]string, error)` / `(ctx, pkg, ver, file)` | Read-only Gitea generic-package metadata | sha comes from package metadata — artifact bytes are never downloaded. Newest-semver-first sort. |
|
||||
| `(*gitea.Client).FetchFile` + `(*bundlefiles.Resolver).Same` / `bundlefiles.FilesDigest` | hub/internal/gitea/gitea.go, hub/internal/bundlefiles/bundlefiles.go | `(ctx, pkg, ver, file, maxBytes) ([]byte, error)` / `(boxVer, boxSHA, vouchedVer, vouchedSHA) bool` | „Do two config bundles hold the same files under another label?” (R-1392) | The one place the hub downloads artifact bytes. Bytes count only when they hash to a sha256 the caller already trusts; anything unread answers false (the old „behind” verdict). Cached per sha256; a failed read is retried after 10 min. |
|
||||
| `(*Server).artifactChoices` | hub/internal/web/server.go (~L155) | `(ctx, pkg, file) []artifactChoice` | Version+sha dropdown data | nil Gitea client / unreachable → nil → UI degrades to manual entry. One bad version drops itself, not the list. |
|
||||
| `(*Handler).handleArtifactManifest` | hub/internal/api/handler.go (~L1550) | `GET /api/v1/artifacts/{id}` | Serving the vouched set to the bootstrap script | Auth mirrors handleConfigRetrieve exactly. Unset manifest = empty fields, not an error. |
|
||||
| `normalizeFloorInput` / `normalizeSHA256` | hub/internal/web/configs.go (~L27 / ~L627) | `(raw string) (string, bool)` | Validating operator-typed versions / shas | Empty string is VALID (means "clear"). Reuse for any new version/sha form field. |
|
||||
|
||||
@@ -354,6 +354,15 @@ an installed box by reinstall or by hand.
|
||||
operator (`runbooks/config-bundle.md`).
|
||||
- **Visibility.** System page "Root files" column; alarm `os_config_bundle_behind` after 7 days
|
||||
(`OS_ALARM_BUNDLE_BEHIND_AFTER`; decided by CC unattended — operator may reverse).
|
||||
- **„Behind” is judged on the FILES, not on the bundle's label (hub v0.181.0, R-1392, `09` §3 decision 304).** The
|
||||
bundle carries its `agent_version`, so its sha256 moves with every agent release — also when `configs/` did not
|
||||
change and the release sends no bundle job (measured: 0.172.1 → 0.173.0, 32 files equal, two sha256s). When the box's
|
||||
bundle sha256 differs from the vouched one, the hub fetches both bundles from the package registry, accepts each
|
||||
only if its bytes hash to the sha256 already trusted (the vouched one; the one the box reports), and compares
|
||||
everything but the label. Equal → not behind: no amber, no alarm, the „behind since” mark is cleared. Anything it
|
||||
cannot read, verify or parse → the old verdict (behind). `hub/internal/bundlefiles`; pinned by `TestSame*`,
|
||||
`TestBundleAlarm_R1392_*`, `TestBundleCell_R1392`. **Not covered:** a box whose bundle version was pruned from the
|
||||
registry reads „behind” (true enough: it is older than the kept versions).
|
||||
- **Measured live** (`audits/r840-config-bundle-2026-10-04/partB/`): both demo boxes had every file equal to the release
|
||||
except `felhom-os-apply`; after the bootstrap the signed bundle wrote 0 of 22 (21 same, 1 setting kept), self-check
|
||||
ok, capability probe 71/71. demo-hp: a wrong-sha job refused (nothing changed); a bundle with one deliberate change
|
||||
|
||||
@@ -1,3 +1,27 @@
|
||||
## v0.181.0 (2026-11-14) — R-1392: root files are „behind” only when the FILES differ; Go 1.27.4 (R-1391) — NOT DEPLOYED YET
|
||||
|
||||
- **The defect (R-1392, found 2026-11-14).** The agent's config bundle carries its `agent_version`, so its sha256
|
||||
moves with every agent release. The hub compared that one sha256. Agent 0.173.0 changed no root file and sent no
|
||||
bundle job, so all three test boxes read „root files behind the vouched agent's” from the vouch (2026-11-10), and
|
||||
`os_config_bundle_behind` was due for each on 2026-11-17 — about files that were the vouched ones.
|
||||
- **The ruling (`09` §3 decision 304, D81 = yes).** The hub must not call vouched files „behind”.
|
||||
- **The fix (`internal/bundlefiles`, new).** When the two sha256s differ, the hub fetches both bundles from the package
|
||||
registry (`gitea.Client.FetchFile`, new, 4 MB cap), accepts each only if its bytes hash to the sha256 already
|
||||
trusted, and compares everything but `agent_version`. Equal → not behind, for the alarm
|
||||
(`osupdates.Service.SameBundleFiles`) and for the System page's cell (`bundleCell`, whose title then says „the same
|
||||
files … only the label differs”). A verified answer is cached for the process's life; a failed read is asked again
|
||||
after 10 minutes. A version or sha256 that does not look like one never reaches the registry.
|
||||
- **Fail direction.** No registry, a read error, a sha256 mismatch, no `files` list → „not the same” → the old verdict.
|
||||
- **Tests, each seen red** (the fix line switched off): `TestBundleAlarm_R1392_SameFilesNewLabel` (no alarm after
|
||||
8 days, the mark cleared; different files still alarm), `TestBundleAlarm_R1392_NeverGotABundleStillAlarms` (through
|
||||
the real resolver), `TestBundleCell_R1392`; `bundlefiles`: `TestSame`, `TestSame_UnverifiedBytesNeverCount`,
|
||||
`TestSame_RegistryAway`, `TestFilesDigest_NoFilesIsAnError`. The two real bundles (0.172.1, 0.173.0) were compared by
|
||||
hand: 32 files, equal but for the label.
|
||||
- **Go 1.27.4 (R-1391, GO-2026-6859).** `go.mod` and the builder image
|
||||
(`golang:1.27.4-alpine3.24@sha256:0a5f7fe7…`). Reach, read 2026-11-14: the hub has no `MaxBytesReader`,
|
||||
`MaxBytesHandler` or `TimeoutHandler` at all, so no hub handler matches the advisory's crash pattern.
|
||||
- Design: `documentation/architecture/11-os-updates.md` §5.4.2.
|
||||
|
||||
## v0.180.0 (2026-11-10) — D68: a full host disk is the operator's alarm (image `sha256:768e73ab1ab502a8c3fe23a9d42cc038443a6456a1f40dcec853a2c588d04a8f` built from `97b7e471`, CI run 2616; the operator's yes 2026-11-10 15:05 UTC; the manifest bump is the commit that carries this line)
|
||||
|
||||
- **The ruling (`09` §3 decision 287, R-1371).** A household is not mailed about a disk it cannot free.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# R-972: a supported, patched Go and the current Alpine, pinned by version and digest (no moving tag).
|
||||
# upstream: osv:Go/stdlib
|
||||
FROM golang:1.27.3-alpine3.24@sha256:b8c9b82affbbb82a020bbcf998dad2ba9516944ac7e883524642a481a9505e9c AS builder
|
||||
FROM golang:1.27.4-alpine3.24@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/accesslog"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/api"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/assets"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/bundlefiles"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/claim"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/dbsnap"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/gitea"
|
||||
@@ -497,6 +498,18 @@ func main() {
|
||||
logger.Printf("[ERROR] OS_APPROVE_NIGHTS=%q invalid — keeping 1", v)
|
||||
}
|
||||
}
|
||||
// R-1392 (`09` §3 decision 304): a box whose config bundle holds the vouched FILES under an older label is not
|
||||
// "behind". Needs the package registry; without it the old verdict stays (compare the bundle's sha256 only).
|
||||
if giteaClient != nil {
|
||||
bundleSame := &bundlefiles.Resolver{Logger: logger, Fetch: func(ctx context.Context, version string) ([]byte, error) {
|
||||
return giteaClient.FetchFile(ctx, "felhom-agent", version, "felhom-config-bundle.json", 4<<20)
|
||||
}}
|
||||
osSvc.SameBundleFiles = bundleSame.Same
|
||||
webServer.SetSameBundleFiles(bundleSame.Same)
|
||||
logger.Printf("[INFO] Root files: bundles are compared by their files (R-1392)")
|
||||
} else {
|
||||
logger.Printf("[WARN] Root files: no package registry — bundles are compared by sha256 only (R-1392 not active)")
|
||||
}
|
||||
osSvc.DockerNights = 2
|
||||
if v := os.Getenv("OS_DOCKER_APPROVE_NIGHTS"); v != "" {
|
||||
if n, nerr := strconv.Atoi(v); nerr == nil && n >= 0 {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
module gitea.dooplex.hu/admin/felhom-hub
|
||||
|
||||
go 1.27.3
|
||||
go 1.27.4
|
||||
|
||||
require (
|
||||
golang.org/x/crypto v0.58.0
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// Package bundlefiles answers one question for the "root files" verdict (R-1392, `09` §3 decision 304): do two config
|
||||
// bundles hold THE SAME FILES under a different label?
|
||||
//
|
||||
// WHY. The agent's config bundle (`felhom-config-bundle.json`, `11` §5.4.2) carries its own `agent_version`, so its
|
||||
// sha256 moves with every agent release — also when `configs/` did not change and the release (rightly) sent no bundle
|
||||
// job. The hub compared that one sha256, so every such release turned every box amber and, 7 days later, mailed
|
||||
// `os_config_bundle_behind` about files that were the vouched ones (measured 2026-11-14: 0.172.1 vs 0.173.0).
|
||||
//
|
||||
// HOW. A bundle is fetched from the package registry by its version, and it counts ONLY when the bytes hash to the
|
||||
// sha256 the caller already trusts (the vouched one, or the one the box reports). Then everything but the label
|
||||
// (`agent_version`) is hashed: the format and the whole `files` list (path, mode, check, policy, sha256, content).
|
||||
//
|
||||
// FAIL DIRECTION. Anything that cannot be read, verified or parsed answers "not the same" — the old verdict (behind,
|
||||
// amber, the alarm after its wait). A registry that is away never makes a box look current.
|
||||
package bundlefiles
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Fetcher returns the published bundle file of one agent version.
|
||||
type Fetcher func(ctx context.Context, version string) ([]byte, error)
|
||||
|
||||
var (
|
||||
versionRE = regexp.MustCompile(`^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$`) // the builder's own rule
|
||||
shaRE = regexp.MustCompile(`^[0-9a-f]{64}$`)
|
||||
)
|
||||
|
||||
const (
|
||||
retryAfter = 10 * time.Minute // a failed read is not asked again sooner (the System page calls this too)
|
||||
fetchTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
type entry struct {
|
||||
digest string // "" = failed
|
||||
at time.Time
|
||||
}
|
||||
|
||||
// Resolver caches the files digest per bundle sha256. Safe for concurrent use.
|
||||
type Resolver struct {
|
||||
Fetch Fetcher
|
||||
Logger *log.Logger
|
||||
Now func() time.Time
|
||||
|
||||
mu sync.Mutex
|
||||
cache map[string]entry
|
||||
}
|
||||
|
||||
func (r *Resolver) now() time.Time {
|
||||
if r.Now != nil {
|
||||
return r.Now()
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func (r *Resolver) logf(format string, a ...any) {
|
||||
if r.Logger != nil {
|
||||
r.Logger.Printf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// FilesDigest hashes a bundle's content without its label. It errors on a bundle with no `files` list.
|
||||
func FilesDigest(bundle []byte) (string, error) {
|
||||
var body map[string]any
|
||||
if err := json.Unmarshal(bundle, &body); err != nil {
|
||||
return "", fmt.Errorf("not JSON: %w", err)
|
||||
}
|
||||
files, ok := body["files"].([]any)
|
||||
if !ok || len(files) == 0 {
|
||||
return "", errors.New("no files list")
|
||||
}
|
||||
delete(body, "agent_version")
|
||||
canon, err := json.Marshal(body) // map keys are sorted by encoding/json
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
sum := sha256.Sum256(canon)
|
||||
return hex.EncodeToString(sum[:]), nil
|
||||
}
|
||||
|
||||
func (r *Resolver) digest(version, sha string) string {
|
||||
if r == nil || r.Fetch == nil || !versionRE.MatchString(version) || !shaRE.MatchString(sha) {
|
||||
return ""
|
||||
}
|
||||
r.mu.Lock()
|
||||
if e, ok := r.cache[sha]; ok && (e.digest != "" || r.now().Sub(e.at) < retryAfter) {
|
||||
r.mu.Unlock()
|
||||
return e.digest
|
||||
}
|
||||
r.mu.Unlock()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), fetchTimeout)
|
||||
defer cancel()
|
||||
d := ""
|
||||
data, err := r.Fetch(ctx, version)
|
||||
switch {
|
||||
case err != nil:
|
||||
r.logf("[WARN] [bundlefiles] bundle %s: cannot be read (%v) — its files are not compared", version, err)
|
||||
default:
|
||||
sum := sha256.Sum256(data)
|
||||
if got := hex.EncodeToString(sum[:]); got != sha {
|
||||
r.logf("[WARN] [bundlefiles] bundle %s: the published file is sha256 %s, expected %s — its files are not compared", version, got, sha)
|
||||
} else if d, err = FilesDigest(data); err != nil {
|
||||
r.logf("[WARN] [bundlefiles] bundle %s: %v — its files are not compared", version, err)
|
||||
d = ""
|
||||
}
|
||||
}
|
||||
r.mu.Lock()
|
||||
if r.cache == nil {
|
||||
r.cache = map[string]entry{}
|
||||
}
|
||||
r.cache[sha] = entry{digest: d, at: r.now()}
|
||||
r.mu.Unlock()
|
||||
return d
|
||||
}
|
||||
|
||||
// Same reports whether the box's bundle and the vouched bundle hold the same files. Equal sha256s are the caller's
|
||||
// business (nothing is fetched for them); false on anything unread.
|
||||
func (r *Resolver) Same(boxVersion, boxSHA, vouchedVersion, vouchedSHA string) bool {
|
||||
if boxSHA == vouchedSHA {
|
||||
return boxSHA != ""
|
||||
}
|
||||
a := r.digest(vouchedVersion, vouchedSHA)
|
||||
if a == "" {
|
||||
return false
|
||||
}
|
||||
b := r.digest(boxVersion, boxSHA)
|
||||
same := b != "" && a == b
|
||||
if same {
|
||||
r.logf("[DEBUG] [bundlefiles] bundle %s holds the same files as the vouched %s (only the label differs)", boxVersion, vouchedVersion)
|
||||
}
|
||||
return same
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package bundlefiles
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func bundle(version, wrapperSHA string) []byte {
|
||||
return []byte(`{
|
||||
"agent_version": "` + version + `",
|
||||
"files": [
|
||||
{"check": "", "content_b64": "QQ==", "mode": "0o755", "path": "/usr/local/sbin/felhom-os-apply", "policy": "replace", "sha256": "` + wrapperSHA + `"}
|
||||
],
|
||||
"format": 1
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func sha(b []byte) string { s := sha256.Sum256(b); return hex.EncodeToString(s[:]) }
|
||||
|
||||
type reg struct {
|
||||
files map[string][]byte
|
||||
calls int
|
||||
err error
|
||||
}
|
||||
|
||||
func (g *reg) fetch(_ context.Context, v string) ([]byte, error) {
|
||||
g.calls++
|
||||
if g.err != nil {
|
||||
return nil, g.err
|
||||
}
|
||||
b, ok := g.files[v]
|
||||
if !ok {
|
||||
return nil, errors.New("404")
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// R-1392: the three verdicts, and the fail direction.
|
||||
func TestSame(t *testing.T) {
|
||||
old, relabel, changed := bundle("0.172.1", "aa"), bundle("0.173.0", "aa"), bundle("0.174.0", "bb")
|
||||
g := ®{files: map[string][]byte{"0.172.1": old, "0.173.0": relabel, "0.174.0": changed}}
|
||||
r := &Resolver{Fetch: g.fetch}
|
||||
|
||||
if sha(old) == sha(relabel) {
|
||||
t.Fatal("fixture: the label must move the bundle's sha256")
|
||||
}
|
||||
if !r.Same("0.172.1", sha(old), "0.173.0", sha(relabel)) {
|
||||
t.Fatal("same files under a new label must be the same")
|
||||
}
|
||||
if r.Same("0.172.1", sha(old), "0.174.0", sha(changed)) {
|
||||
t.Fatal("one file differs: must NOT be the same")
|
||||
}
|
||||
if r.Same("none", "", "0.173.0", sha(relabel)) {
|
||||
t.Fatal("a box that never got a bundle must NOT be the same")
|
||||
}
|
||||
if r.Same("", "", "", "") {
|
||||
t.Fatal("nothing vouched and nothing on the box is not 'the same'")
|
||||
}
|
||||
// The cache: every bundle was read once.
|
||||
n := g.calls
|
||||
r.Same("0.172.1", sha(old), "0.173.0", sha(relabel))
|
||||
if g.calls != n {
|
||||
t.Fatalf("a verified bundle was read again (%d -> %d)", n, g.calls)
|
||||
}
|
||||
}
|
||||
|
||||
// A bundle counts only when its bytes hash to the sha256 the caller trusts.
|
||||
func TestSame_UnverifiedBytesNeverCount(t *testing.T) {
|
||||
old, relabel := bundle("0.172.1", "aa"), bundle("0.173.0", "aa")
|
||||
g := ®{files: map[string][]byte{"0.172.1": old, "0.173.0": relabel}}
|
||||
r := &Resolver{Fetch: g.fetch}
|
||||
wrong := sha([]byte("something else"))
|
||||
if r.Same("0.172.1", wrong, "0.173.0", sha(relabel)) {
|
||||
t.Fatal("the box's sha256 does not match the published file: must NOT be the same")
|
||||
}
|
||||
if r.Same("0.172.1", sha(old), "0.173.0", wrong) {
|
||||
t.Fatal("the vouched sha256 does not match the published file: must NOT be the same")
|
||||
}
|
||||
if r.Same("../../x", sha(old), "0.173.0", sha(relabel)) {
|
||||
t.Fatal("a version that is not a version must never reach the registry")
|
||||
}
|
||||
}
|
||||
|
||||
// A registry that is away answers "not the same", is not hammered, and is asked again later.
|
||||
func TestSame_RegistryAway(t *testing.T) {
|
||||
old, relabel := bundle("0.172.1", "aa"), bundle("0.173.0", "aa")
|
||||
g := ®{files: map[string][]byte{"0.172.1": old, "0.173.0": relabel}, err: errors.New("dial tcp: refused")}
|
||||
now := time.Date(2026, 11, 14, 10, 0, 0, 0, time.UTC)
|
||||
r := &Resolver{Fetch: g.fetch, Now: func() time.Time { return now }}
|
||||
if r.Same("0.172.1", sha(old), "0.173.0", sha(relabel)) {
|
||||
t.Fatal("unreadable must NOT be the same")
|
||||
}
|
||||
n := g.calls
|
||||
r.Same("0.172.1", sha(old), "0.173.0", sha(relabel))
|
||||
if g.calls != n {
|
||||
t.Fatal("a failed read was retried at once")
|
||||
}
|
||||
g.err = nil
|
||||
now = now.Add(11 * time.Minute)
|
||||
if !r.Same("0.172.1", sha(old), "0.173.0", sha(relabel)) {
|
||||
t.Fatal("the registry is back after the retry wait: must be the same")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilesDigest_NoFilesIsAnError(t *testing.T) {
|
||||
for _, b := range []string{`{}`, `{"files":[]}`, `{"files":"x"}`, `not json`} {
|
||||
if _, err := FilesDigest([]byte(b)); err == nil {
|
||||
t.Fatalf("%q: no error", b)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,6 +177,35 @@ func (c *Client) getJSON(ctx context.Context, url string, out interface{}) error
|
||||
return json.NewDecoder(resp.Body).Decode(out)
|
||||
}
|
||||
|
||||
// FetchFile downloads one file of a generic package version, refusing a body above maxBytes (R-1392: the agent's config
|
||||
// bundle, so the hub can compare the FILES of two bundles). The caller verifies the bytes against a sha256 it trusts.
|
||||
func (c *Client) FetchFile(ctx context.Context, pkg, version, file string, maxBytes int64) ([]byte, error) {
|
||||
url := fmt.Sprintf("%s/api/packages/%s/generic/%s/%s/%s", c.baseURL, c.owner, pkg, version, file)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.token != "" {
|
||||
req.SetBasicAuth(c.user, c.token)
|
||||
}
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, &StatusError{URL: url, Code: resp.StatusCode}
|
||||
}
|
||||
data, err := io.ReadAll(io.LimitReader(resp.Body, maxBytes+1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if int64(len(data)) > maxBytes {
|
||||
return nil, fmt.Errorf("gitea GET %s: larger than %d bytes", url, maxBytes)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// compareSemver returns >0 if a>b, 0 if equal, <0 if a<b. Falls back to a lexical compare on a
|
||||
// non-"X.Y.Z" input (mirrors web.compareVersions; kept local to avoid an import cycle).
|
||||
func compareSemver(a, b string) int {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package osupdates
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/bundlefiles"
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/store"
|
||||
)
|
||||
|
||||
@@ -88,3 +92,54 @@ func TestBundleAlarm_UnknownAndNoVouchedBundleSayNothing(t *testing.T) {
|
||||
t.Fatalf("nothing vouched, nothing behind: %v", sent)
|
||||
}
|
||||
}
|
||||
|
||||
// R-1392 (`09` §3 decision 304): an agent release that changed no root file gives the bundle a new label and a new
|
||||
// sha256. A box on the same files is not behind: no alarm after the wait, and a "behind since" mark set before the
|
||||
// fix is cleared. A box whose files differ, and a box that never got a bundle, still alarm.
|
||||
func TestBundleAlarm_R1392_SameFilesNewLabel(t *testing.T) {
|
||||
f := newFix(t)
|
||||
if err := f.s.Store.SetArtifactManifest(store.ArtifactManifest{AgentVersion: "0.173.0", AgentSHA256: "x", BundleSHA256: "new"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bundleReport(t, f, "cust1", "0.172.1", "old")
|
||||
if _, err := f.s.Alarms(); err != nil { // before the fix: the mark is set
|
||||
t.Fatal(err)
|
||||
}
|
||||
if f.s.Store.BundleBehindSince("cust1").IsZero() {
|
||||
t.Fatal("fixture: without the answer the box must be marked behind")
|
||||
}
|
||||
f.s.SameBundleFiles = func(bv, bs, vv, vs string) bool {
|
||||
return bv == "0.172.1" && bs == "old" && vv == "0.173.0" && vs == "new"
|
||||
}
|
||||
f.now = f.now.Add(8 * 24 * time.Hour)
|
||||
if sent, _ := f.s.Alarms(); count(sent, EventBundleBehind) != 0 {
|
||||
t.Fatalf("same files under a new label alarmed: %v", sent)
|
||||
}
|
||||
if !f.s.Store.BundleBehindSince("cust1").IsZero() {
|
||||
t.Fatal("the behind-since mark was not cleared")
|
||||
}
|
||||
// One file differs: behind, and the alarm after its wait.
|
||||
bundleReport(t, f, "cust1", "0.171.0", "older")
|
||||
f.s.Alarms()
|
||||
f.now = f.now.Add(8 * 24 * time.Hour)
|
||||
if sent, _ := f.s.Alarms(); count(sent, EventBundleBehind) != 1 {
|
||||
t.Fatalf("different files did not alarm: %v", sent)
|
||||
}
|
||||
}
|
||||
|
||||
// The same question through the REAL resolver (a fake registry): a box that never got a bundle has no sha256 to
|
||||
// verify, so it stays behind and alarms.
|
||||
func TestBundleAlarm_R1392_NeverGotABundleStillAlarms(t *testing.T) {
|
||||
f := newFix(t)
|
||||
vouched := []byte(`{"agent_version":"0.143.0","files":[{"path":"/x","sha256":"aa"}],"format":1}`)
|
||||
sum := sha256.Sum256(vouched)
|
||||
vouch(t, f, hex.EncodeToString(sum[:]))
|
||||
r := &bundlefiles.Resolver{Fetch: func(_ context.Context, v string) ([]byte, error) { return vouched, nil }}
|
||||
f.s.SameBundleFiles = r.Same
|
||||
bundleReport(t, f, "cust1", "none", "")
|
||||
f.s.Alarms()
|
||||
f.now = f.now.Add(8 * 24 * time.Hour)
|
||||
if sent, _ := f.s.Alarms(); count(sent, EventBundleBehind) != 1 {
|
||||
t.Fatalf("a box with no bundle did not alarm: %v", sent)
|
||||
}
|
||||
}
|
||||
@@ -199,6 +199,10 @@ type Service struct {
|
||||
// BundleBehindAfter: a box's config bundle differs from the vouched one this long → an operator alarm (R-840;
|
||||
// decided by CC unattended — operator may reverse). Zero = 7 d.
|
||||
BundleBehindAfter time.Duration
|
||||
// SameBundleFiles (R-1392, `09` §3 decision 304): the box's bundle holds the same files as the vouched one under
|
||||
// another label (an agent release that changed no root file) — then the box is NOT behind. nil, or anything it
|
||||
// cannot read, answers false: the old verdict. Pinned by TestBundleAlarm_R1392_*.
|
||||
SameBundleFiles func(boxVersion, boxSHA, vouchedVersion, vouchedSHA string) bool
|
||||
// AgentBehindAfter: a box runs an agent older than the vouched one this long → an operator alarm (R-530; decided
|
||||
// by CC — operator may reverse, env OS_ALARM_AGENT_BEHIND_AFTER). Zero = 7 d.
|
||||
AgentBehindAfter time.Duration
|
||||
@@ -1180,6 +1184,9 @@ func (s *Service) Alarms() ([]string, error) {
|
||||
continue
|
||||
}
|
||||
behind := sys.Bundle.BundleSHA256 != man.BundleSHA256
|
||||
if behind && s.SameBundleFiles != nil && s.SameBundleFiles(sys.Bundle.Version, sys.Bundle.BundleSHA256, man.AgentVersion, man.BundleSHA256) {
|
||||
behind = false // R-1392: the same files under an older label
|
||||
}
|
||||
since := s.Store.BundleBehindSince(h.HostID)
|
||||
switch {
|
||||
case !behind && !since.IsZero():
|
||||
|
||||
@@ -77,6 +77,7 @@ type Server struct {
|
||||
offsiteWindowGrant func(customerID string) error
|
||||
offsiteWindowGrantMax func(customerID string, maxRemove int) error
|
||||
osUpdates OSUpdateAdmin
|
||||
sameBundleFiles func(boxVersion, boxSHA, vouchedVersion, vouchedSHA string) bool // R-1392; nil = never the same
|
||||
offsiteWindowSwitch func(on bool) error
|
||||
// operator key-file clean-up (decision 72) and abandonment cancel (decision 74). nil → 503.
|
||||
offsiteRemoveUnpinned func(ctx context.Context, customerID string) (int, error)
|
||||
@@ -254,6 +255,11 @@ type OSUpdateAdmin interface {
|
||||
// SetOSUpdateAdmin wires the OS-update operator routes.
|
||||
func (s *Server) SetOSUpdateAdmin(a OSUpdateAdmin) { s.osUpdates = a }
|
||||
|
||||
// SetSameBundleFiles wires the "same files under another label" answer for the System page's Root files cell (R-1392).
|
||||
func (s *Server) SetSameBundleFiles(f func(boxVersion, boxSHA, vouchedVersion, vouchedSHA string) bool) {
|
||||
s.sameBundleFiles = f
|
||||
}
|
||||
|
||||
// SetOffsiteWindowLargeGrant wires the operator's one-window raised cap (R-833).
|
||||
func (s *Server) SetOffsiteWindowLargeGrant(fn func(string, int) error) { s.offsiteWindowGrantMax = fn }
|
||||
|
||||
|
||||
@@ -270,9 +270,10 @@ func guestTrimText(g sysfacts.GuestTrim, now time.Time) (text string, warn bool,
|
||||
return text, warn, why
|
||||
}
|
||||
|
||||
// bundleCell is the "Root files" cell (R-840): the box's config bundle against the vouched agent's. Amber while behind,
|
||||
// bundleCell is the "Root files" cell (R-840): the box's config bundle against the vouched agent's. Amber while behind
|
||||
// (never when the files are the same under another label — sameFiles, R-1392, pinned by TestBundleCell_R1392),
|
||||
// red from the alarm's wait on, amber when a file was changed by hand (drift); "unknown" is never coloured as a fact.
|
||||
func bundleCell(f sysfacts.System, vouchedAgent, vouchedSHA string, since time.Time, after time.Duration, now time.Time) cell {
|
||||
func bundleCell(f sysfacts.System, vouchedAgent, vouchedSHA string, sameFiles bool, since time.Time, after time.Duration, now time.Time) cell {
|
||||
b := f.Bundle
|
||||
if !f.Present || b.Version == "" || b.Version == sysfacts.Unknown {
|
||||
return unknownCell("")
|
||||
@@ -281,6 +282,9 @@ func bundleCell(f sysfacts.System, vouchedAgent, vouchedSHA string, since time.T
|
||||
switch {
|
||||
case vouchedSHA == "":
|
||||
c.Title = "no vouched bundle to compare with (the vouched agent carries none)"
|
||||
case b.BundleSHA256 != vouchedSHA && sameFiles:
|
||||
// R-1392: an agent release that changed no root file gives the bundle a new label and a new sha256.
|
||||
c.Title = "the same files as the vouched agent " + vouchedAgent + "'s bundle (only the label differs)"
|
||||
case b.BundleSHA256 != vouchedSHA:
|
||||
c.Class, c.Title = "warn", "behind the vouched agent "+vouchedAgent+"'s bundle — send it with a signed agent_config_update"
|
||||
if !since.IsZero() {
|
||||
@@ -453,7 +457,7 @@ func (s *Server) handleSystem(w http.ResponseWriter, r *http.Request) {
|
||||
hosts, _ := s.store.ListHosts()
|
||||
now := time.Now()
|
||||
in := systemInput{Lines: lines, Facts: map[string]sysfacts.System{}, Names: map[string]string{}, Controllers: map[string]string{},
|
||||
Agents: map[string]string{}, KernelLines: map[string]osupdates.KernelLine{}, BundleSince: map[string]time.Time{},
|
||||
Agents: map[string]string{}, KernelLines: map[string]osupdates.KernelLine{}, BundleSince: map[string]time.Time{}, BundleSame: map[string]bool{},
|
||||
AgentSince: map[string]time.Time{}, BundleAfter: view.BundleThreshold(), AgentAfter: view.AgentThreshold(),
|
||||
GlobalFloor: s.store.GetGlobalMinControllerVersion(), Releases: view.Releases(), Cancelled: view.CancelledReleases(),
|
||||
Candidates: view.Candidates(), Now: now}
|
||||
@@ -479,6 +483,13 @@ func (s *Server) handleSystem(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
man := s.store.GetArtifactManifest()
|
||||
in.VouchedAgent, in.VouchedBundle = man.AgentVersion, man.BundleSHA256
|
||||
if s.sameBundleFiles != nil && man.BundleSHA256 != "" {
|
||||
for id, f := range in.Facts {
|
||||
if b := f.Bundle; f.Present && b.BundleSHA256 != "" && b.BundleSHA256 != man.BundleSHA256 {
|
||||
in.BundleSame[id] = s.sameBundleFiles(b.Version, b.BundleSHA256, man.AgentVersion, man.BundleSHA256)
|
||||
}
|
||||
}
|
||||
}
|
||||
ovs, oerr := s.store.CustomerFloorOverrides()
|
||||
if oerr != nil {
|
||||
s.logger.Printf("[ERROR] system page: floor overrides: %v", oerr)
|
||||
|
||||
@@ -14,19 +14,36 @@ func TestBundleCell(t *testing.T) {
|
||||
cur := sys(`{"system":{"config_bundle":{"version":"0.143.0","bundle_sha256":"new"}}}`)
|
||||
old := sys(`{"system":{"config_bundle":{"version":"none"}}}`)
|
||||
drift := sys(`{"system":{"config_bundle":{"version":"0.143.0","bundle_sha256":"new"},"facts":{"host":{"config_bundle":{"version":"0.143.0","drift":["/usr/local/sbin/felhom-pbs-apply"]}}}}}`)
|
||||
if c := bundleCell(cur, "0.143.0", "new", time.Time{}, 7*24*time.Hour, now); c.Class != "" || c.Text != "0.143.0" {
|
||||
if c := bundleCell(cur, "0.143.0", "new", false, time.Time{}, 7*24*time.Hour, now); c.Class != "" || c.Text != "0.143.0" {
|
||||
t.Fatalf("current: %+v", c)
|
||||
}
|
||||
if c := bundleCell(old, "0.143.0", "new", now.Add(-time.Hour), 7*24*time.Hour, now); c.Class != "warn" || c.Text != "none" {
|
||||
if c := bundleCell(old, "0.143.0", "new", false, now.Add(-time.Hour), 7*24*time.Hour, now); c.Class != "warn" || c.Text != "none" {
|
||||
t.Fatalf("behind 1 h: %+v", c)
|
||||
}
|
||||
if c := bundleCell(old, "0.143.0", "new", now.Add(-8*24*time.Hour), 7*24*time.Hour, now); c.Class != "bad" {
|
||||
if c := bundleCell(old, "0.143.0", "new", false, now.Add(-8*24*time.Hour), 7*24*time.Hour, now); c.Class != "bad" {
|
||||
t.Fatalf("behind 8 days: %+v", c)
|
||||
}
|
||||
if c := bundleCell(drift, "0.143.0", "new", time.Time{}, 7*24*time.Hour, now); c.Class != "warn" || c.Title == "" {
|
||||
if c := bundleCell(drift, "0.143.0", "new", false, time.Time{}, 7*24*time.Hour, now); c.Class != "warn" || c.Title == "" {
|
||||
t.Fatalf("drift: %+v", c)
|
||||
}
|
||||
if c := bundleCell(sys(`{}`), "0.143.0", "new", time.Time{}, 7*24*time.Hour, now); c.Text != "unknown" {
|
||||
if c := bundleCell(sys(`{}`), "0.143.0", "new", false, time.Time{}, 7*24*time.Hour, now); c.Text != "unknown" {
|
||||
t.Fatalf("no stanza: %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
// R-1392 (`09` §3 decision 304): the same files under an older label are not "behind" — no colour, also after the
|
||||
// alarm's wait; a bundle whose files differ stays amber; drift is still amber.
|
||||
func TestBundleCell_R1392(t *testing.T) {
|
||||
now := time.Date(2026, 11, 14, 10, 0, 0, 0, time.UTC)
|
||||
box := sysfacts.Parse(`{"system":{"config_bundle":{"version":"0.172.1","bundle_sha256":"old"}}}`)
|
||||
if c := bundleCell(box, "0.173.0", "new", true, now.Add(-8*24*time.Hour), 7*24*time.Hour, now); c.Class != "" || c.Text != "0.172.1" || c.Title == "" {
|
||||
t.Fatalf("same files, new label: %+v", c)
|
||||
}
|
||||
if c := bundleCell(box, "0.173.0", "new", false, now.Add(-time.Hour), 7*24*time.Hour, now); c.Class != "warn" {
|
||||
t.Fatalf("different files: %+v", c)
|
||||
}
|
||||
drift := sysfacts.Parse(`{"system":{"config_bundle":{"version":"0.172.1","bundle_sha256":"old"},"facts":{"host":{"config_bundle":{"version":"0.172.1","drift":["/etc/sudoers.d/felhom-agent"]}}}}}`)
|
||||
if c := bundleCell(drift, "0.173.0", "new", true, time.Time{}, 7*24*time.Hour, now); c.Class != "warn" {
|
||||
t.Fatalf("drift under the same files: %+v", c)
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ type systemInput struct {
|
||||
Names, Controllers, Agents map[string]string // by host id
|
||||
KernelLines map[string]osupdates.KernelLine
|
||||
BundleSince, AgentSince map[string]time.Time
|
||||
BundleSame map[string]bool // R-1392: the box's bundle = the vouched files under another label
|
||||
Stale, Reboot, NotCov time.Duration
|
||||
BundleAfter, AgentAfter time.Duration
|
||||
VouchedAgent, VouchedBundle string
|
||||
@@ -51,7 +52,7 @@ func buildSystemPage(in systemInput) map[string]interface{} {
|
||||
for i := range rows {
|
||||
id := rows[i].HostID
|
||||
rows[i].KernelDefault, rows[i].KernelStep = kernelCells(in.Facts[id], in.KernelLines[id], in.Now)
|
||||
rows[i].Bundle = bundleCell(in.Facts[id], in.VouchedAgent, in.VouchedBundle, in.BundleSince[id], in.BundleAfter, in.Now)
|
||||
rows[i].Bundle = bundleCell(in.Facts[id], in.VouchedAgent, in.VouchedBundle, in.BundleSame[id], in.BundleSince[id], in.BundleAfter, in.Now)
|
||||
rows[i].Agent = agentCell(in.Agents[id], in.VouchedAgent, in.AgentSince[id], in.AgentAfter, in.Now)
|
||||
rows[i].Controller = unknownCell(in.Controllers[id])
|
||||
summariseRow(&rows[i], latest)
|
||||
|
||||
Reference in new issue
Block a user