mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 19:17:28 +01:00
* s3tables: table policy and maintenance reads refuse views and unfinished records readTableMetadataAttr only checked that the table-metadata attribute was present, so the table policy and maintenance operations accepted a view or a record a create or rename had not finished writing. Route it through tableMetadata, the check GetTable and the other table operations use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: tagging a table ARN refuses a view or unfinished record TagResource, ListTagsForResource and UntagResource read the table-metadata attribute directly for a table ARN, so a view or a record still being created or renamed under that name took and answered tags as a table. Read a table target through readTableMetadataAttr. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: table record writes refuse a view requireTableCreatedAt compared only the creation time, so a view holding the name at write time was not rejected on its own. Refuse it, so table policy, tag and maintenance writes never land on a view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: test table operations against a view and an unfinished record Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
4.3 KiB
Go
98 lines
4.3 KiB
Go
package s3tables
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// A view, or a table its create has not finished writing, is not a table: the
|
|
// table policy, maintenance and tag operations answer NoSuchTable for its name
|
|
// and write nothing to it.
|
|
func TestTableOperationsRefuseViewAndUnfinishedRecord(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
seedView(t, fs, "v")
|
|
nsPath := GetNamespacePath(renameTestBucket, "ns")
|
|
fs.Put(nsPath, "c", map[string][]byte{
|
|
ExtendedKeyMetadata: []byte(`{"name":"c","namespace":"ns","ownerAccountId":"` + DefaultAccountID + `"}`),
|
|
ExtendedKeyDeleting: []byte(createClaim),
|
|
})
|
|
bucketARN := mustBucketARN(t)
|
|
|
|
for _, name := range []string{"v", "c"} {
|
|
before := extendedOf(t, fs, nsPath, name)
|
|
tableARN, err := BuildTableARN(DefaultRegion, DefaultAccountID, renameTestBucket, "ns", name)
|
|
require.NoError(t, err)
|
|
ops := []struct {
|
|
operation string
|
|
input interface{}
|
|
}{
|
|
{"PutTablePolicy", &PutTablePolicyRequest{
|
|
TableBucketARN: bucketARN,
|
|
Namespace: []string{"ns"},
|
|
Name: name,
|
|
ResourcePolicy: `{"Statement":[{"Effect":"Allow","Principal":"*","Action":"s3tables:*","Resource":"*"}]}`,
|
|
}},
|
|
{"GetTablePolicy", &GetTablePolicyRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: name}},
|
|
{"DeleteTablePolicy", &DeleteTablePolicyRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: name}},
|
|
{"PutTableMaintenanceConfiguration", &PutTableMaintenanceConfigurationRequest{
|
|
TableBucketARN: bucketARN,
|
|
Namespace: []string{"ns"},
|
|
Name: name,
|
|
Type: MaintenanceTypeIcebergCompaction,
|
|
Value: &MaintenanceConfigurationValue{Status: MaintenanceStatusEnabled},
|
|
}},
|
|
{"GetTableMaintenanceConfiguration", &GetTableMaintenanceConfigurationRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: name}},
|
|
{"GetTableMaintenanceJobStatus", &GetTableMaintenanceJobStatusRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: name}},
|
|
{"TagResource", &TagResourceRequest{ResourceARN: tableARN, Tags: map[string]string{"k": "v"}}},
|
|
{"ListTagsForResource", &ListTagsForResourceRequest{ResourceARN: tableARN}},
|
|
{"UntagResource", &UntagResourceRequest{ResourceARN: tableARN, TagKeys: []string{"k"}}},
|
|
}
|
|
for _, op := range ops {
|
|
t.Run(name+"/"+op.operation, func(t *testing.T) {
|
|
status, resp := runHandler(t, m, fs.Client, op.operation, op.input)
|
|
assert.Equal(t, http.StatusNotFound, status, "%+v", resp)
|
|
assert.Equal(t, ErrCodeNoSuchTable, resp.Type, "%+v", resp)
|
|
})
|
|
}
|
|
assert.Equal(t, before, extendedOf(t, fs, nsPath, name), "%s must not be written to", name)
|
|
}
|
|
}
|
|
|
|
// An identity granted only s3tables:PutTablePolicy cannot plant a policy on
|
|
// another account's view through the table API and so open the view to itself.
|
|
func TestPutTablePolicyCannotOpenAView(t *testing.T) {
|
|
fs, m := startRenameManager(t)
|
|
m.SetTrusted(false)
|
|
m.SetDefaultAllow(false)
|
|
seedView(t, fs, "v")
|
|
bucketARN := mustBucketARN(t)
|
|
|
|
call := func(operation string, input interface{}) int {
|
|
body, err := json.Marshal(input)
|
|
require.NoError(t, err)
|
|
identity := &testIdentity{Name: "other", Account: &testIdentityAccount{Id: "other"},
|
|
Actions: []string{"s3tables:PutTablePolicy"}}
|
|
req, err := newManagerRequest(s3_constants.SetIdentityInContext(assignedCtx(), identity), operation, body, "other")
|
|
require.NoError(t, err)
|
|
rec := httptest.NewRecorder()
|
|
m.handler.HandleRequest(rec, req, NewManagerClient(fs.Client))
|
|
return rec.Code
|
|
}
|
|
|
|
assert.Equal(t, http.StatusNotFound, call("PutTablePolicy", &PutTablePolicyRequest{
|
|
TableBucketARN: bucketARN,
|
|
Namespace: []string{"ns"},
|
|
Name: "v",
|
|
ResourcePolicy: `{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":"*","Action":"s3tables:*","Resource":"*"}]}`,
|
|
}))
|
|
assert.NotEqual(t, http.StatusOK, call("GetView", &GetViewRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "v"}))
|
|
assert.NotEqual(t, http.StatusOK, call("DeleteView", &DeleteViewRequest{TableBucketARN: bucketARN, Namespace: []string{"ns"}, Name: "v"}))
|
|
assert.NotNil(t, fs.Get(GetNamespacePath(renameTestBucket, "ns"), "v"), "the view must still be stored")
|
|
}
|