carlos / platform Public

objstore: provenance fixes from the Task 3 review (round 1)

Astra and Fable, round 1 of media conversion plan 2 Task 3.

- A custom S3 endpoint never earns Minted: awsProvisioner records the
  endpoint, and CreateNewBucket answers created only against AWS's own
  S3 outside us-east-1. EnsureBucket's success behaviour is unchanged.
- Provenance is invalidated before anything is destroyed. Teardown
  clears the conversion block before its first destructive step. A
  grant that makes a replacement bucket, or moves the store's endpoint
  or region, clears it before delivery. The console then verifies the
  replacement with a new incarnation.
- Tests for the first-grant conjunct of minting and for the console's
  name check on an adopted bucket.
- storecfg is stdlib-only: Want carries LifecycleHash and CORSHash in
  place of *objstore.Uploads, and a go list -deps test shows it links
  no github.com/aws package.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 4b38c99af4f32238c399ab24c861ed6f2312b0ea parent d959b2e
8 files changed, +424 −42
  • internal/console/mediastore.go +3 −1
  • internal/console/mediastore_test.go +87 −0
  • internal/objstore/aws.go +12 −4
  • internal/objstore/aws_test.go +85 −11
  • internal/objstore/walk.go +30 −1
  • internal/objstore/walk_test.go +151 −0
  • internal/storecfg/storecfg.go +12 −15
  • internal/storecfg/storecfg_test.go +44 −10
diff --git a/internal/console/mediastore.go b/internal/console/mediastore.go
index 75a15838b..91d765e74 100644
--- a/internal/console/mediastore.go
+++ b/internal/console/mediastore.go
@@ -71,7 +71,9 @@ func (s *Server) mediaStoreEligible(ctx context.Context, acct *Account, app stri
if rec.Conversion != nil {
uploads = rec.Conversion.Uploads
}
- want.Uploads = uploads
+ if uploads != nil {
+ want.LifecycleHash, want.CORSHash = uploads.LifecycleHash, uploads.CORSHash
+ }
if failed := storecfg.Verify(facts, want); failed != "" {
return rec, mediaCodeStoreUnverified, failed, nil
}
diff --git a/internal/console/mediastore_test.go b/internal/console/mediastore_test.go
index 3fc849e9e..05b998d0d 100644
--- a/internal/console/mediastore_test.go
+++ b/internal/console/mediastore_test.go
@@ -4,11 +4,13 @@ import (
"bytes"
"context"
"errors"
+ "net/http"
"regexp"
"testing"
"time"
"github.com/carlosframework/platform/internal/objstore"
+ "github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/storecfg"
)
@@ -335,3 +337,88 @@ func TestRecreatedStoreHasANewIncarnation(t *testing.T) {
})
}
}
+
+// Fable fix round 1: the name check reaches the console. An operator adopts
+// a bucket that is not the name this deployment mints; every other fact is
+// good, and the store is refused for its name with nothing written.
+func TestEligibleRefusesAnAdoptedName(t *testing.T) {
+ fx, _, buckets, token := mediaStoreFixture(t, "code-media-adopted", false)
+ declareStore(t, fx, token)
+ const adopted = "shop-uploads"
+ if status, out := postJSON(t, storeURL(fx, "titogo")+"/grant", map[string]any{"bucket": adopted}, token); status != http.StatusOK {
+ t.Fatalf("grant with adopt = %d %v", status, out)
+ }
+ rec := storedRecord(t, fx, "titogo")
+ if rec.Provisioned == nil || rec.Provisioned.Bucket != adopted || rec.Conversion != nil {
+ t.Fatalf("fixture: provisioned %+v, conversion %+v", rec.Provisioned, rec.Conversion)
+ }
+ buckets.Facts[adopted] = goodBucket()
+ before, beforeTag := rawStoreRecord(t, fx)
+ if _, code, check, err := eligible(t, fx); err != nil || code != "store_unverified" || check != "name" {
+ t.Fatalf("adopted bucket: %q %q %v; want store_unverified name", code, check, err)
+ }
+ if after, afterTag := rawStoreRecord(t, fx); afterTag != beforeTag || !bytes.Equal(after, before) {
+ t.Fatalf("the refusal wrote the record:\n%s\n->\n%s", before, after)
+ }
+}
+
+// failDeleteOnce fails the first Delete of key: a teardown that dies after
+// its destructive steps (bucket, user and delivered variables gone).
+type failDeleteOnce struct {
+ release.Store
+ key string
+}
+
+func (f *failDeleteOnce) Delete(ctx context.Context, key string) error {
+ if key == f.key {
+ f.key = ""
+ return errors.New("injected: delete failed")
+ }
+ return f.Store.Delete(ctx, key)
+}
+
+// Astra fix round 1, P1, end to end: a minted store's teardown fails at the
+// scan sidecar, the record stands, the grant that follows makes a
+// replacement bucket. The console must check the replacement afresh and give
+// it a new incarnation, never accept the old Minted claim.
+func TestInterruptedTeardownStoreIsVerifiedAfresh(t *testing.T) {
+ fx, prov, buckets, token := mediaStoreFixture(t, "code-media-interrupted", false)
+ grantStore(t, fx, token)
+ first, code, _, err := eligible(t, fx)
+ if err != nil || code != "" || !first.Conversion.Minted {
+ t.Fatalf("fixture: %q %v %+v", code, err, first.Conversion)
+ }
+
+ func() {
+ defer fx.srv.storeWalks.lock(fx.sqid, "titogo", "")()
+ s := &failDeleteOnce{Store: fx.srv.cfg.Releases, key: objstore.ScanKey(fx.sqid, "titogo")}
+ if err := objstore.Teardown(context.Background(), s, prov, nil, fx.sqid, "titogo"); err == nil {
+ t.Fatal("teardown: no error from the injected failure")
+ }
+ }()
+ if rec := storedRecord(t, fx, "titogo"); rec == nil || rec.Provisioned == nil || rec.Conversion != nil {
+ t.Fatalf("after the failed teardown: %+v", rec)
+ }
+ // Between the teardown and the regrant there is no bucket to inspect: an
+ // error, not an eligible store.
+ if _, code, _, err := eligible(t, fx); err == nil || code != "" {
+ t.Fatalf("store with no bucket: code %q, err %v; want an error", code, err)
+ }
+
+ if status, out := postJSON(t, storeURL(fx, "titogo")+"/grant", map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("regrant = %d %v", status, out)
+ }
+ buckets.Facts[mediaMintedName(fx)] = goodBucket()
+ inspects := buckets.CallCount("Inspect")
+ second, code, _, err := eligible(t, fx)
+ if err != nil || code != "" {
+ t.Fatalf("replacement store: %q %v", code, err)
+ }
+ c := second.Conversion
+ if c.Minted || c.VerifiedAt == nil || c.Incarnation == first.Conversion.Incarnation || !mediaHex32.MatchString(c.Incarnation) {
+ t.Fatalf("replacement conversion = %+v, first incarnation %q", c, first.Conversion.Incarnation)
+ }
+ if buckets.CallCount("Inspect") != inspects+1 {
+ t.Fatal("the replacement was not inspected")
+ }
+}
diff --git a/internal/objstore/aws.go b/internal/objstore/aws.go
index a03193f9b..2e879a025 100644
--- a/internal/objstore/aws.go
+++ b/internal/objstore/aws.go
@@ -56,6 +56,11 @@ type awsProvisioner struct {
// user this provisioner creates. See EnsureUser for why it is not
// optional in any deployment whose console role can reach IAM.
boundary string
+ // endpoint is the S3-compatible endpoint the S3 client was built for, ""
+ // for AWS itself. CreateNewBucket never answers created through one: an
+ // S3-compatible backend's answer to re-creating a bucket its caller
+ // already owns is not AWS's, so a success there proves nothing.
+ endpoint string
}
var _ Provisioner = (*awsProvisioner)(nil)
@@ -100,7 +105,7 @@ func NewAWSProvisionerWith(ctx context.Context, region, endpoint, boundary strin
return nil, fmt.Errorf("objstore: load aws config: %w", err)
}
iamClient := iam.NewFromConfig(cfg)
- return &awsProvisioner{s3: s3Client, iam: iamClient, region: region, boundary: boundary}, nil
+ return &awsProvisioner{s3: s3Client, iam: iamClient, region: region, boundary: boundary, endpoint: endpoint}, nil
}
// S3ClientFor builds a bare *s3.Client the same way NewAWSProvisioner builds
@@ -298,14 +303,17 @@ func (p *awsProvisioner) EnsureBucket(ctx context.Context, name string) (string,
var _ BucketCreator = (*awsProvisioner)(nil)
// CreateNewBucket is EnsureBucket that also says whether this call created
-// the bucket. Only a success from CreateBucket outside us-east-1 counts:
+// the bucket. Only a success from AWS's own S3 outside us-east-1 counts:
// there, an existing bucket of ours answers BucketAlreadyOwnedByYou. In
// us-east-1 (and with no region, which lands there) AWS answers a bare
// success to an owner creating its own bucket again, so a success proves
-// nothing and is created == false.
+// nothing and is created == false. Through a custom endpoint (an
+// S3-compatible backend) it is false too: nothing says that backend
+// refuses a re-create the way AWS does.
func (p *awsProvisioner) CreateNewBucket(ctx context.Context, name string) (string, bool, error) {
in := &awss3.CreateBucketInput{Bucket: aws.String(name)}
located := p.region != "" && p.region != "us-east-1"
+ provable := located && p.endpoint == ""
if located {
in.CreateBucketConfiguration = &s3types.CreateBucketConfiguration{
LocationConstraint: s3types.BucketLocationConstraint(p.region),
@@ -318,7 +326,7 @@ func (p *awsProvisioner) CreateNewBucket(ctx context.Context, name string) (stri
}
return p.region, false, nil
}
- return p.region, located, nil
+ return p.region, provable, nil
}
// EmptyBucket deletes every object in name, paginating ListObjectsV2 and
diff --git a/internal/objstore/aws_test.go b/internal/objstore/aws_test.go
index 0477f74ac..3d819ca9b 100644
--- a/internal/objstore/aws_test.go
+++ b/internal/objstore/aws_test.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"testing"
+ "time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/iam"
@@ -11,6 +12,7 @@ import (
awss3 "github.com/aws/aws-sdk-go-v2/service/s3"
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go"
+ "github.com/carlosframework/platform/internal/release"
)
// TestNewAWSProvisioner is construction-only: it must succeed offline (the
@@ -657,20 +659,24 @@ func TestAWSCreateNewBucketTable(t *testing.T) {
return nil, &s3types.BucketAlreadyExists{Message: aws.String("someone else's")}
}
for _, tc := range []struct {
- name, region string
- create func(*awss3.CreateBucketInput) (*awss3.CreateBucketOutput, error)
- created bool
- wantErr bool
+ name, region, endpoint string
+ create func(*awss3.CreateBucketInput) (*awss3.CreateBucketOutput, error)
+ created bool
+ wantErr bool
}{
- {"success", "eu-west-1", ok, true, false},
- {"already-owned", "eu-west-1", owned, false, false},
- {"us-east-1-success", "us-east-1", ok, false, false},
- {"no-region-success", "", ok, false, false},
- {"us-east-1-already-owned", "us-east-1", owned, false, false},
- {"taken", "eu-west-1", taken, false, true},
+ {"success", "eu-west-1", "", ok, true, false},
+ {"already-owned", "eu-west-1", "", owned, false, false},
+ {"us-east-1-success", "us-east-1", "", ok, false, false},
+ {"no-region-success", "", "", ok, false, false},
+ {"us-east-1-already-owned", "us-east-1", "", owned, false, false},
+ {"taken", "eu-west-1", "", taken, false, true},
+ // An S3-compatible backend may answer 200 to an owner re-creating
+ // its own bucket, so its success proves nothing.
+ {"custom-endpoint-success", "eu-west-1", "https://s3.example.net", ok, false, false},
+ {"custom-endpoint-already-owned", "eu-west-1", "https://s3.example.net", owned, false, false},
} {
t.Run(tc.name, func(t *testing.T) {
- p := &awsProvisioner{region: tc.region, s3: &stubS3{t: t, createBucket: tc.create}}
+ p := &awsProvisioner{region: tc.region, endpoint: tc.endpoint, s3: &stubS3{t: t, createBucket: tc.create}}
region, created, err := p.CreateNewBucket(context.Background(), "b1")
if tc.wantErr {
if err == nil || created {
@@ -691,3 +697,71 @@ func TestAWSCreateNewBucketTable(t *testing.T) {
})
}
}
+
+// The constructor records the endpoint it built the S3 client for, which is
+// what CreateNewBucket reads.
+func TestNewAWSProvisionerRecordsEndpoint(t *testing.T) {
+ t.Setenv("AWS_ACCESS_KEY_ID", "AKIDEXAMPLE")
+ t.Setenv("AWS_SECRET_ACCESS_KEY", "secret")
+ for _, endpoint := range []string{"", "https://s3.example.net"} {
+ p, err := NewAWSProvisioner(context.Background(), "eu-west-1", endpoint, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got := p.(*awsProvisioner).endpoint; got != endpoint {
+ t.Fatalf("endpoint = %q, want %q", got, endpoint)
+ }
+ }
+}
+
+// A whole first grant through the AWS provisioner: minted against AWS's own
+// S3 outside us-east-1, and never through a custom endpoint, even though the
+// create succeeds the same way.
+func TestAWSGrantMintsOnlyWithoutCustomEndpoint(t *testing.T) {
+ for _, tc := range []struct {
+ name, endpoint string
+ minted bool
+ }{
+ {"aws", "", true},
+ {"custom-endpoint", "https://s3.example.net", false},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ _, pub := testSealKeypair(t)
+ s := release.NewDirStore(t.TempDir())
+ declare(t, s, "bab", "titogo", "TITO_S3")
+ p := &awsProvisioner{region: "eu-west-1", endpoint: tc.endpoint,
+ s3: &stubS3{t: t, createBucket: func(*awss3.CreateBucketInput) (*awss3.CreateBucketOutput, error) {
+ return &awss3.CreateBucketOutput{}, nil
+ }},
+ iam: &stubIAM{t: t,
+ createUser: func(in *iam.CreateUserInput) (*iam.CreateUserOutput, error) {
+ return &iam.CreateUserOutput{User: &iamtypes.User{Arn: aws.String("arn:aws:iam::123456789012:user/carlos-store/" + aws.ToString(in.UserName))}}, nil
+ },
+ putUserPolicy: func(*iam.PutUserPolicyInput) (*iam.PutUserPolicyOutput, error) {
+ return &iam.PutUserPolicyOutput{}, nil
+ },
+ listAccessKeys: func(*iam.ListAccessKeysInput) (*iam.ListAccessKeysOutput, error) {
+ return &iam.ListAccessKeysOutput{}, nil
+ },
+ createAccessKey: func(*iam.CreateAccessKeyInput) (*iam.CreateAccessKeyOutput, error) {
+ return &iam.CreateAccessKeyOutput{AccessKey: &iamtypes.AccessKey{
+ AccessKeyId: aws.String("AKIAEXAMPLE"), SecretAccessKey: aws.String("secretexample")}}, nil
+ },
+ }}
+ d := testDeployment()
+ d.Endpoint = tc.endpoint
+ rec, err := Grant(context.Background(), s, p, d, storeTestSealer(pub, "bab", "titogo"),
+ "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC())
+ if err != nil {
+ t.Fatal(err)
+ }
+ got := rec.Conversion != nil && rec.Conversion.Minted
+ if got != tc.minted {
+ t.Fatalf("minted = %v (%+v), want %v", got, rec.Conversion, tc.minted)
+ }
+ if !tc.minted && rec.Conversion != nil {
+ t.Fatalf("conversion = %+v through a custom endpoint", rec.Conversion)
+ }
+ })
+ }
+}
diff --git a/internal/objstore/walk.go b/internal/objstore/walk.go
index 1cf68ae90..939683f6c 100644
--- a/internal/objstore/walk.go
+++ b/internal/objstore/walk.go
@@ -361,6 +361,24 @@ func claimRawGrantIn(ctx context.Context, s release.Store, p Provisioner, d Depl
minted = &Conversion{Incarnation: inc, Minted: true}
rec.Conversion = minted
}
+ // Provenance describes one bucket at one place. A walk that found the
+ // store's bucket gone and made another (a teardown that died before its
+ // record went, a bucket deleted by hand), or that moves the store to
+ // another endpoint or region, invalidates whatever the record held: an
+ // old incarnation must never name the replacement, and a Minted claim
+ // must never outlive the bucket it was about. Persisted here, before the
+ // key and delivery steps, so a walk that fails after this point cannot
+ // leave the old block standing over the new estate. The console then
+ // verifies the store afresh, with a new incarnation.
+ if minted == nil && rec.Conversion != nil {
+ moved := rec.Provisioned != nil && (rec.Provisioned.Endpoint != d.Endpoint || rec.Provisioned.Region != region)
+ if created || moved {
+ rec.Conversion = nil
+ if etag, err = PutIn(ctx, s, acct, app, env, rec, etag); err != nil {
+ return nil, fmt.Errorf("objstore: clear conversion provenance for %s/%s: %w", acct, app, err)
+ }
+ }
+ }
// 4. key. Reap first: reaching here means delivery is missing, so any
// existing CURRENT key is either undelivered (its secret died with a
// failed config write — unrecoverable) or stranded by a crash between mint
@@ -627,7 +645,7 @@ func claimRawTeardown(ctx context.Context, s release.Store, p Provisioner, sc Sc
// the bucket, the principal and the bundle the vars come out of are all named
// by this record alone.
func claimRawTeardownIn(ctx context.Context, s release.Store, p Provisioner, sc Scanner, acct, app, env string) error {
- rec, _, err := GetIn(ctx, s, acct, app, env)
+ rec, etag, err := GetIn(ctx, s, acct, app, env)
if err != nil {
return err
}
@@ -692,6 +710,17 @@ func claimRawTeardownIn(ctx context.Context, s release.Store, p Provisioner, sc
if bucketShared {
bucket = ""
}
+ // Provenance goes first, before anything is destroyed (media conversion
+ // spec §5.2). A teardown that fails partway leaves the record standing,
+ // and a later grant may make a replacement bucket under the same name;
+ // the old incarnation and any Minted claim must not survive to describe
+ // it. A lost write here stops the walk with nothing destroyed.
+ if rec.Conversion != nil {
+ rec.Conversion = nil
+ if _, err := PutIn(ctx, s, acct, app, env, rec, etag); err != nil {
+ return fmt.Errorf("objstore: clear conversion provenance for %s/%s: %w", acct, app, err)
+ }
+ }
// The scanner goes BEFORE the bucket, while the record that names it still
// exists. A Malware Protection plan (and its managed EventBridge rule)
// outlives the bucket it protects, counting against a non-adjustable
diff --git a/internal/objstore/walk_test.go b/internal/objstore/walk_test.go
index 42f08d955..6cc0a4761 100644
--- a/internal/objstore/walk_test.go
+++ b/internal/objstore/walk_test.go
@@ -1901,3 +1901,154 @@ func TestConversionBlockWireNames(t *testing.T) {
t.Fatalf("old record: %+v, %v", rec.Conversion, err)
}
}
+
+// failingDeleteStore fails the FIRST Delete of failKeyOnce, then behaves
+// normally: a teardown that dies after its destructive steps.
+type failingDeleteStore struct {
+ release.Store
+ failKeyOnce string
+}
+
+func (f *failingDeleteStore) Delete(ctx context.Context, key string) error {
+ if key != "" && key == f.failKeyOnce {
+ f.failKeyOnce = ""
+ return errors.New("injected: delete failed")
+ }
+ return f.Store.Delete(ctx, key)
+}
+
+// Astra fix round 1, P1: a teardown that destroys the bucket, the user and
+// the delivered variables and then fails (here, at the scan sidecar) leaves
+// the record standing. The grant that follows makes a replacement bucket
+// under the same name; the old incarnation and its Minted claim must not
+// describe it.
+func TestInterruptedTeardownThenRegrantDropsProvenance(t *testing.T) {
+ ctx := context.Background()
+ _, pub := testSealKeypair(t)
+ inner := release.NewDirStore(t.TempDir())
+ s := &failingDeleteStore{Store: inner}
+ p := NewMemProvisioner("eu-west-1")
+ declare(t, s, "bab", "titogo", "TITO_S3")
+ first, err := grantOnce(t, s, p, pub, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if first.Conversion == nil || !first.Conversion.Minted {
+ t.Fatalf("fixture: first grant not minted: %+v", first.Conversion)
+ }
+ bucket := first.Provisioned.Bucket
+
+ s.failKeyOnce = ScanKey("bab", "titogo")
+ if err := Teardown(ctx, s, p, nil, "bab", "titogo"); err == nil {
+ t.Fatal("teardown: no error from the injected sidecar failure")
+ }
+ if _, ok := p.Buckets[bucket]; ok {
+ t.Fatal("fixture: the bucket survived the teardown")
+ }
+ half, _, err := Get(ctx, s, "bab", "titogo")
+ if err != nil || half == nil || half.Provisioned == nil {
+ t.Fatalf("fixture: record after the failed teardown = %+v, %v", half, err)
+ }
+ if half.Conversion != nil {
+ t.Fatalf("the failed teardown left provenance standing: %+v", half.Conversion)
+ }
+
+ rec, err := grantOnce(t, s, p, pub, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, ok := p.Buckets[bucket]; !ok {
+ t.Fatal("fixture: the regrant made no replacement bucket")
+ }
+ if rec.Conversion != nil || storedConversion(t, s) != nil {
+ t.Fatalf("regrant over the replacement: %+v, want no provenance (verified afresh)", rec.Conversion)
+ }
+}
+
+// The grant side, on its own: a bucket gone from under a standing record
+// (deleted by hand, or by a teardown from before provenance was cleared
+// first) is made again, and the walk drops the old block before delivery.
+func TestGrantReplacingTheBucketDropsProvenance(t *testing.T) {
+ ctx := context.Background()
+ _, pub := testSealKeypair(t)
+ s := release.NewDirStore(t.TempDir())
+ p := NewMemProvisioner("eu-west-1")
+ declare(t, s, "bab", "titogo", "TITO_S3")
+ first, err := grantOnce(t, s, p, pub, "")
+ if err != nil || first.Conversion == nil {
+ t.Fatalf("first grant: %+v, %v", first, err)
+ }
+ delete(p.Buckets, first.Provisioned.Bucket)
+ if _, err := appconfig.Apply(ctx, s, "bab", "titogo", nil, []string{"TITO_S3_BUCKET"}); err != nil {
+ t.Fatal(err)
+ }
+ // Fail delivery, so only the step-3 write can have dropped the block.
+ p.FailNext["MintKey"] = errors.New("injected")
+ if _, err := grantOnce(t, s, p, pub, ""); err == nil {
+ t.Fatal("regrant: no error from the injected failure")
+ }
+ if c := storedConversion(t, s); c != nil {
+ t.Fatalf("a regrant that made a replacement bucket kept %+v", c)
+ }
+ if _, err := grantOnce(t, s, p, pub, ""); err != nil {
+ t.Fatal(err)
+ }
+ if c := storedConversion(t, s); c != nil {
+ t.Fatalf("after the regrant: %+v", c)
+ }
+}
+
+// Moving a store to another endpoint invalidates its provenance: the block
+// described a bucket on the old backend.
+func TestGrantMovingTheEndpointDropsProvenance(t *testing.T) {
+ ctx := context.Background()
+ _, pub := testSealKeypair(t)
+ s := release.NewDirStore(t.TempDir())
+ p := NewMemProvisioner("eu-west-1")
+ declare(t, s, "bab", "titogo", "TITO_S3")
+ first, err := grantOnce(t, s, p, pub, "")
+ if err != nil || first.Conversion == nil {
+ t.Fatalf("first grant: %+v, %v", first, err)
+ }
+ d := testDeployment()
+ d.Endpoint = "https://s3.example.net"
+ rec, err := Grant(ctx, s, p, d, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC())
+ if err != nil {
+ t.Fatal(err)
+ }
+ if rec.Provisioned.Endpoint != d.Endpoint {
+ t.Fatalf("fixture: endpoint = %q", rec.Provisioned.Endpoint)
+ }
+ if rec.Conversion != nil || storedConversion(t, s) != nil {
+ t.Fatalf("endpoint move kept %+v", rec.Conversion)
+ }
+}
+
+// Fable fix round 1: the first-grant conjunct of `minting`. A first grant
+// adopts the minted name and dies at EnsureUser, before the bucket step, so
+// its grant block pins the name; the re-run, with no adopt, creates the
+// bucket. It is still an adopted bucket and must not mint.
+func TestAdoptedFirstGrantRerunIsNotMinted(t *testing.T) {
+ _, pub := testSealKeypair(t)
+ s := release.NewDirStore(t.TempDir())
+ p := NewMemProvisioner("eu-west-1")
+ declare(t, s, "bab", "titogo", "TITO_S3")
+ minted := MintedBucket(testDeployment(), "bab", "titogo")
+ p.FailNext["EnsureUser"] = errors.New("injected")
+ if _, err := grantOnce(t, s, p, pub, minted); err == nil {
+ t.Fatal("first grant: no error")
+ }
+ if _, ok := p.Buckets[minted]; ok {
+ t.Fatal("fixture: the first grant reached the bucket step")
+ }
+ rec, err := grantOnce(t, s, p, pub, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, ok := p.Buckets[minted]; !ok || rec.Provisioned.Bucket != minted {
+ t.Fatalf("fixture: re-run did not create %q", minted)
+ }
+ if rec.Conversion != nil || storedConversion(t, s) != nil {
+ t.Fatalf("an adopted first grant's re-run minted: %+v", rec.Conversion)
+ }
+}
diff --git a/internal/storecfg/storecfg.go b/internal/storecfg/storecfg.go
index 5eeca028b..98824124b 100644
--- a/internal/storecfg/storecfg.go
+++ b/internal/storecfg/storecfg.go
@@ -3,9 +3,11 @@
// what a bucket's settings are, whether they are the ones conversion relies
// on, and the one CORS rule and one lifecycle rule the platform writes.
//
-// It is provider-neutral. Buckets is the seam; the AWS adapter lives in
-// internal/mediaaws (plan 3), and Fake serves the tests. This package
-// imports the standard library and internal/objstore only.
+// It is provider-neutral and imports the standard library only, so it links
+// no cloud SDK (TestStorecfgLinksNoCloudSDK). Buckets is the seam; the AWS
+// adapter lives in internal/mediaaws (plan 3), and Fake serves the tests.
+// The caller turns the store record's objstore.Uploads into Want's two
+// hashes.
package storecfg
import (
@@ -14,8 +16,6 @@ import (
"encoding/hex"
"encoding/json"
"slices"
-
- "github.com/carlosframework/platform/internal/objstore"
)
// Facts is what a bucket holds, as Buckets.Inspect reads it.
@@ -144,7 +144,7 @@ func UploadsCORS(origins []string) []byte { return CanonicalCORS(UploadsCORSRule
// UploadsLifecycle is the canonical JSON of UploadsLifecycleRules().
func UploadsLifecycle() []byte { return CanonicalLifecycle(UploadsLifecycleRules()) }
-// Hash is the hex SHA-256 of b, the form Conversion.Uploads records.
+// Hash is the hex SHA-256 of b, the form objstore.Uploads records.
func Hash(b []byte) string {
sum := sha256.Sum256(b)
return hex.EncodeToString(sum[:])
@@ -170,11 +170,12 @@ var Checks = []string{CheckName, CheckOwner, CheckRegion, CheckEncryption,
// Want is what a store's bucket must be for conversion. Bucket is the
// bucket the store record names; MintedName the name this deployment would
// mint for the store; Account this deployment's cloud account; Region the
-// store's region. Uploads is what the platform recorded writing, nil when
-// it wrote nothing.
+// store's region. LifecycleHash and CORSHash are the hashes the store
+// record says the platform wrote (objstore.Uploads), "" when it wrote
+// nothing.
type Want struct {
Bucket, MintedName, Account, Region string
- Uploads *objstore.Uploads
+ LifecycleHash, CORSHash string
}
// Verify answers "" when f is a bucket conversion may rely on, else the first
@@ -201,14 +202,10 @@ func Verify(f Facts, want Want) (check string) {
case f.HasPolicy:
return CheckPolicy
}
- var lifecycleHash, corsHash string
- if want.Uploads != nil {
- lifecycleHash, corsHash = want.Uploads.LifecycleHash, want.Uploads.CORSHash
- }
- if !recorded(f.Lifecycle, lifecycleHash) {
+ if !recorded(f.Lifecycle, want.LifecycleHash) {
return CheckLifecycle
}
- if !recorded(f.CORS, corsHash) {
+ if !recorded(f.CORS, want.CORSHash) {
return CheckCORS
}
return ""
diff --git a/internal/storecfg/storecfg_test.go b/internal/storecfg/storecfg_test.go
index 9b669b7cc..05a101a5e 100644
--- a/internal/storecfg/storecfg_test.go
+++ b/internal/storecfg/storecfg_test.go
@@ -4,9 +4,12 @@ import (
"bytes"
"context"
"errors"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "strings"
"testing"
-
- "github.com/carlosframework/platform/internal/objstore"
)
const (
@@ -23,8 +26,11 @@ func goodWant() Want {
return Want{Bucket: testBucket, MintedName: testBucket, Account: testAccount, Region: testRegion}
}
-func recordedUploads(origins []string) *objstore.Uploads {
- return &objstore.Uploads{Origins: origins, CORSHash: Hash(UploadsCORS(origins)), LifecycleHash: Hash(UploadsLifecycle())}
+// withUploads is w carrying the hashes of the platform's own rules for
+// origins, as the console fills them from the record's Uploads block.
+func withUploads(w Want, origins []string) Want {
+ w.CORSHash, w.LifecycleHash = Hash(UploadsCORS(origins)), Hash(UploadsLifecycle())
+ return w
}
// One passing bucket, then one failure per check in Verify's order. Each
@@ -51,7 +57,7 @@ func TestVerifyTable(t *testing.T) {
f := goodFacts()
f.CORS, f.Lifecycle = UploadsCORS(origins), UploadsLifecycle()
return f
- }(), func() Want { w := goodWant(); w.Uploads = recordedUploads(origins); return w }(), ""},
+ }(), withUploads(goodWant(), origins), ""},
{"name-adopted", allBad(goodFacts()), func() Want { w := goodWant(); w.Bucket = "shop-uploads"; return w }(), CheckName},
{"name-unset", goodFacts(), func() Want { w := goodWant(); w.MintedName = ""; return w }(), CheckName},
{"owner-foreign", func() Facts { f := allBad(goodFacts()); f.Owner = "999999999999"; return f }(), goodWant(), CheckOwner},
@@ -73,13 +79,13 @@ func TestVerifyTable(t *testing.T) {
// may have, and its CORS twin could carry any origin.
{"lifecycle-ours-unrecorded", func() Facts { f := goodFacts(); f.Lifecycle = UploadsLifecycle(); return f }(), goodWant(), CheckLifecycle},
{"lifecycle-other-than-recorded", func() Facts { f := goodFacts(); f.Lifecycle = foreignLifecycle; return f }(),
- func() Want { w := goodWant(); w.Uploads = recordedUploads(origins); return w }(), CheckLifecycle},
+ withUploads(goodWant(), origins), CheckLifecycle},
{"cors-foreign", func() Facts { f := goodFacts(); f.CORS = foreignCORS; return f }(), goodWant(), CheckCORS},
{"cors-other-origins-than-recorded", func() Facts {
f := goodFacts()
f.CORS, f.Lifecycle = UploadsCORS([]string{"https://evil.example.net"}), UploadsLifecycle()
return f
- }(), func() Want { w := goodWant(); w.Uploads = recordedUploads(origins); return w }(), CheckCORS},
+ }(), withUploads(goodWant(), origins), CheckCORS},
} {
t.Run(tc.name, func(t *testing.T) {
if got := Verify(tc.facts, tc.want); got != tc.check {
@@ -159,9 +165,7 @@ func TestFakeUploadsRoundTrip(t *testing.T) {
if Hash(got.CORS) != Hash(UploadsCORS(origins)) || Hash(got.Lifecycle) != Hash(UploadsLifecycle()) {
t.Fatalf("after PutUploads: %+v", got)
}
- w := goodWant()
- w.Uploads = recordedUploads(origins)
- if c := Verify(got, w); c != "" {
+ if c := Verify(got, withUploads(goodWant(), origins)); c != "" {
t.Fatalf("Verify after our own uploads = %q", c)
}
if err := f.DeleteUploads(ctx, testBucket); err != nil {
@@ -185,3 +189,33 @@ func TestFakeUploadsRoundTrip(t *testing.T) {
t.Fatalf("Inspect calls = %d, want 5", n)
}
}
+
+// Fix round 1, controller ruling: storecfg is stdlib-only, so it links no
+// cloud SDK on any platform the core builds for (provider-neutral core).
+// Checked on the link graph, not the import lines: importing a package that
+// itself imports the SDK (objstore does) links it just the same.
+func TestStorecfgLinksNoCloudSDK(t *testing.T) {
+ gobin := filepath.Join(runtime.GOROOT(), "bin", "go")
+ if _, err := os.Stat(gobin); err != nil {
+ if gobin, err = exec.LookPath("go"); err != nil {
+ t.Skip("no go toolchain to list dependencies with")
+ }
+ }
+ for _, arch := range []string{"amd64", "arm64"} {
+ cmd := exec.Command(gobin, "list", "-deps", "-f", "{{.ImportPath}} {{.Standard}}", ".")
+ cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH="+arch, "CGO_ENABLED=0")
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("go list (%s): %v\n%s", arch, err, out)
+ }
+ for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
+ path, std, _ := strings.Cut(line, " ")
+ if strings.HasPrefix(path, "github.com/aws/") {
+ t.Errorf("linux/%s: storecfg links %s", arch, path)
+ }
+ if std != "true" && path != "github.com/carlosframework/platform/internal/storecfg" {
+ t.Errorf("linux/%s: storecfg links non-standard package %s", arch, path)
+ }
+ }
+ }
+}