diff --git a/weed/s3api/iceberg/handlers_table.go b/weed/s3api/iceberg/handlers_table.go index 90d760b535..136fc5fd55 100644 --- a/weed/s3api/iceberg/handlers_table.go +++ b/weed/s3api/iceberg/handlers_table.go @@ -583,8 +583,9 @@ func (s *Server) buildLoadTableResult(r *http.Request, getResp s3tables.GetTable return LoadTableResult{}, fmt.Errorf("build metadata for %s: %w", tableName, err) } + catalogOnly := s3tables.IsCatalogOnlyFormat(getResp.Format) config, storageCredentials := s.buildFileIOConfig(r, location, func() bool { - return s.mayUpdateTable(r, bucketName, namespace, tableName) + return !catalogOnly && s.mayUpdateTable(r, bucketName, namespace, tableName) }) return LoadTableResult{ MetadataLocation: getResp.MetadataLocation, diff --git a/weed/s3api/iceberg/iceberg_lance_record_test.go b/weed/s3api/iceberg/iceberg_lance_record_test.go new file mode 100644 index 0000000000..1483c251c1 --- /dev/null +++ b/weed/s3api/iceberg/iceberg_lance_record_test.go @@ -0,0 +1,68 @@ +package iceberg + +import ( + "context" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/gorilla/mux" + "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" + "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants" + "github.com/seaweedfs/seaweedfs/weed/s3api/s3tables" +) + +func TestIcebergRESTKeepsOffLanceTables(t *testing.T) { + fc := newMemFiler() + seedNamespace(fc, "warehouse", "finance", "alice") + s := NewServer(fc, nil) + arn := buildTableBucketARN("warehouse") + for name, format := range map[string]string{"vec": s3tables.FormatLance, "ice": s3tables.FormatIceberg} { + if err := fc.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error { + return s.tablesManager.Execute(context.Background(), s3tables.NewManagerClient(client), "CreateTable", + &s3tables.CreateTableRequest{TableBucketARN: arn, Namespace: []string{"finance"}, Name: name, Format: format}, nil, "alice") + }); err != nil { + t.Fatal(err) + } + } + vendor := &stubVendor{credentials: &VendedCredentials{AccessKeyID: "ASIAEXAMPLE"}} + s.SetCredentialVendor(vendor) + s.s3Endpoint = "http://127.0.0.1:8333" + load := func(name string) int { + r := httptest.NewRequest(http.MethodGet, "/v1/warehouse/namespaces/finance/tables/"+name, nil) + r = mux.SetURLVars(r, map[string]string{"prefix": "warehouse", "namespace": "finance", "table": name}) + r.Header.Set(accessDelegationHeader, "vended-credentials") + w := httptest.NewRecorder() + s.handleLoadTable(w, r.WithContext(s3_constants.SetIdentityNameInContext(r.Context(), "alice"))) + return w.Code + } + // positive control: the owner of an Iceberg table gets write credentials + if code := load("ice"); code != http.StatusOK || vendor.gotReadOnly { + t.Fatalf("load of an Iceberg table: %d, readOnly=%v; want 200 with write credentials", code, vendor.gotReadOnly) + } + if code := load("vec"); code != http.StatusOK || !vendor.gotReadOnly { + t.Errorf("load of a Lance table: %d, readOnly=%v; want 200 with read-only credentials", code, vendor.gotReadOnly) + } + + before := string(fc.entries[s3tables.GetTablePath("warehouse", "finance", "vec")].Extended[s3tables.ExtendedKeyMetadata]) + cr := httptest.NewRequest(http.MethodPost, "/v1/warehouse/namespaces/finance/tables/vec", + strings.NewReader(`{"requirements":[],"updates":[{"action":"set-properties","updates":{"k":"v"}}]}`)) + cr = mux.SetURLVars(cr, map[string]string{"prefix": "warehouse", "namespace": "finance", "table": "vec"}) + cw := httptest.NewRecorder() + s.handleUpdateTable(cw, cr.WithContext(s3_constants.SetIdentityNameInContext(cr.Context(), "alice"))) + if cw.Code != http.StatusBadRequest { + t.Errorf("commit to a Lance table: %d (%s), want 400", cw.Code, cw.Body.String()) + } + tr := httptest.NewRequest(http.MethodPost, "/v1/warehouse/transactions/commit", strings.NewReader( + `{"table-changes":[{"identifier":{"namespace":["finance"],"name":"vec"},"requirements":[],"updates":[{"action":"set-properties","updates":{"k":"v"}}]}]}`)) + tr = mux.SetURLVars(tr, map[string]string{"prefix": "warehouse"}) + tw := httptest.NewRecorder() + s.handleCommitTransaction(tw, tr.WithContext(s3_constants.SetIdentityNameInContext(tr.Context(), "alice"))) + if tw.Code != http.StatusBadRequest { + t.Errorf("transaction on a Lance table: %d (%s), want 400", tw.Code, tw.Body.String()) + } + if after := string(fc.entries[s3tables.GetTablePath("warehouse", "finance", "vec")].Extended[s3tables.ExtendedKeyMetadata]); after != before { + t.Errorf("an Iceberg write changed the Lance record:\n before %s\n after %s", before, after) + } +}