fix: probe signs with the delivered key, one attempt, strict wire
Managed fleets 2b-2 Task 5, fix round 1 (Astra R1, Fable R1 P3s). - The box's storage challenge is signed with exactly the key pair parsed from /etc/carlos/credentials: new lease.NewStaticFilesStore builds the S3 client from a literal config with a static provider, so no env keys (AWS_ACCESS_KEY/AWS_SECRET_KEY aliases included), profile, shared file, web identity or IMDS can sign instead, and the reported key ID is the signing key. One attempt per request (NopRetryer): a probe is exactly PUT, GET, DELETE, and a transient failure is a failed check. - Probe request and reply decoders refuse duplicate keys, null for any field, keys in another case, and a storage object without exactly ok, key_id and code. - The cleanup DELETE runs under context.WithoutCancel with its own 2 s budget; the hub takes each verified probe signature once (bounded seen-set over the skew window); the console gives distinct router reasons for a hub with no tunnel (503), a wrong answer (502) and an unreachable hub. Witnesses count real HTTP requests and Authorization key IDs through the production constructor; the worker budget witness counts heartbeat GETs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+493
−90
internal/console/managedprobe.go+29 −14internal/console/managedprobe_test.go+22 −9internal/edge/edge.go+3 −0internal/edge/fleetprobe.go+27 −1internal/edge/fleetprobe_test.go+32 −1internal/host/managedprobe.go+29 −22internal/host/managedprobe_test.go+186 −20internal/lease/endpoint.go+27 −0internal/managedboot/probe.go+68 −19internal/managedboot/probe_test.go+63 −0internal/provision/managed_fleets_2b2_census_test.go+7 −4
diff --git a/internal/console/managedprobe.go b/internal/console/managedprobe.go| index 51c1dc37e..1604d27d8 100644 |
| --- a/internal/console/managedprobe.go |
| +++ b/internal/console/managedprobe.go |
| @@ -41,6 +41,9 @@ const managedProbeTimeout = 10 * time.Second |
| // COPY: readiness reasons await controller copy review. |
| const ( |
| managedProbeRouterWaiting = "waiting for the box to answer a probe through its own tunnel" // COPY |
| + managedProbeRouterNoTunnel = "the fleet hub has no tunnel to this box right now" // COPY |
| + managedProbeRouterBadAnswer = "the box did not answer the probe correctly" // COPY |
| + managedProbeRouterNoHub = "the console could not reach the fleet hub" // COPY |
| managedProbeStorageWaiting = "waiting for the box to answer a storage probe" // COPY |
| managedProbeStorageFailed = "the box could not write, read back and delete a test object in the fleet bucket (%s)" // COPY |
| managedProbeKeyNotDelivered = "the box is using an access key that was not delivered to this fleet" // COPY |
| @@ -69,15 +72,19 @@ func newManagedProbeChecks(s *Server) *managedProbeChecks { |
| } |
| } |
| -// Checks implements managedExtraChecks. |
| +// Checks implements managedExtraChecks. A publishing box is probed too: |
| +// when its passing checks have gone stale before the ready object was |
| +// written, the worker's refreshManagedPublication observes it again |
| +// (within the same once-a-minute attempt budget) before a new PUT. |
| func (p *managedProbeChecks) Checks(ctx context.Context, b managedBox) (storage, router managedCheck, err error) { |
| storage = managedCheck{State: "pending", Reason: managedProbeStorageWaiting} |
| router = managedCheck{State: "pending", Reason: managedProbeRouterWaiting} |
| if p.s.cfg.HostClaim || (b.State != "enrolled" && b.State != "publishing") { |
| return storage, router, nil |
| } |
| - reply, ok := p.probe(ctx, b) |
| - if !ok { |
| + reply, why := p.probe(ctx, b) |
| + if why != "" { |
| + router.Reason = why |
| return storage, router, nil |
| } |
| router = managedCheck{State: "pass"} |
| @@ -85,49 +92,57 @@ func (p *managedProbeChecks) Checks(ctx context.Context, b managedBox) (storage, |
| } |
| // probe sends one signed request and returns the reply only when the hub |
| -// attests b's own channel and the reply echoes the request exactly. |
| -func (p *managedProbeChecks) probe(ctx context.Context, b managedBox) (managedboot.ProbeReply, bool) { |
| +// attests b's own channel and the reply echoes the request exactly; else |
| +// the router reason for what went wrong. |
| +func (p *managedProbeChecks) probe(ctx context.Context, b managedBox) (managedboot.ProbeReply, string) { |
| + none := managedboot.ProbeReply{} |
| current, next := p.s.edgeProofKeys(ctx) |
| nonce, err := managedboot.NewProbeNonce() |
| if err != nil { |
| - return managedboot.ProbeReply{}, false |
| + return none, managedProbeRouterWaiting |
| } |
| req := managedboot.ProbeRequest{Fleet: b.Fleet, Label: b.Label, Op: b.OpID, Nonce: nonce, Storage: true} |
| body, err := managedboot.EncodeProbeRequest(req) |
| if err != nil { |
| - return managedboot.ProbeReply{}, false |
| + return none, managedProbeRouterWaiting |
| } |
| channel := req.Channel() |
| auth := edge.SignFleetProbe(current, next, channel, body, time.Now()) |
| if auth == "" { |
| - return managedboot.ProbeReply{}, false |
| + return none, managedProbeRouterWaiting |
| } |
| ctx, cancel := context.WithTimeout(ctx, managedProbeTimeout) |
| defer cancel() |
| hr, err := http.NewRequestWithContext(ctx, http.MethodPost, p.url, bytes.NewReader(body)) |
| if err != nil { |
| - return managedboot.ProbeReply{}, false |
| + return none, managedProbeRouterWaiting |
| } |
| hr.Header.Set("Content-Type", "application/json") |
| hr.Header.Set(edge.FleetProbeAuthHeader, auth) |
| resp, err := p.client.Do(hr) |
| if err != nil { |
| - return managedboot.ProbeReply{}, false |
| + return none, managedProbeRouterNoHub |
| } |
| defer resp.Body.Close() |
| + switch resp.StatusCode { |
| + case http.StatusServiceUnavailable: |
| + return none, managedProbeRouterNoTunnel |
| + case http.StatusBadGateway: |
| + return none, managedProbeRouterBadAnswer |
| + } |
| attested := resp.Header.Values(edge.FleetProbeChannelHeader) |
| if resp.StatusCode != http.StatusOK || len(attested) != 1 || attested[0] != channel { |
| - return managedboot.ProbeReply{}, false |
| + return none, managedProbeRouterWaiting |
| } |
| raw, err := io.ReadAll(io.LimitReader(resp.Body, managedboot.MaxProbeReply+1)) |
| if err != nil || len(raw) > managedboot.MaxProbeReply { |
| - return managedboot.ProbeReply{}, false |
| + return none, managedProbeRouterWaiting |
| } |
| reply, err := managedboot.ParseProbeReply(raw) |
| if err != nil || !reply.Echoes(req) { |
| - return managedboot.ProbeReply{}, false |
| + return none, managedProbeRouterWaiting |
| } |
| - return reply, true |
| + return reply, "" |
| } |
| // storage judges an authentic reply's storage half. |
diff --git a/internal/console/managedprobe_test.go b/internal/console/managedprobe_test.go| index bbe1d7ed7..a2d7d2458 100644 |
| --- a/internal/console/managedprobe_test.go |
| +++ b/internal/console/managedprobe_test.go |
| @@ -222,6 +222,13 @@ func TestManagedProbeChecks(t *testing.T) { |
| before := g.hub.calls.Load() |
| storage, router := g.check() |
| pending(name, storage, router) |
| + want := map[string]string{"hub 503": managedProbeRouterNoTunnel, "hub 502 attested": managedProbeRouterBadAnswer}[name] |
| + if want == "" { |
| + want = managedProbeRouterWaiting |
| + } |
| + if router.Reason != want || storage.Reason != managedProbeStorageWaiting { |
| + t.Errorf("%s: router reason %q, want %q; storage %q", name, router.Reason, want, storage.Reason) |
| + } |
| if g.hub.calls.Load() != before+1 { |
| t.Errorf("%s: %d hub calls, want 1 (no redirect followed, no retry)", name, g.hub.calls.Load()-before) |
| } |
| @@ -291,6 +298,9 @@ func TestManagedProbeChecks(t *testing.T) { |
| // The hub unreachable: pending, no error. |
| g.hub.srv.Close() |
| pendingNow("hub unreachable", g.check) |
| + if _, router := g.check(); router.Reason != managedProbeRouterNoHub { |
| + t.Errorf("hub unreachable: %q", router.Reason) |
| + } |
| // No probe on a host-claim console, for a box not enrolled or |
| // publishing, or with no mesh key to sign with. |
| @@ -374,34 +384,37 @@ func TestManagedProbeBudget(t *testing.T) { |
| attest(w, req.Channel(), probeEcho(req, "", nil)) // router passes, storage waits |
| }) |
| b := g.b |
| + st := countReadiness(g.s) |
| + beat := "fleets/" + b.Fleet + "/status/boxes/" + b.Label + ".json" |
| for i := 0; i < 10; i++ { |
| b = workerStep(t, g.s, g.now.Add(time.Duration(i)*5*time.Second)) |
| } |
| - if n := g.hub.calls.Load(); n != 1 || b.State != "enrolled" { |
| - t.Fatalf("10 passes in 50 s: %d probes, state %s", n, b.State) |
| + if n := g.hub.calls.Load(); n != 1 || st.gets[beat] != 1 || b.State != "enrolled" { |
| + t.Fatalf("10 passes in 50 s: %d probes, %d heartbeat GETs, state %s", n, st.gets[beat], b.State) |
| } |
| - readyBeat(t, g.s, b, status.Box{Label: b.Label, GeneratedAt: g.now.Add(time.Minute), Metrics: &status.BoxMetrics{Release: "v0.34.0", RootfsReady: true, Tunnel: "connected"}}) |
| + readyBeatIn(t, st.Store, b, status.Box{Label: b.Label, GeneratedAt: g.now.Add(time.Minute), Metrics: &status.BoxMetrics{Release: "v0.34.0", RootfsReady: true, Tunnel: "connected"}}) |
| g.hub.set(func(req managedboot.ProbeRequest, w http.ResponseWriter) { |
| attest(w, req.Channel(), probeEcho(req, g.fp, nil)) |
| }) |
| b = workerStep(t, g.s, g.now.Add(time.Minute)) |
| - if n := g.hub.calls.Load(); n != 2 || b.State != "ready" { |
| - t.Fatalf("after a minute: %d probes, state %s %+v", n, b.State, b.Checks) |
| + if n := g.hub.calls.Load(); n != 2 || st.gets[beat] != 2 || b.State != "ready" { |
| + t.Fatalf("after a minute: %d probes, %d heartbeat GETs, state %s %+v", n, st.gets[beat], b.State, b.Checks) |
| } |
| for i := 1; i <= 30; i++ { |
| b = workerStep(t, g.s, g.now.Add(time.Minute+time.Duration(i)*time.Minute)) |
| } |
| - if n := g.hub.calls.Load(); n != 2 || b.State != "ready" { |
| - t.Fatalf("ready box: %d probes, state %s", n, b.State) |
| + if n := g.hub.calls.Load(); n != 2 || st.gets[beat] != 2 || b.State != "ready" { |
| + t.Fatalf("ready box: %d probes, %d heartbeat GETs, state %s", n, st.gets[beat], b.State) |
| } |
| f := newProbeRig(t) |
| + fst := countReadiness(f.s) |
| workerAdvance(t, f.s, f.b, func(b *managedBox) { b.State = "failed"; b.LastError = "managed_test_failed" }) |
| for i := 0; i < 10; i++ { |
| workerStep(t, f.s, f.now.Add(time.Duration(i)*time.Minute)) |
| } |
| - if st := workerBox(t, f.s).State; f.hub.calls.Load() != 0 || st == "ready" || st == "enrolled" { |
| - t.Fatalf("failed box: %d probes, state %s", f.hub.calls.Load(), st) |
| + if state := workerBox(t, f.s).State; f.hub.calls.Load() != 0 || fst.gets[beat] != 0 || state == "ready" || state == "enrolled" { |
| + t.Fatalf("failed box: %d probes, %d heartbeat GETs, state %s", f.hub.calls.Load(), fst.gets[beat], state) |
| } |
| idle := managedAPIFixture(t) |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index fe249b9f3..1f7eb5d13 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -145,6 +145,9 @@ type Edge struct { |
| // managedProbe answers the hub's readiness probe on a managed box |
| // (fleetprobe.go); nil everywhere else. |
| managedProbe ManagedProbeResponder |
| + // fleetProbeSeen is the hub's memory of probe signatures already |
| + // taken, so a captured probe is not accepted twice (fleetprobe.go). |
| + fleetProbeSeen fleetProbeReplays |
| // held is the edge-held event streams this edge holds (heldstream.go), |
| // built in New with DefaultHeldConfig; SetHeldConfig replaces it before |
| // serving. |
diff --git a/internal/edge/fleetprobe.go b/internal/edge/fleetprobe.go| index a10b2e5c0..cfafc6a12 100644 |
| --- a/internal/edge/fleetprobe.go |
| +++ b/internal/edge/fleetprobe.go |
| @@ -11,6 +11,7 @@ import ( |
| "net/http" |
| "strconv" |
| "strings" |
| + "sync" |
| "time" |
| "github.com/carlosframework/platform/internal/managedboot" |
| @@ -54,6 +55,24 @@ const ( |
| FleetProbeChannelHeader = fleetProbeChannelHeader |
| ) |
| +// fleetProbeSeenMax bounds the hub's replay memory. At one probe per |
| +// enrolled box per minute it covers thousands of boxes over the window. |
| +const fleetProbeSeenMax = 4096 |
| + |
| +// fleetProbeReplays is the hub's seen-set of verified probe signatures, |
| +// each kept for twice the timestamp skew (the window in which it would |
| +// verify), as burst notices keep theirs. Usable at its zero value. |
| +type fleetProbeReplays struct { |
| + once sync.Once |
| + seen burstSeen |
| +} |
| + |
| +// add records the signature header and reports whether it was new. |
| +func (r *fleetProbeReplays) add(header string, now time.Time) bool { |
| + r.once.Do(func() { r.seen.n, r.seen.keys = fleetProbeSeenMax, map[string]int64{} }) |
| + return r.seen.add(strings.ToLower(header), now) |
| +} |
| + |
| // fleetProbeTimeout bounds the hub's whole exchange with the box; a |
| // variable so witnesses run without real waits. |
| var fleetProbeTimeout = 10 * time.Second |
| @@ -163,7 +182,14 @@ func (e *Edge) serveFleetProbe(w http.ResponseWriter, r *http.Request) { |
| auth := r.Header.Values(fleetProbeAuthHeader) |
| req, err := managedboot.ParseProbeRequest(body) |
| current, next := e.homes.Load().meshKeys() |
| - if err != nil || len(auth) != 1 || !verifyFleetProbeEitherKey(current, next, req.Channel(), auth[0], body, time.Now()) { |
| + now := time.Now() |
| + if err != nil || len(auth) != 1 || !verifyFleetProbeEitherKey(current, next, req.Channel(), auth[0], body, now) { |
| + w.WriteHeader(http.StatusUnauthorized) |
| + return |
| + } |
| + // A verified probe is taken once: a copy within its window is refused |
| + // with the same answer as a bad signature, before any channel. |
| + if !e.fleetProbeSeen.add(auth[0], now) { |
| w.WriteHeader(http.StatusUnauthorized) |
| return |
| } |
diff --git a/internal/edge/fleetprobe_test.go b/internal/edge/fleetprobe_test.go| index b4a00f34a..5f58ff541 100644 |
| --- a/internal/edge/fleetprobe_test.go |
| +++ b/internal/edge/fleetprobe_test.go |
| @@ -361,7 +361,7 @@ func TestFleetProbeAuth(t *testing.T) { |
| if resp := g.post(http.MethodGet, g.host, auth, nil); resp.StatusCode != http.StatusNotFound { |
| t.Errorf("GET: %d", resp.StatusCode) |
| } |
| - if resp := g.post(http.MethodPost, "other.example", auth, body); resp.StatusCode == http.StatusOK { |
| + if resp := g.post(http.MethodPost, "other.example", auth, body); resp.StatusCode != http.StatusNotFound { |
| t.Errorf("another host: %d", resp.StatusCode) |
| } |
| if a.calls.Load() != before { |
| @@ -544,3 +544,34 @@ type closedAdmission struct{} |
| func (closedAdmission) TenantAdmitted() bool { return false } |
| func (closedAdmission) TenantAdmissionStarting() bool { return true } |
| func (closedAdmission) TenantAdmissionExempt(registry.Route) bool { return false } |
| + |
| +// TestFleetProbeReplay (fix round 1, Fable P3-2): a verified probe is taken |
| +// once. Its exact copy, and the same copy with the hex in capitals, get |
| +// the bad-signature 401 inside the window and never reach the box; a fresh |
| +// probe still passes. |
| +func TestFleetProbeReplay(t *testing.T) { |
| + g := newProbeRig(t) |
| + a := g.connect("box-a") |
| + req, body := probeRequest(t, "box-a") |
| + auth := signFleetProbe(g.key, req.Channel(), body, time.Now()) |
| + if resp := g.post(http.MethodPost, g.host, auth, body); resp.StatusCode != http.StatusOK { |
| + t.Fatalf("first: %d", resp.StatusCode) |
| + } |
| + for name, h := range map[string]string{"copy": auth, "capitals": strings.ToUpper(auth)} { |
| + resp := g.post(http.MethodPost, g.host, h, body) |
| + if resp.StatusCode != http.StatusUnauthorized || len(readAll(t, resp)) != 0 || resp.Header.Get(fleetProbeChannelHeader) != "" { |
| + t.Errorf("%s: %d", name, resp.StatusCode) |
| + } |
| + } |
| + if a.calls.Load() != 1 { |
| + t.Fatalf("the replay reached the box: %d calls", a.calls.Load()) |
| + } |
| + if _, resp := g.probe("box-a"); resp.StatusCode != http.StatusOK || a.calls.Load() != 2 { |
| + t.Fatalf("fresh probe: %d", resp.StatusCode) |
| + } |
| + var r fleetProbeReplays |
| + now := time.Now() |
| + if !r.add("x", now) || r.add("x", now.Add(59*time.Second)) || !r.add("x", now.Add(61*time.Second)) { |
| + t.Fatal("the seen-set does not hold a signature for its window only") |
| + } |
| +} |
diff --git a/internal/host/managedprobe.go b/internal/host/managedprobe.go| index 0780fbfa8..d8d5858bd 100644 |
| --- a/internal/host/managedprobe.go |
| +++ b/internal/host/managedprobe.go |
| @@ -31,8 +31,17 @@ import ( |
| // file (never the secret) and, whatever happened, the fingerprint of the |
| // secrets key the box has installed, for the console to check against what |
| // it delivered and registered. It runs as the carlos user, as the agent |
| -// does, through the normal SDK chain over /etc/carlos/credentials (root:carlos |
| -// 0640), the same file the hibernate lease uses. One probe at a time. |
| +// does, and reads /etc/carlos/credentials (root:carlos 0640), the file the |
| +// hibernate lease uses. One probe at a time. |
| +// |
| +// Why static credentials, built from that file and nothing else: the |
| +// reported key ID must be the key the requests were signed with. The SDK's |
| +// default chain would let environment keys (including the AWS_ACCESS_KEY |
| +// and AWS_SECRET_KEY aliases), a profile, web identity or instance metadata |
| +// win over the file, and then storage would "pass" for a key the console |
| +// never delivered. lease.NewStaticFilesStore signs with exactly the parsed |
| +// pair, so no environment name needs checking, and makes one HTTP request |
| +// per operation, so a probe is exactly three bucket requests. |
| // managedProbeTimeout bounds the storage challenge, inside the hub's 10 s. |
| const managedProbeTimeout = 8 * time.Second |
| @@ -40,10 +49,14 @@ const managedProbeTimeout = 8 * time.Second |
| // managedProbeCredentialsLimit bounds the read of the credentials file. |
| const managedProbeCredentialsLimit = 4 << 10 |
| +// managedProbeCleanup bounds the challenge object's DELETE, which runs even |
| +// when the probe's own context has ended so the object is not left behind. |
| +const managedProbeCleanup = 2 * time.Second |
| + |
| type managedProber struct { |
| id managedboot.Identity |
| getenv func(string) string |
| - open func(context.Context) (release.Store, error) |
| + open func(context.Context, managedboot.EnrolCredentials) (release.Store, error) |
| readCreds func() ([]byte, error) |
| busy sync.Mutex |
| timeout time.Duration |
| @@ -56,12 +69,12 @@ func managedProberFor(j *managedJoin) *managedProber { |
| return nil |
| } |
| p := &managedProber{id: j.id, getenv: os.Getenv, timeout: managedProbeTimeout} |
| - p.open = func(ctx context.Context) (release.Store, error) { |
| + p.open = func(_ context.Context, c managedboot.EnrolCredentials) (release.Store, error) { |
| bucket, region := p.getenv("CARLOS_HIBERNATE_BUCKET"), p.getenv("CARLOS_HIBERNATE_REGION") |
| if bucket == "" || region == "" { |
| return nil, errors.New("managed probe: host.env names no fleet bucket") |
| } |
| - return lease.NewFilesStore(ctx, bucket, region) |
| + return lease.NewStaticFilesStore(bucket, region, c.ID, string(c.Secret)) |
| } |
| p.readCreds = func() ([]byte, error) { |
| f, err := os.Open(managedboot.CredentialsPath) |
| @@ -114,36 +127,27 @@ func (p *managedProber) installedKeyFP() string { |
| return appconfig.KeyFingerprint(priv.PublicKey()) |
| } |
| -// keyID is the delivered credentials' access key ID. The SDK chain would |
| -// prefer environment keys or a named profile over the file, so either one |
| -// set means the bucket calls would not prove the delivered key: refused. |
| -func (p *managedProber) keyID() (string, error) { |
| - if p.getenv("AWS_SHARED_CREDENTIALS_FILE") != managedboot.CredentialsPath { |
| - return "", errors.New("managed probe: not the delivered credentials file") |
| - } |
| - for _, k := range []string{"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "AWS_PROFILE", "AWS_DEFAULT_PROFILE"} { |
| - if p.getenv(k) != "" { |
| - return "", errors.New("managed probe: credentials would not come from the delivered file") |
| - } |
| - } |
| +// credentials is the delivered key pair from the credentials file. |
| +func (p *managedProber) credentials() (managedboot.EnrolCredentials, error) { |
| raw, err := p.readCreds() |
| if err != nil { |
| - return "", err |
| + return managedboot.EnrolCredentials{}, err |
| } |
| - return managedboot.CredentialsKeyID(raw) |
| + return managedboot.ParseCredentials(raw) |
| } |
| // challenge writes, reads back and deletes one object under the box's own |
| // probe prefix: three bucket calls, two when the write fails. |
| func (p *managedProber) challenge(ctx context.Context, req managedboot.ProbeRequest) managedboot.ProbeStorage { |
| - id, err := p.keyID() |
| + creds, err := p.credentials() |
| if err != nil { |
| return managedboot.ProbeStorage{Code: managedboot.ProbeNoCredentials} |
| } |
| + id := creds.ID |
| fail := func(code string) managedboot.ProbeStorage { return managedboot.ProbeStorage{KeyID: id, Code: code} } |
| ctx, cancel := context.WithTimeout(ctx, p.timeout) |
| defer cancel() |
| - s, err := p.open(ctx) |
| + s, err := p.open(ctx, creds) |
| if err != nil { |
| return fail(managedboot.ProbeNoBucket) |
| } |
| @@ -173,7 +177,10 @@ func (p *managedProber) challenge(ctx context.Context, req managedboot.ProbeRequ |
| code = managedboot.ProbeMismatch |
| } |
| } |
| - if err := s.Delete(ctx, key); err != nil && code == "" { |
| + // The cleanup outlives a cancelled or expired probe, on its own budget. |
| + cleanup, done := context.WithTimeout(context.WithoutCancel(ctx), managedProbeCleanup) |
| + defer done() |
| + if err := s.Delete(cleanup, key); err != nil && code == "" { |
| code = managedboot.ProbeDeleteFailed |
| } |
| if code != "" { |
diff --git a/internal/host/managedprobe_test.go b/internal/host/managedprobe_test.go| index b3bd0f368..209419df6 100644 |
| --- a/internal/host/managedprobe_test.go |
| +++ b/internal/host/managedprobe_test.go |
| @@ -12,6 +12,7 @@ import ( |
| "io" |
| "net/http" |
| "net/http/httptest" |
| + "os" |
| "path/filepath" |
| "strings" |
| "sync" |
| @@ -36,6 +37,7 @@ type probeBucket struct { |
| failPut, failGet, failD bool |
| swap []byte // replaces the stored body before the read-back |
| hold chan struct{} |
| + onOpen func() // runs as the read-back starts |
| } |
| func (b *probeBucket) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| @@ -61,11 +63,17 @@ func (b *probeBucket) Open(ctx context.Context, key string) (io.ReadCloser, stri |
| b.mu.Lock() |
| b.gets++ |
| b.keys = append(b.keys, "GET "+key) |
| - fail := b.failGet |
| + fail, onOpen := b.failGet, b.onOpen |
| b.mu.Unlock() |
| + if onOpen != nil { |
| + onOpen() |
| + } |
| if fail { |
| return nil, "", errors.New("SlowDown") |
| } |
| + if err := ctx.Err(); err != nil { |
| + return nil, "", err |
| + } |
| return b.DirStore.Open(ctx, key) |
| } |
| @@ -77,6 +85,12 @@ func (b *probeBucket) Get(ctx context.Context, key string) ([]byte, string, erro |
| } |
| func (b *probeBucket) Delete(ctx context.Context, key string) error { |
| + if err := ctx.Err(); err != nil { |
| + b.mu.Lock() |
| + b.deletes++ |
| + b.mu.Unlock() |
| + return err |
| + } |
| b.mu.Lock() |
| b.deletes++ |
| b.keys = append(b.keys, "DELETE "+key) |
| @@ -135,7 +149,7 @@ func probeFixture(t *testing.T) (*edge.Edge, *managedProber, *probeBucket, *join |
| if err != nil { |
| t.Fatal(err) |
| } |
| - p.open = func(context.Context) (release.Store, error) { return bucket, nil } |
| + p.open = func(context.Context, managedboot.EnrolCredentials) (release.Store, error) { return bucket, nil } |
| p.readCreds = func() ([]byte, error) { return creds, nil } |
| p.getenv = managedProbeEnv("") |
| e, err := edge.New(openTestRegistry(t), nil) |
| @@ -276,18 +290,11 @@ func TestManagedProbeResponder(t *testing.T) { |
| {"read-back differs", func() { bucket.swap = []byte("someone else's bytes") }, managedboot.ProbeMismatch, 3}, |
| {"delete fails", func() { bucket.failD = true }, managedboot.ProbeDeleteFailed, 3}, |
| {"no bucket", func() { |
| - p.open = func(context.Context) (release.Store, error) { return nil, errors.New("no region") } |
| + p.open = func(context.Context, managedboot.EnrolCredentials) (release.Store, error) { |
| + return nil, errors.New("no region") |
| + } |
| }, managedboot.ProbeNoBucket, 0}, |
| {"no credentials file", func() { p.readCreds = func() ([]byte, error) { return nil, errors.New("ENOENT") } }, managedboot.ProbeNoCredentials, 0}, |
| - {"credentials from elsewhere", func() { |
| - env := managedProbeEnv(priv) |
| - p.getenv = func(k string) string { |
| - if k == "AWS_ACCESS_KEY_ID" { |
| - return "AKIAOTHEROTHEROTHER1" |
| - } |
| - return env(k) |
| - } |
| - }, managedboot.ProbeNoCredentials, 0}, |
| } { |
| t.Run(c.name, func(t *testing.T) { |
| saveOpen, saveCreds, saveEnv := p.open, p.readCreds, p.getenv |
| @@ -341,18 +348,177 @@ func TestManagedProbeResponder(t *testing.T) { |
| } |
| } |
| -// TestManagedProbeBudgetBucketCalls: each storage probe is exactly three |
| -// fleet-bucket requests, whatever the number of probes. |
| +// fakeS3 is a path-style S3 endpoint for the production store: it counts |
| +// every HTTP request, records the access key ID each was signed with, and |
| +// fails the next request of a method with a 503 when asked. |
| +type fakeS3 struct { |
| + mu sync.Mutex |
| + objects map[string][]byte |
| + log []string // "METHOD key-id" |
| + fail map[string]int |
| +} |
| + |
| +func (f *fakeS3) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| + auth := r.Header.Get("Authorization") |
| + keyID := "" |
| + if _, cred, ok := strings.Cut(auth, "Credential="); ok { |
| + keyID, _, _ = strings.Cut(cred, "/") |
| + } |
| + body, _ := io.ReadAll(r.Body) |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + f.log = append(f.log, r.Method+" "+keyID) |
| + if f.fail[r.Method] > 0 { |
| + f.fail[r.Method]-- |
| + w.Header().Set("Content-Type", "application/xml") |
| + w.WriteHeader(http.StatusServiceUnavailable) |
| + io.WriteString(w, `<?xml version="1.0" encoding="UTF-8"?><Error><Code>SlowDown</Code><Message>slow down</Message></Error>`) |
| + return |
| + } |
| + switch r.Method { |
| + case http.MethodPut: |
| + f.objects[r.URL.Path] = body |
| + w.Header().Set("ETag", `"e1"`) |
| + case http.MethodGet: |
| + b, ok := f.objects[r.URL.Path] |
| + if !ok { |
| + w.Header().Set("Content-Type", "application/xml") |
| + w.WriteHeader(http.StatusNotFound) |
| + io.WriteString(w, `<?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><Message>no</Message></Error>`) |
| + return |
| + } |
| + w.Header().Set("ETag", `"e1"`) |
| + w.Write(b) |
| + case http.MethodDelete: |
| + delete(f.objects, r.URL.Path) |
| + w.WriteHeader(http.StatusNoContent) |
| + default: |
| + w.WriteHeader(http.StatusMethodNotAllowed) |
| + } |
| +} |
| + |
| +func (f *fakeS3) take() []string { |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + out := f.log |
| + f.log = nil |
| + return out |
| +} |
| + |
| +// productionProbe is the prober managedProberFor builds, with its |
| +// production store constructor pointed at a fake S3 endpoint; only the |
| +// credentials file's bytes are supplied by the test. |
| +func productionProbe(t *testing.T, creds []byte) (http.Handler, *fakeS3, managedboot.Identity) { |
| + t.Helper() |
| + s3 := &fakeS3{objects: map[string][]byte{}, fail: map[string]int{}} |
| + srv := httptest.NewServer(s3) |
| + t.Cleanup(srv.Close) |
| + t.Setenv("CARLOS_S3_ENDPOINT", srv.URL) |
| + t.Setenv("CARLOS_HIBERNATE_BUCKET", "shop-data") |
| + t.Setenv("CARLOS_HIBERNATE_REGION", "eu-west-1") |
| + f := newJoinFixture(t) |
| + p := managedProberFor(f.join(t)) |
| + p.readCreds = func() ([]byte, error) { return creds, nil } |
| + e, err := edge.New(openTestRegistry(t), nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + edge.WithManagedProbe(p)(e) |
| + return e, s3, f.m.ID |
| +} |
| + |
| +func deliveredCreds(t *testing.T) []byte { |
| + t.Helper() |
| + creds, err := managedboot.RenderCredentials(managedboot.EnrolCredentials{ID: "AKIAEXAMPLEEXAMPLE01", Secret: []byte(probeSecret)}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return creds |
| +} |
| + |
| +// TestManagedProbeSignsWithDeliveredKey (fix round 1, Astra P1-1): every |
| +// bucket request the production prober makes is signed with the key ID it |
| +// reports, the delivered one, whatever the environment offers instead: |
| +// the SDK's key variables and their AWS_ACCESS_KEY/AWS_SECRET_KEY aliases, |
| +// a profile, another shared credentials file, web identity. |
| +func TestManagedProbeSignsWithDeliveredKey(t *testing.T) { |
| + other := filepath.Join(t.TempDir(), "credentials") |
| + if err := os.WriteFile(other, []byte("[default]\naws_access_key_id = AKIAOTHERFILEOTHER01\naws_secret_access_key = otherotherotherotherother\n[shop]\naws_access_key_id = AKIAOTHERPROFILE0001\naws_secret_access_key = otherotherotherotherother\n"), 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + for k, v := range map[string]string{ |
| + "AWS_ACCESS_KEY_ID": "AKIAOTHERENVOTHER001", |
| + "AWS_SECRET_ACCESS_KEY": "otherotherotherotherother", |
| + "AWS_ACCESS_KEY": "AKIAOTHERALIASOTHER1", |
| + "AWS_SECRET_KEY": "otherotherotherotherother", |
| + "AWS_SESSION_TOKEN": "token", |
| + "AWS_PROFILE": "shop", |
| + "AWS_DEFAULT_PROFILE": "shop", |
| + "AWS_SHARED_CREDENTIALS_FILE": other, |
| + "AWS_CONFIG_FILE": other, |
| + "AWS_WEB_IDENTITY_TOKEN_FILE": other, |
| + "AWS_ROLE_ARN": "arn:aws:iam::123456789012:role/other", |
| + } { |
| + t.Setenv(k, v) |
| + } |
| + e, s3, id := productionProbe(t, deliveredCreds(t)) |
| + w, reply := probeAsk(t, e, probeFor(t, id), true, true) |
| + if w.Code != http.StatusOK || !reply.Storage.OK || reply.Storage.KeyID != "AKIAEXAMPLEEXAMPLE01" { |
| + t.Fatalf("%d %+v", w.Code, reply) |
| + } |
| + got := s3.take() |
| + want := []string{"PUT AKIAEXAMPLEEXAMPLE01", "GET AKIAEXAMPLEEXAMPLE01", "DELETE AKIAEXAMPLEEXAMPLE01"} |
| + if strings.Join(got, "|") != strings.Join(want, "|") { |
| + t.Fatalf("requests %q, want %q", got, want) |
| + } |
| +} |
| + |
| +// TestManagedProbeBudgetBucketCalls (fix round 1, Astra P2-1): counted at |
| +// the HTTP endpoint, a probe is exactly PUT, GET, DELETE, one attempt |
| +// each. A transient failure is a failed check, never a retry. |
| func TestManagedProbeBudgetBucketCalls(t *testing.T) { |
| - e, _, bucket, f := probeFixture(t) |
| - for i := 1; i <= 5; i++ { |
| - if w, _ := probeAsk(t, e, probeFor(t, f.m.ID), true, true); w.Code != http.StatusOK { |
| - t.Fatal(w.Code) |
| + e, s3, id := productionProbe(t, deliveredCreds(t)) |
| + for i := 0; i < 3; i++ { |
| + if w, reply := probeAsk(t, e, probeFor(t, id), true, true); w.Code != http.StatusOK || !reply.Storage.OK { |
| + t.Fatalf("probe %d: %d %+v", i, w.Code, reply) |
| } |
| - if bucket.puts != i || bucket.gets != i || bucket.deletes != i { |
| - t.Fatalf("after %d probes: %d puts %d gets %d deletes", i, bucket.puts, bucket.gets, bucket.deletes) |
| + if got := s3.take(); len(got) != 3 { |
| + t.Fatalf("probe %d: %d requests %q", i, len(got), got) |
| } |
| } |
| + for _, c := range []struct { |
| + method, code string |
| + requests int |
| + }{ |
| + {http.MethodGet, managedboot.ProbeGetFailed, 3}, |
| + {http.MethodPut, managedboot.ProbePutFailed, 1}, |
| + {http.MethodDelete, managedboot.ProbeDeleteFailed, 3}, |
| + } { |
| + s3.mu.Lock() |
| + s3.fail[c.method] = 1 |
| + s3.mu.Unlock() |
| + w, reply := probeAsk(t, e, probeFor(t, id), true, true) |
| + got := s3.take() |
| + if w.Code != http.StatusOK || reply.Storage.OK || reply.Storage.Code != c.code || len(got) != c.requests { |
| + t.Fatalf("transient %s: %d %+v, requests %q", c.method, w.Code, reply, got) |
| + } |
| + } |
| +} |
| + |
| +// TestManagedProbeCleanupOutlivesCancel (fix round 1, Fable P3-1): a probe |
| +// whose context ends during the read-back still deletes its object. |
| +func TestManagedProbeCleanupOutlivesCancel(t *testing.T) { |
| + _, p, bucket, f := probeFixture(t) |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + bucket.onOpen = cancel |
| + st := p.challenge(ctx, probeFor(t, f.m.ID)) |
| + if st.OK || bucket.deletes != 1 { |
| + t.Fatalf("%+v, %d deletes", st, bucket.deletes) |
| + } |
| + keys, _ := bucket.DirStore.List(context.Background(), managedboot.ProbePrefix) |
| + if len(keys) != 0 { |
| + t.Fatalf("left behind: %q", keys) |
| + } |
| } |
| // TestManagedProbeWiring: the agent hands the edge a prober only on a |
diff --git a/internal/lease/endpoint.go b/internal/lease/endpoint.go| index 25e624713..8ca273264 100644 |
| --- a/internal/lease/endpoint.go |
| +++ b/internal/lease/endpoint.go |
| @@ -22,6 +22,7 @@ import ( |
| "github.com/aws/aws-sdk-go-v2/aws" |
| awsconfig "github.com/aws/aws-sdk-go-v2/config" |
| + "github.com/aws/aws-sdk-go-v2/credentials" |
| awss3 "github.com/aws/aws-sdk-go-v2/service/s3" |
| lss3 "github.com/benbjohnson/litestream/s3" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -195,3 +196,29 @@ func NewFilesStore(ctx context.Context, bucket, region string) (release.Store, e |
| }) |
| return &release.S3Store{Client: client, Bucket: bucket}, nil |
| } |
| + |
| +// NewStaticFilesStore is NewFilesStore signed with exactly the given key |
| +// pair and nothing else: the config is built here, not loaded, so no |
| +// environment variable (AWS_ACCESS_KEY_ID or its AWS_ACCESS_KEY alias), no |
| +// shared file or profile, no web identity and no instance metadata can |
| +// supply or replace the credentials, and the region is the one given. Each |
| +// operation is one HTTP request (aws.NopRetryer): a caller that counts its |
| +// requests, or must know which key a request proved, gets exactly that. A |
| +// managed box's readiness probe uses it (internal/host's managedProber). |
| +func NewStaticFilesStore(bucket, region, accessKeyID, secretAccessKey string) (release.Store, error) { |
| + if bucket == "" || region == "" || accessKeyID == "" || secretAccessKey == "" { |
| + return nil, errors.New("files store: static credentials need a bucket, a region and a key pair") |
| + } |
| + cfg := aws.Config{ |
| + Region: region, |
| + Credentials: aws.NewCredentialsCache(credentials.NewStaticCredentialsProvider(accessKeyID, secretAccessKey, "")), |
| + Retryer: func() aws.Retryer { return aws.NopRetryer{} }, |
| + } |
| + client := awss3.NewFromConfig(cfg, s3compat.Options(), func(o *awss3.Options) { |
| + o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired |
| + o.ResponseChecksumValidation = aws.ResponseChecksumValidationWhenRequired |
| + o.Retryer = aws.NopRetryer{} |
| + o.RetryMaxAttempts = 0 |
| + }) |
| + return &release.S3Store{Client: client, Bucket: bucket}, nil |
| +} |
diff --git a/internal/managedboot/probe.go b/internal/managedboot/probe.go| index 1ea0af655..3de5c03a2 100644 |
| --- a/internal/managedboot/probe.go |
| +++ b/internal/managedboot/probe.go |
| @@ -8,6 +8,7 @@ import ( |
| "errors" |
| "io" |
| "regexp" |
| + "slices" |
| "strings" |
| ) |
| @@ -139,7 +140,7 @@ func EncodeProbeRequest(r ProbeRequest) ([]byte, error) { |
| // or missing fields, trailing values and invalid fields are refused. |
| func ParseProbeRequest(b []byte) (ProbeRequest, error) { |
| var r ProbeRequest |
| - if len(b) > MaxProbeRequest || strictProbe(b, &r, []string{"fleet", "label", "op", "nonce", "storage"}) != nil { |
| + if len(b) > MaxProbeRequest || strictProbe(b, &r, probeRequestFields, "", nil) != nil { |
| return ProbeRequest{}, errProbe |
| } |
| if err := r.Validate(); err != nil { |
| @@ -163,7 +164,7 @@ func EncodeProbeReply(r ProbeReply) ([]byte, error) { |
| // ParseProbeReply decodes at most MaxProbeReply bytes strictly. |
| func ParseProbeReply(b []byte) (ProbeReply, error) { |
| var r ProbeReply |
| - if len(b) > MaxProbeReply || strictProbe(b, &r, []string{"fleet", "label", "op", "nonce", "storage", "secrets_key_fp"}) != nil { |
| + if len(b) > MaxProbeReply || strictProbe(b, &r, probeReplyFields, "storage", probeStorageFields) != nil { |
| return ProbeReply{}, errProbe |
| } |
| if err := r.Validate(); err != nil { |
| @@ -172,16 +173,29 @@ func ParseProbeReply(b []byte) (ProbeReply, error) { |
| return r, nil |
| } |
| -// strictProbe decodes one JSON object into v with no unknown fields and |
| -// every top-level field in required present exactly once. |
| -func strictProbe(b []byte, v any, required []string) error { |
| - var fields map[string]json.RawMessage |
| - if err := json.Unmarshal(b, &fields); err != nil || len(fields) != len(required) { |
| - return errProbe |
| +// Every top-level field of the request and the reply, and every member of |
| +// the reply's storage object: each must appear exactly once and none may |
| +// be null. |
| +var ( |
| + probeRequestFields = []string{"fleet", "label", "op", "nonce", "storage"} |
| + probeReplyFields = []string{"fleet", "label", "op", "nonce", "storage", "secrets_key_fp"} |
| + probeStorageFields = []string{"ok", "key_id", "code"} |
| +) |
| + |
| +// strictProbe decodes one JSON object into v. encoding/json alone keeps |
| +// the last of two duplicate keys, matches keys without regard to case and |
| +// leaves a field untouched for null, so the object's members are checked |
| +// first: exactly the required names, each once, none null; nested, when |
| +// set, names a member that must itself be such an object with exactly |
| +// nestedFields. Then v is decoded with unknown fields refused. |
| +func strictProbe(b []byte, v any, required []string, nested string, nestedFields []string) error { |
| + fields, err := probeMembers(b, required) |
| + if err != nil { |
| + return err |
| } |
| - for _, name := range required { |
| - if _, ok := fields[name]; !ok { |
| - return errProbe |
| + if nested != "" { |
| + if _, err := probeMembers(fields[nested], nestedFields); err != nil { |
| + return err |
| } |
| } |
| dec := json.NewDecoder(bytes.NewReader(b)) |
| @@ -189,28 +203,63 @@ func strictProbe(b []byte, v any, required []string) error { |
| if dec.Decode(v) != nil { |
| return errProbe |
| } |
| - var extra any |
| - if dec.Decode(&extra) != io.EOF { |
| - return errProbe |
| - } |
| return nil |
| } |
| +// probeMembers reads b as exactly one JSON object whose member names are |
| +// exactly required, each once, with no null value, and nothing after it. |
| +func probeMembers(b []byte, required []string) (map[string]json.RawMessage, error) { |
| + dec := json.NewDecoder(bytes.NewReader(b)) |
| + if t, err := dec.Token(); err != nil || t != json.Delim('{') { |
| + return nil, errProbe |
| + } |
| + fields := map[string]json.RawMessage{} |
| + for dec.More() { |
| + t, err := dec.Token() |
| + name, ok := t.(string) |
| + if err != nil || !ok { |
| + return nil, errProbe |
| + } |
| + var raw json.RawMessage |
| + if err := dec.Decode(&raw); err != nil { |
| + return nil, errProbe |
| + } |
| + if _, dup := fields[name]; dup || !slices.Contains(required, name) || bytes.Equal(bytes.TrimSpace(raw), []byte("null")) { |
| + return nil, errProbe |
| + } |
| + fields[name] = raw |
| + } |
| + if t, err := dec.Token(); err != nil || t != json.Delim('}') || len(fields) != len(required) { |
| + return nil, errProbe |
| + } |
| + if _, err := dec.Token(); err != io.EOF { |
| + return nil, errProbe |
| + } |
| + return fields, nil |
| +} |
| + |
| // CredentialsKeyID is the access key ID in CredentialsPath's bytes, which |
| // must be exactly RenderCredentials' form. |
| func CredentialsKeyID(b []byte) (string, error) { |
| + c, err := ParseCredentials(b) |
| + return c.ID, err |
| +} |
| + |
| +// ParseCredentials is CredentialsPath's key pair, from exactly |
| +// RenderCredentials' form. |
| +func ParseCredentials(b []byte) (EnrolCredentials, error) { |
| const head = "[default]\naws_access_key_id = " |
| rest, ok := strings.CutPrefix(string(b), head) |
| if !ok { |
| - return "", errProbe |
| + return EnrolCredentials{}, errProbe |
| } |
| id, secret, ok := strings.Cut(rest, "\naws_secret_access_key = ") |
| if !ok || !accessKeyRE.MatchString(id) { |
| - return "", errProbe |
| + return EnrolCredentials{}, errProbe |
| } |
| secret, ok = strings.CutSuffix(secret, "\n") |
| if !ok || !secretKeyRE.MatchString(secret) { |
| - return "", errProbe |
| + return EnrolCredentials{}, errProbe |
| } |
| - return id, nil |
| + return EnrolCredentials{ID: id, Secret: []byte(secret)}, nil |
| } |
diff --git a/internal/managedboot/probe_test.go b/internal/managedboot/probe_test.go| index e6b93944e..3db676168 100644 |
| --- a/internal/managedboot/probe_test.go |
| +++ b/internal/managedboot/probe_test.go |
| @@ -137,3 +137,66 @@ func TestManagedProbeCredentialsKeyID(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestManagedProbeWireStrict (fix round 1, Astra P2-2): a duplicate key, a |
| +// null for any field, a key in another case, a missing or extra member of |
| +// the reply's storage object and a wrong type are refused by both |
| +// decoders; the canonical encodings still parse. |
| +func TestManagedProbeWireStrict(t *testing.T) { |
| + req := probeTestRequest(t) |
| + n, op := req.Nonce, req.Op |
| + request := func(storage string) string { |
| + return `{"fleet":"shop","label":"box-a","op":"` + op + `","nonce":"` + n + `",` + storage + `}` |
| + } |
| + if _, err := ParseProbeRequest([]byte(request(`"storage":true`))); err != nil { |
| + t.Fatalf("canonical request: %v", err) |
| + } |
| + for name, body := range map[string]string{ |
| + "duplicate storage": request(`"storage":false,"storage":true`), |
| + "duplicate fleet": `{"fleet":"shop","fleet":"shop","label":"box-a","op":"` + op + `","nonce":"` + n + `","storage":true}`, |
| + "null storage": request(`"storage":null`), |
| + "null fleet": `{"fleet":null,"label":"box-a","op":"` + op + `","nonce":"` + n + `","storage":true}`, |
| + "storage as string": request(`"storage":"true"`), |
| + "key in other case": `{"Fleet":"shop","label":"box-a","op":"` + op + `","nonce":"` + n + `","storage":true}`, |
| + "array": `[` + request(`"storage":true`) + `]`, |
| + "two objects": request(`"storage":true`) + request(`"storage":true`), |
| + "storage as object": request(`"storage":{}`), |
| + "empty object": `{}`, |
| + "trailing garbage": request(`"storage":true`) + `x`, |
| + "nested in storage?": request(`"storage":true,"storage2":true`), |
| + } { |
| + if _, err := ParseProbeRequest([]byte(body)); err == nil { |
| + t.Errorf("request %s: accepted", name) |
| + } |
| + } |
| + |
| + head := `{"fleet":"shop","label":"box-a","op":"` + op + `","nonce":"` + n + `",` |
| + reply := func(storage, fp string) string { |
| + return head + `"storage":` + storage + `,"secrets_key_fp":` + fp + `}` |
| + } |
| + okStorage := `{"ok":true,"key_id":"AKIAEXAMPLEEXAMPLE01","code":""}` |
| + if _, err := ParseProbeReply([]byte(reply(okStorage, `""`))); err != nil { |
| + t.Fatalf("canonical reply: %v", err) |
| + } |
| + for name, body := range map[string]string{ |
| + "empty storage": reply(`{}`, `""`), |
| + "storage without code": reply(`{"ok":true,"key_id":"AKIAEXAMPLEEXAMPLE01"}`, `""`), |
| + "storage without ok": reply(`{"key_id":"AKIAEXAMPLEEXAMPLE01","code":"put_failed"}`, `""`), |
| + "storage without key": reply(`{"ok":false,"code":"put_failed"}`, `""`), |
| + "null storage": reply(`null`, `""`), |
| + "null ok": reply(`{"ok":null,"key_id":"","code":"put_failed"}`, `""`), |
| + "null code": reply(`{"ok":true,"key_id":"AKIAEXAMPLEEXAMPLE01","code":null}`, `""`), |
| + "duplicate ok": reply(`{"ok":false,"ok":true,"key_id":"AKIAEXAMPLEEXAMPLE01","code":""}`, `""`), |
| + "duplicate storage": head + `"storage":` + okStorage + `,"storage":` + okStorage + `,"secrets_key_fp":""}`, |
| + "null fingerprint": reply(okStorage, `null`), |
| + "extra storage member": reply(`{"ok":true,"key_id":"AKIAEXAMPLEEXAMPLE01","code":"","secret":"x"}`, `""`), |
| + "storage member case": reply(`{"OK":true,"key_id":"AKIAEXAMPLEEXAMPLE01","code":""}`, `""`), |
| + "storage as bool": reply(`true`, `""`), |
| + "duplicate nonce": `{"fleet":"shop","label":"box-a","op":"` + op + `","nonce":"` + n + `","nonce":"` + n + `","storage":` + okStorage + `,"secrets_key_fp":""}`, |
| + "fingerprint as number": reply(okStorage, `1`), |
| + } { |
| + if _, err := ParseProbeReply([]byte(body)); err == nil { |
| + t.Errorf("reply %s: accepted", name) |
| + } |
| + } |
| +} |
diff --git a/internal/provision/managed_fleets_2b2_census_test.go b/internal/provision/managed_fleets_2b2_census_test.go| index d29c761df..c4d24358a 100644 |
| --- a/internal/provision/managed_fleets_2b2_census_test.go |
| +++ b/internal/provision/managed_fleets_2b2_census_test.go |
| @@ -57,10 +57,13 @@ package provision |
| // - host.managedProber.challenge (the agent, as carlos, answering the |
| // console's readiness probe on a managed box) PUTs |
| // _carlos/probes/<label>/<nonce> create-only (ifMatch "") into the |
| -// fleet's OWN bucket (lease.NewFilesStore over the delivered |
| -// credentials file), reads it back and deletes it. Random bytes, no |
| +// fleet's OWN bucket (lease.NewStaticFilesStore, signed with exactly |
| +// the delivered key pair from the credentials file, one attempt per |
| +// request), reads it back and deletes it (the DELETE on its own 2 s |
| +// budget even after the probe's context ends). Random bytes, no |
| // instance or sidecar record and no deployment-store key: nonrecord. |
| -// Witnessed by TestManagedProbeResponder and |
| +// Witnessed by TestManagedProbeResponder, |
| +// TestManagedProbeSignsWithDeliveredKey and |
| // TestManagedProbeBudgetBucketCalls. |
| // - Edge.serveDemoTraffic also scrubs the managed probe marker and the |
| // hub's channel attestation from demo requests (two names added to its |
| @@ -70,7 +73,7 @@ func managedFleets2b2WriteCensusInventory() []censusEntry { |
| entries := append([]censusEntry(nil), managedFleets2b1WriteCensusInventory()...) |
| entries = append(entries, censusEntry{"internal/managedboot/hostenv.go", "ManagedHostEnv", "key-site", "lit:instances", "475c33aef5f55a5ffcaa97f8caa8eb30b0027a0d19486e88f1980909e468b5f5"}) |
| entries = append(entries, censusEntry{"internal/host/managedkey.go", "ensureFleetKey", "nonrecord", "sel:Put", "2c319a1f3d4c4920f120b91e1b9f5063257225d161399934160d08a23c6b9984"}) |
| - entries = append(entries, censusEntry{"internal/host/managedprobe.go", "managedProber.challenge", "nonrecord", "sel:Put", "8ddc47d1e39d847d7adfdba3abdae49aec045868ca2be1d4a5602dc911216625"}) |
| + entries = append(entries, censusEntry{"internal/host/managedprobe.go", "managedProber.challenge", "nonrecord", "sel:Put", "53a26637a4adf4b07a8f5aace39443f5b1abe83226b5ed1f498c9d4a327184d2"}) |
| repins := []censusEntry{ |
| {"internal/console/server.go", "NewServer", "key-site", "lit:instances", "30ef695663c7c0807d1dd8c20e66c32adb9a607d40ec6e30624c6ca403cee281"}, |
| {"internal/console/managedworker.go", "Server.managedPublishFresh", "nonrecord", "sel:Put", "a9345cd73b16e931e72637adf34274479ce2c7ad001eb8d53d088844a8af9c53"}, |