carlos / platform Public

group verb: read each bucket in its own region

The flagship deployment bucket is in eu-west-1 and its US group in
us-east-1; S3's 301 is not followed by the SDK, so every edges read
refused as Uncertain(api). Each bucket's region is now resolved once by
an unsigned HeadBucket and read through that region's client; an
unresolved region or a 301 is Uncertain(bucket_region) naming the
bucket. A required flag left out (bare plan, no --config) prints usage,
status 2, as argparse did. Spec V14. Astra r1 P2/P3 fixed, r2 clean;
census envelopes approved on #280. New text bucket_region not yet
copy-reviewed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from group-bucket-region into main.
claude cdc3cc360a805b34eaa110ad399db21ccd896257 parent a5225f7
14 files changed, +411 −41
  • docs/superpowers/notes/census-proposal-group-bucket-region.md +11 −0
  • docs/superpowers/specs/2026-11-09-group-roll-verb-design.md +1 −0
  • internal/grouproll/box.go +12 −3
  • internal/grouproll/text.go +1 −0
  • internal/grouproll/text_test.go +4 −3
  • internal/grouprollaws/group.go +13 −1
  • internal/grouprollaws/objects.go +129 −6
  • internal/grouprollaws/objects_test.go +138 −5
  • internal/grouprollaws/recorder_test.go +7 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv +5 −0
  • internal/release/openers_test.go +1 −1
  • system_group.go +30 −0
  • system_group_test.go +58 −21

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-group-bucket-region.md b/docs/superpowers/notes/census-proposal-group-bucket-region.md
new file mode 100644
index 000000000..221bbfa33
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-group-bucket-region.md
@@ -0,0 +1,11 @@
+# Census approval: group-bucket-region
+
+Ruling `census-ruling-group-bucket-region`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `.`, `internal/grouproll`, `internal/grouprollaws`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Seal: `733204d61bea49fe418d8ff0f1bfa20d77bdffb1f08a216d9de92923eea22557` → `733204d61bea49fe418d8ff0f1bfa20d77bdffb1f08a216d9de92923eea22557`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md
index 2520d4409..5367bc3e4 100644
--- a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md
+++ b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md
@@ -374,6 +374,7 @@ build to it.
| V11 | After the terminate check, any `desired` or `minimum` below N is raised again (`:2248-2255`), so an outside reduction after the restore launches capacity | Once a fresh read shows a restore reached N, a later value below N is a failed probe (`desired_changed`); only an unanswered restore is retried | Same review; H4 forbids the tool from raising capacity it already restored |
| V12 | `refuse_while_moving` is skipped once any `exit-intent` exists (`:1828`), though that row is written before dispatch and dispatch can be refused or cut | Before every ExitStandby of a failed drain's member the drain check runs on the status the request acts on, whatever earlier intents exist | Branch review round 1 (Astra P1, 2026-11-10): the r2 cut must hold on resume |
| V13 | Under DR-4, `roll` prints the rule ("Replace only lock-free members") and goes on: Standby, then apply, which restarts the edge with no drain | Under DR-4, `roll` refuses up front when a lock names the member: it runs the lock sweep (`locks_naming_member`) immediately before the first group write and closes `floor-refused` with no group write (`floor_refused`, then `lock_held`; `floor_config` without `data_bucket` or `data_prefix`; a sweep that cannot read refuses too). A resumed process sweeps again before the next write that leads to Standby, whatever intents the journal holds (an intent is written before dispatch); a finding then restores a lowered minimum and closes `lock-refused`. It re-checks immediately before the mutation, after Standby and the permit: a lock or a failed sweep returns the member unchanged, revokes the permit and closes `lock-refused` | Dev W2 2026-11-10 restarted a lease-holding member without a drain (8a3d302 P1) |
+| V14 | `aws s3api` follows S3's 301 to the bucket's region, so a deployment bucket in another region than the group reads normally | Each bucket is read through a client on its own region's endpoint, resolved once per process by an unsigned HeadBucket (`x-amz-bucket-region`); an unresolved region, or a 301 after resolution, is Uncertain(`bucket_region`) naming the bucket. A required flag left out prints the verb's usage, status 2 (argparse); given empty, it is refused as before | Flagship step 4 2026-11-10: the US group (us-east-1) reads the eu-west-1 deployment bucket; plan refused every edges read |
Not deviations, recorded so nobody "fixes" them in the port: the drain-rerun
backoff and the TakeHost `wake_timeout` follow-ups from the held build stay
diff --git a/internal/grouproll/box.go b/internal/grouproll/box.go
index 8da092302..679f1315f 100644
--- a/internal/grouproll/box.go
+++ b/internal/grouproll/box.go
@@ -93,11 +93,17 @@ type Box interface {
type Uncertain struct {
Key string
Timeout bool
- ExitCode *int // set for a failed provider process (the script's api case)
- OutputTooLarge bool // the provider's answer exceeded the 4 MiB output cap
+ ExitCode *int // set for a failed provider process (the script's api case)
+ OutputTooLarge bool // the provider's answer exceeded the 4 MiB output cap
+ Bucket string // bucket_region: the bucket whose region is unknown
}
-func (u Uncertain) Error() string { return Text(u.Key) }
+func (u Uncertain) Error() string {
+ if u.Key == "bucket_region" {
+ return Text(u.Key, "bucket", u.Bucket)
+ }
+ return Text(u.Key)
+}
// Details is the script's exc.details, as the error row records it.
func (u Uncertain) Details() map[string]any {
@@ -112,6 +118,9 @@ func (u Uncertain) Details() map[string]any {
// An SDK adapter has no process exit code, only the cap.
d["output_too_large"] = true
}
+ if u.Bucket != "" {
+ d["bucket"] = u.Bucket
+ }
return d
}
diff --git a/internal/grouproll/text.go b/internal/grouproll/text.go
index c9a1b8e54..73f35af1e 100644
--- a/internal/grouproll/text.go
+++ b/internal/grouproll/text.go
@@ -73,6 +73,7 @@ var text = map[string]string{
"hook": "The immutable launch hook must have a 900-second ABANDON default",
"remote": "The command on the member returned no complete result",
"api": "An AWS response is unavailable or invalid",
+ "bucket_region": "The AWS region of bucket {bucket} is unknown or has changed",
"rollback_refused": "Rollback requires this transaction's consumed apply in Standby",
"rollback_digest": "The installed artifact does not match the recorded old or new digest",
"unsupported": "Unsupported operation",
diff --git a/internal/grouproll/text_test.go b/internal/grouproll/text_test.go
index e82abd1c3..389429b8d 100644
--- a/internal/grouproll/text_test.go
+++ b/internal/grouproll/text_test.go
@@ -14,9 +14,10 @@ var placeholderPattern = regexp.MustCompile(`\{([a-z_]+)\}`)
func TestTextRendersEveryKey(t *testing.T) {
// 139 approved, plus floor_fixed_missing, floor_fixed_boxes,
// floor_fixed_both, drain_peers_many, floor_legacy and floor_population
- // (held floor capability, 2026-11-10), not yet copy-reviewed.
- if len(text) != 145 {
- t.Fatalf("text has %d keys, want the 139 approved plus 6", len(text))
+ // (held floor capability, 2026-11-10), and bucket_region (a bucket in
+ // another region than the group, 2026-11-10), not yet copy-reviewed.
+ if len(text) != 146 {
+ t.Fatalf("text has %d keys, want the 139 approved plus 7", len(text))
}
for key, raw := range text {
var args []string
diff --git a/internal/grouprollaws/group.go b/internal/grouprollaws/group.go
index bff9a5e13..78c6791b5 100644
--- a/internal/grouprollaws/group.go
+++ b/internal/grouprollaws/group.go
@@ -12,6 +12,7 @@ import (
"regexp"
"strconv"
"strings"
+ "sync"
"time"
"unicode/utf8"
@@ -53,8 +54,14 @@ type Adapter struct {
ec2 ec2Ops
ssm ssmOps
sts *sts.Client
- s3 *s3.Client // objects.go: edges files, locks, release pointers
+ s3 *s3.Client // objects.go: the config region's client; it resolves bucket regions
plugin pluginCheck // session.go: the plugin's path and version, once
+
+ // objects.go: each bucket's resolved region, and a client per other
+ // region (edges files, locks, release pointers).
+ bucketsMu sync.Mutex
+ bucketRegion map[string]string
+ regionS3 map[string]*s3.Client
}
func newAdapter(cfg aws.Config, c grouproll.Config) *Adapter {
@@ -154,6 +161,11 @@ func call[T any](parent context.Context, fn func(context.Context) (T, error)) (T
if parent.Err() != nil {
return zero, parent.Err()
}
+ // The adapter's own answer (objects.go's bucket_region) stands.
+ var own grouproll.Uncertain
+ if errors.As(err, &own) {
+ return zero, own
+ }
if errors.Is(err, errOutputTooLarge) {
return zero, grouproll.Uncertain{Key: "api", OutputTooLarge: true}
}
diff --git a/internal/grouprollaws/objects.go b/internal/grouprollaws/objects.go
index 5927954c4..80a880e8c 100644
--- a/internal/grouprollaws/objects.go
+++ b/internal/grouprollaws/objects.go
@@ -2,9 +2,15 @@ package grouprollaws
import (
"context"
+ "errors"
+ "net"
+ "net/http"
+ "regexp"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
+ "github.com/aws/smithy-go/middleware"
+ smithyhttp "github.com/aws/smithy-go/transport/http"
"github.com/carlosframework/platform/internal/grouproll"
"github.com/carlosframework/platform/internal/release"
@@ -27,31 +33,148 @@ func newS3(cfg aws.Config) *s3.Client {
// pointers), the script's s3api get-object and list-objects-v2: each read
// is bounded as every provider call is, every failure (a missing object
// too) is Uncertain(api), and the store has no write path.
+//
+// A bucket may live in another region than the group: the flagship's
+// deployment bucket is in eu-west-1 and its US group in us-east-1. S3
+// answers a request sent to the wrong region's endpoint with a 301 that the
+// SDK does not follow (the script's aws CLI did). So each bucket is read
+// through a client on its own region's endpoint, the region resolved once
+// per process from HeadBucket's x-amz-bucket-region header. A region that
+// cannot be resolved, and a 301 after resolution, are Uncertain(bucket_region)
+// naming the bucket, never the generic api answer.
func (a *Adapter) Bucket(name string) release.Store {
- return readStore{s: &release.S3Store{Client: a.s3, Bucket: name}}
+ return readStore{a: a, bucket: name}
}
-type readStore struct{ s *release.S3Store }
+// bucketRegionHeader is S3's own region answer, on a 200, a 301 and a 403
+// alike.
+const bucketRegionHeader = "X-Amz-Bucket-Region"
+
+// awsRegion is the config's region shape (grouproll configRegion).
+var awsRegion = regexp.MustCompile(`^[a-z]{2}(?:-[a-z]+)+-[0-9]$`)
+
+// bucketClient is the client for bucket's region, resolving the region on
+// the first read of that bucket.
+func (a *Adapter) bucketClient(ctx context.Context, bucket string) (*s3.Client, error) {
+ a.bucketsMu.Lock()
+ defer a.bucketsMu.Unlock()
+ region, ok := a.bucketRegion[bucket]
+ if !ok {
+ got, err := call(ctx, func(ctx context.Context) (string, error) { return headBucketRegion(ctx, a.s3, bucket) })
+ if err != nil {
+ var u grouproll.Uncertain
+ if ctx.Err() != nil || (errors.As(err, &u) && (u.Timeout || u.OutputTooLarge)) {
+ return nil, err
+ }
+ return nil, grouproll.Uncertain{Key: "bucket_region", Bucket: bucket}
+ }
+ if !awsRegion.MatchString(got) {
+ return nil, grouproll.Uncertain{Key: "bucket_region", Bucket: bucket}
+ }
+ if a.bucketRegion == nil {
+ a.bucketRegion = map[string]string{}
+ }
+ region = got
+ a.bucketRegion[bucket] = region
+ }
+ if region == a.cfg.Region {
+ return a.s3, nil
+ }
+ if c, ok := a.regionS3[region]; ok {
+ return c, nil
+ }
+ cfg := a.cfg.Copy()
+ cfg.Region = region
+ c := newS3(cfg)
+ if a.regionS3 == nil {
+ a.regionS3 = map[string]*s3.Client{}
+ }
+ a.regionS3[region] = c
+ return c, nil
+}
+
+// headBucketRegion is the feature/s3/manager GetBucketRegion recipe: an
+// unsigned HeadBucket (no IAM grant is needed, and a signature for the
+// wrong region could not be checked) whose answer, whatever its status,
+// carries the bucket's region in a header.
+func headBucketRegion(ctx context.Context, client *s3.Client, bucket string) (string, error) {
+ var region string
+ capture := middleware.DeserializeMiddlewareFunc("CarlosBucketRegion", func(ctx context.Context,
+ in middleware.DeserializeInput, next middleware.DeserializeHandler) (middleware.DeserializeOutput, middleware.Metadata, error) {
+ out, md, err := next.HandleDeserialize(ctx, in)
+ if r, ok := out.RawResponse.(*smithyhttp.Response); ok && r != nil && r.Response != nil {
+ region = r.Header.Get(bucketRegionHeader)
+ }
+ return out, md, err
+ })
+ _, err := client.HeadBucket(ctx, &s3.HeadBucketInput{Bucket: aws.String(bucket)}, func(o *s3.Options) {
+ o.Credentials = nil
+ o.APIOptions = append(o.APIOptions, func(st *middleware.Stack) error {
+ return st.Deserialize.Add(capture, middleware.After)
+ })
+ })
+ if region != "" {
+ return region, nil
+ }
+ if err == nil {
+ err = errNoBucketRegion
+ }
+ return "", err
+}
+
+var errNoBucketRegion = errors.New("grouprollaws: no bucket region in the answer")
+
+// movedBucket reports S3's wrong-region answer: a 301 (PermanentRedirect).
+func movedBucket(err error) bool {
+ var status interface{ HTTPStatusCode() int }
+ return errors.As(err, &status) && status.HTTPStatusCode() == http.StatusMovedPermanently
+}
+
+type readStore struct {
+ a *Adapter
+ bucket string
+}
type object struct {
body []byte
etag string
}
+// read runs fn on bucket's regional store, as one bounded provider call.
+func read[T any](ctx context.Context, r readStore, fn func(context.Context, *release.S3Store) (T, error)) (T, error) {
+ var zero T
+ c, err := r.a.bucketClient(ctx, r.bucket)
+ if err != nil {
+ return zero, err
+ }
+ store := &release.S3Store{Client: c, Bucket: r.bucket}
+ return call(ctx, func(ctx context.Context) (T, error) {
+ out, err := fn(ctx, store)
+ // A 301 whose body stalled or overran the cap keeps call's
+ // timeout or cap answer: only a whole 301 is a wrong region.
+ var netErr net.Error
+ if err != nil && movedBucket(err) && !errors.Is(err, errOutputTooLarge) &&
+ !errors.Is(err, context.DeadlineExceeded) && !(errors.As(err, &netErr) && netErr.Timeout()) {
+ return out, grouproll.Uncertain{Key: "bucket_region", Bucket: r.bucket}
+ }
+ return out, err
+ })
+}
+
func (r readStore) Get(ctx context.Context, key string) ([]byte, string, error) {
- out, err := call(ctx, func(ctx context.Context) (object, error) {
- b, etag, err := r.s.Get(ctx, key)
+ out, err := read(ctx, r, func(ctx context.Context, s *release.S3Store) (object, error) {
+ b, etag, err := s.Get(ctx, key)
return object{b, etag}, err
})
return out.body, out.etag, err
}
func (r readStore) List(ctx context.Context, prefix string) ([]string, error) {
- return call(ctx, func(ctx context.Context) ([]string, error) { return r.s.List(ctx, prefix) })
+ return read(ctx, r, func(ctx context.Context, s *release.S3Store) ([]string, error) { return s.List(ctx, prefix) })
}
func (r readStore) ListDirs(ctx context.Context, prefix string) ([]string, error) {
- return call(ctx, func(ctx context.Context) ([]string, error) { return r.s.ListDirs(ctx, prefix) })
+ return read(ctx, r, func(ctx context.Context, s *release.S3Store) ([]string, error) { return s.ListDirs(ctx, prefix) })
}
func (readStore) Put(context.Context, string, []byte, string) (string, error) {
diff --git a/internal/grouprollaws/objects_test.go b/internal/grouprollaws/objects_test.go
index ab6dcaee5..87f9ae12b 100644
--- a/internal/grouprollaws/objects_test.go
+++ b/internal/grouprollaws/objects_test.go
@@ -9,20 +9,58 @@ import (
"testing"
"github.com/carlosframework/platform/internal/grouproll"
+ "github.com/carlosframework/platform/internal/release"
)
-// s3Recorder answers S3 REST requests: GETs of objects, nothing else.
+// s3Recorder answers S3 REST requests as S3 does: an unsigned HeadBucket
+// on any region's endpoint gets a 403 naming the bucket's region (region,
+// default the test config's eu-west-1; headStatus and noRegion vary it),
+// a request on another region's endpoint gets the 301 PermanentRedirect
+// the SDK does not follow, and GETs of objects get status and body.
type s3Recorder struct {
- mu sync.Mutex
- reqs []*http.Request
- status int
- body string
+ mu sync.Mutex
+ reqs []*http.Request // every request but the HeadBuckets
+ heads []*http.Request
+ status int
+ body string
+ region string
+ headStatus int
+ noRegion bool
+ // redirectBody replaces the 301's body (default a PermanentRedirect).
+ redirectBody string
}
func (r *s3Recorder) Do(req *http.Request) (*http.Response, error) {
+ region := r.region
+ if region == "" {
+ region = "eu-west-1"
+ }
+ header := http.Header{"Content-Type": []string{"application/xml"}}
+ if !r.noRegion {
+ header.Set("X-Amz-Bucket-Region", region)
+ }
+ if req.Method == http.MethodHead {
+ r.mu.Lock()
+ r.heads = append(r.heads, req)
+ r.mu.Unlock()
+ status := r.headStatus
+ if status == 0 {
+ status = 403
+ }
+ return &http.Response{StatusCode: status, Status: http.StatusText(status), Header: header,
+ Body: io.NopCloser(bytes.NewReader(nil)), Request: req}, nil
+ }
r.mu.Lock()
r.reqs = append(r.reqs, req)
r.mu.Unlock()
+ if !strings.Contains(req.URL.Host, "s3."+region+".amazonaws.com") {
+ body := `<Error><Code>PermanentRedirect</Code><Message>x</Message><Endpoint>b.s3.` + region + `.amazonaws.com</Endpoint></Error>`
+ if r.redirectBody != "" {
+ body = r.redirectBody
+ }
+ return &http.Response{StatusCode: 301, Status: http.StatusText(301), Header: header,
+ Body: io.NopCloser(bytes.NewReader([]byte(body))), Request: req}, nil
+ }
status, body := r.status, r.body
if status != 200 && body == "" {
body = `<Error><Code>NoSuchKey</Code><Message>x</Message></Error>`
@@ -81,3 +119,98 @@ func TestBucketReadsOnly(t *testing.T) {
}
var _ grouproll.Objects = testAdapterWith(t, rec)
}
+
+// The flagship's shape: the group in us-east-1, its deployment bucket in
+// eu-west-1. The bucket's region is resolved once, by one unsigned
+// HeadBucket, and every read of it goes to the eu-west-1 endpoint signed
+// for eu-west-1; a bucket in the config's own region uses the config's
+// client.
+func TestBucketReadsCrossRegion(t *testing.T) {
+ rec := &s3Recorder{status: 200, body: `{"v":1}`, region: "eu-west-1"}
+ a := testAdapterIn(t, rec, "us-east-1")
+ store := a.Bucket("carlos-flagship-store")
+ for _, key := range []string{"control/edges/g-1.json", "control/edges/g-2.json"} {
+ body, _, err := store.Get(ctx, key)
+ if err != nil || string(body) != `{"v":1}` {
+ t.Fatalf("Get %s = %q, %v", key, body, err)
+ }
+ }
+ if _, err := a.Bucket("carlos-flagship-store").List(ctx, "control/edges/"); err != nil {
+ t.Fatalf("List: %v", err)
+ }
+ if len(rec.heads) != 1 {
+ t.Fatalf("HeadBuckets = %d, want one per bucket per process", len(rec.heads))
+ }
+ h := rec.heads[0]
+ if !strings.HasPrefix(h.URL.Host, "carlos-flagship-store.s3.us-east-1.amazonaws.com") || h.Header.Get("Authorization") != "" {
+ t.Fatalf("HeadBucket = %s (Authorization %q), want unsigned on the config region",
+ h.URL.Host, h.Header.Get("Authorization"))
+ }
+ for _, q := range rec.reqs {
+ if !strings.HasPrefix(q.URL.Host, "carlos-flagship-store.s3.eu-west-1.amazonaws.com") ||
+ !strings.Contains(q.Header.Get("Authorization"), "/eu-west-1/s3/aws4_request") {
+ t.Fatalf("read %s %s signed %q, want the bucket's region", q.Method, q.URL.Host, q.Header.Get("Authorization"))
+ }
+ }
+ // A bucket in the config's region: resolved the same way, read there.
+ same := &s3Recorder{status: 200, body: `{}`, region: "us-east-1"}
+ if _, _, err := testAdapterIn(t, same, "us-east-1").Bucket("carlos-data-us").Get(ctx, "k"); err != nil {
+ t.Fatalf("same-region Get: %v", err)
+ }
+ if q := same.reqs[0]; !strings.HasPrefix(q.URL.Host, "carlos-data-us.s3.us-east-1.amazonaws.com") {
+ t.Fatalf("same-region read went to %s", q.URL.Host)
+ }
+}
+
+// A 301 is never the generic api answer: an unresolvable region and a
+// wrong-region answer after resolution are Uncertain(bucket_region) naming
+// the bucket, for Get, List and ListDirs alike.
+func TestBucketRegionNeverSilent(t *testing.T) {
+ reads := map[string]func(release.Store) error{
+ "Get": func(s release.Store) error { _, _, err := s.Get(ctx, "k"); return err },
+ "List": func(s release.Store) error { _, err := s.List(ctx, "p/"); return err },
+ "ListDirs": func(s release.Store) error { _, err := s.ListDirs(ctx, "p/"); return err },
+ }
+ want := func(t *testing.T, what string, err error) {
+ t.Helper()
+ u := uncertainKey(t, err)
+ if u.Key != "bucket_region" || u.Bucket != "carlos-flagship-store" || u.Timeout {
+ t.Fatalf("%s: %+v, want bucket_region naming the bucket", what, u)
+ }
+ if got := err.Error(); !strings.Contains(got, "carlos-flagship-store") {
+ t.Fatalf("%s: text %q does not name the bucket", what, got)
+ }
+ if d := u.Details(); d["bucket"] != "carlos-flagship-store" {
+ t.Fatalf("%s: details %v", what, d)
+ }
+ }
+ for name, fn := range reads {
+ // No region in the HeadBucket answer: refused before any read.
+ rec := &s3Recorder{status: 200, noRegion: true}
+ want(t, name+" unresolved", fn(testAdapterIn(t, rec, "us-east-1").Bucket("carlos-flagship-store")))
+ if len(rec.reqs) != 0 {
+ t.Fatalf("%s: %d reads sent with no region", name, len(rec.reqs))
+ }
+ // A malformed region is not trusted either.
+ rec = &s3Recorder{status: 200, region: "eu-west-1/../x"}
+ want(t, name+" malformed", fn(testAdapterIn(t, rec, "us-east-1").Bucket("carlos-flagship-store")))
+ // Resolved, then S3 answers 301 (the region moved or was wrong).
+ rec = &s3Recorder{status: 200, region: "eu-west-1"}
+ a := testAdapterIn(t, rec, "us-east-1")
+ a.bucketRegion = map[string]string{"carlos-flagship-store": "eu-central-1"}
+ want(t, name+" 301", fn(a.Bucket("carlos-flagship-store")))
+ }
+ // A 301 whose body overruns the output cap is the cap's answer, not a
+ // wrong region (Astra r1 P2).
+ big := &s3Recorder{status: 200, region: "eu-west-1", redirectBody: strings.Repeat("x", outputCap+1)}
+ a := testAdapterIn(t, big, "us-east-1")
+ a.bucketRegion = map[string]string{"carlos-flagship-store": "eu-central-1"}
+ if _, _, err := a.Bucket("carlos-flagship-store").Get(ctx, "k"); !uncertainKey(t, err).OutputTooLarge {
+ t.Fatalf("301 over the cap: %v", err)
+ }
+ // The resolution's other failures keep their meaning: a HeadBucket
+ // that answers 500 with no region is bucket_region, not api.
+ rec := &s3Recorder{headStatus: 500, noRegion: true}
+ _, _, err := testAdapterIn(t, rec, "us-east-1").Bucket("carlos-flagship-store").Get(ctx, "k")
+ want(t, "head 500", err)
+}
diff --git a/internal/grouprollaws/recorder_test.go b/internal/grouprollaws/recorder_test.go
index 2258087d2..d10eea93f 100644
--- a/internal/grouprollaws/recorder_test.go
+++ b/internal/grouprollaws/recorder_test.go
@@ -147,9 +147,15 @@ func testAdapter(t *testing.T, rec *recorder) *Adapter {
}
func testAdapterWith(t *testing.T, h aws.HTTPClient) *Adapter {
+ t.Helper()
+ return testAdapterIn(t, h, "eu-west-1")
+}
+
+// testAdapterIn is testAdapterWith with the config's region.
+func testAdapterIn(t *testing.T, h aws.HTTPClient, region string) *Adapter {
t.Helper()
cfg := aws.Config{
- Region: "eu-west-1",
+ Region: region,
Credentials: credentials.NewStaticCredentialsProvider("AKIATEST", "secret", ""),
HTTPClient: h,
RetryMaxAttempts: 1,
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 03887cecc..a9ae8ca31 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -163,3 +163,4 @@ plan14-root-reads-retry-after-503.tsv eea13e9a0b04164ea3fc7f8258bd1ab0a613d1e23f
plan14-root-reads-fix-rootfs-jit-kill-854.tsv eea13e9a0b04164ea3fc7f8258bd1ab0a613d1e23ffe0cd028bc85058576c248
plan14-root-reads-demo-terms-links.tsv c8e2c7ed3850823a8e379d880738982772b870ad8549238cc02abce24c80eb93
plan14-root-reads-fix-silent-start-kill-861.tsv 733204d61bea49fe418d8ff0f1bfa20d77bdffb1f08a216d9de92923eea22557
+plan14-root-reads-group-bucket-region.tsv 733204d61bea49fe418d8ff0f1bfa20d77bdffb1f08a216d9de92923eea22557
diff --git a/internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv b/internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv
new file mode 100644
index 000000000..c0a9cb82e
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-group-bucket-region.tsv
@@ -0,0 +1,5 @@
+# Census overlay group-bucket-region, written by census-propose (#369). census-ruling-group-bucket-region, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-group-bucket-region.md.
+# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage . 180b6b00ad6c25822a2474b30fc97e21116c88afa138d3af95ee4ff431f29889
+@coverage internal/grouproll 5dd9fe9aa86128357a02395a03d8e700e0b75f2edf1bacf55095531da1964cb0
+@coverage internal/grouprollaws 48da80615cbb5b2116dc5e85c31023c9c8a295a45e5e40643fb5daeed92406ef
diff --git a/internal/release/openers_test.go b/internal/release/openers_test.go
index 4ed824f89..fb9405401 100644
--- a/internal/release/openers_test.go
+++ b/internal/release/openers_test.go
@@ -54,7 +54,7 @@ var otherBucketOpeners = map[string]openerEntry{
"internal/lease/execution_store.go:ExecutionStore": {"execution/build state: the hibernate and claim data bucket, keyed by host prefix", 1},
"internal/lease/endpoint.go:NewFilesStore": {"per-instance files store: the data/hibernate bucket, a host's published files under its hibernate prefix (files/0/), not the deployment bucket", 1},
"internal/status/dryrun.go:DryRun": {"status dry run: a throwaway scratch directory, not a deployment", 1},
- "internal/grouprollaws/objects.go:Bucket": {"carlos system group's read-only operator store (edges files, locks, router pointers in the deployment and data buckets) over the region's own endpoint, never a configured one; its Put and Delete refuse, so no change-index bump is needed", 1},
+ "internal/grouprollaws/objects.go:read": {"carlos system group's read-only operator store (edges files, locks, router pointers in the deployment and data buckets) over each bucket's own region endpoint, never a configured one; its Put and Delete refuse, so no change-index bump is needed", 1},
}
// deploymentManualSites are stores over the deployment (CARLOS_DEPLOYMENT_DIR
diff --git a/system_group.go b/system_group.go
index 72ac3f75a..99ee4f914 100644
--- a/system_group.go
+++ b/system_group.go
@@ -189,6 +189,18 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool)
if fs.NArg() > 0 {
return f, groupRefused(grouproll.Refusal{Key: "usage_positional", Args: map[string]string{"arg": fs.Arg(0)}}), false
}
+ // A required flag left out is argparse's usage error: the verb's usage
+ // on stderr, status 2. A required flag given empty is refused below, as
+ // the script refused it.
+ given := map[string]bool{}
+ fs.Visit(func(fl *flag.Flag) { given[fl.Name] = true })
+ for _, name := range append([]string{"config"}, requiredGroupFlags(verb)...) {
+ if !given[name] {
+ fs.Usage()
+ groupEnv.stderr.Write(out.Bytes())
+ return f, 2, false
+ }
+ }
if f.config == "" {
return f, groupRefused(grouproll.Refusal{Key: "config_required"}), false
}
@@ -199,6 +211,24 @@ func parseGroupFlags(verb string, args []string) (f groupFlags, rc int, ok bool)
return f, 0, true
}
+// requiredGroupFlags are verb's flags the script's argparse declared
+// required=True besides --config, which every verb requires (the probe
+// verbs follow their checkGroupArgs needs).
+func requiredGroupFlags(verb string) []string {
+ switch verb {
+ case "plan", "roll":
+ return []string{"member", "to-sha256"}
+ case "replace", "remove", "probe start":
+ return []string{"member"}
+ case "rollback", "cancel-drain":
+ return []string{"member", "transaction"}
+ case "resume", "status", "return", "abandon", "close-lost",
+ "probe resume", "probe status", "probe abandon", "probe close-lost":
+ return []string{"transaction"}
+ }
+ return nil
+}
+
// checkGroupArgs refuses a verb's missing or malformed arguments before
// any state, config or provider is touched: a chosen roll transaction id
// the drain and fence verbs could not take (the script's main checked it
diff --git a/system_group_test.go b/system_group_test.go
index c2ec4d625..35b97cde9 100644
--- a/system_group_test.go
+++ b/system_group_test.go
@@ -117,10 +117,18 @@ func TestCLIRefusesRootBoxWindows(t *testing.T) {
}
})
t.Run("no config", func(t *testing.T) {
+ // Left out: argparse's usage error (Astra r1 P3).
h := newGroupHarness(t)
- if rc := h.run("plan", plan[2:]...); rc != 1 || h.stderr.String() != h.refused("config_required") || len(h.steps) != 0 {
+ if rc := h.run("plan", plan[2:]...); rc != 2 || !strings.Contains(h.stderr.String(), "-config") ||
+ strings.Contains(h.stderr.String(), grouproll.Text("refused", "reason", "")) || len(h.steps) != 0 {
t.Fatalf("rc %d stderr %q", rc, h.stderr.String())
}
+ // Given empty: refused, as before.
+ h = newGroupHarness(t)
+ if rc := h.run("plan", append([]string{"--config", ""}, plan[2:]...)...); rc != 1 ||
+ h.stderr.String() != h.refused("config_required") || len(h.steps) != 0 {
+ t.Fatalf("empty: rc %d stderr %q", rc, h.stderr.String())
+ }
})
t.Run("attended", func(t *testing.T) {
h := newGroupHarness(t)
@@ -303,35 +311,64 @@ func TestCLIGroupLeaves(t *testing.T) {
args []string
key string
}{
- {"roll", sha, "config_invalid"},
- {"roll", member, "config_invalid"},
- {"plan", member, "config_invalid"},
- {"rollback", tx, "config_invalid"},
- {"rollback", member, "record"},
- {"resume", nil, "record"},
- {"return", nil, "record"},
- {"abandon", nil, "record"},
- {"close-lost", nil, "record"},
+ {"roll", sha, "usage"},
+ {"roll", member, "usage"},
+ {"plan", member, "usage"},
+ {"rollback", tx, "usage"},
+ {"rollback", member, "usage"},
+ {"resume", nil, "usage"},
+ {"return", nil, "usage"},
+ {"abandon", nil, "usage"},
+ {"close-lost", nil, "usage"},
{"roll", join(member, sha, []string{"--transaction", ""}), "record"},
{"roll", join(member, sha, []string{"--transaction", "probe-x"}), "record"},
{"roll", join(member, sha, []string{"--transaction", "../escape"}), "record"},
{"roll", join(member, sha, []string{"--transaction", strings.Repeat("x", 81)}), "record"},
// replace, remove and cancel-drain (DepartArgvTests.test_transaction_ids).
- {"replace", nil, "config_invalid"},
- {"remove", tx, "config_invalid"},
+ {"replace", nil, "usage"},
+ {"remove", tx, "usage"},
{"replace", join(member, []string{"--transaction", "-leading"}), "record"},
{"replace", join(member, []string{"--transaction=probe-x"}), "record"},
{"remove", join(member, []string{"--transaction", ""}), "record"},
- {"cancel-drain", tx, "config_invalid"},
- {"cancel-drain", member, "record"},
+ {"cancel-drain", tx, "usage"},
+ {"cancel-drain", member, "usage"},
}
for _, c := range refusals {
+ h := newGroupHarness(t)
+ args := append([]string{"--config", h.config, "--attended-by", "op"}, c.args...)
+ rc := h.run(c.verb, args...)
+ if c.key == "usage" {
+ // A required flag left out: the verb's usage, status 2.
+ if rc != 2 || !strings.Contains(h.stderr.String(), "-member") && !strings.Contains(h.stderr.String(), "-transaction") ||
+ strings.Contains(h.stderr.String(), grouproll.Text("refused", "reason", "")) || len(h.steps) != 0 {
+ t.Errorf("%s %v: rc %d stderr %q steps %v", c.verb, c.args, rc, h.stderr.String(), h.steps)
+ }
+ continue
+ }
+ if rc != 1 || h.stderr.String() != h.refused(c.key) || len(h.steps) != 0 {
+ t.Errorf("%s %v: rc %d stderr %q steps %v", c.verb, c.args, rc, h.stderr.String(), h.steps)
+ }
+ }
+ // A required flag given empty is still refused, as the script refused it.
+ for _, c := range []struct {
+ verb string
+ args []string
+ key string
+ }{
+ {"plan", join([]string{"--member", ""}, sha), "config_invalid"},
+ {"plan", join(member, []string{"--to-sha256", ""}), "config_invalid"},
+ {"resume", []string{"--transaction", ""}, "record"},
+ } {
h := newGroupHarness(t)
args := append([]string{"--config", h.config, "--attended-by", "op"}, c.args...)
if rc := h.run(c.verb, args...); rc != 1 || h.stderr.String() != h.refused(c.key) || len(h.steps) != 0 {
t.Errorf("%s %v: rc %d stderr %q steps %v", c.verb, c.args, rc, h.stderr.String(), h.steps)
}
}
+ // The bare verb (the operator's first try) prints its usage.
+ if h := newGroupHarness(t); h.run("plan") != 2 || !strings.Contains(h.stderr.String(), grouproll.Text("plan")) {
+ t.Errorf("bare plan: stderr %q", h.stderr.String())
+ }
state := func(h *groupHarness) {
if err := os.MkdirAll(filepath.Join(groupEnv.getenv("HOME"), ".local", "state", "carlos", "group"), 0o700); err != nil {
t.Fatal(err)
@@ -420,20 +457,20 @@ func TestCLIProbeLeaves(t *testing.T) {
args []string
key string
}{
- {"probe start", nil, "config_invalid"},
+ {"probe start", nil, "usage"},
{"probe start", []string{"--transaction", "t"}, ""},
- {"probe resume", nil, "record"},
- {"probe status", nil, "record"},
- {"probe abandon", nil, "record"},
- {"probe close-lost", nil, "record"},
+ {"probe resume", nil, "usage"},
+ {"probe status", nil, "usage"},
+ {"probe abandon", nil, "usage"},
+ {"probe close-lost", nil, "usage"},
{"probe resume", []string{"--member", "i-0123456789abcdef0"}, ""},
}
for _, c := range refusals {
h := newGroupHarness(t)
args := append([]string{"--config", h.config, "--attended-by", "op"}, c.args...)
rc := h.run(c.verb, args...)
- if c.key == "" {
- // A flag the leaf does not take is a usage error.
+ if c.key == "" || c.key == "usage" {
+ // A flag the leaf does not take, or a required one left out, is a usage error.
if rc != 2 || len(h.steps) != 0 {
t.Errorf("%s %v: rc %d stderr %q", c.verb, c.args, rc, h.stderr.String())
}