mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
iceberg: a Lance record loads with read-only credentials (#13159)
iceberg: the Iceberg REST catalog keeps off Lance tables A Lance dataset's catalog record lives in the same table bucket as Iceberg tables, and the Iceberg REST endpoint serves it as a table: LoadTable vends write credentials over the dataset's directory to anyone who may update the table, and CommitTable or CommitTransaction on it writes Iceberg metadata into the dataset's directory and repoints the record at it. Reproduced on master: the record's metadataLocation became finance/vec/metadata/v2.metadata.json, its format still LANCE. notIcebergTable now refuses a commit and a transaction on a record of another format with 400, after the commit's authorization; LoadTable serves a catalog-only record as an empty table (its metadata is never read as Iceberg) with read-only credentials. A REST create of the name already answered 409. Test: TestIcebergRESTKeepsOffLanceTables: an Iceberg table's owner gets write credentials (positive control), the Lance table read-only ones; commit and transaction 400; the Lance record unchanged. Red with each of the three rules undone. Co-authored-by: Javier de la Torre <jatorre@carto.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2 files changed
+70
-1
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user